在YOLACT/YOLACT++中只预测一个class(人)
Predict only one class (person) in YOLACT/YOLACT++
我只想预测一个 class,即正在检查和预测的所有 84 个 class 中的人。
供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
为了在推理时显示单个 class (person, 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
会给你一个class推断。
作者在issue#218中提到:
you can make the change to save on NMS computation,
simply add cur_scores[<everything but your desired class>] *= 0
For the index, if you wanted only person (class 0), you can put 1:
, but if you wanted another class than that you'd need to do 2 statements: one with :<class_idx>
and the other with <class_idx>+1
:. Then when you run eval, run it with --cross_class_nms=True
and that'll remove all the other classes from NMS.
另一种方法是修改output_utils.py
中的输出。
我只想预测一个 class,即正在检查和预测的所有 84 个 class 中的人。
供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
为了在推理时显示单个 class (person, 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
会给你一个class推断。
作者在issue#218中提到:
you can make the change to save on NMS computation, simply add
cur_scores[<everything but your desired class>] *= 0
For the index, if you wanted only person (class 0), you can put
1:
, but if you wanted another class than that you'd need to do 2 statements: one with:<class_idx>
and the other with<class_idx>+1
:. Then when you run eval, run it with--cross_class_nms=True
and that'll remove all the other classes from NMS.
另一种方法是修改output_utils.py
中的输出。