MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / imageVectorToText

Function imageVectorToText

mnist-transfer-cnn/util.js:28–44  ·  view source on GitHub ↗
(imageVector, imageSize)

Source from the content-addressed store, hash-verified

26// Returns:
27// A String representing the image.
28export 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].

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected