使用
python detect.py
时,我们可以使用标志 --hide-conf
隐藏置信水平
我的问题是,我们可以在使用
model=torch.hub.load()
然后使用 results=model(img)
时做同样的事情吗?一旦我们写下 results.show()
,我只想要图像上带有类别名称的框,并希望隐藏置信度分数。
我尝试过使用,
model_damage_annot.conf=0.4
model_damage_annot.iou=0.15
model_damage_annot.max_det=20
这有效,但
model_damage_annot.hide_conf=True
不起作用。正确的做法是什么?
生成的图片显示了置信度分数,我想隐藏它们。请指导我
谢谢你!
我尝试更改 detector.py 文件并添加像您一样的参数,但它们都不适合我。但由于可以提取置信度得分及其边界框(xmax、xmin、ymax、ymin),我将它们存储在变量中,然后自己绘制边界框。你可以试试我的代码。
results = model(img)
bboxes = results.pred[0][:, :4]
total_area_covered = 0
x1, y1, x2, y2 = 0, 0, 0, 0
draw = ImageDraw.Draw(img)
for bbox in bboxes:
x1, y1, x2, y2 = bbox.int().tolist()
for i in range(x1, x2, 4):
draw.line([(i, y1), (i + 2, y1)], fill="black", width=3)
draw.line([(i, y2), (i + 2, y2)], fill="black", width=3)
for i in range(y1, y2, 4):
draw.line([(x1, i), (x1, i + 2)], fill="black", width=3)
draw.line([(x2, i), (x2, i + 2)], fill="black", width=3)
total_area_covered += (x2 - x1) * (y2 - y1)
img.save(output_path)