image-classifier
v1.1.0
Published
Machine Learning Image Classifier for NodeJS
Downloads
19
Maintainers
Readme
Image Classifier NodeJS Package
Machine Learning Image Classifier for NodeJS
Installation
npm install image-classifier
Getting Started
// CommonJS
const ImageClassifier = require('image-classifier');
// Or ES Modules
import ImageClassifier from "image-classifier/lib/ImageClassifier";
Creating an ImageClassifier
ImageClassifier.create()
Create a new instance of ImageClassifier
from scratch
const classifier = await ImageClassifier.create()
ImageClassifier.load(datasetPath: string)
Create a new instance of ImageClassifier
from a dataset
const classifier = await ImageClassifier.load('./dataset.json');
ImageClassifier
ImageClassifier.prototype.save(datasetDestination: string)
Save the ImageClassifier's dataset to a json file
await classifier.save('./carset.json');
ImageClassifier.prototype.addExample(label: string, image: string | Buffer)
Add an example image and label it to train the ImageClassifier
// Add Toyota Examples from path
await classifier.addExample('Toyota', './toyota0.png');
await classifier.addExample('Toyota', './toyota1.png');
await classifier.addExample('Toyota', './toyota2.png');
// Add Toyota Example from raw image
const toyotaRawImage = fs.readFileSync('./toyota3.png');
await classifier.addExample('Toyota', toyotaRawImage);
/* ...Add more examples */
// Add Honda Examples
await classifier.addExample('Honda', './honda0.png');
await classifier.addExample('Honda', './honda1.png');
await classifier.addExample('Honda', './honda2.png');
// Add Honda Example from raw image
const hondaRawImage = await fs.promises.readFile('./honda3.png');
await classifier.addExample('Honda', hondaRawImage);
/* ...Add more examples */
ImageClassifier.prototype.dropClassifier(label: string)
Drop all classification for the specified label
classifier.dropClassifier('Honda');
ImageClassifier.prototype.predict(image: string | Buffer)
Predict the label for an image
// Predict by image path
const prediction1 = await classifier.predict('./toyotaTest0.png');
// Predict by raw image
const toyotaTestRawImage = fs.readFileSync('./toyotaTest1.png');
const prediction2 = await classifier.predict('./toyotaTest1.png');
{
"classIndex": "<Index of Label>",
"label": "<Label>",
"confidences": {
"Toyota": "<Percentile>",
"Honda": "<Percentile>"
}
}