1
votes

I have installed caffe from source. I have used the Cmake for installation. I have updated the respective paths as well. My caffe root directory is: /home/ashj/caffe I have updated the PYTHON path as: export PYTHONPATH=<caffe-home>/python:$PYTHONPATH which is by using **export PYTHONPATH=/home/ashj/caffe/python:$PYTHONPATH**

I could load import the module caffe. However I am not able to access any methods or any layers inside the caffe like set_mode_gpu(), set_mode_cpu() or layers or params. I am getting errors like:

When I used

import caffe

caffe.set_mode_gpu()

I am getting following error:

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

AttributeError: module 'caffe' has no attribute 'set_mode_gpu'

PS: I have also tried using caffe.__caffe.set_mode_gpu() as mentioned in this link. but it is not working for me. My system specs: Ubuntu 18.04

TIA

2
did you also make pycaffe and make distribute? - LeKhan9
I did 'make pycaffe' but I did not do 'make distribute'. 'make pycaffe' did not throw any error. - Ashj

2 Answers

1
votes

Though may be late, but I encountered this same problem and found a way work around:

sys.path.insert(0, '/path/to/caffe/python')
import caffe
caffe.set_mode_gpu()

namely, add the caffe/pathon path to you sys.path before import caffe.
Wrote a post here for detailed analysis, hope helpful.


This problem may be the results of package caffe's path.

For me, if I do the following from the Ubuntu Terminal, everything goes fine: from_terminal

but if I do from the Pycharm IDE, errors occur:

from_pycharm

note that I tested the package caffe's path in both ways, and got different results:
- in the Ubuntu terminal, namely the way which goes fine, I got

'/home/CVAR-B/softwares/caffe/caffe/python/caffe/__init__.pyc'

which is the expected result; - in the Pycharm IDE way, namely the way error occurs, I got

'/usr/local/lib/python2.7/dist-packages/caffe/__init__.pyc'

which is not the expected result.

In view of this discovery, I did this one more thing to handle the error:

sys.path.insert(0, '/path/to/caffe/python')
import caffe
caffe.set_mode_gpu()

namely, add the caffe/pathon path to you sys.path before import caffe.

and the result shows this can be a workaround: pycharm_IDE_success
(source: ax2x.com)

See the caffe.__file__'s result, now returns the expected path.

0
votes

Try these steps and then set your python PATH: You might've already done steps 1 and 3.

make all 
make pycaffe
make distribute
mkdir ~/python 
mv distribute/python/caffe ~/python

Set your PYTHONPATH after this — this should be some dir like caffe/python/caffe