How to use @tensorflow/tfjs-data - 3 common examples

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 / tfjs / integration_tests / models / benchmarks.ts View on Github external
log = common.getLogFlagFromKarmaFlags();
    }
    console.log(`Boolean flag log = ${log}`);

    const taskType = 'model';
    let environmentInfo: EnvironmentInfo;
    if (isNodeJS) {
      environmentInfo = common.getNodeEnvironmentInfo(tfn);
    } else {
      environmentInfo = common.getBrowserEnvironmentInfo();
    }
    const versionSet: VersionSet = isNodeJS ? {versions: tfn.version} : {
      versions: {
        'tfjs-converter': tfconverter.version_converter,
        'tfjs-core': tfc.version_core,
        'tfjs-data': tfd.version_data,
        'tfjs-layers': tfl.version_layers
      }
    };

    let suiteLog: common.SuiteLog;
    if (isNodeJS) {
      // tslint:disable-next-line:no-require-imports
      const fs = require('fs');
      suiteLog = JSON.parse(fs.readFileSync(BENCHMARKS_JSON_PATH, 'utf-8'));
    } else {
      suiteLog =
          await (await fetch(BENCHMARKS_JSON_URL)).json() as common.SuiteLog;
    }
    const pyEnvironmentInfo = suiteLog.environmentInfo;
    const pyEnvironmentId =
        log ? await addEnvironmentInfoToFirestore(pyEnvironmentInfo) : null;
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();
github tensorflow / tfjs-data / tfjs-data / demo / boston-housing / data.ts View on Github external
private async prepareDataset(url: string) {
    // We want to predict the column "medv", which represents a median value of
    // a home (in $1000s), so we mark it as a label.
    const csvDataset = tfd.csv(url, {columnConfigs: {medv: {isLabel: true}}});

    // Reduces the object-type data to an array of numbers.
    const convertedDataset =
        csvDataset.map((row: Array<{[key: string]: number}>) => {
          const [rawFeatures, rawLabel] = row;
          const convertedFeatures = Object.values(rawFeatures);
          const convertedLabel = [rawLabel['medv']];
          return [convertedFeatures, convertedLabel];
        });
    return {
      dataset: convertedDataset.shuffle(100),
      numFeatures: (await csvDataset.columnNames()).length - 1
    };
  }
}

@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