rbgirshick / py-faster-rcnn

Faster R-CNN (Python implementation) -- see https://github.com/ShaoqingRen/faster_rcnn for the official MATLAB version
Other
8.07k stars 4.11k forks source link

ImportError: No module named _caffe #427

Closed aquibjaved closed 4 years ago

aquibjaved commented 7 years ago

After doing the steps, I tried to run the demo.py I am getting error : ImportError: No module named _caffe But I already have installed caffe. When I try to import caffe from python terminal there's no error.

Where's the Problem?

screenshot from 2016-12-05 15-45-14

yanxp commented 7 years ago

You should make pycaffe

aquibjaved commented 7 years ago

Hi @yanxp while installing I've made pycaffe. But this is in another folder do I need to build caffe in the folder below

RCN_ROOT/caffe-fast-rcnn
# Now follow the Caffe installation instructions here:
#   http://caffe.berkeleyvision.org/installation.html

# If you're experienced with Caffe and have all of the requirements installed
# and your Makefile.config in place, then simply do:
make -j8 && make pycaffe
eonurk commented 7 years ago

Maybe you should do ;

export CAFFE_ROOT=/home/USERNAME/py-faster-rcnn/caffe-fast-rcnn

Note that you should change username properly!

aquibjaved commented 7 years ago

Hi @eonurk Thank you for replying I hit the command

export CAFFE_ROOT=/home/aquib/py-faster-rcnn/caffe-fast-rcnn

What this error mean?

screenshot from 2016-12-08 11-05-31

HarrisXia commented 7 years ago

hi, aquibjaved, I met the same problem as you did, do you hav solved it?:)

aquibjaved commented 7 years ago

Hi @TJUNatsume, No I didn't get any solution. I don't why no one is replying to this error I m still stuck at this point I also tried in another laptop I installed everything from beginning and again stuck here.

yanxp commented 7 years ago

@aquibjaved have you export PYTHONPATH=/path/caffe/python:$PYTHONPATH?maybe it helps.

aseem3213 commented 7 years ago

Hi @aquibjaved and @TJUNatsume , did you guys got this issue resolved? I am also facing the same issue. In my case, error is

Traceback (most recent call last): File "demo.py", line 18, in from fast_rcnn.test import im_detect File "/home/cvpr/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 16, in import caffe File "/home/cvpr/py-faster-rcnn/tools/../caffe-fast-rcnn/python/caffe/init.py", line 1, in from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver File "/home/cvpr/py-faster-rcnn/tools/../caffe-fast-rcnn/python/caffe/pycaffe.py", line 13, in from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \ ImportError: No module named 'caffe._caffe'

aquibjaved commented 7 years ago

Hi, @aseem3213 No, the problem is not solved yet, and I also stopped trying it. What I found is, Caffe module need Cuda to run, I am using AMD system with Radeon Graphics card. CUDA only support Nvidea graphics card for gpu usage.

eonurk commented 7 years ago

Did you guys do "make py" after making the caffe? Also check that if you installed prerequisites completely. In addition to that, you dont have to work with your GPU. Go to Makefile.config and enable CPU mode. Do "make clean" and then make it again.

aquibjaved commented 7 years ago

@eonurk after making caffe mean?

eonurk commented 7 years ago

Maybe you can follow this link;

http://caffe.berkeleyvision.org/installation.html#compilation

zhangpzh commented 7 years ago

Hi ! I was also trapped into this problem... Did you guys got this issue solved ? Thanks.

onkarganjewar commented 7 years ago

I also had the same problem. FWIW, here are the list of things that I did along with the mistakes I've made to resolve this issue:

  1. Even though I cloned the repository with --recursive flag, somehow my caffe-fast-rcnn sub-module was not updated and was not on the faster-rcnn branch; I don't know why. So, I did the step 2 from their instructions manual git submodule update --init --recursive

    Additionally, you should check whether you're on the correct branch (faster-rcnn) of the said sub-module.

  2. Add these lines of code at the top of your demo.py import sys sys.path.insert(0,"/path/to/caffe/python")

    Note: These lines of code should be at the start of your demo.py or it would not work (at least for me, it didn't). Also, make sure that you provide the caffe/python path correct.

  3. Make sure your PYTHONPATH and CAFFE_ROOT are correct. For example, $ echo $PYTHONPATH /home/student/objectDetection/py-faster-rcnn/caffe-fast-rcnn/python $ echo $CAFFE_ROOT /home/student/objectDetection/py-faster-rcnn/caffe-fast-rcnn

    Note: Notice, the paths are from py-faster-rcnn repository itself and not some external directory where you might have downloaded/installed the caffe by yourself. This is one of the mistakes that I did and gave the paths of the external directory instead of using their own version of caffe module.

  4. Recompile and rebuild the Caffe and pycaffe modules. Your code might work even without rebuilding caffe modules but I would strongly suggest you repeat steps 3 and 4 from the instructions manual after you've completed step 1.

Hope this helps someone and save their time. Since it definitely has cost me a significant amount of time and stress to find out the naive mistakes that I did. Cheers!!

P.S. This is my interpretation of the mistakes that I made while running the demo. I may be wrong in some of the explanations given above, I apologize if that is the case. However, these are the steps that I did and it has worked for me.

monajalal commented 6 years ago

I did all these with no error but I still get the error:

1205  cd caffe/
 1206  make clean
 1207  sudo make clean
 1208  mkdir build
 1209  cd build/
 1210  cmake -DBLAS=open ..
 1211  make -j8
 1212  make pycaffe
 1213  echo $PYTHONPATH
 1214  echo $CAFFE_ROOT
 1215  make install

[jalal@goku build]$ python
Python 3.5.4 |Anaconda custom (64-bit)| (default, Nov  9 2017, 00:39:12) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/scratch/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
  File "/scratch/caffe/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: dynamic module does not define module export function (PyInit__caffe)
Sam813 commented 6 years ago

@monajalal Hi Mona, Have you solved the issue?

nn-ww commented 6 years ago

@monajalal Hi Mona, I also have the same error. Have you solved the error?

ghost commented 6 years ago

I think problem comes when you install Caffe on your own in another folder. While cloning the faster-rcnn project, you get Caffe once again in caffe-fast-rcnn. The repository code is set in order to look for Caffe by default in that folder. So you need to remove (or rename) caffe-fast-rcnn folder and add in the env variables your caffe path (as explained by @yanxp )

Hiker01 commented 5 years ago

You should make pycaffe

I make caffe with cmake, should I make pycaffe?

who1129 commented 4 years ago

To compile the Python and MATLAB wrappers do make pycaffe and make matcaffe respectively. Be sure to set your MATLAB and Python paths in Makefile.config first! $make pycaffe [ 1%] Built target caffeproto [ 98%] Built target caffe [100%] Built target pycaffe