tfjs-image-node
v2.2.0
Published
A simple image classifier using tfjs and running in node.js
Downloads
32
Maintainers
Readme
tfjs-image-node
A simple image classifier using tfjs, that can run in Node.js
Install
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.
const classifyImage = require("tfjs-image-node");
// or
import classifyImage from "tfjs-image-node";
Example
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 }