Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-classifier

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-classifier

Machine Learning Image Classifier for NodeJS

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
decreased by-30.43%
Maintainers
1
Weekly downloads
 
Created
Source

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

Example:
const classifier = await ImageClassifier.create()

ImageClassifier.load(datasetPath: string)

Create a new instance of ImageClassifier from a dataset

ParameterDescriptionTypeMemory
datasetPathPath to load the datasetStringTrue
Example:
const classifier = await ImageClassifier.load('./dataset.json');

ImageClassifier

ImageClassifier.prototype.save(datasetDestination: string)

Save the ImageClassifier's dataset to a json file

ParameterDescriptionTypeMemory
datasetPathPath to save the datasetStringTrue

Example:
await classifier.save('./carset.json');

ImageClassifier.prototype.addExample(label: string, image: string | Buffer)

Add an example image and label it to train the ImageClassifier

ParameterDescriptionTypeMemory
labelCategory label for what the image isStringTrue
imagePath to image or raw image data to add as an example for the labelStringTrue

Example:
// 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

ParameterDescriptionTypeMemory
label Label for classifier you would like to remove from ImageClassifier. Drops all examples of specified label. StringTrue

Example:
classifier.dropClassifier('Honda');

ImageClassifier.prototype.predict(image: string | Buffer)

Predict the label for an image

ParameterDescriptionTypeMemory
imagePath to image or raw image data for evaluating a prediction with your ImageClassifierStringTrue

Example:
// 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');
Prediction:
{
    "classIndex": "<Index of Label>",
    "label": "<Label>",
    "confidences": {
        "Toyota": "<Percentile>",
        "Honda": "<Percentile>"
    }
}

Keywords

FAQs

Package last updated on 21 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc