Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing Caffe on Ubuntu 16.04 and above (CPU ONLY, WITHOUT CUDA OR GPU SUPPORT)

This is a guide on how to install Caffe for Ubuntu 16.04 and above, without GPU support (No CUDA required).

Prerequisites:

OpenCV

sudo apt-get install libopencv-dev python-opencv

OpenBLAS OR Atlas

OpenBLAS

sudo apt-get install libopenblas-dev

Atlas

sudo apt-get install libatlas-base-dev

Boost

sudo apt-get install libboost-all-dev

Protobuf (USING PIP)

sudo pip install protobuf

If you don't have pip yet, install it using the following commands:
sudo apt-get install python-pip python-dev build-essential

sudo pip install --upgrade pip

General Dependencies

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler 

sudo apt-get install the python-dev 

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev 

Getting Caffe

git clone https://github.com/BVLC/caffe

You will now find the caffe folder in your Home directory.

We have to make a copy of Makefile.config.example, which we generally name as, Makefile.config to which we can make changes based on our system settings.

cd caffe
cp Makefile.config.example Makefile.config

Making Changes In Makefile.config

Make sure you are still in the caffe directory, then use this command to open Makefile.config

gedit Makefile.config 
Note- The following line numbers may vary.
  • On line 8, uncomment CPU_ONLY := 1

  • On Line 21, uncomment OPENCV_VERSION := 3 if you're using OpenCV 3 or above. If you aren't sure, try this in another terminal

$ python
>>> import cv2
>>> cv2.__version__
'3.0.0'
  • On line 25, uncomment CUSTOM_CXX := g++

  • On line 50, set BLAS := open if you've installed OpenBLAS, or let it be the default BLAS := atlas if you've installed Atlas.

  • On line 94, change

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include

to

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include  /usr/include/hdf5/serial 
  • On line 95, change
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib

to

LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib  /usr/lib/x86_64-linux-gnu/hdf5/serial

This should resolve hdf5 errors when running make

Now within the caffe directory, run the following one after the other

make all
make test
make runtest

These should run smoothly without any errors. If you do however, encounter errors, refer the ones at the end of this post or elsewhere to resolve them.

Make sure to REMOVE BUILD every time you resolve an error, and run those three commands again to rebuild.

This is VERY IMPORTANT, otherwise the errors will persist.

To remove build,

rm -rf ./build*/

Once all three run without errors, while in the caffe directory, type

make pycaffe

This will build a python wrapper. You will also find a python folder within the caffe folder now.

To use caffe within python, export its path as

export PYTHONPATH=~/Home/_username_/caffe/python:$PYTHONPATH

Replace _username_ with the your username in the system.

Once you've done this, run the python terminal and import caffe

>>> import caffe
>>>

This, should work. If it throws a 'module not found' error, check if it has been appended in pythonpath properly by typing

>>> import sys
>>> sys.path
['', '/home/nikita/caffe/python', '/home/nikita', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib
/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/nikita/.local/lib/python2.7/site-
packages']

If you see that the /home/_username_/caffe/python path, isn't there, then do

>>> sys.path.append('/Home/_username_/caffe/python')

Alternatively, just use

caffe/python

depending on whether your export is already under home/username

That's all there is to installing caffe.

Common Errors

OpenCV Errors

.
.
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_videoio
collect2: error: ld returned 1 exit status

This usually happens when you've either forgotten to uncomment line 21 when you have OpenCV 3, or if you haven't checked the version properly. If you're using OpenCV < 3, this shouldn't be an error at all. If it still shows on OpenCV >= 3.0, then in the Makefile ( NOT Makefile.config ) on line 181 (in my case), add libraries such that it looks like

LIBRARIES += glog gflags protobuf leveldb snappy \
  lmdb boost_system hdf5_hl hdf5 \
  opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

Also, make sure to rebuild!

OpenBLAS Errors

/usr/bin/ld: cannot find -lcblas
collect2: ld returned 1 exit status
make: *** [.build_release/lib/libcaffe.so] Error 1

This happens if you've not installed OpenBLAS properly, or if you've set
BLAS := open when you have only Atlas installed. It may sound silly, but 'to err is human'.

If it persists after rebuild, install Atlas instead and change to BLAS := atlas

@madhusshivakumar

This comment has been minimized.

Copy link

@madhusshivakumar madhusshivakumar commented Jul 4, 2017

WOW this was so useful thank u so much .

@Manoj-M-97

This comment has been minimized.

Copy link

@Manoj-M-97 Manoj-M-97 commented Jul 14, 2017

Thanks for the support.
There is a change in the above description.

sys.append('/Home/username/caffe/python')
This should be
sys.path.append('/Home/username/caffe/python')
Do update that.

@awaisrauf

This comment has been minimized.

Copy link

@awaisrauf awaisrauf commented Aug 17, 2017

Nicely written thing. Thanks a lot :)

