ML5 FeatureExtractor addImage 不工作
ML5 FeatureExtractor addImage not working
我正在关注 ML5.js featureExtractor 的基本示例。我没有使用视频。加载模型后,我向其添加新图像,然后再次训练。我收到以下错误:
Mobilenet.js:323 Uncaught (in promise) Error: Batch size is 0 or NaN. Please choose a non-zero fraction.
at t. (Mobilenet.js:323)
我的代码似乎是正确的,according to the documentation - 使用视频是可选的,所以我希望我应该能够在手动添加图像后重新训练模型。我使用了 addImage
函数的回调,以确保在调用 train
之前确实添加了图像
let added = 0
let classifier
let featureExtractor = ml5.featureExtractor('MobileNet', modelLoaded)
function modelLoaded() {
classifier = featureExtractor.classification()
classifier.addImage(document.getElementById('person1'), 'nomask', addedImage)
classifier.addImage(document.getElementById('mask1'), 'mask', addedImage)
}
// this gets called twice, but then train goes wrong
function addedImage(){
added++
if(added == 2){
classifier.train((lossValue) => {
console.log('Loss is', lossValue);
})
}
您需要添加至少 3 张图像才能使训练生效。
下面的代码应该可以工作。
let added = 0;
let classifier;
let featureExtractor = ml5.featureExtractor('MobileNet', modelLoaded);
function modelLoaded() {
classifier = featureExtractor.classification()
classifier.addImage(document.getElementById('person1'), 'nomask', addedImage);
classifier.addImage(document.getElementById('person2'), 'nomask', addedImage);
classifier.addImage(document.getElementById('mask1'), 'mask', addedImage);
}
function addedImage(){
added++;
if(added == 3){
classifier.train((lossValue) => {
console.log('Loss is', lossValue);
});
}
一个工作示例:https://glitch.com/edit/#!/ml5-feature-extractor-addimage
我正在关注 ML5.js featureExtractor 的基本示例。我没有使用视频。加载模型后,我向其添加新图像,然后再次训练。我收到以下错误:
Mobilenet.js:323 Uncaught (in promise) Error: Batch size is 0 or NaN. Please choose a non-zero fraction. at t. (Mobilenet.js:323)
我的代码似乎是正确的,according to the documentation - 使用视频是可选的,所以我希望我应该能够在手动添加图像后重新训练模型。我使用了 addImage
函数的回调,以确保在调用 train
let added = 0
let classifier
let featureExtractor = ml5.featureExtractor('MobileNet', modelLoaded)
function modelLoaded() {
classifier = featureExtractor.classification()
classifier.addImage(document.getElementById('person1'), 'nomask', addedImage)
classifier.addImage(document.getElementById('mask1'), 'mask', addedImage)
}
// this gets called twice, but then train goes wrong
function addedImage(){
added++
if(added == 2){
classifier.train((lossValue) => {
console.log('Loss is', lossValue);
})
}
您需要添加至少 3 张图像才能使训练生效。
下面的代码应该可以工作。
let added = 0;
let classifier;
let featureExtractor = ml5.featureExtractor('MobileNet', modelLoaded);
function modelLoaded() {
classifier = featureExtractor.classification()
classifier.addImage(document.getElementById('person1'), 'nomask', addedImage);
classifier.addImage(document.getElementById('person2'), 'nomask', addedImage);
classifier.addImage(document.getElementById('mask1'), 'mask', addedImage);
}
function addedImage(){
added++;
if(added == 3){
classifier.train((lossValue) => {
console.log('Loss is', lossValue);
});
}
一个工作示例:https://glitch.com/edit/#!/ml5-feature-extractor-addimage