opencv.js中的yolov4检测引起的例外
我正在尝试使用opencv.js将Yolov4检测到工作。
看来我已经成功地使用了网络阅读
const net = cv.readNetFromDarknet(files.config, files.weights);
,并且我正在使用getBlobFromimage
来自教程要获取网络输入:
getBlobFromImage = function(inputSize, mean, std, swapRB, image) {
let mat;
if (typeof(image) === 'string') {
mat = cv.imread(image);
} else {
mat = image;
}
let matC3 = new cv.Mat(mat.matSize[0], mat.matSize[1], cv.CV_8UC3);
cv.cvtColor(mat, matC3, cv.COLOR_RGBA2BGR);
let input = cv.blobFromImage(matC3, std, new cv.Size(inputSize[0], inputSize[1]),
new cv.Scalar(mean[0], mean[1], mean[2]), swapRB);
matC3.delete();
return input;
}
但是,当我尝试在网络上运行forward
时,我会收到一个错误,说undfult <
/code>随后是一个看似随机的数字。
我已经尝试了
net.setInput(blob)
net.forward()
,我发现了错误。
我在网上找到了一个源,您需要使用fordrof2
使用图层名称和输出向量,因此我尝试了使用硬编码的图层名称(因为OpenCV.JS都不揭示获得的方法来获取图层名称):
net.setInput(blob)
const outs = new cv.MatVector();
net.forward2(outs, ["yolo_139", "yolo_150", "yolo_161"]);
我仍然会收到未闻的错误。我还调整了图像大小,因此宽度和高度都是32的倍数,我在某个地方读到的倍数是必要的。
有什么想法吗?我一直在寻找答案,但还没有找到任何答案。
编辑:有关错误的更多详细信息
我只是尝试运行几次,这是输出:
Uncaught 279968808
Uncaught 279899688
[then, after refresh]
Uncaught 279968808
Uncaught 279899688
这是堆栈跟踪:
___cxa_throw opencv.js:30
<anonymous> opencv.js line 30 > WebAssembly.instantiate:899300
<anonymous> opencv.js line 30 > WebAssembly.instantiate:898391
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315351
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315293
<anonymous> opencv.js line 30 > WebAssembly.instantiate:545156
<anonymous> opencv.js line 30 > WebAssembly.instantiate:525900
<anonymous> opencv.js line 30 > WebAssembly.instantiate:525121
<anonymous> opencv.js line 30 > WebAssembly.instantiate:65086
<anonymous> opencv.js line 30 > WebAssembly.instantiate:65049
<anonymous> opencv.js line 30 > WebAssembly.instantiate:5596483
dynCall_iiiii opencv.js:30
dynCall_iiiii_9 opencv.js line 30 > Function:4
constructor_body opencv.js:30
constructor opencv.js:30
Mat opencv.js line 30 > Function:4
matFromImageData opencv.js:30
imread opencv.js:30
getBlobFromImage DetectApp.js:24
run DetectApp.js:63
<anonymous> debugger eval code:1
因此,这是它无法运行getBlobFromimage
的实例。 ,但这只是偶尔失败,通常会成功。这是更常见的堆栈跟踪,在dnn_net $ fordrof2
中发生故障:
___cxa_throw opencv.js:30
<anonymous> opencv.js line 30 > WebAssembly.instantiate:899300
<anonymous> opencv.js line 30 > WebAssembly.instantiate:898391
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315351
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315293
<anonymous> opencv.js line 30 > WebAssembly.instantiate:545156
<anonymous> opencv.js line 30 > WebAssembly.instantiate:525900
<anonymous> opencv.js line 30 > WebAssembly.instantiate:526317
<anonymous> opencv.js line 30 > WebAssembly.instantiate:697106
<anonymous> opencv.js line 30 > WebAssembly.instantiate:327453
<anonymous> opencv.js line 30 > WebAssembly.instantiate:529953
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2720179
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2717263
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2717095
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3384719
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3323788
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3318607
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3365552
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2646791
<anonymous> opencv.js line 30 > WebAssembly.instantiate:141167
<anonymous> opencv.js line 30 > WebAssembly.instantiate:204282
<anonymous> opencv.js line 30 > WebAssembly.instantiate:5596551
dynCall_viiii opencv.js:30
dynCall_viiii_1868 opencv.js line 30 > Function:4
dnn_Net$forward2 opencv.js line 30 > Function:10
run DetectApp.js:66
<anonymous> debugger eval code:1
I'm trying to get YOLOv4 detection to work using OpenCV.js.
It looks like I've successfully gotten the net read using
const net = cv.readNetFromDarknet(files.config, files.weights);
And I'm using getBlobFromImage
from the tutorial to get the network input:
getBlobFromImage = function(inputSize, mean, std, swapRB, image) {
let mat;
if (typeof(image) === 'string') {
mat = cv.imread(image);
} else {
mat = image;
}
let matC3 = new cv.Mat(mat.matSize[0], mat.matSize[1], cv.CV_8UC3);
cv.cvtColor(mat, matC3, cv.COLOR_RGBA2BGR);
let input = cv.blobFromImage(matC3, std, new cv.Size(inputSize[0], inputSize[1]),
new cv.Scalar(mean[0], mean[1], mean[2]), swapRB);
matC3.delete();
return input;
}
However, when I try to run forward
on the network, I get an error that says Uncaught
followed by a seemingly random number.
I've tried
net.setInput(blob)
net.forward()
And I get the error.
I found a source online that said you need to use layer names and an output vector using forward2
, so I've tried that with hardcoded layer names (as OpenCV.js doesn't expose a method to get layer names):
net.setInput(blob)
const outs = new cv.MatVector();
net.forward2(outs, ["yolo_139", "yolo_150", "yolo_161"]);
And I still get the uncaught error. I've also resized my image so width and height are both multiples of 32, which I read somewhere was necessary.
Any ideas? I've been searching for answers but haven't found anything yet.
Edit: More detail on error
I just tried running it a few times, and here is the output:
Uncaught 279968808
Uncaught 279899688
[then, after refresh]
Uncaught 279968808
Uncaught 279899688
Here's the stack trace:
___cxa_throw opencv.js:30
<anonymous> opencv.js line 30 > WebAssembly.instantiate:899300
<anonymous> opencv.js line 30 > WebAssembly.instantiate:898391
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315351
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315293
<anonymous> opencv.js line 30 > WebAssembly.instantiate:545156
<anonymous> opencv.js line 30 > WebAssembly.instantiate:525900
<anonymous> opencv.js line 30 > WebAssembly.instantiate:525121
<anonymous> opencv.js line 30 > WebAssembly.instantiate:65086
<anonymous> opencv.js line 30 > WebAssembly.instantiate:65049
<anonymous> opencv.js line 30 > WebAssembly.instantiate:5596483
dynCall_iiiii opencv.js:30
dynCall_iiiii_9 opencv.js line 30 > Function:4
constructor_body opencv.js:30
constructor opencv.js:30
Mat opencv.js line 30 > Function:4
matFromImageData opencv.js:30
imread opencv.js:30
getBlobFromImage DetectApp.js:24
run DetectApp.js:63
<anonymous> debugger eval code:1
So that's an instance of it failing to run getBlobFromImage
, but that only fails occasionally, it usually succeeds. Here's the more common stack trace, with a failure in dnn_Net$forward2
:
___cxa_throw opencv.js:30
<anonymous> opencv.js line 30 > WebAssembly.instantiate:899300
<anonymous> opencv.js line 30 > WebAssembly.instantiate:898391
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315351
<anonymous> opencv.js line 30 > WebAssembly.instantiate:315293
<anonymous> opencv.js line 30 > WebAssembly.instantiate:545156
<anonymous> opencv.js line 30 > WebAssembly.instantiate:525900
<anonymous> opencv.js line 30 > WebAssembly.instantiate:526317
<anonymous> opencv.js line 30 > WebAssembly.instantiate:697106
<anonymous> opencv.js line 30 > WebAssembly.instantiate:327453
<anonymous> opencv.js line 30 > WebAssembly.instantiate:529953
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2720179
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2717263
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2717095
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3384719
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3323788
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3318607
<anonymous> opencv.js line 30 > WebAssembly.instantiate:3365552
<anonymous> opencv.js line 30 > WebAssembly.instantiate:2646791
<anonymous> opencv.js line 30 > WebAssembly.instantiate:141167
<anonymous> opencv.js line 30 > WebAssembly.instantiate:204282
<anonymous> opencv.js line 30 > WebAssembly.instantiate:5596551
dynCall_viiii opencv.js:30
dynCall_viiii_1868 opencv.js line 30 > Function:4
dnn_Net$forward2 opencv.js line 30 > Function:10
run DetectApp.js:66
<anonymous> debugger eval code:1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误消息非常不透明。如果您在最新构建上运行,但仍然没有明显错误消息崩溃,也许可以在OpenCV's的OPENCV的问题上提交 github ,但首先检查是否尚未报告。
我没有在您的推理代码中看到任何调整大小。如果您的推理代码尚未调整输入大小,则应尝试添加它。
神经网络通常期望特定大小*的输入。对于 416x416或224x224 (Tiny?)的Yolov4,在设计网络时确定哪个。
在培训期间,所有输入都已经是正确的大小,或者培训脚本都大大化了输入。
*完全卷积网络采用任意大小
The error messages are quite opaque. If you're running on the latest build and still this crashes without clear error messages, perhaps submit an issue on OpenCV's github but check first if that hasn't been reported already.
I did not see any resizing in your inference code. If the inference code you have doesn't already resize inputs, you should try adding that.
Neural networks usually expect inputs of a specific size*. For YOLOv4 that might be 416x416 or 224x224 (tiny?), which are determined when the network is designed.
During training, either all the inputs are already the right size, or the training script resizes the inputs.
* fully convolutional networks take arbitrary sizes
未熟悉的
数字不是随机数,它们是指数。通常情况下,当分类器未正确配置时,就会发生这种问题。
确保配置和权重参数有效,也尝试使用
The
Uncaught
numbers aren't random numbers, they are pointers.Usually problem like this happen when the classifier hasn't been correctly configured.
Make sure config and weights parameters are valid, also try to explicit the backend choice with