(imageVector, imageSize)
| 26 | // Returns: |
| 27 | // A String representing the image. |
| 28 | export function imageVectorToText(imageVector, imageSize) { |
| 29 | if (imageVector.length !== imageSize * imageSize) { |
| 30 | throw new Error( |
| 31 | 'Incorrect length of image vector (expected ' + imageSize * imageSize + |
| 32 | '; got ' + imageVector.length + ')'); |
| 33 | } |
| 34 | let text = ''; |
| 35 | for (let i = 0; i < imageSize * imageSize; ++i) { |
| 36 | if (i % imageSize === 0 && i > 0) { |
| 37 | text += '\n'; |
| 38 | } |
| 39 | const numString = imageVector[i].toString(); |
| 40 | text += |
| 41 | ' '.repeat(numString.length < 4 ? 4 - numString.length : 0) + numString; |
| 42 | } |
| 43 | return text; |
| 44 | } |
| 45 | |
| 46 | // Convert a text representation of an MNIST image into an deeplearn Tensor4D |
| 47 | // of shape [1, imageSize, imageSize, 1]. |
nothing calls this directly
no outgoing calls
no test coverage detected