@gilvanmaia

This comment has been minimized.

Copy link

@gilvanmaia gilvanmaia commented Jan 15, 2018

This worked like a charm. Thank you a lot!

If you may, let me point two little improvements:

  • if you downloaded Caffe to another directory, you can create a symbolic link using ln -s command. For example, go to your home directory in a terminal, then type ln -s ~/Downloads/caffe assuming caffe is in your Download folder. Once this is done, I got caffe installed at /home/gilva/caffe/python, then caffe got loaded correctly when I used export PYTHONPATH=/home/gilvan/caffe/python:$PYTHONPATH
  • if your system also missed the scikit-image Python binding, then an error ImportError: No module named skimage.io was shown when importing Caffe to python. Try installing the python-skimage package by typing the command sudo apt-get install python-skimage and it will be gone.
@JoseRubio15

This comment has been minimized.

Copy link

@JoseRubio15 JoseRubio15 commented Feb 11, 2018

Hello!

I have a problem with caffe installation. I follow all the steps but when I run the command 'make runtest' (in Caffe directory) I get some problems which I cannot solve:

jose@jose-IdeaPad-U330p:~/caffe$ make runtest
.build_release/tools/caffe
caffe: command line brew
usage: caffe

commands:
train train or finetune a model
test score a model
device_query show GPU diagnostic information
time benchmark model execution time

Flags from tools/caffe.cpp:
-gpu (Optional; run in GPU mode on given device IDs separated by ','.Use
'-gpu all' to run on all available GPUs. The effective training batch
size is multiplied by the number of devices.) type: string default: ""
-iterations (The number of iterations to run.) type: int32 default: 50
-level (Optional; network level.) type: int32 default: 0
-model (The model definition protocol buffer text file.) type: string
default: ""
-phase (Optional; network phase (TRAIN or TEST). Only used for 'time'.)
type: string default: ""
-sighup_effect (Optional; action to take when a SIGHUP signal is received:
snapshot, stop or none.) type: string default: "snapshot"
-sigint_effect (Optional; action to take when a SIGINT signal is received:
snapshot, stop or none.) type: string default: "stop"
-snapshot (Optional; the snapshot solver state to resume training.)
type: string default: ""
-solver (The solver definition protocol buffer text file.) type: string
default: ""
-stage (Optional; network stages (not to be confused with phase), separated
by ','.) type: string default: ""
-weights (Optional; the pretrained weights to initialize finetuning,
separated by ','. Cannot be set simultaneously with snapshot.)
type: string default: ""
.build_release/test/test_all.testbin 0 --gtest_shuffle
Cuda number of devices: 0
Setting to use device 0
Current device id: 0
Current device name:
Note: Randomizing tests' orders with a seed of 7068 .
[==========] Running 2063 tests from 271 test cases.
[----------] Global test environment set-up.
[----------] 2 tests from HDF5DataLayerTest/2, where TypeParam = caffe::GPUDevice
[ RUN ] HDF5DataLayerTest/2.TestRead
E0211 17:10:40.137262 22869 common.cpp:114] Cannot create Cublas handle. Cublas won't be available.
E0211 17:10:40.137725 22869 common.cpp:121] Cannot create Curand generator. Curand won't be available.
F0211 17:10:40.293733 22869 syncedmem.hpp:22] Check failed: error == cudaSuccess (35 vs. 0) CUDA driver version is insufficient for CUDA runtime version
*** Check failure stack trace: ***
@ 0x7f03d56e85cd google::LogMessage::Fail()
@ 0x7f03d56ea433 google::LogMessage::SendToLog()
@ 0x7f03d56e815b google::LogMessage::Flush()
@ 0x7f03d56eae1e google::LogMessageFatal::~LogMessageFatal()
@ 0x7f03d2e654f1 caffe::SyncedMemory::mutable_cpu_data()
@ 0x7f03d2e7c330 caffe::Blob<>::Reshape()
@ 0x7f03d2dfd820 caffe::hdf5_load_nd_dataset_helper<>()
@ 0x7f03d2dfb0a9 caffe::hdf5_load_nd_dataset<>()
@ 0x7f03d2f26833 caffe::HDF5DataLayer<>::LoadHDF5FileData()
@ 0x7f03d2f237f7 caffe::HDF5DataLayer<>::LayerSetUp()
@ 0x49f6a0 caffe::Layer<>::SetUp()
@ 0x593222 caffe::HDF5DataLayerTest_TestRead_Test<>::TestBody()
@ 0x8f6f43 testing::internal::HandleExceptionsInMethodIfSupported<>()
@ 0x8f055a testing::Test::Run()
@ 0x8f06a8 testing::TestInfo::Run()
@ 0x8f0785 testing::TestCase::Run()
@ 0x8f1a5f testing::internal::UnitTestImpl::RunAllTests()
@ 0x8f1d83 testing::UnitTest::Run()
@ 0x46899d main
@ 0x7f03d21a8830 __libc_start_main
@ 0x470099 _start
@ (nil) (unknown)
Makefile:532: fallo en las instrucciones para el objetivo 'runtest'
make: *** [runtest] Abortado (core dumped) [Núcleo vaciado a un archivo]

