How to use the @tensorflow/tfjs-node.io 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 adblockradio / adblockradio / predictor-ml / ml-worker.js View on Github external
(async function() {
	const handler = tf.io.fileSystem(process.env.modelFile); // see https://stackoverflow.com/a/53766926/5317732
	model = await tf.loadLayersModel(handler);

	// load model from remote file
	//const path = 'https://www.adblockradio.com/models/' + canonical + '/model.json';
	//model = await tf.loadModel(path);
	log.info(process.env.canonical + ': ML model loaded');
	send({ type: 'loading', err: null, loaded: true });
})();
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function saveModelAndRandomInputsAndOutputs(
    model, exportPathprefix, inputIntegerMax) {
  await model.save(tfjsNode.io.fileSystem(`${exportPathprefix}`));

  const xs = [];
  const xsData = [];
  const xsShapes = [];
  for (const inputTensor of model.inputs) {
    const inputShape = inputTensor.shape;
    inputShape[0] = 1;
    if (inputShape.indexOf(null) !== -1) {
      throw new Error(
          `It is assumed that the only the first dimension of the tensor ` +
          `is undetermined, but the assumption is not satisfied for ` +
          `input shape ${JSON.stringify(inputTensor.shape)}`);
    }
    const xTensor = inputIntegerMax == null ?
        tfc.randomNormal(inputShape) :
        tfc.floor(tfc.randomUniform(inputShape, 0, inputIntegerMax));
github tensorflow / tfjs / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function saveModelAndRandomInputsAndOutputs(
    model, exportPathprefix, inputIntegerMax) {
  await model.save(tfjsNode.io.fileSystem(`${exportPathprefix}`));

  const xs = [];
  const xsData = [];
  const xsShapes = [];
  for (const inputTensor of model.inputs) {
    const inputShape = inputTensor.shape;
    inputShape[0] = 1;
    if (inputShape.indexOf(null) !== -1) {
      throw new Error(
          `It is assumed that the only the first dimension of the tensor ` +
          `is undetermined, but the assumption is not satisfied for ` +
          `input shape ${JSON.stringify(inputTensor.shape)}`);
    }
    const xTensor = inputIntegerMax == null ?
        tfc.randomNormal(inputShape) :
        tfc.floor(tfc.randomUniform(inputShape, 0, inputIntegerMax));
github anandanand84 / technicalindicators / src / patterndetection / patterndetection.ts View on Github external
loadingPromise = new Promise(async function(resolve, reject) {
        if(isNodeEnvironment) {
            tf = require('@tensorflow/tfjs')
            console.log('Nodejs Environment detected ');
            var tfnode = require('@tensorflow/tfjs-node');
            var modelPath = require('path').resolve(__dirname, '../tf_model/model.json');
            model = await tf.loadModel(tfnode.io.fileSystem(modelPath));
        } else {
            if(typeof (window as any).tf == "undefined") {
                modelLoaded = false;
                laodingModel = false;
                console.log('Tensorflow js not imported, pattern detection may not work');
                resolve();
                return;
            }
            tf = (window as any).tf;
            console.log('Browser Environment detected ', tf);
            console.log('Loading model ....')
            model = await tf.loadModel('/tf_model/model.json');
            modelLoaded = true;
            laodingModel = false;
            setTimeout(resolve, 1000);
            console.log('Loaded model');
github anandanand84 / technicalindicators / lib / patterndetection / patterndetection.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
                if (isNodeEnvironment) {
                    tf = require('@tensorflow/tfjs');
                    console.log('Nodejs Environment detected ');
                    var tfnode = require('@tensorflow/tfjs-node');
                    var modelPath = require('path').resolve(__dirname, '../tf_model/model.json');
                    model = yield tf.loadModel(tfnode.io.fileSystem(modelPath));
                }
                else {
                    if (typeof window.tf == "undefined") {
                        modelLoaded = false;
                        laodingModel = false;
                        console.log('Tensorflow js not imported, pattern detection may not work');
                        resolve();
                        return;
                    }
                    tf = window.tf;
                    console.log('Browser Environment detected ', tf);
                    console.log('Loading model ....');
                    model = yield tf.loadModel('/tf_model/model.json');
                    modelLoaded = true;
                    laodingModel = false;
                    setTimeout(resolve, 1000);