JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 17
  • Score
    100M100P100Q39111F
  • License MIT

TensorflowJS based hooks for react.js

Package Exports

  • react-tensorflow

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-tensorflow) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

React-Tensorflow

github-watch-badge github-star-badge twitter-badge Typed with TypeScript

A library of React hooks and HOCs written in Typescript to use Tensorflow models in your application! 🤖🧠

Installation

yarn add react-tensorflow
npm i react-tensorflow -S

Peer dependencies

Basic usage

import { useModel } from 'react-tensorflow'

const MyModelComponent = () => {
  const model = useModel(`${PATH_TO_MODEL}`)

  // ...do something with the model

  return null
}

API

useModel

useModel(url?: string, opts?: { layers: boolean }): GraphModel | LayersModel | null

If url is omitted useModel will look to find the ModelProvider as it's context for returning the model. When loading a model with this hook, the opts.layers boolean is passed if your TF model should be loaded with the function tf.loadLayersModel otherwise it is assumed the model should be loaded with tf.loadGraphModel.

ModelProvider

<ModelProvider url={string} layers={boolean}>
  <App />
</ModelProvider>

Wraps the children in a React Provider to be consumed by Context's in either the useModel hook or withModel HOC. The props passed to this provider are the same as the documented props for useModel.

withModel

withModel(Component: React.ComponentType): JSX.Element

Wraps the provided component in a React Context, passing the model give to the provider as a prop.

Roadmap

So far there is only one hook to include the model in your react-app. As this library goes the plan would be to add more specific hooks to use with specific models e.g usePredicition as well as other helper hooks such as useWebcam.

  • useModel as hook and HOX
  • useWebcam
  • usePrediction
  • useClassifier
  • useObjects
  • usePoses

Suggestions should be made through the issues tab.