I have used python 2.4.9.1 and configure it using atlas. As there is some error, when I try to import caffe, I have the following problem:

Traceback (most recent call last):
File "", line 1, in
ImportError: No module named caffe

So, due to this, when I try to configure Cmake I get the following problem:

CMake Error at /usr/share/cmake-3.5/Modules/ExternalProject.cmake:1915 (message):
No download info given for 'openpose_caffe' and its source directory:

/home/jose/openpose/3rdparty/caffe

is not an existing non-empty directory. Please specify one of:

  • SOURCE_DIR with an existing non-empty directory
  • URL
  • GIT_REPOSITORY
  • HG_REPOSITORY
  • CVS_REPOSITORY and CVS_MODULE
  • SVN_REVISION
  • DOWNLOAD_COMMAND
    Call Stack (most recent call first):
    /usr/share/cmake-3.5/Modules/ExternalProject.cmake:2459 (_ep_add_download_command)
    CMakeLists.txt:391 (ExternalProject_Add)

captura de pantalla de 2018-02-11 17-17-05

Please some help, I don't know how to solve it and this is the last step to run Openpose! Thanks in advanced!!

@varteev

This comment has been minimized.

Copy link

@varteev varteev commented Feb 22, 2018

Thank you for that article!

@priyablue

This comment has been minimized.

Copy link

@priyablue priyablue commented Mar 7, 2018

hi, I am successfully done with all the commands listed, but in the last while checking using "import caffe" it says Import error: no module named caffe.

can you help me in encountering this error.

@thassanzadeh

This comment has been minimized.

Copy link

@thassanzadeh thassanzadeh commented Mar 7, 2018

Hi
I installed it successfully, after all when I import it by python3, it works but it can not find the caffe modules.
same as this:(try to import it with python3)
(caffe2) VirtualBox:~$ python3
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import caffe

but it can not find the caffe modules.
File "./t.py", line 9, in
caffe.set_mode_cpu()
AttributeError: module 'caffe' has no attribute 'set_mode_cpu'

@chickenrun525

This comment has been minimized.

Copy link

@chickenrun525 chickenrun525 commented Mar 14, 2018

Hi,

Thanks for sharing this. I have one comment want to let you know.
if you do it using "export PYTHONPATH=/Home/username/caffe/python:$PYTHONPATH", the path added will be something like "/home/username/Home/username/caffe/python". I think you can use "export PYTHONPATH=/username/caffe/python:$PYTHONPATH" instead.

@ray3110

This comment has been minimized.

Copy link

@ray3110 ray3110 commented Apr 25, 2018

Thanks for sharing. It saves me lot of time.

@martinbel

This comment has been minimized.

Copy link

@martinbel martinbel commented May 26, 2018

puff, after trying to install with anaconda this is the only way I could manage to install this.

@BalajiB197

This comment has been minimized.

Copy link

@BalajiB197 BalajiB197 commented Jun 13, 2018

usr/lib/x86_64-linux-gnu/libopencv_highgui.so: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0'
Makefile:620: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1
my opencv is 3.4.1 installed through condaforge

