tensorflow/tfjs-examples
Examples built with TensorFlow.js
What this project is
TensorFlow.js Examples is a collection of ready-to-run example programs that show how to use TensorFlow.js, a JavaScript library for machine learning. Each example lives in its own folder and is fully self-contained, so you can copy a folder into your own project and use it as a starting point.
What's inside
The repository contains dozens of examples covering a wide range of machine-learning tasks. Here's a quick breakdown of what you'll find:
- Input types: Some examples work with numbers, others with text, images, or sequences of data.
- Task types: Examples include classification (e.g., identifying handwritten digits or iris flowers), regression (predicting a number, like housing prices), sequence-to-sequence tasks (like translation or date conversion), reinforcement learning (training an agent to play a game), object detection, generative models (creating new images), and more.
- Where they run: Some examples run entirely in the browser, some run in Node.js (server-side JavaScript), and some train in one place and run in the other.
- Model types: The examples use different neural-network architectures — multilayer perceptrons, convolutional neural networks (CNNs), recurrent networks (RNNs, LSTMs, GRUs), attention mechanisms, variational autoencoders, and others.
- API style: Most use the high-level "Layers" API, but a few use the lower-level "Core (Ops)" API.
- Model persistence: Several examples demonstrate saving trained models to disk or browser storage and loading them later.
Some examples also show how to integrate TensorFlow.js into specific environments, like Chrome extensions, Electron desktop apps, or Angular apps.
How to use it
To run any example:
- Install dependencies: You'll need Node.js version 8.9 or higher, plus either the NPM command-line tool or Yarn.
- Go into the example folder: For example,
cd mnist-core. - Install packages: Run
yarn(ornpm install). - Start developing: Run
yarn watch(ornpm run watch) to start a local server that auto-reloads when you edit the code. - Build for deployment: Run
yarn build(ornpm run build) to create adist/folder with the deployable files.
Contributing
The maintainers want to keep this collection small and curated, so before submitting a new example, you should reach out on the TensorFlow.js GitHub issues page. If you do submit a pull request, run the presubmit tests first from the root directory:
yarn
yarn presubmit
This runs unit tests and lint checks for all examples that have them. You can also test individual examples by going into their folder and running yarn test and/or yarn lint.
Related
- Project
- Project
- Project
- Project