tfjs/tfjs-tfdf
Shivam Mishra 818d672e1b
Fixed typos in documentation string. (#7782)
* Migrate stale management probot to Github action

* Migrate stale management probot to Github action

* Fixed typos in documentation string.

* Fixed typos in documentation string.

---------

Co-authored-by: Matthew Soulanille <msoulanille@google.com>
Co-authored-by: Linchenn <40653845+Linchenn@users.noreply.github.com>
Co-authored-by: Ping Yu <4018+pyu10055@users.noreply.github.com>
2024-02-05 18:41:41 +00:00
..
src Add TFDF setLocateFile function (#7027) 2022-11-15 14:03:36 -08:00
wasm Load tflite and tfdf wasm files with http_archive (#7124) 2022-11-29 14:01:53 -08:00
.npmignore
.npmrc
BUILD.bazel Fixed typos in documentation string. (#7782) 2024-02-05 18:41:41 +00:00
README.md Fixed typos in documentation string. (#7782) 2024-02-05 18:41:41 +00:00
package.json Make tfjs-tfdf work with bundlers (#7054) 2022-11-17 12:39:46 -08:00
tfdf_repositories.bzl Update dependency to the latest version of TF-DecisionForests (#7497) 2023-03-23 04:56:42 -07:00
tsconfig.json
yarn.lock Add TFDF setLocateFile function (#7027) 2022-11-15 14:03:36 -08:00

README.md

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