@rmaria

This comment has been minimized.

Copy link

@rmaria rmaria commented Jun 28, 2018

Hello Nikita,

I installed mxnet in a python virtualenv and now I want to install caffe. Everything works fine until I run:
make pycaffe

There I get an error:
Makefile:507: recipe for target 'python/caffe/_caffe.so' failed

Do you have any idea what is the problem? The Makefile.config looks like this (i took out the comments):

CPU_ONLY := 1
OPENCV_VERSION := 3

CUSTOM_CXX := g++

BLAS := atlas

PYTHON_LIBRARIES := boost_python3 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5
/usr/local/lib/python3.5/dist-packages/numpy/core/include/

PYTHON_LIB := /usr/lib

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

BUILD_DIR := build
DISTRIBUTE_DIR := distribute

TEST_GPUID := 0
Q ?= @

@void32

This comment has been minimized.

Copy link

@void32 void32 commented Jul 20, 2018

Hi Nikita
Thanks for this how to, very nice.

I found a this error in the export cmd:
export PYTHONPATH=~/Home/_username_/caffe/python:$PYTHONPATH
should be
export PYTHONPATH=/home/_username_/caffe/python:$PYTHONPATH

The ~ indicated home for current user.

Perhaps this even better:
export PYTHONPATH=/home/$USER/caffe/python:$PYTHONPATH
then you can just do a copy-and-paste?

@fdkssdks

This comment has been minimized.

Copy link

@fdkssdks fdkssdks commented Jul 24, 2018

I am getting the error when doing make pycaffe.

CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
/usr/bin/ld: cannot find -lboost_python3
collect2: error: ld returned 1 exit status
Makefile:507: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1

Caffe was build successfully w/ any error.

@akshayjaryal603

This comment has been minimized.

Copy link

@akshayjaryal603 akshayjaryal603 commented Jul 26, 2018

import caffe
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named caffe

This error show when I import caffe

@NgoThiTien

This comment has been minimized.

Copy link

@NgoThiTien NgoThiTien commented Sep 7, 2018

This error show When i install caffe:
make all
CXX .build_release/src/caffe/proto/caffe.pb.cc
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:0:
.build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
#error This file was generated by a newer version of protoc which is
^~~~~
.build_release/src/caffe/proto/caffe.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
#error incompatible with your Protocol Buffer headers. Please update
^~~~~
.build_release/src/caffe/proto/caffe.pb.h:14:2: error: #error your headers.
#error your headers.
^~~~~
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:0:
.build_release/src/caffe/proto/caffe.pb.h:25:10: fatal error: google/protobuf/generated_message_table_driven.h: No such file or directory
#include <google/protobuf/generated_message_table_driven.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:598: recipe for target '.build_release/src/caffe/proto/caffe.pb.o' failed
make: *** [.build_release/src/caffe/proto/caffe.pb.o] Error 1

@mbmamin1996

This comment has been minimized.

Copy link

@mbmamin1996 mbmamin1996 commented Oct 10, 2018

hi i run a code then i have this
Traceback (most recent call last):
File "test_spatial_narrow_as_op.py", line 16, in
from caffe2.proto import caffe2_pb2
ImportError: No module named caffe2.proto

i used python 2 and ubuntu 16

thanks for helping

@AshuMaths1729

This comment has been minimized.

Copy link

@AshuMaths1729 AshuMaths1729 commented Oct 12, 2018

Thanks a lot for this. I had been loitering around on the net for 2 days and then I found this.

@keerthanss

This comment has been minimized.

Copy link

@keerthanss keerthanss commented Nov 14, 2018

Thank you so much for this! It's very useful and saves a lot of time!

@rali20

This comment has been minimized.

Copy link

@rali20 rali20 commented Nov 22, 2018

