frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Setting up API, getting "Caffe Import Error"

I'm trying to setup the SDK, the toolkit installed fine and now I'm getting an error setting up the API.

karl@karl-Lenovo-YOGA-710-15IKB:~/Downloads/ncapi$ ./setup.sh 
[sudo] password for karl: 
Selecting previously unselected package mvnc.
(Reading database ... 235173 files and directories currently installed.)
Preparing to unpack redist/mvnc_1.07_amd64.deb ...
Unpacking mvnc (0.0.36+0~20170713190651.36~1.gbpef8e6c) ...
Selecting previously unselected package mvnc-dev.
Preparing to unpack redist/mvnc-dev_1.07_amd64.deb ...
Unpacking mvnc-dev (0.0.36+0~20170713190651.36~1.gbpef8e6c) ...
Selecting previously unselected package python3-mvnc.
Preparing to unpack .../python3-mvnc_1.07_all.deb ...
Unpacking python3-mvnc (0.0.36+0~20170713190651.36~1.gbpef8e6c) ...
Setting up mvnc (0.0.36+0~20170713190651.36~1.gbpef8e6c) ...
Setting up mvnc-dev (0.0.36+0~20170713190651.36~1.gbpef8e6c) ...
Setting up python3-mvnc (0.0.36+0~20170713190651.36~1.gbpef8e6c) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
--2017-08-24 11:33:38--  http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel
Resolving dl.caffe.berkeleyvision.org (dl.caffe.berkeleyvision.org)... 169.229.222.251
Connecting to dl.caffe.berkeleyvision.org (dl.caffe.berkeleyvision.org)|169.229.222.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 53533754 (51M) [application/octet-stream]
Saving to: ‘../networks/GoogLeNet/bvlc_googlenet.caffemodel’

bvlc_googlenet.caffemodel     100%[==============================================>]  51.05M   277KB/s    in 65s     

2017-08-24 11:34:43 (808 KB/s) - ‘../networks/GoogLeNet/bvlc_googlenet.caffemodel’ saved [53533754/53533754]

--2017-08-24 11:34:43--  http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel
Resolving dl.caffe.berkeleyvision.org (dl.caffe.berkeleyvision.org)... 169.229.222.251
Connecting to dl.caffe.berkeleyvision.org (dl.caffe.berkeleyvision.org)|169.229.222.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 243862414 (233M) [application/octet-stream]
Saving to: ‘../networks/AlexNet/bvlc_alexnet.caffemodel’

bvlc_alexnet.caffemodel       100%[==============================================>] 232.56M  1.17MB/s    in 3m 42s  

2017-08-24 11:38:25 (1.05 MB/s) - ‘../networks/AlexNet/bvlc_alexnet.caffemodel’ saved [243862414/243862414]

--2017-08-24 11:38:25--  https://github.com/DeepScale/SqueezeNet/raw/master/SqueezeNet_v1.0/squeezenet_v1.0.caffemodel
Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/DeepScale/SqueezeNet/master/SqueezeNet_v1.0/squeezenet_v1.0.caffemodel [following]
--2017-08-24 11:38:25--  https://raw.githubusercontent.com/DeepScale/SqueezeNet/master/SqueezeNet_v1.0/squeezenet_v1.0.caffemodel
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5001403 (4.8M) [application/octet-stream]
Saving to: ‘../networks/SqueezeNet/squeezenet_v1.0.caffemodel’

squeezenet_v1.0.caffemodel    100%[==============================================>]   4.77M  1.81MB/s    in 2.6s    

Last-modified header missing -- time-stamps turned off.
2017-08-24 11:38:28 (1.81 MB/s) - ‘../networks/SqueezeNet/squeezenet_v1.0.caffemodel’ saved [5001403/5001403]

Downloading...
--2017-08-24 11:38:28--  http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz
Resolving dl.caffe.berkeleyvision.org (dl.caffe.berkeleyvision.org)... 169.229.222.251
Connecting to dl.caffe.berkeleyvision.org (dl.caffe.berkeleyvision.org)|169.229.222.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17858008 (17M) [application/octet-stream]
Saving to: ‘caffe_ilsvrc12.tar.gz’

caffe_ilsvrc12.tar.gz         100%[==============================================>]  17.03M  1.56MB/s    in 12s     

2017-08-24 11:38:41 (1.38 MB/s) - ‘caffe_ilsvrc12.tar.gz’ saved [17858008/17858008]

Unzipping...
Done.
--2017-08-24 11:38:41--  https://dl.dropboxusercontent.com/u/38822310/gender_net.caffemodel
Resolving dl.dropboxusercontent.com (dl.dropboxusercontent.com)... 162.125.2.6
Connecting to dl.dropboxusercontent.com (dl.dropboxusercontent.com)|162.125.2.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45649168 (44M) [application/octet-stream]
Saving to: ‘../networks/Gender/gender_net.caffemodel’

