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.
Download the library from here and import:
<script src="p5ML.min.js"></script>
To use with ES6
npm install p5ML --save
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.
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
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
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)
See CONTRIBUTING