PROTOC src/caffe/proto/caffe.proto
CXX src/caffe/blob.cpp
CXX src/caffe/data_transformer.cpp
CXX src/caffe/common.cpp
CXX src/caffe/internal_thread.cpp
In file included from ./include/caffe/blob.hpp:8:0,
from src/caffe/blob.cpp:4:
./include/caffe/common.hpp:5:10: fatal error: gflags/gflags.h: No such file or directory
#include <gflags/gflags.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
src/caffe/common.cpp:1:10: fatal error: glog/logging.h: No such file or directory
#include <glog/logging.h>
^~~~~~~~~~~~~~~~
compilation terminated.
Makefile:499: recipe for target '.build_release/src/caffe/blob.o' failed
make: *** [.build_release/src/caffe/blob.o] Error 1
make: *** Waiting for unfinished jobs....
Makefile:499: recipe for target '.build_release/src/caffe/common.o' failed
make: *** [.build_release/src/caffe/common.o] Error 1
In file included from ./include/caffe/blob.hpp:8:0,
from ./include/caffe/data_transformer.hpp:6,
from src/caffe/data_transformer.cpp:6:
./include/caffe/common.hpp:5:10: fatal error: gflags/gflags.h: No such file or directory
#include <gflags/gflags.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:499: recipe for target '.build_release/src/caffe/data_transformer.o' failed
make: *** [.build_release/src/caffe/data_transformer.o] Error 1
In file included from ./include/caffe/internal_thread.hpp:4:0,
from src/caffe/internal_thread.cpp:2:
./include/caffe/common.hpp:5:10: fatal error: gflags/gflags.h: No such file or directory
#include <gflags/gflags.h>
^~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:499: recipe for target '.build_release/src/caffe/internal_thread.o' failed
make: *** [.build_release/src/caffe/internal_thread.o] Error 1

@rali20

This comment has been minimized.

Copy link

@rali20 rali20 commented Nov 22, 2018

I am getting this error while building

@symisc

This comment has been minimized.

Copy link

@symisc symisc commented Nov 24, 2018

Before running make pycaffe, you shroud run on the directory where the caffe source reside:

sudo pip install -r ./python/requirements.txt

@nayanleo

This comment has been minimized.

Copy link

@nayanleo nayanleo commented Jan 8, 2019

hello all,

I am getting erros while runnning commnad : ~/caffe$ make all
getting error like:
CXX/LD -o .build_release/tools/caffe.bin
//home/vikram/anaconda3/lib/libpng16.so.16: undefined reference to `inflateValidate@ZLIB_1.2.9'
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1

can you please help me to resolve this problem,
thank you in advance.

@vijeshkpaei

This comment has been minimized.

Copy link

@vijeshkpaei vijeshkpaei commented Jan 16, 2019

surely open in python folder for checking caffe installed or not

ie,

open your terminal in caffe>>python
$python

import caffe

@vijeshkpaei

This comment has been minimized.

Copy link

@vijeshkpaei vijeshkpaei commented Jan 16, 2019

and all are pls check your opencv version and copy paste to Makefile.config file for make

Uncomment if you're using OpenCV 3

OPENCV_VERSION := 3.4.3

@Bhu69sh6an

This comment has been minimized.

Copy link

@Bhu69sh6an Bhu69sh6an commented Jan 22, 2019

hello all
i am getting errors while running ~/caffe$ make all
CXX src/caffe/layer_factory.cpp
In file included from ./include/caffe/common.hpp:19:0,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/layer.hpp:8,
from src/caffe/layer_factory.cpp:8:
./include/caffe/util/device_alternate.hpp:34:23: fatal error: cublas_v2.h: No such file or directory
compilation terminated.
Makefile:591: recipe for target '.build_release/src/caffe/layer_factory.o' failed
make: *** [.build_release/src/caffe/layer_factory.o] Error 1

can you please help me to resolve this problem,
thank you in advance.

@Bhu69sh6an

This comment has been minimized.

Copy link

@Bhu69sh6an Bhu69sh6an commented Jan 23, 2019

hello all
i am getting errors while running ~/caffe$ make all
CXX src/caffe/layer_factory.cpp
In file included from ./include/caffe/common.hpp:19:0,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/layer.hpp:8,
from src/caffe/layer_factory.cpp:8:
./include/caffe/util/device_alternate.hpp:34:23: fatal error: cublas_v2.h: No such file or directory
compilation terminated.
Makefile:591: recipe for target '.build_release/src/caffe/layer_factory.o' failed
make: *** [.build_release/src/caffe/layer_factory.o] Error 1

i have made the changes in the Makefile.config

can you please help me to resolve this problem,
thank you in advance.

@rivaldo4t

This comment has been minimized.

Copy link

@rivaldo4t rivaldo4t commented Mar 12, 2019

I got an ImportError: No module named google.protobuf.internal which was resolved by this
Also, for some implementations, you might stumble across Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python. To get rid of it, look here.

