问题1:
由于不同数据集中图片分辨率存在一定的差异性,比如自身数据集图片大小为1920×1080,发现在预测过程中bbox检测框太细,最终甚至无法看清楚实际预测值。
问题2:
部分小伙伴的检测框太粗而导致检测目标被遮挡,尤其是当目标较小并且很密集时,目标很容易就被框挡住,不容易观察整体检测效果如何。
解决方法:
在detect.py文件中找到下面这行:
# Process detections
for i, det in enumerate(pred): # detections per image
if webcam: # batch_size >= 1
p, s, im0, frame = path[i], '%g: ' % i, im0s[i].copy(), dataset.count
else:
p, s, im0, frame = path, '', im0s, getattr(dataset, 'frame', 0)
p = Path(p) # to Path
save_path = str(save_dir / p.name) # img.jpg
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
s += '%gx%g ' % img.shape[2:] # print string
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
if len(det):
# Rescale boxes from img_size to im0 size
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
# Print results
for c in det[:, -1].unique():
n = (det[:, -1] == c).sum() # detections per class
s += f"{n} {names[int(c)]}{'s' * (n > 1)}, " # add to string
# Write results
for *xyxy, conf, cls in reversed(det):
if save_txt: # Write to file
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
with open(txt_path + '.txt', 'a') as f:
f.write(('%g ' * len(line)).rstrip() % line + '\n')
if save_img or view_img: # Add bbox to image
label = f'{names[int(cls)]} {conf:.3f}'
############################
plot_one_box(xyxy, im0, label=label,
color=colors[int(cls)], line_thickness=6)
各位小伙伴可自行调整line_thickness值大小,就可以改变预测框的粗细啦~
方便的话,顺便给博主点个赞哇~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)