最近参加的智能船舶挑战赛对结果的格式要求:
包含目标边界框从左上角开始的顺时针标注点坐标,目标类别以及目标类别分数,并用空格分开。如下图所示:
故对yolov5的detect.py进行修改,定位到Write results,替换如下:
for *xyxy, conf, cls in reversed(det):
if save_txt:
c1, c2 = (int(xyxy[0]), int(xyxy[1])), (int(xyxy[2]), int(xyxy[3]))
line = (int(c1[0]),int(c1[1]),int(c2[0]),int(c1[1]),int(c2[0]),int(c2[1]),int(c1[0]),int(c2[1]),cls, conf) if opt.save_conf else (cls, *xywh)
with open(txt_path + '.txt', 'a') as f:
f.write(('%g ' * len(line)).rstrip() % line + '\n')
with open(txt_path + '.txt') as f:
lines =f.readlines()
with open(txt_path + '.txt', 'w') as f:
for ll in lines:
ll_split =ll.strip().split()
ll_split[8]='ship'
f.write(ll_split[0]+' '+ll_split[1]+' '+ll_split[2]+' '+ll_split[3]+' '+ll_split[4]+' '+ll_split[5]+' '+ll_split[6]+' '+ll_split[7]+' '+ll_split[8]+' '+ll_split[9]+'\n')
if save_img or view_img:
label = f'{names[int(cls)]} {conf:.2f}'
plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=1)
用yolov5的测试命令进行测试
python detect.py --weights runs/train/exp3/weights/best.pt --conf 0.25 --img-size 512 --source SAR_test1_images --save-txt --save-conf
结果如下:
每一张测试图像对应一个txt结果文件,结果文件名与图像名相同。txt内容如下:
275 68 338 68 338 121 275 121 ship 0.39502
251 69 335 69 335 157 251 157 ship 0.483398
186 46 249 46 249 93 186 93 ship 0.654785
144 3 205 3 205 52 144 52 ship 0.668945
286 143 349 143 349 185 286 185 ship 0.679199
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)