@ideallyworld

This comment has been minimized.

Copy link

@ideallyworld ideallyworld commented Mar 26, 2019

Hi,
I install in my ubutun 16.4 step by stepy and all is OK untill the make pycaffe and find a python folder within the caffe folder.

Then error come out when import caffe in python just as follow:

import caffe

root@ubuntu:/caffe/python# cd ..
root@ubuntu:
/caffe# ls
build cmake CONTRIBUTING.md data docker examples INSTALL.md Makefile Makefile.config.example models README.md src
caffe.cloc CMakeLists.txt CONTRIBUTORS.md distribute docs include LICENSE Makefile.config matlab python scripts tools
root@ubuntu:/caffe# export PYTHONPATH=/caffe/python:$PYTHONPATH
root@ubuntu:/caffe# import caffe
import: not authorized `caffe' @ error/constitute.c/WriteImage/1028.
root@ubuntu:
/caffe# python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import caffe
Traceback (most recent call last):
File "", line 1, in
File "/root/caffe/python/caffe/init.py", line 1, in
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/root/caffe/python/caffe/pycaffe.py", line 13, in
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
ImportError: No module named _caffe
sys.path
Traceback (most recent call last):
File "", line 1, in
NameError: name 'sys' is not defined
import sys
sys.path
['', '/root/caffe/python', '/root/caffe', '/opt/movidius/caffe/python', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
sys.path.append('/caffe/python')
File "", line 1
sys.path.append('/caffe/python')
^
IndentationError: unexpected indent
sys.path.append('/caffe/python')
import caffe
Traceback (most recent call last):
File "", line 1, in
File "/root/caffe/python/caffe/init.py", line 1, in
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/root/caffe/python/caffe/pycaffe.py", line 13, in
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
ImportError: No module named _caffe
import sys.path
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named path

Could someone please help me to fix this problem?

BRs,
Thanks.

@NguyenDangBinh

This comment has been minimized.

Copy link

@NguyenDangBinh NguyenDangBinh commented Apr 1, 2019

dear all.
I had issue like that:
(OpenSSL) binh@binh:~/3Dpose_ssl/caffe-3dssl$ make all
CXX src/caffe/solver.cpp
In file included from ./include/caffe/util/device_alternate.hpp:40:0,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/net.hpp:10,
from ./include/caffe/solver.hpp:7,
from src/caffe/solver.cpp:6:
./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’:
./include/caffe/util/cudnn.hpp:21:10: warning: enumeration value ‘CUDNN_STATUS_RUNTIME_PREREQUISITE_MISSING’ not handled in switch [-Wswitch]
switch (status) {
^
./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::setConvolutionDesc(cudnnConvolutionStruct**, cudnnTensorDescriptor_t, cudnnFilterDescriptor_t, int, int, int, int)’:
./include/caffe/util/cudnn.hpp:113:70: error: too few arguments to function ‘cudnnStatus_t cudnnSetConvolution2dDescriptor(cudnnConvolutionDescriptor_t, int, int, int, int, int, int, cudnnConvolutionMode_t, cudnnDataType_t)’
pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION));
^
./include/caffe/util/cudnn.hpp:15:28: note: in definition of macro ‘CUDNN_CHECK’
cudnnStatus_t status = condition;
^
In file included from ./include/caffe/util/cudnn.hpp:5:0,
from ./include/caffe/util/device_alternate.hpp:40,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/net.hpp:10,
from ./include/caffe/solver.hpp:7,
from src/caffe/solver.cpp:6:
/home/binh/anaconda2/envs/OpenSSL/include/cudnn.h:500:27: note: declared here
cudnnStatus_t CUDNNWINAPI cudnnSetConvolution2dDescriptor( cudnnConvolutionDescriptor_t convDesc,
^
Makefile:575: recipe for target '.build_release/src/caffe/solver.o' failed
make: *** [.build_release/src/caffe/solver.o] Error 1

How to solve? Thank you so much.

@NguyenDangBinh

This comment has been minimized.

Copy link

@NguyenDangBinh NguyenDangBinh commented Apr 1, 2019

dear all.
I had issue like that:
(OpenSSL) binh@binh:~/3Dpose_ssl/caffe-3dssl$ make all
CXX src/caffe/solver.cpp
In file included from ./include/caffe/util/device_alternate.hpp:40:0,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/net.hpp:10,
from ./include/caffe/solver.hpp:7,
from src/caffe/solver.cpp:6:
./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’:
./include/caffe/util/cudnn.hpp:21:10: warning: enumeration value ‘CUDNN_STATUS_RUNTIME_PREREQUISITE_MISSING’ not handled in switch [-Wswitch]
switch (status) {
^
./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::setConvolutionDesc(cudnnConvolutionStruct**, cudnnTensorDescriptor_t, cudnnFilterDescriptor_t, int, int, int, int)’:
./include/caffe/util/cudnn.hpp:113:70: error: too few arguments to function ‘cudnnStatus_t cudnnSetConvolution2dDescriptor(cudnnConvolutionDescriptor_t, int, int, int, int, int, int, cudnnConvolutionMode_t, cudnnDataType_t)’
pad_h, pad_w, stride_h, stride_w, 1, 1, CUDNN_CROSS_CORRELATION));
^
./include/caffe/util/cudnn.hpp:15:28: note: in definition of macro ‘CUDNN_CHECK’
cudnnStatus_t status = condition;
^
In file included from ./include/caffe/util/cudnn.hpp:5:0,
from ./include/caffe/util/device_alternate.hpp:40,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/net.hpp:10,
from ./include/caffe/solver.hpp:7,
from src/caffe/solver.cpp:6:
/home/binh/anaconda2/envs/OpenSSL/include/cudnn.h:500:27: note: declared here
cudnnStatus_t CUDNNWINAPI cudnnSetConvolution2dDescriptor( cudnnConvolutionDescriptor_t convDesc,
^
Makefile:575: recipe for target '.build_release/src/caffe/solver.o' failed
make: *** [.build_release/src/caffe/solver.o] Error 1

How to solve? Thank you so much.

@Kannank97

This comment has been minimized.

Copy link

@Kannank97 Kannank97 commented Apr 26, 2019

Hey, Thank you so much. This saved me a lot of time for my work

@ilyes-ouled-omar

This comment has been minimized.

Copy link

@ilyes-ouled-omar ilyes-ouled-omar commented Apr 30, 2019

Thank you!!!
It was really helpful :)

@ashikrai

This comment has been minimized.

Copy link

@ashikrai ashikrai commented Aug 9, 2019

I have followed all the given steps but im getting error on
make all

Error is given below, can anyone help me:

CXX .build_release/src/caffe/proto/caffe.pb.cc
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:0:
.build_release/src/caffe/proto/caffe.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
#error This file was generated by a newer version of protoc which is
^
.build_release/src/caffe/proto/caffe.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
#error incompatible with your Protocol Buffer headers. Please update
^
.build_release/src/caffe/proto/caffe.pb.h:14:2: error: #error your headers.
#error your headers.
^
In file included from .build_release/src/caffe/proto/caffe.pb.cc:4:0:
.build_release/src/caffe/proto/caffe.pb.h:23:35: fatal error: google/protobuf/arena.h: No such file or directory
compilation terminated.
Makefile:598: recipe for target '.build_release/src/caffe/proto/caffe.pb.o' failed
make: *** [.build_release/src/caffe/proto/caffe.pb.o] Error 1

@roni580

This comment has been minimized.

Copy link

@roni580 roni580 commented Oct 9, 2019

hi, I am successfully done with all the commands listed, but in the last while checking using "import caffe" it says Import error: no module named caffe.

can you help me in encountering this error.
import sys
caffe_root = '/home/nvidia/caffe/' # this file should be run from {caffe_root}/examples (otherwise change this line)
sys.path.insert(0, caffe_root + 'python')

import caffe
@Zrufy

This comment has been minimized.

Copy link

@Zrufy Zrufy commented Oct 24, 2019

unsupported GNU version! gcc versions later than 8 are not supported!

@ziggyjosh16

This comment has been minimized.

Copy link

@ziggyjosh16 ziggyjosh16 commented Dec 6, 2019

I'm wondering if it is possible to install caffe inside a conda environment

@roni580

This comment has been minimized.

Copy link

@roni580 roni580 commented Dec 6, 2019

@roni580

This comment has been minimized.

Copy link

@roni580 roni580 commented Dec 6, 2019

@Hassan313

This comment has been minimized.

Copy link

@Hassan313 Hassan313 commented Sep 5, 2020

Thank you very much. Really appreciate your work here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment