MCPcopy
hub / github.com/tensorflow/tfjs-examples / readImageTensorFromFile

Function readImageTensorFromFile

quantization/eval_mobilenetv2.js:52–71  ·  view source on GitHub ↗
(filePath, height, width)

Source from the content-addressed store, hash-verified

50}
51
52async function readImageTensorFromFile(filePath, height, width) {
53 return new Promise((resolve, reject) => {
54 jimp.read(filePath, (err, image) => {
55 if (err) {
56 reject(err);
57 } else {
58 const h = image.bitmap.height;
59 const w = image.bitmap.width;
60 const buffer = tf.buffer([1, h, w, 3], 'float32');
61 image.scan(0, 0, w, h, function(x, y, index) {
62 buffer.set(image.bitmap.data[index], 0, y, x, 0);
63 buffer.set(image.bitmap.data[index + 1], 0, y, x, 1);
64 buffer.set(image.bitmap.data[index + 2], 0, y, x, 2);
65 });
66 resolve(tf.tidy(() => tf.image.resizeBilinear(
67 buffer.toTensor(), [height, width]).div(255)));
68 }
69 });
70 });
71}
72
73async function main() {
74 const args = parseArgs();

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected