[英]Segmentation fault (core dumped) when using YOLOv3 from pjreddie
我想使用YOLOv3算法进行检测。 我正在使用安装了 Linux 的英特尔 DE10 Nano FPGA 板。 当我构建 YOLOv3(来自原始源)并运行它时,我收到错误“分段错误(核心转储)”。 我做了很多研究,但没有一个有助于解决这个问题。
我使用了预先构建的权重和配置文件,即我运行了以下命令
./darknet detect cfg/yolov3-tiny.cfg yolov3-tiny.weights data/dog.jpg
但得到了如上所述的错误。但同样的事情在我的电脑和其他几个人上没有任何打嗝,但在我的开发板上没有。 然后我开始调试(使用大量 printf 语句)来自“python”目录中“darknet.py”的代码,发现错误位于
"yolo_layer.c" file
line.no.336-> "dets[count].prob[j] = (prob > thresh) ? prob : 0;"
in "get_yolo_detections" function.
我怎样才能解决这个问题? 我已经按照函数和文件到文件来查看错误的来源。
int get_yolo_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, int relative, detection *dets)
{
int i,j,n;
float *predictions = l.output;
if (l.batch == 2) avg_flipped_yolo(l);
int count = 0;
for (i = 0; i < l.w*l.h; ++i){
int row = i / l.w;
int col = i % l.w;
for(n = 0; n < l.n; ++n){
int obj_index = entry_index(l, 0, n*l.w*l.h + i, 4);
float objectness = predictions[obj_index];
if(objectness <= thresh) continue;
int box_index = entry_index(l, 0, n*l.w*l.h + i, 0);
dets[count].bbox = get_yolo_box(predictions, l.biases, l.mask[n], box_index, col, row, l.w, l.h, netw, neth, l.w*l.h);
dets[count].objectness = objectness;
dets[count].classes = l.classes;
for(j = 0; j < l.classes; ++j){
int class_index = entry_index(l, 0, n*l.w*l.h + i, 4 + 1 + j);
float prob = objectness*predictions[class_index];
//|||||||error in below line||||||||
dets[count].prob[j] = (prob > thresh) ? prob : 0;
//^^--error in the above line(got from debugging)
}
++count;
}
}
correct_yolo_boxes(dets, count, w, h, netw, neth, relative);
return count;
}
最后,找到了问题和解决方案。 问题在于加载权重时的“src/parser.c”文件。 从“.weights”文件加载权重的函数依赖于底层机器架构(32 位或 64 位)。 训练时创建的 .weights 文件以 64 位大小编写,因为训练是在 64 位机器上完成的,因为像 jetson、raspberry pi、de10 Nano 等设备有 32 位架构,它们加载权重为权重文件中的 32 位格式。
因此存在兼容性问题(权重不是跨平台)。
要解决此问题,请更改
fwrite(net->seen, sizeof(size_t), 1, fp);// in save_weights_upto() function
到(在第 1024 行 - )
fwrite(net->seen, 8, 1, fp);
和 - - - - - - - - - - - - - - - - - - - - - - - - - ------------------
fread(net->seen, sizeof(size_t), 1, fp);//in load_weights_upto() function
到(在第 1237 行)
fread(net->seen, 8, 1, fp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.