gender_net.caffemodel         100%[==============================================>]  43.53M  1.00MB/s    in 41s     

Last-modified header missing -- time-stamps turned off.
2017-08-24 11:39:23 (1.06 MB/s) - ‘../networks/Gender/gender_net.caffemodel’ saved [45649168/45649168]

--2017-08-24 11:39:23--  https://dl.dropboxusercontent.com/u/38822310/age_net.caffemodel
Resolving dl.dropboxusercontent.com (dl.dropboxusercontent.com)... 162.125.2.6
Connecting to dl.dropboxusercontent.com (dl.dropboxusercontent.com)|162.125.2.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45661480 (44M) [application/octet-stream]
Saving to: ‘../networks/Age/age_net.caffemodel’

age_net.caffemodel            100%[==============================================>]  43.55M  1.46MB/s    in 27s     

Last-modified header missing -- time-stamps turned off.
2017-08-24 11:39:51 (1.63 MB/s) - ‘../networks/Age/age_net.caffemodel’ saved [45661480/45661480]

--2017-08-24 11:39:51--  https://dl.dropboxusercontent.com/u/38822310/mean.binaryproto
Resolving dl.dropboxusercontent.com (dl.dropboxusercontent.com)... 162.125.2.6
Connecting to dl.dropboxusercontent.com (dl.dropboxusercontent.com)|162.125.2.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 786446 (768K) [application/octet-stream]
Saving to: ‘../mean/age_gender/mean.binaryproto’

mean.binaryproto              100%[==============================================>] 768.01K   942KB/s    in 0.8s    

Last-modified header missing -- time-stamps turned off.
2017-08-24 11:39:52 (942 KB/s) - ‘../mean/age_gender/mean.binaryproto’ saved [786446/786446]

Traceback (most recent call last):
  File "convert_mean.py", line 1, in <module>
    import caffe
ImportError: No module named 'caffe'
--2017-08-24 11:39:52--  https://github.com/BVLC/caffe/raw/master/examples/images/cat.jpg
Resolving github.com (github.com)... 192.30.255.113, 192.30.255.112
Connecting to github.com (github.com)|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/BVLC/caffe/master/examples/images/cat.jpg [following]
--2017-08-24 11:39:53--  https://raw.githubusercontent.com/BVLC/caffe/master/examples/images/cat.jpg
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 140391 (137K) [image/jpeg]
Saving to: ‘../images/cat.jpg’

cat.jpg                       100%[==============================================>] 137.10K   519KB/s    in 0.3s    

Last-modified header missing -- time-stamps turned off.
2017-08-24 11:39:53 (519 KB/s) - ‘../images/cat.jpg’ saved [140391/140391]

../../bin
mvNCCompile v02.00, Copyright @ Movidius Ltd 2016

Caffe Import Error
mvNCCompile v02.00, Copyright @ Movidius Ltd 2016

Caffe Import Error
mvNCCompile v02.00, Copyright @ Movidius Ltd 2016

Caffe Import Error
mvNCCompile v02.00, Copyright @ Movidius Ltd 2016

Caffe Import Error
mvNCCompile v02.00, Copyright @ Movidius Ltd 2016

Caffe Import Error

