How to use the @tensorflow/tfjs-data.webcam function in @tensorflow/tfjs-data

To help you get started, we’ve selected a few @tensorflow/tfjs-data 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 tensorflow / tfjs-examples / webcam-transfer-learning / index.ts View on Github external
async function init() {
  try {
    // await webcam.setup();
    webcamDataset = tfd.webcam(
        document.getElementById('webcam') as HTMLVideoElement,
        {frameRate: 10, width: 224, height: 224});
    await webcamDataset.init();
  } catch (e) {
    document.getElementById('no-webcam').style.display = 'block';
  }
  truncatedMobileNet = await loadTruncatedMobileNet();

  // Warm up the model. This uploads weights to the GPU and compiles the WebGL
  // programs so the first time we collect data from the webcam it will be
  // quick.
  const screenShot = await webcamDataset.capture();
  truncatedMobileNet.predict(screenShot.expandDims(0));
  screenShot.dispose();

  ui.init();

@tensorflow/tfjs-data

TensorFlow Data API in JavaScript

Apache-2.0
Latest version published 27 days ago

Package Health Score

95 / 100
Full package analysis