A simple image classifier using tfjs, that can run in Node.js
npm i tfjs-image-node
# or
pnpm add tfjs-image-node
const classifyImage = require("tfjs-image-node");
// or
import { classifyImage } from "tfjs-image-node";
const classifyImage = require("tfjs-image-node");
const model = "https://teachablemachine.withgoogle.com/models/jAIOHvmge";
const image =
"https://www.stgeorges.nhs.uk/wp-content/uploads/2014/03/hand-2.jpeg";
(async () => {
const prediction = await classifyImage(model, image);
console.log(prediction[0]);
})();
// expected output:
// { label: 'Hand', probability: 0.9999574422836304 }
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}" with no "/" at the end! |
IMAGE_FILE_PATH | string | The file path or URL to the image you want classified. |
PLATFORM | "node" | "regular" | Choose whether to use tfjs-node or regular tfjs as the ML Platform (Defaults to node). |