0.0.1-alpha.24 • Published 11 days ago

@tensorflow/tfjs-tfdf v0.0.1-alpha.24

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 days ago

Tensorflow Decision Forests support for Tensorflow.js

This package enables users to run arbitrary Tensorflow Decision Forests models on the web that are converted using tfjs-converter. Users can load a TFDF model from a URL, use TFJS tensors to set the model's input data, run inference, and get the output back in TFJS tensors. Under the hood, the TFDF C++ runtime is packaged in a set of WASM modules.

Usage

Import the packages

To use this package, you will need a TFJS backend installed. You will also need to import @tensorflow/tfjs-core for manipulating tensors, and @tensorflow/tfjs-converter for loading models.

Via NPM

// Import @tensorflow/tfjs-core
import * as tf from '@tensorflow/tfjs-core';
// Adds the CPU backend.
import '@tensorflow/tfjs-backend-cpu';
// Import @tensorflow/tfjs-converter
import * as tf from '@tensorflow/tfjs-converter';
// Import @tensorflow/tfjs-tfdf.
import * as tfdf from '@tensorflow/tfjs-tfdf';

Via a script tag

<!-- Import @tensorflow/tfjs-core -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
<!-- Adds the CPU backend -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-cpu"></script>
<!-- Import @tensorflow/tfjs-converter -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter"></script>
<!--
  Import @tensorflow/tfjs-tfdf

  Note that we need to explicitly load dist/tf-tfdf.min.js so that it can
  locate WASM module files from their default location (dist/).
-->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-tfdf/dist/tf-tfdf.min.js"></script>

Set WASM modules location (optional)

By default, it will try to load the WASM modules from the same location where the package or your own script is served. Use setLocateFile to set your own location. See src/tfdf_web_api_client.d.ts for more details.

// `base` is the URL to the main javascript file's directory.
// To return the default URL of the file use `${base}${path}`.
tfdf.setLocateFile((path, base) => {
  return `https://your-server/.../${path}`;
});

Load a TFDF model

const tfdfModel = await tfdf.loadTFDFModel('url/to/your/model.json');

Run inference

// Prepare input tensors.
const input = tf.tensor1d(['test', 'strings']);

// Run inference and get output tensors.
const outputTensor = await tfdfModel.executeAsync(input);
console.log(outputTensor.dataSync());

Development

Building

$ yarn
$ yarn build

Testing

$ yarn test

Deployment

$ yarn build-npm
0.0.1-alpha.24

11 days ago

0.0.1-alpha.23

17 days ago

0.0.1-alpha.22

24 days ago

0.0.1-alpha.21

30 days ago

0.0.1-alpha.20

3 months ago

0.0.1-alpha.19

4 months ago

0.0.1-alpha.18

4 months ago

0.0.1-alpha.17

4 months ago

0.0.1-alpha.16

5 months ago

0.0.1-alpha.15

5 months ago

0.0.1-alpha.14

5 months ago

0.0.1-alpha.12

7 months ago

0.0.1-alpha.11

8 months ago

0.0.1-alpha.13

7 months ago

0.0.1-alpha.10

9 months ago

0.0.1-alpha.9

10 months ago

0.0.1-alpha.8

11 months ago

0.0.1-alpha.7

11 months ago

0.0.1-alpha.6

12 months ago

0.0.1-alpha.5

1 year ago

0.0.1-alpha.4

1 year ago

0.0.1-alpha.3

1 year ago

0.0.1-alpha.2

1 year ago

0.0.1-alpha.1

1 year ago