如果谁知道.onnx如何在matlab重新训练,请告知!!
1 调用的方法
参考cuixingxing的代码。
model = "./onnxPretrainedModels/"+"yolov5x.onnx";
customYoloV5FcnName = 'yolov5fcn';
inputSize = [640,640];
throushHold = 0.3;
nmsThroushHold = 0.5;
outs = cell(3,1); % 3个检测head输出
classesNames = categorical(readlines("yoloV5ONNX\coco.names"));
colors = randi(255,length(classesNames),3);
params = importONNXFunction(model,customYoloV5FcnName);
2 相关参数查看
2.1 输入参数
matlab和.onnx的图谱格式不同,需要对读入的图片格式进行设置
the permutation from HWCN (MATLAB standard) to NCHW (ONNX standard) uses the vector
[4 3 1 2].
图片格式转为.onnx的输入
img = imresize(image,inputSize);
img = rescale(img,0,1);% 转换到[0,1]
img = permute(img,[3,1,2]);%调整矩阵顺序,符合.onnx的格式
img = dlarray(reshape(img,[1,size(img)])); % bs*n*c*h*w,[0,1],RGB顺序
2.2 输出参数
模型识别结果
参考:yolov5目标框预测_yolov5锚框_王定邦的博客-CSDN博客
输入为640*640:则 输出的分别为20*20*3*85; 40*40*3*85;80*80*3*85. 3为anchor数量,85为80(类别)+5 x,y,wh,+pro
结果与out的矩阵大小一致。
2.3 输出处理
以前用matlab内部的模型直接就可以得到需要的结果,但是.onnx的输出需要做nms处理。
% NMS非极大值抑制
if ~isempty(allBBoxes)
[bboxes,scores,labels] = selectStrongestBboxMulticlass(allBBoxes,allScores,allLabels,...
'RatioType','Min','OverlapThreshold',nmsThroushHold);
annotations = string(labels) + ": " + string(scores);
[~,ids] = ismember(labels,classesNames);
color = colors(ids,:);
% figure, imshow(img1)
image = insertObjectAnnotation(image,...
'rectangle',bboxes,cellstr(annotations),...
'Color','red',...
'LineWidth',3);
end
实际上处理的结果不是很好!!
3 我们的模型
3.1 GPR识别的模型
3.2 测试结果分析
检测头的输出不对。4个类。第一行应改为1*20*20*3*9
3.3 后处理
为了能融合模型到系统,这几天是两条路走。
matlab上 查了帮助,知道问题了。
这里有不同的输出
我也查看到了展平输出的处理方式,或者直接用X360,415和470的结果。
参考了一个yolov5的例子,将他内部的NMS等工具移植过来。可以解决目前的问题了。
对outs做了个矩阵排序,然后进行后处理。这里的阈值设置为0.5.
新的问题:
我对x360,x415,x471进行拼接,然后再进行识别总是因为数据格式不对没有完成。 cuixingxing的方法就是对这3个检测头的数据进行处理的。