https://github.com/kevinanielsen/tfjs-image-node
A simple image classifier using tfjs, that can run in Node.js
https://github.com/kevinanielsen/tfjs-image-node
ai learning machine ml node tensorflow tensorflowjs tf tfjs tfjs-node typescript
Last synced: about 2 months ago
JSON representation
A simple image classifier using tfjs, that can run in Node.js
- Host: GitHub
- URL: https://github.com/kevinanielsen/tfjs-image-node
- Owner: kevinanielsen
- License: mit
- Created: 2023-10-20T12:43:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-14T10:12:54.000Z (6 months ago)
- Last Synced: 2025-03-28T05:45:26.961Z (2 months ago)
- Topics: ai, learning, machine, ml, node, tensorflow, tensorflowjs, tf, tfjs, tfjs-node, typescript
- Language: TypeScript
- Homepage: https://kevinanielsen.github.io/tfjs-image-node/
- Size: 2.02 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# tfjs-image-node
[](https://snyk.io/test/github/kevinanielsen/tfjs-image-node?targetFile=package.json)
[](https://badge.fury.io/js/tfjs-image-node)
[](https://github.com/kevinanielsen/tfjs-image-node/actions/workflows/main.yml)A simple image classifier using tfjs, that can run in Node.js
### Install
```bash
npm i tfjs-image-node
# or
pnpm add tfjs-image-node
```### Import
tfjs-image-node has two different exports. One for the tfjs-node platform and one for the regular tfjs package - one package is preferred for operations in the node runtime, the other is preferred for regular javascript.
```typescript
const classifyImage = require("tfjs-image-node");
// or
import classifyImage from "tfjs-image-node";
```## Example
```typescript
import classifyImage from "tfjs-image-node/node";const model = "https://teachablemachine.withgoogle.com/models/jAIOHvmge";
const image = "https://www.stgeorges.nhs.uk/wp-content/uploads/2014/03/hand-2.jpeg";// With tfjs-node as the platform
(async () => {
const prediction = await classifyImage(model, image);
console.log(prediction[0]);
})();// With classic tfjs as the platform
(async () => {
const prediction = await classifyImage(model, image, "classic");
console.log(prediction[0]);
})();// expected output:
// { label: 'Hand', probability: 0.9999574422836304 }
```## Parameters
Name
Type
Description
MODEL_URL
string
The URL to your AI model (currently only supports teachable machine URLs like "https://teachablemachine.withgoogle.com/models/{model_id}".
IMAGE_FILE_PATH
string
The file path or URL to the image you want classified.
PLATFORM
"node" or "classic" (optional)
Choose the platform to use for the computation of the prediction. If you want to use the tfjs-node platform, use "node" as the parameter, otherwise use "classic".
METADATA
metadata.json (optional)
If you want to specify a set of metadata for the model.