Skip to content

Repository for Experimentation with p5 and deeplearn.js

Notifications You must be signed in to change notification settings

cvalenzuela/ml5js-library

 
 

Repository files navigation

p5ML

This project is currently in development.

p5ML is a high level javascript library for machine learning. The main idea of this project is to further reduce the barriers between lower level machine learning and creative outputs using javascript.

p5ML provides two main functionalities:

  • A wrapper around deeplearn.js providing a simplier interface, that makes it easier to work with GPU accelerated machine learning in javascript.
  • Custom ML methods.

Usage

Download the library from here and import:

<script src="p5ML.min.js"></script>

To use with ES6

npm install p5ML --save

Examples

Demos

API Reference

LSTM

Use a pretrained LSTM model and run it in inference mode. Returns an object.

var lstm = new p5ML.LSTM(path);
lstm.generate([options], callback)
  • path: The folder where the deeplearn.js model is.
  • options: An object that specifies the seed, length and temperature of the input. Defaults to {seed: "a", length:20, temperature:0.5}
  • callback: A function to execute once the model has run.

See this simple example and this interactive example.

ImageNet

Classify an image using a given model. Returns an array of objects containing categories and probabilities.

var imagenet = new p5ml.ImageNet(model);
var prediction = imagenet.predict(img, callback);
  • model: Specify the model to use. For now only 'Squeezenet' is supported.
  • img: The DOM element of the image to classify.
  • callback: A function to execute once the model has run.

See this simple example and this webcam example

KNN Image Classifier

A KNN Image Classifier

var knn = new p5ml.KNNImageClassifier(callback);
knn.addImage(video, index);
knn.predict(video, callback);
knn.getClassExampleCount();
knn.clearClass(classIndex);

See this webcam example

Neural Network

A Simple Artificial Neural Network

var nn = new p5ml.NeuralNetwork(input_nodes, hidden_nodes, output_nodes, learning_rate);
nn.train(inputs, targets);
var result = nn.query(inputs)

Contributing

See CONTRIBUTING

About

Repository for Experimentation with p5 and deeplearn.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 77.7%
  • CSS 10.4%
  • JavaScript 6.7%
  • Python 5.2%