ykasten / layered-neural-atlases

MIT License
595 stars 65 forks source link

RuntimeError: No such operator detectron2::nms_rotated #8

Closed denabazazian closed 2 years ago

denabazazian commented 2 years ago

Thanks for sharing your code. I have a problem with running preprocess_mask_rcnn.py. I get the following error: RuntimeError: No such operator detectron2::nms_rotated. I followed all your instructions for creating the required environment, and it seems that detectron2 is installed successfully based on this line: Successfully installed antlr4-python3-runtime-4.8 detectron2-0.4+cu101 future-0.18.2 fvcore-0.1.3.post20210317 google-auth-1.35.0 iopath-0.1.9 omegaconf-2.1.2 portalocker-2.4.0 pycocotools-2.0.4 pydot-1.4.2 tabulate-0.8.9 termcolor-1.1.0 yacs-0.1.8 I can import detectron2 without any problem, but after running from detectron2 import model_zoo, I get the error below:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda3/envs/neural_atlases/lib/python3.7/site-packages/detectron2/model_zoo/__init__.py", line 8, in <module>
    from .model_zoo import get, get_config_file, get_checkpoint_url, get_config
  File "/anaconda3/envs/neural_atlases/lib/python3.7/site-packages/detectron2/model_zoo/model_zoo.py", line 9, in <module>
    from detectron2.modeling import build_model
  File "/anaconda3/envs/neural_atlases/lib/python3.7/site-packages/detectron2/modeling/__init__.py", line 2, in <module>
    from detectron2.layers import ShapeSpec
  File "/anaconda3/envs/neural_atlases/lib/python3.7/site-packages/detectron2/layers/__init__.py", line 5, in <module>
    from .nms import batched_nms, batched_nms_rotated, nms, nms_rotated
  File "/anaconda3/envs/neural_atlases/lib/python3.7/site-packages/detectron2/layers/nms.py", line 16, in <module>
    nms_rotated_func = torch.ops.detectron2.nms_rotated
  File "/.local/lib/python3.7/site-packages/torch/_ops.py", line 61, in __getattr__
    op = torch._C._jit_get_operation(qualified_op_name)
RuntimeError: No such operator detectron2::nms_rotated

I am wondering to find out why this error happens and how I can solve it. Thank you.

denabazazian commented 2 years ago

I could solve this issue by going to this file:

"/anaconda3/envs/neural_atlases/lib/python3.7/site-packages/detectron2/layers/nms.py"

and change these lines:

if TORCH_VERSION < (1, 7):
    from detectron2 import _C

    nms_rotated_func = _C.nms_rotated
else:
    nms_rotated_func = torch.ops.detectron2.nms_rotated

to:

from detectron2 import _C
nms_rotated_func = _C.nms_rotated

I installed the pytorch=1.6.0 as mentioned in your conda environment installation, but probably the PyTorch version was upgraded by installing detectron2 since it requires a higher PyTorch version based on the detectron2 installation tutorial.

ykasten commented 2 years ago

Thanks for sharing the solution.