Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.on('parsed', () => {
const images = tf.tensor4d(inputPng.data, [1, inputPng.height, inputPng.width, 4]);
resolve({images});
})
.on('error', reject);
embeddings.set(prediction.dataSync(), embeddingsOffset);
labels.set([labelIndex], labelsOffset);
});
t.dispose();
embeddingsOffset += embeddingsFlatSize;
labelsOffset += 1;
}
console.timeLog("Loading Training Data", {
label: element.label,
count: element.images.length
});
}
this.dataset = {
images: tf.tensor4d(embeddings, embeddingsShape),
labels: tf.oneHot(tf.tensor1d(labels, "int32"), numClasses)
};
}
}
return tf.tidy(() =>
tf
.tensor4d(pixelData, outShape, "int32")
.toFloat()
.resizeBilinear([224, 224])
.div(tf.scalar(127))
.sub(tf.scalar(1))
);
async function run() {
const trainLabels = await mnist.getTrainLabels();
const trainDigits = await mnist.getTrainImages();
const testLabels = await mnist.getTestLabels();
const testDigits = await mnist.getTestImages();
const trainDigitsTensor = tf.tensor4d(trainDigits.map(mnist.normalize),
[trainDigits.length / (28 * 28), 28, 28, 1]);
const testDigitsTensor = tf.tensor4d(testDigits.map(mnist.normalize),
[testDigits.length / (28 * 28), 28, 28, 1]);
const outputs = [];
for (let ix = 0; ix < trainLabels.length; ix++) {
const output = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
output[trainLabels[ix]] = 1;
outputs.push(output);
}
const trainLabelsTensor = tf.tensor2d(outputs);
const testOutputs = [];
for (let ix = 0; ix < testLabels.length; ix++) {
const output = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
async function run() {
const trainLabels = await mnist.getTrainLabels();
const trainDigits = await mnist.getTrainImages();
const testLabels = await mnist.getTestLabels();
const testDigits = await mnist.getTestImages();
const trainDigitsTensor = tf.tensor4d(trainDigits.map(mnist.normalize),
[trainDigits.length / (28 * 28), 28, 28, 1]);
const testDigitsTensor = tf.tensor4d(testDigits.map(mnist.normalize),
[testDigits.length / (28 * 28), 28, 28, 1]);
const outputs = [];
for (let ix = 0; ix < trainLabels.length; ix++) {
const output = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
output[trainLabels[ix]] = 1;
outputs.push(output);
}
const trainLabelsTensor = tf.tensor2d(outputs);
const testOutputs = [];
for (let ix = 0; ix < testLabels.length; ix++) {
const output = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
output[testLabels[ix]] = 1;
testOutputs.push(output);
}