我正在通过 ml-5 库进行一些图像分类。我在测试时编写了所有用于从模型中获取预测的分类代码。现在将其集成到主代码中时,图像分类函数的回调不起作用。它甚至没有抛出任何错误。
这是对分类器函数的调用。
classifier.classify(img, function (err, result) {
console.log("classification complete");
console.log(err);
console.log(result);
});
这里的 img
是传递给分类的 HTML 图像元素。
err 和 result 是 classify()
函数应该在其回调中返回的参数。
我试过调试,发现进入 classify()
函数时所有的值都是正常的,但它根本不执行它的回调,它被跳过了
测试时使用了几乎相同的代码。
函数没有给出任何错误,只是忽略了回调
最佳答案
I have tried debugging and found that all values are normal while going inside the classify() function, but it simply doesn't execute its callback and it is skipped
它没有被跳过,它没有被调用,因为 callback
只在 classify
完成时被调用。
关于javascript - 是什么导致 javascript 函数不运行它的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57283718/