本文共 7714 字,大约阅读时间需要 25 分钟。
Caffe community:
Caffe code:
Following are the commands used:
#Install prerequisites for ubuntu16.04sudo apt-get install libprotobuf-devsudo apt-get install libleveldb-devsudo apt-get install libsnappy-devsudo apt-get install libopencv-devsudo apt-get install libhdf5-serial-devsudo apt-get install protobuf-compilersudo apt-get install libgflags-devsudo apt-get install libgoogle-glog-devsudo apt-get install liblmdb-devsudo apt-get install libatlas-base-devsudo apt-get install --no-install-recommends libboost-all-devsudo make allsudo make testsudo make runtestfinally, following will be seen:[----------] Global test environment tear-down[==========] 1158 tests from 152 test cases ran. (41526 ms total)[ PASSED ] 1158 tests.python caffe:sudo apt-get install python-pipsudo apt-get install gfortrancd ~/caffe/pythonfor req in $(cat requirements.txt); do pip install $req; done#reinstall dateutil if neededsudo apt-get remove --auto-remove python-dateutilsudo apt-get purge --auto-remove python-dateutil#Download python_dateutil-2.7.3-py2.py3-none-any.whl from https://pypi.org/project/python-dateutil/2.7.1/pip install python_dateutil-2.7.3-py2.py3-none-any.whlpip list | grep dateutilmake pycaffe#checkpythonimport caffe#if no error was reported, it has beened installed in python.
Following is the details when I tried to run caffe on ubuntu16.04.
It mainly follows . Another link seems to be helpful too (Try in another pc?)Install prerequisites:sudo apt-get install libprotobuf-devsudo apt-get install libleveldb-devsudo apt-get install libsnappy-devsudo apt-get install libopencv-devsudo apt-get install libhdf5-serial-devsudo apt-get install protobuf-compilersudo apt-get install libgflags-devsudo apt-get install libgoogle-glog-devsudo apt-get install liblmdb-devsudo apt-get install libatlas-base-devgit clone git://github.com/BVLC/caffe.gitcd caffecp Makefile.config.example Makefile.config#make following changes to Makefile.config :~/work/ai/opensource/caffe$ diff Makefile.config.example Makefile.config 8c8 < # CPU_ONLY := 1 --- > CPU_ONLY := 1 95,96c95,96 < INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include < LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/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:~/work/ai/opensource/caffe$ sudo make allPROTOC src/caffe/proto/caffe.protoCXX .build_release/src/caffe/proto/caffe.pb.ccCXX src/caffe/solver.cppsrc/caffe/solver.cpp:6:38: fatal error: boost/algorithm/string.hpp: No such file or directorycompilation terminated.Makefile:581: recipe for target '.build_release/src/caffe/solver.o' failedmake: *** [.build_release/src/caffe/solver.o] Error 1sudo apt-get install libboost-devsudo make all#following errors are seen:/usr/bin/ld: cannot find -lboost_system/usr/bin/ld: cannot find -lboost_filesystem/usr/bin/ld: cannot find -lboost_threadcollect2: error: ld returned 1 exit statussudo apt-get install --no-install-recommends libboost-all-dev# continue to makesudo make allsudo make testsudo make runtestfinally, following will be seen:[----------] Global test environment tear-down[==========] 1158 tests from 152 test cases ran. (41526 ms total)[ PASSED ] 1158 tests.# pythonsudo apt-get install python-pipsudo apt-get install gfortran#cat ./python/requirements.txtcd ~/caffe/pythonfor req in $(cat requirements.txt); do pip install $req; donesudo pip install -r requirements.txt#安装成功的,都会显示Requirement already satisfied,没安装成功的,会继续进行安装Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-zu_pEe/ipython/You are using pip version 8.1.1, however version 10.0.1 is available.You should consider upgrading via the 'pip install --upgrade pip' command.pip install --upgrade pipRequirement already up-to-date: pip in /home/csr/.local/lib/python2.7/site-packages (10.0.1):~/work/ai/opensource/caffe/python$ sudo pip install -r requirements.txtTraceback (most recent call last): File "/usr/bin/pip", line 9, infrom pip import mainImportError: cannot import name mainhttps://www.cnblogs.com/dylan9/p/8981155.htmlcd /usr/binsudo vi pipimport reimport sysfrom pip._internal import main as _mainif __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(_main())sudo pip install -r requirements.txtthen:pandas 0.23.0 has requirement python-dateutil>=2.5.0, but you'll have python-dateutil 1.5 which is incompatible.matplotlib 2.2.2 has requirement python-dateutil>=2.1, but you'll have python-dateutil 1.5 which is incompatible.sudo pip install python-dateutil --upgradeFor Ubuntu:uninstall python-dateutil and it's dependenciessudo apt-get remove --auto-remove python-dateutilpurging your config/data toosudo apt-get purge --auto-remove python-dateutilreinstall it#sudo apt-get install python-dateutilDownload python_dateutil-2.7.3-py2.py3-none-any.whl from https://pypi.org/project/python-dateutil/2.7.1/sudo -H pip install python_dateutil-2.7.3-py2.py3-none-any.whl:~/work/ai/opensource/caffe$ pip list | grep dateutilpython-dateutil 2.7.3:~/work/ai/opensource/caffe$ sudo pip install -r requirements.txtThe directory '/home/csr/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.The directory '/home/csr/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt':~/work/ai/opensource/caffe$ pip install -r requirements.txtCould not open requirements file: [Errno 2] No such file or directory: 'requirements.txt':~/work/ai/opensource/caffe$:~/work/ai/opensource/caffe$ sudo -H pip install -r requirements.txtTraceback (most recent call last): File "/usr/bin/pip", line 7, in from pip._internal import main as _mainImportError: No module named _internalAn answer from askUbuntu works.you can at firstcurl https://bootstrap.pypa.io/get-pip.py -o get-pip.pythenpython2.7 get-pip.py --force-reinstallto reinstall pip.#execute it again:sudo -H pip install -r requirements.txt:~/work/ai/opensource/caffe$ make pycaffeCXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpppython/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directorycompilation terminated.Change as following:--- a/Makefile.config+++ b/Makefile.config@@ -67,7 +67,7 @@ BLAS := atlas # NOTE: this is required only if you will compile the python interface. # We need to be able to find Python.h and numpy/arrayobject.h. PYTHON_INCLUDE := /usr/include/python2.7 \- /usr/lib/python2.7/dist-packages/numpy/core/include+ /usr/local/lib/python2.7/dist-packages/numpy/core/includeThen,make pycaffeFinally, "import caffe" can be run in python.
./build/examples/cpp_classification/classification.bin \
examples/mnist/deploy.prototxt \ examples/mnist/lenet_iter_10000.caffemodel \ examples/mnist/mean.binaryproto \ examples/mnist/synset_words.txt \ examples/images/3.jpg ———- Prediction for examples/images/num_3.bmp ———- 1.0000 - “3” 0.0000 - “4” 0.0000 - “1” 0.0000 - “0” 0.0000 - “2”