只预测YOLACT/YOLACT++中的一个类别(人)。

3
我想预测其中一个类别,即“人”,而不是对所有被检查和预测的84个类别都进行预测。关于YOLACT的参考资料请参阅https://github.com/dbolya/yolact。预测结果还不错,但我认为我只需要修改其中一段代码,且修改方式应该很简单,但我找不到方法。
在此问题中,我按照他提到的方法执行了相关操作,如在Yolact/layers/output_utils.py中添加了4行代码,但没有进行其他更改。这四行代码如下:
boxes = torch.cat((boxes[classes==0], boxes[classes==2]),dim=0)
scores = torch.cat((scores[classes==0], scores[classes==2]),dim=0)
masks = torch.cat((masks[classes==0], masks[classes==2]),dim=0)
classes = torch.cat((classes[classes==0], classes[classes==2]),dim=0)

但是它会产生以下错误:

RuntimeError: strides[cur - 1] == sizes[cur] * strides[cur] INTERNAL ASSERT FAILED at 
/opt/conda/conda-bld/pytorch_1573049310284/work/torch/csrc/jit/fuser/executor.cpp:175, 
please report a bug to PyTorch. 
The above operation failed in interpreter, with the following stack trace:

terminate called without an active exception
Aborted (core dumped)

我尝试按照提到的方法添加if条件,但仍然出错。我正在使用PyTorch 1.3。

1个回答

1
为了在推断时显示单个类别(人,id:0)的输出,您只需要添加
cur_scores[1:] *= 0

yolact/layers/functions/detection.py的第83行中,cur_scores = conf_preds[batch_idx, 1:, :]之后运行。
!python eval.py --trained_model=weights/yolact_resnet50_54_800000.pth --score_threshold=0.15 --top_k=15 --image=input_image.png:output_image.png

会给您提供单个类别的推断结果。

正如作者在问题#218中所提到的:

您可以进行更改以节省NMS计算量,只需添加cur_scores[<everything but your desired class>] *= 0

对于索引,如果您只想要人(类别0),则可以放置1:,但是如果您想要其他类别,则需要执行2个语句:一个带有:<class_idx>,另一个带有<class_idx>+1。然后,在运行eval时,使用--cross_class_nms=True运行它,这将从NMS中删除所有其他类别。

另一种方法是修改output_utils.py中的输出。


请问,是否可以仅保存掩码? - Greg Rov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接