How to use the @tensorflow/tfjs.loadModel function in @tensorflow/tfjs

To help you get started, we’ve selected a few @tensorflow/tfjs 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 grimmer0125 / alphago-zero-tictactoe-js / src / tictactoe / tensorflow / NNet.js View on Github external
async loadPretrained(url) {
    console.log('load model start');

    // 'https://foo.bar/tfjs_artifacts/model.json'
    this.preTrainedModel = await tf.loadModel(url);
    console.log('load model ok');
  }
github aike / n4m_tensorflow_example / electron / src / App.jsx View on Github external
componentDidMount() {
	    // init SignaturePad
	    this.drawElement = document.getElementById('draw-area');
	    this.signaturePad = new SignaturePad(this.drawElement, {
	       minWidth: 6,
	       maxWidth: 6,
	       penColor: 'white',
	       backgroundColor: 'black',
	    });

	    // load pre-trained model
	    tf.loadModel('./model/model.json')
	      .then(pretrainedModel => {
	        document.getElementById('predict-button').classList.remove('is-loading');
	        this.model = pretrainedModel;
	      });
	}
github tensorflow / tfjs / demos / pacman / pacman.ts View on Github external
async function loadMobilenet(): Promise {
  // TODO(nsthorat): Move these to GCP when they are no longer JSON.
  const model = await tf.loadModel(
      // tslint:disable-next-line:max-line-length
      'https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_0.25_224/model.json');

  // Return a model that outputs an internal activation.
  const layer = model.getLayer('conv_pw_13_relu');
  return tf.model({inputs: model.inputs, outputs: layer.output});
}
github radi-cho / tfjs-firebase / functions / src / bow_model / test_model.js View on Github external
const data = snap.data()
    if (data.label) return;

    const tempJSONPath = path.join(os.tmpdir(), "model.json");
    const tempBINPath = path.join(os.tmpdir(), "weights.bin");

    const existJSON = await bucket.file("model.json").exists().then(ex => ex[0]);
    const existBIN = await bucket.file("weights.bin").exists().then(ex => ex[0]);

    if (!existJSON || !existBIN) throw Error("Missing artifacts.")

    await bucket.file("model.json").download({ destination: tempJSONPath });
    await bucket.file("weights.bin").download({ destination: tempBINPath });

    const modelPath = "file://" + tempJSONPath;
    const model = await tf.loadModel(modelPath);

    const test_x = [fitData(data.text)];
    const score = model.predict(tf.tensor2d(test_x)).dataSync()[0];

    data.label = score < 0.5 ? "negative" : "positive";
    db.collection("comments").doc(snap.id).set(data)

    fs.unlinkSync(tempJSONPath);
    fs.unlinkSync(tempBINPath);
  });
github microsoft / onnxjs / benchmark / src / index.js View on Github external
async init(backend, modelPath, imageSize) {
        this.imageSize = imageSize;
        tf.disposeVariables();
        if(backend) {
            console.log(`Setting the backend to ${backend}`);
            tf.setBackend(backend);
        }
        this.model = await tf.loadModel(modelPath);
        console.log('Model loaded');
    }
    async runModel(data) {
github mimic-sussex / sema / src / machineLearning / tfjs / lstm-txt-gen.js View on Github external
async loadModel(lstmLayerSizes) {
    const modelsInfo = await tf.io.listModels();
    if (this.modelSavePath_ in modelsInfo) {
      console.log(`Loading existing model...`);
      this.model = await tf.loadModel(this.modelSavePath_);
      console.log(`Loaded model from ${this.modelSavePath_}`);
    } else {
      throw new Error(
          `Cannot find model at ${this.modelSavePath_}. ` +
          `Creating model from scratch.`);
    }
  }
github tensorflow / tfjs-examples / lstm-text-generation / index.js View on Github external
async loadModel(lstmLayerSizes) {
    const modelsInfo = await tf.io.listModels();
    if (this.modelSavePath_ in modelsInfo) {
      console.log(`Loading existing model...`);
      this.model = await tf.loadModel(this.modelSavePath_);
      console.log(`Loaded model from ${this.modelSavePath_}`);
    } else {
      throw new Error(
          `Cannot find model at ${this.modelSavePath_}. ` +
          `Creating model from scratch.`);
    }
  }
github lukasy09 / What_Is_That / src / content / mnistView / MnistView.js View on Github external
async loadModel(){
        this.model = await tfjs.loadModel("https://raw.githubusercontent.com/lukasy09/IchLerneCNN.py/master/MNIST/model/model.json");
    };
github lukasy09 / What_Is_That / src / content / Content.js View on Github external
async loadModel() {

         this.model = await tf.loadModel("https://raw.githubusercontent.com/lukasy09/KernelBase.py/master/Objects/src/models/model_40.json/model.json");
    };
github AngularFirebase / 97-tensorflowjs-quick-start / src / app / app.component.ts View on Github external
async loadModel() {
    this.model = await tf.loadModel('/assets/model.json');
  }