Michael McCullough
Semester 2, 2024
Major Project is due at 28 October 2024.
Still looking forward to seeing your discussions on the forum!
What is machine learning?
How can I use ML in p5?
How can we make art with this?
Creating computer programs without explicitly programming them.
Algorithms that learn by example.
Algorithms that learn through experience.
Kind of a big deal ($$$)
Kind of problematic (!!!)
Suppose the boss wants a program where the screen colour changes to red when the mouse moves to certain locations.
mouseX | red background |
---|---|
15 | no |
75 | no |
173 | no |
250 | yes |
312 | yes |
375 | yes |
(N.B.: the screen is 400 pixels wide)
Let’s write a configurable algorithm!
if (mouseX > ??) {
background(255,0,0);
} else {
background(0,0,0);
}
one decision (red or black background)
one input (mouseX
)
Maybe we could make more complicated decisions?
Likely to get more complicated to configure the algorithm.
Pictures are 2D arrays of colours! (represented as numbers)
So we had enough if
s and else
s then maybe we could make a doggo classifier!
Ashleigh Robertson
Doggo (Unsplash link)
One trick we often use is to design a configurable algorithm which can:
The “configuration” would be “choosing how much of each input to listen to”
One example is a “perceptron” (1958)
Trick 1: feed the outputs of perceptrons into more perceptrons in a kind of network
Trick 2: tricky algorithms to choose the configuration
Trick 3: big fast computers with lots of data to learn from
By the way, another name for a perceptron is an artificial neuron. So the above is a… neural network…
Model: an instance of a trainable algorithm
Pre-Trained Model: a trainable algorithm which has… already been trained.
Training/Optimising: using training data to make a trained model.
Prediction/Inference: using a trained model to generate an output using unseen data
Classification: an ML task for choosing a “class” (or description) for a piece of data
Want to make the learning process work faster? Great idea to have a maths/CS major.
Want to make interesting art with the most relevant new technology of today? Ok, you’re ready to go!
ml5.js is a JavaScript library that provides access to machine learning models in a web browser.
You can load up pre-trained models and start doing prediction right away!
Related to and inspired by p5.js
.
Just need to load it in our index.html
:
<script src="https://unpkg.com/ml5@0.5.0/dist/ml5.min.js" type="text/javascript"></script>
Open up a p5 web editor sketch with ml5 already loaded.
Let’s classify some doggos. We’ll use a pretrained model called MobileNet
// load the classifier
classifier = ml5.imageClassifier('MobileNet');
// classify an image
classifier.classify(img, gotResult)
Where does the result go? Need to define a callback function gotResult(error, results)
.
We can access a webcam in our sketch:
video = createCapture(VIDEO);
video.size(320, 240);
video.hide();
And we can just ask the classifier to only make predictions from this video stream:
classifier = ml5.imageClassifier('MobileNet', video);
classifier.classify(gotResult); // classify one frame
Photo by Alina Grubnyak on Unsplash
Let’s make our own custom image classifier with Teachable Machine
Sketch RNN is a model that generates a drawing by moving an imaginary pen around the screen.
Each “prediction” is a pen movement in x
and y
coordinates.
(This is a really fun model to try out).
model = ml5.sketchRNN('cat'); // load the model with a "class" to draw.
The prediction is an object with x
, y
, and pen
states (the pen can move up and down to make spaces in the drawing.
Here’s an example
There are lots of models available! (check the reference)
Many (e.g., posenet) are related to image classification and processing (images are so hot right now).
There are also sound recognition models.
And text generation models.
Thanks for coming on this journey with me!
For more creative coding, see Sound and Music Computing
If you’re a CS student, think about a project with Charles Martin