When I added Image to my classifier for training then it throws some exceptions. We are using the Mobilenet model of ml5.js in which when we call train() method.
let features = ml5.featureExtractor('MobileNet');
const classifier = features.classification();
console.log("setup classifier DONE", classifier);
var img2;
console.log("adding images");
const gorra = new Image();
gorra.src = ".jpg";
gorra.width = 224;
gorra.height = 224;
console.log("adding images DONE", gorra);
img2 = new Image();
img2.src = "{!$Resource.cat}"
img2.width = 224;
img2.height = 224;
console.log(img2);
var img3;
img3 = new Image();
img3.src = "{!$Resource.car}"
img3.width = 224;
img3.height = 224;
console.log(img3);
console.log("setup classifier");
var img4;
img4 = new Image();
img4.src = "{!$Resource.car1}"
img4.width = 224;
img4.height = 224;
console.log(img4);
console.log("setup classifier");
console.log("adding example image...");
const ex = classifier.addImage(document.getElementById('imgshow'), "Gorra");
console.log("adding ex image DONE!...", ex);
const ex1 = classifier.addImage(img2, "Gorra");
console.log("adding ex1 image DONE!...", ex1);
const ex2 = classifier.addImage(img3, "car");
console.log("adding ex1 image DONE!...", ex2);
const ex3 = classifier.addImage(img4, "car");
console.log("adding ex1 image DONE!...", ex3);
console.log('claasifier'+classifier);
console.log("Training");
// const trainer ;
setTimeout(function(){ const trainer = classifier.train(); console.log("Training DONE", trainer);}, 30000);
after adding image whenever train() run it throws this error enter image description here which is taking reference of Mobilnet.js library, I have highlighted the line where it causes that error enter image description here
please let me know, how can we resolve this.
When I added Image to my classifier for training then it throws some exceptions. We are using the Mobilenet model of ml5.js in which when we call train() method.
let features = ml5.featureExtractor('MobileNet');
const classifier = features.classification();
console.log("setup classifier DONE", classifier);
var img2;
console.log("adding images");
const gorra = new Image();
gorra.src = "https://ml5js/docs/assets/img/bird.jpg";
gorra.width = 224;
gorra.height = 224;
console.log("adding images DONE", gorra);
img2 = new Image();
img2.src = "{!$Resource.cat}"
img2.width = 224;
img2.height = 224;
console.log(img2);
var img3;
img3 = new Image();
img3.src = "{!$Resource.car}"
img3.width = 224;
img3.height = 224;
console.log(img3);
console.log("setup classifier");
var img4;
img4 = new Image();
img4.src = "{!$Resource.car1}"
img4.width = 224;
img4.height = 224;
console.log(img4);
console.log("setup classifier");
console.log("adding example image...");
const ex = classifier.addImage(document.getElementById('imgshow'), "Gorra");
console.log("adding ex image DONE!...", ex);
const ex1 = classifier.addImage(img2, "Gorra");
console.log("adding ex1 image DONE!...", ex1);
const ex2 = classifier.addImage(img3, "car");
console.log("adding ex1 image DONE!...", ex2);
const ex3 = classifier.addImage(img4, "car");
console.log("adding ex1 image DONE!...", ex3);
console.log('claasifier'+classifier);
console.log("Training");
// const trainer ;
setTimeout(function(){ const trainer = classifier.train(); console.log("Training DONE", trainer);}, 30000);
after adding image whenever train() run it throws this error enter image description here which is taking reference of Mobilnet.js library, I have highlighted the line where it causes that error enter image description here
please let me know, how can we resolve this.
Share Improve this question edited Jan 22, 2019 at 11:44 ANKIT SHARMA asked Jan 22, 2019 at 11:11 ANKIT SHARMAANKIT SHARMA 931 gold badge2 silver badges10 bronze badges 9- Hi. Can you please edit your post in order to add the errors that is been throw to the console when you run your code? – Ricardo Rocha Commented Jan 22, 2019 at 11:18
-
img2.src = "{!$Resource.cat}"
What does this line of code suppose to do? Are you trying to add a URL toimg2.src
? – Vivek Commented Jan 22, 2019 at 11:23 - @Vivek img2.src taking src or path of that image which I'm taking from the static resource. – ANKIT SHARMA Commented Jan 22, 2019 at 11:46
- this type of problem is mostly happening when you not put your jquery file path in a proper order. – karan Commented Jan 22, 2019 at 11:53
- @ANKITSHARMA``` taking from the static resource``` -> Can you post that part of the code? – Vivek Commented Jan 22, 2019 at 11:59
1 Answer
Reset to default 1You need to provide a callback for the .train()
function.
From the documentation for ml5js, the callback for .train()
function is not optional.
You can replace your train statement
const trainer = classifier.train();
with the below code.
const trainer = classifier.train(function(lossValue) {
console.log('Loss is', lossValue)
});
This should solve the issue.