Comments

  • 12 Comments sorted by Votes Date Added
  • I had this issue despite PYTHONPATH being set correctly. Instead of running the setup script again, I just went into ncapi/tools and ran ./get_models.sh then ./convert_models.sh separately.

  • @karl Sounds like your PYTHONPATH variable isn't being set. After running the toolkit setup script, you should begin the API installation by opening a new terminal to refresh the PYTHONPATH environment variable set by the toolkit setup script. If you have already opened a new window after using the toolkit setup script and you are still getting this error, try double checking your bashrc file to make sure your PYTHONPATH environment variable is there and pointing to the directory where you installed Caffe.

    The default PYTHONPATH set by the toolkit is /opt/movidius/caffe/python and in your bashrc file, it should look like this: export PYTHONPATH=$env:"/opt/movidius/caffe/python":$PYTHONPATH. You can also confirm this by typing in: echo $PYTHONPATH in your terminal. Let me know if this works for you. Thanks.

  • It appears that the installation process needs a strange mix of sudo and non-sudo commands. For the toolkit setup, I had to use sudo to get it to work (otherwise it cant get past git lock in Caffe installation), but then Caffe gets installed as root user, leading to Caffe import error when doing the API installation.
    The only combinations that worked for me were
    1. Run Toolkit installation: sudo ./setup.sh
    2. sudo chown -R currentuser /opt/movidius/caffe/
    3. Run API installation: ./setup.sh (or ./get_models.sh and ./convert_models.sh) without sudo, as currentuser

    As dropbox links are broken for some of the models, I commented out the lines related to those models in get_models and convert_models scripts to avoid issues. Similar to @snatch59 I had PYTHONPATH set and displayed correctly throughout the process.

    convert_models.sh also needed updating:

    NCS_TOOLKIT_ROOT='/path_to_ncs_sdk/bin'
    NCS_API_ROOT='/path_to_ncs_sdk/ncapi' 
    python3 $NCS_TOOLKIT_ROOT/mvNCCompile.pyc $NCS_API_ROOT/networks/AlexNet/NetworkConfig.prototxt -w $NCS_API_ROOT/networks/AlexNet/bvlc_alexnet.caffemodel -o $NCS_API_ROOT/networks/AlexNet/graph
    # .... further lines for other models 
    
  • Hello , I've have finished shell like this , however , it does not solve problem , could anyone help?
    echo $PYTHONPATH
    /opt/movidius/caffe/python:/opt/movidius/mvnc/python::/opt/movidius/caffe/python

    python image-classifier.py
    Traceback (most recent call last):
    File "image-classifier.py", line 10, in
    import mvnc.mvncapi as mvnc
    ImportError: No module named mvnc.mvncapi

  • @WaitingForU For my setup, I get a slightly different output.

    tome@mycomputer:~$ echo $PYTHONPATH
    :/opt/movidius/caffe/python
  • Any clue how to resolve this
    Traceback (most recent call last):
    File "./detectionExample/Main.py", line 5, in
    from ObjectWrapper import *
    File "/home/movidius/YoloV2NCS/detectionExample/ObjectWrapper.py", line 17, in
    class ObjectWrapper():
    File "/home/movidius/YoloV2NCS/detectionExample/ObjectWrapper.py", line 18, in ObjectWrapper
    mvnc.global_set_option(mvnc.GlobalOption.RW_LOG_LEVEL, 2)
    AttributeError: module 'mvnc.mvncapi' has no attribute 'global_set_option'

    i am using ncsdk version 1

  • @alokprasad Looks like you are using a NCSDK 2 API app and you have NCSDK 1 installed. Please look at the NCSDK 1 API example of Global Set Option at https://github.com/movidius/ncappzoo/blob/master/apps/benchmarkncs/benchmarkncs.py#L26.

  • Thansk Tome, Yes figured it out there are API changes in ncsdkv1 and ncsdkv2...

  • when i run hello_ncs.py,it works . but when i run the ncappzoo's examples,it show "Error importing caffe" .
    like this:

    sijiu@sijiu-32G:~/workspace/ncappzoo/apps/hello_ncs_py$ python3 hello_ncs.py 
    Hello NCS! Device opened normally.
    Goodbye NCS! Device closed normally.
    NCS device working.
    

    sijiu@sijiu-32G:~/workspace/ncappzoo/caffe/SqueezeNet$ sudo make compile[sudo] password for sijiu: making prereqs (cd ../../data/ilsvrc12; make) make[1]: Entering directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12' make[1]: Leaving directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12' LICENSE file already exists making prototxt Prototxt file already exists making caffemodel caffemodel file already exists making compile mvNCCompile -w squeezenet_v1.0.caffemodel -s 12 deploy.prototxt mvNCCompile v02.00, Copyright @ Movidius Ltd 2016 /usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_gtk3.py:54: DeprecationWarning: Gdk.Cursor.new is deprecated cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR), /usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_gtk3agg.py:18: UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo. Try installing cairocffi. "The Gtk3Agg backend is known to not work on Python 3.x with pycairo. " Error importing caffe
  • @wenbin.lu Try using make compile without the sudo and let me know what your results are. If you are seeing a Caffe import error, your PYTHONPATH in bashrc may not be set. You can manually edit the bashrc file and add the python path by using the following steps:

    1. With your favorite text editor, edit the bashrc file (example: gedit ~/.bashrc)
    2. Scroll down to the end of the bashrc file and type in the following on a new line: export PYTHONPATH="$PYTHONPATH:/opt/movidius/caffe/python". Then save the file and close the terminal window.
    3. Open a new window and try compiling Squeezenet again using make compile
  • when i set $PYTHONPATH$ and using $make compile$ ,shows the flowing error :

    sijiu@sijiu-32G:~/workspace/ncappzoo/caffe/SqueezeNet$ make compile
    
    making prereqs
    (cd ../../data/ilsvrc12; make)
    make[1]: Entering directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12'
    make[1]: Leaving directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12'
    sed: couldn't open temporary file ./sedKWFOVe: Permission denied
    Makefile:23: recipe for target 'prereqs' failed
    make: *** [prereqs] Error 4
    
  • i changed ncappzoo 's owner and grouper from root to myself, and then compiling Seqeezenet again used make compile

    sijiu@sijiu-32G:~/workspace/ncappzoo/caffe/SqueezeNet$ make compile
    
    making prereqs
    (cd ../../data/ilsvrc12; make)
    make[1]: Entering directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12'
    make[1]: Leaving directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12'
    LICENSE file already exists
    
    making prototxt
    Prototxt file already exists
    
    making caffemodel
    caffemodel file already exists
    
    making compile
    mvNCCompile -w squeezenet_v1.0.caffemodel -s 12 deploy.prototxt
    mvNCCompile v02.00, Copyright @ Movidius Ltd 2016
    
    /usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_gtk3.py:54: DeprecationWarning: Gdk.Cursor.new is deprecated
      cursors.MOVE          : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
    /usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_gtk3agg.py:18: UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo. Try installing cairocffi.
      "The Gtk3Agg backend is known to not work on Python 3.x with pycairo. "
    Error importing caffe
    

    and when I use my windows connect my Raspberry pi by SSH ,and then compiling Seqeezenet by make compile ,this message shows:

    sijiu@sijiu-32G:~/workspace/ncappzoo/caffe/SqueezeNet$ make compile
    
    making prereqs
    (cd ../../data/ilsvrc12; make)
    make[1]: Entering directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12'
    make[1]: Leaving directory '/home/sijiu/workspace/ncappzoo/data/ilsvrc12'
    LICENSE file already exists
    
    making prototxt
    Prototxt file already exists
    
    making caffemodel
    caffemodel file already exists
    
    making compile
    mvNCCompile -w squeezenet_v1.0.caffemodel -s 12 deploy.prototxt
    mvNCCompile v02.00, Copyright @ Movidius Ltd 2016
    
    Failed to connect to Mir: Failed to connect to server socket: No such file or directory
    Unable to init server: Could not connect: Connection refused
    Failed to connect to Mir: Failed to connect to server socket: No such file or directory
    Unable to init server: Could not connect: Connection refused
    /usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_gtk3.py:54: DeprecationWarning: Gdk.Cursor.new is deprecated
      cursors.MOVE          : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
    
    (mvNCCompile:10219): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
    Traceback (most recent call last):
      File "/usr/local/bin/mvNCCompile", line 118, in <module>
        create_graph(args.network, args.inputnode, args.outputnode, args.outfile, args.nshaves, args.inputsize, args.weights)
      File "/usr/local/bin/mvNCCompile", line 100, in create_graph
        from Controllers.CaffeParser import parse_caffe
      File "/usr/local/bin/ncsdk/Controllers/CaffeParser.py", line 29, in <module>
        import caffe
      File "/opt/movidius/caffe/python/caffe/__init__.py", line 1, in <module>
        from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
      File "/opt/movidius/caffe/python/caffe/pycaffe.py", line 15, in <module>
        import caffe.io
      File "/opt/movidius/caffe/python/caffe/io.py", line 2, in <module>
        import skimage.io
      File "/usr/local/lib/python3.5/dist-packages/skimage/io/__init__.py", line 15, in <module>
        reset_plugins()
      File "/usr/local/lib/python3.5/dist-packages/skimage/io/manage_plugins.py", line 93, in reset_plugins
        _load_preferred_plugins()
      File "/usr/local/lib/python3.5/dist-packages/skimage/io/manage_plugins.py", line 73, in _load_preferred_plugins
        _set_plugin(p_type, preferred_plugins['all'])
      File "/usr/local/lib/python3.5/dist-packages/skimage/io/manage_plugins.py", line 85, in _set_plugin
        use_plugin(plugin, kind=plugin_type)
      File "/usr/local/lib/python3.5/dist-packages/skimage/io/manage_plugins.py", line 255, in use_plugin
        _load(name)
      File "/usr/local/lib/python3.5/dist-packages/skimage/io/manage_plugins.py", line 299, in _load
        fromlist=[modname])
      File "/usr/local/lib/python3.5/dist-packages/skimage/io/_plugins/matplotlib_plugin.py", line 3, in <module>
        import matplotlib.pyplot as plt
      File "/usr/local/lib/python3.5/dist-packages/matplotlib/pyplot.py", line 115, in <module>
        _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()  File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
        globals(),locals(),[backend_name],0)
      File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 11, in <module>
        from . import backend_gtk3
      File "/usr/local/lib/python3.5/dist-packages/matplotlib/backends/backend_gtk3.py", line 54, in <module>
        cursors.MOVE          : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
    TypeError: constructor returned NULL
    Makefile:88: recipe for target 'compile' failed
    make: *** [compile] Error 1
    
Sign In or Register to comment.