facebookresearch / maskrcnn-benchmark

Fast, modular reference implementation of Instance Segmentation and Object Detection algorithms in PyTorch.
MIT License
9.3k stars 2.49k forks source link

Import Error in Mask_R-CNN_demo #536

Closed Asif6511 closed 5 years ago

Asif6511 commented 5 years ago

Hi! Facing this import error on running the mask_r-cnn_demo! I followed the instruction on Install.md as well.

ImportError Traceback (most recent call last)

in 1 from maskrcnn_benchmark.config import cfg ----> 2 from predictor import COCODemo ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/demo/predictor.py in 4 from torchvision import transforms as T 5 ----> 6 from maskrcnn_benchmark.modeling.detector import build_detection_model 7 from maskrcnn_benchmark.utils.checkpoint import DetectronCheckpointer 8 from maskrcnn_benchmark.structures.image_list import to_image_list ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/__init__.py in 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. ----> 2 from .detectors import build_detection_model ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/detectors.py in 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. ----> 2 from .generalized_rcnn import GeneralizedRCNN 3 4 5 _DETECTION_META_ARCHITECTURES = {"GeneralizedRCNN": GeneralizedRCNN} ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py in 9 from maskrcnn_benchmark.structures.image_list import to_image_list 10 ---> 11 from ..backbone import build_backbone 12 from ..rpn.rpn import build_rpn 13 from ..roi_heads.roi_heads import build_roi_heads ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/backbone/__init__.py in 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. ----> 2 from .backbone import build_backbone 3 from . import fbnet ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/backbone/backbone.py in 5 6 from maskrcnn_benchmark.modeling import registry ----> 7 from maskrcnn_benchmark.modeling.make_layers import conv_with_kaiming_uniform 8 from . import fpn as fpn_module 9 from . import resnet ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/make_layers.py in 8 from torch.nn import functional as F 9 from maskrcnn_benchmark.config import cfg ---> 10 from maskrcnn_benchmark.layers import Conv2d 11 from maskrcnn_benchmark.modeling.poolers import Pooler 12 ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/layers/__init__.py in 7 from .misc import BatchNorm2d 8 from .misc import interpolate ----> 9 from .nms import nms 10 from .roi_align import ROIAlign 11 from .roi_align import roi_align ~/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/layers/nms.py in 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 # from ._utils import _C ----> 3 from maskrcnn_benchmark import _C 4 5 nms = _C.nms ImportError: /home/asif/PyTorch-Tutorial/maskrcnn_benchmark/maskrcnn-benchmark/maskrcnn_benchmark/_C.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN3c105ErrorC1ENS_14SourceLocationERKSs
chengyangfu commented 5 years ago

Hi, This problem is caused when you compiled maskrcnn_benchmark using the different version of PyTorch. Just rm -rf build and compile the code again. This should fix your problem. Once it is done. You can run the following script to test the compiled module is loaded successfully or not.

python
import torch
import maskrcnn_benchmark._C
fmassa commented 5 years ago

Thanks @chengyangfu for the reply. The solution to this problem is exactly the one that was given by @chengyangfu . I'm closing this issue but let us know if you still face problems

Asif6511 commented 5 years ago

@chengyangfu @fmassa Thanks for the quick reply. I compiled this using Pytorch 1.0.1 version. Should I not compile using that version?

Asif6511 commented 5 years ago

An update! Followed your instructions and it works fine! Thank You!

LLH1818 commented 5 years ago

can u tell me which version of PyTorch I should use to compile?

Asif6511 commented 5 years ago

@LLH1818 I used Pytorch 1.0.1 and it compiled fine!

13012476909 commented 5 years ago

ImportError Traceback (most recent call last)

in () 1 from maskrcnn_benchmark.config import cfg ----> 2 from predictor import COCODemo ~/maskrcnn-benchmark/demo/predictor.py in () 4 from torchvision import transforms as T 5 ----> 6 from maskrcnn_benchmark.modeling.detector import build_detection_model 7 from maskrcnn_benchmark.utils.checkpoint import DetectronCheckpointer 8 from maskrcnn_benchmark.structures.image_list import to_image_list ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/modeling/detector/__init__.py in () 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. ----> 2 from .detectors import build_detection_model ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/modeling/detector/detectors.py in () 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. ----> 2 from .generalized_rcnn import GeneralizedRCNN 3 4 5 _DETECTION_META_ARCHITECTURES = {"GeneralizedRCNN": GeneralizedRCNN} ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py in () 9 from maskrcnn_benchmark.structures.image_list import to_image_list 10 ---> 11 from ..backbone import build_backbone 12 from ..rpn.rpn import build_rpn 13 from ..roi_heads.roi_heads import build_roi_heads ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/modeling/backbone/__init__.py in () 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. ----> 2 from .backbone import build_backbone 3 from . import fbnet ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/modeling/backbone/backbone.py in () 5 6 from maskrcnn_benchmark.modeling import registry ----> 7 from maskrcnn_benchmark.modeling.make_layers import conv_with_kaiming_uniform 8 from . import fpn as fpn_module 9 from . import resnet ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/modeling/make_layers.py in () 8 from torch.nn import functional as F 9 from maskrcnn_benchmark.config import cfg ---> 10 from maskrcnn_benchmark.layers import Conv2d 11 from maskrcnn_benchmark.modeling.poolers import Pooler 12 ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/layers/__init__.py in () 7 from .misc import BatchNorm2d 8 from .misc import interpolate ----> 9 from .nms import nms 10 from .roi_align import ROIAlign 11 from .roi_align import roi_align ~/maskrcnn-benchmark/demo/maskrcnn_benchmark/layers/nms.py in () 1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 # from ._utils import _C ----> 3 from maskrcnn_benchmark import _C 4 5 nms = _C.nms ImportError: cannot import name '_C' I don't know how to solve this
Xudangliatiger commented 5 years ago

@13012476909 Have you fixed it?Meet the same error.

M-Alami commented 5 years ago

@chengyangfu I don't understand how simple rm -f can solve the problem. When I downloaded the folder, I followed Install.md instructions and compiled: python setup.py build develop. I don't understand how deleting build and doing the same thing again will solve the problem. However, I did it and still face the same problem as @Asif6511. I don't understand what I am supposed to do. Can someone help me please ?

chengyangfu commented 5 years ago

The problem was caused by compiling and running the code in different versions of PyTorch. Check the PyTorch in your system first and make sure you are using the "same" PyTorch for compiling and running the code. So the command rm -f is only for deleting the old compiled binary.

M-Alami commented 5 years ago

@chengyangfu Thank you very much for answering. I am using Pytorch 1.0.1. I know that in install.md it says that this version should not work, however, many people like @Asif6511 have done the same and found out that it works. I unfortunately can't find the problem...

chengyangfu commented 5 years ago

Hi @M-Alami , I also use PyTorch 1.0 or PyTorch.1.0.1. Both versions work for me. But I install PyTorch by compiling the source code instead of using the precompiled binary. In order to run the code, I would suggest you just updated the PyTorch to the suggested version. That would be an easier way. Besides, are you using the conda or Virtualenv to create a virtual python environment? If not, please try conda or Virtualenv, it would save a lot of problems.

M-Alami commented 5 years ago

Thanks @chengyangfu for all your answers. I finally managed to make it work. I used pytorch 1.2.0.dev20190620 and cuda '10.0.130'.

TheLostIn commented 5 years ago

I rebuilt the apex and the maskrcnn-benchmark,and it worked.I am using pytorch1.2.0 ,cuda10.0.