How to use the @tensorflow/tfjs-node.tensor4d function in @tensorflow/tfjs-node

To help you get started, we’ve selected a few @tensorflow/tfjs-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github piercus / image-augment / test / examples / simple-example.js View on Github external
.on('parsed', () => {
				const images = tf.tensor4d(inputPng.data, [1, inputPng.height, inputPng.width, 4]);
				resolve({images});
			})
			.on('error', reject);
github adwellj / node-tfjs-retrain / data.js View on Github external
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)
        };
    }
}
github adwellj / node-tfjs-retrain / data.js View on Github external
return tf.tidy(() =>
        tf
            .tensor4d(pixelData, outShape, "int32")
            .toFloat()
            .resizeBilinear([224, 224])
            .div(tf.scalar(127))
            .sub(tf.scalar(1))
    );
github ralscha / blog2019 / mnistjs / train / tfjs.js View on Github external
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];
github ralscha / blog2019 / mnistjs / train / tfjs.js View on Github external
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);
    }