0.0.3 • Published 1 year ago

@kozmonos/image-classifier-web v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Web Image Classification

Tensorflow

if you have a NodeJS project you can use @kozmonos/image-classifier package.

This package allows you to interact with 3 simple functions (init, train, predict) using Tensorflow JS's @tensorflow-models/knn-classifier package.

<img id="class0" src="/images/class0.jpg " />
<img id="class1" src="/images/class1.jpg " />
<img id="test" src="/images/test.jpg " />
const imageClassifier = require("@kozmonos/image-classifier-web");

// Initialize the classifier
const classifier = await imageClassifier.init();

// Train the classifier
const image = document.getElementById("class0");
const label = "label";
classifier.train(image, label);

const image2 = document.getElementById("class1");
const label2 = "label2";
classifier.train(image2, label2);

// Predict the class of an image
const image3 = document.getElementById("test");
const result = await classifier.predict(image);
/*
 out: {  classIndex: 0, label: 'label2',  confidences: { label2: 0.6666666666666666, label: 0.3333333333333333 } }
*/