I'm asking for help from the community because I'm stuck with my code. For a project I need to create an image classification program on P5.js using MobileNet and TensorFlow.
I wanted to know how to create a button that randomly displays an image (among the 3 I downloaded) with the MobileNet classification below the image and the information I gave (like "Danger")?
Here is what i've already done. Thank you :)
var model_mobilenet;
var loaded;
function setup() {
createCanvas(400, 300);
mobilenet.load().then(modelLoaded);
military = loadImage('military');
rifle = loadImage('rifle');
revolver = loadImage('revolver');
createButton("Take a picture").mousePressed(btnClicked);
}
function classifyDone(res) {
print(res);
if (res[0].className == "rifle")
{
print("Danger");
createP("Danger");
}
else if (res[0].className == "revolver, six-gun, six-shooter")
{
print("Danger");
createP("Danger");
}
else if (res[0].className == "military uniform")
{
print("Not sure about this one");
createP("Not sure about this one");
}
else {
print("Evrything is okay");
createP("Everything is okay");
}
}
function modelLoaded(net) {
model_mobilenet = net;
loaded = true;
print("Model loaded");
}
function btnClicked() {
image(military, 0, 0, 400, 300);
if (loaded == true)
{
model_mobilenet.classify(military.elt).then(classifyDone);
}
}