Caffe (卷积神经网络框架) Convolutional Architecture for Fast Feature Embedding

  • Introduction
    Caffe (卷积神经网络框架)
    Caffe,全称Convolutional Architecture for Fast Feature Embedding。是一种常用的深度学习框架,主要应用在视频、图像处理方面的应用上。
    caffe是一个清晰,可读性高,快速的深度学习框架。作者是贾扬清,加州大学伯克利的ph.D,现就职于Facebook。caffe的官网是http://caffe.berkeleyvision.org/

http://caffe.berkeleyvision.org/

Caffe community:
https://groups.google.com/forum/#!forum/caffe-users

Caffe code:
https://github.com/BVLC/caffe

Following are the commands used:

#Install prerequisites for ubuntu16.04
sudo apt-get install libprotobuf-dev
sudo apt-get install libleveldb-dev
sudo apt-get install libsnappy-dev
sudo apt-get install libopencv-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install protobuf-compiler
sudo apt-get install libgflags-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install liblmdb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install --no-install-recommends libboost-all-dev
sudo make all
sudo make test
sudo make runtest
finally, 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-pip
sudo apt-get install gfortran
cd ~/caffe/python
for req in $(cat requirements.txt); do pip install $req; done
#reinstall dateutil if needed
sudo apt-get remove --auto-remove python-dateutil
sudo 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.whl
pip list | grep dateutil
make pycaffe
#check
python
import 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 https://blog.csdn.net/u010193446/article/details/53259294.
Another link https://www.linuxidc.com/Linux/2016-09/135034.htm seems to be helpful too (Try in another pc?)

Install prerequisites:
sudo apt-get install libprotobuf-dev
sudo apt-get install libleveldb-dev
sudo apt-get install libsnappy-dev
sudo apt-get install libopencv-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install protobuf-compiler
sudo apt-get install libgflags-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install liblmdb-dev
sudo apt-get install libatlas-base-dev

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

cd caffe
cp 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 all
PROTOC src/caffe/proto/caffe.proto
CXX .build_release/src/caffe/proto/caffe.pb.cc
CXX src/caffe/solver.cpp
src/caffe/solver.cpp:6:38: fatal error: boost/algorithm/string.hpp: No such file or directory
compilation terminated.
Makefile:581: recipe for target '.build_release/src/caffe/solver.o' failed
make: *** [.build_release/src/caffe/solver.o] Error 1

sudo apt-get install libboost-dev


sudo 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_thread
collect2: error: ld returned 1 exit status

sudo apt-get install --no-install-recommends libboost-all-dev


# continue to make
sudo make all
sudo make test
sudo make runtest

finally, following will be seen:
[----------] Global test environment tear-down
[==========] 1158 tests from 152 test cases ran. (41526 ms total)
[  PASSED  ] 1158 tests.



# python
sudo apt-get install python-pip
sudo apt-get install gfortran
#cat ./python/requirements.txt
cd ~/caffe/python
for req in $(cat requirements.txt); do pip install $req; done

sudo 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 pip
Requirement 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.txt
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

https://www.cnblogs.com/dylan9/p/8981155.html

cd /usr/bin
sudo vi pip
import re
import sys
from pip._internal import main as _main
if __name__ == '__main__':
  sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
  sys.exit(_main())

sudo pip install -r requirements.txt
then:
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 --upgrade


For Ubuntu:
uninstall python-dateutil and it's dependencies
sudo apt-get remove --auto-remove python-dateutil
purging your config/data too
sudo apt-get purge --auto-remove python-dateutil
reinstall it
#sudo apt-get install python-dateutil

Download 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 dateutil
python-dateutil                    2.7.3




:~/work/ai/opensource/caffe$ sudo pip install -r requirements.txt
The 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.txt
Could 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.txt
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
    from pip._internal import main as _main
ImportError: No module named _internal

An answer from askUbuntu works.
you can at first
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
then
python2.7 get-pip.py --force-reinstall
to reinstall pip.


#execute it again:
sudo -H pip install -r requirements.txt


:~/work/ai/opensource/caffe$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation 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/include

Then,
make pycaffe

Finally, 
"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”

https://blog.csdn.net/c406495762/article/details/70446385
https://blog.csdn.net/thystar/article/details/50470325
https://blog.csdn.net/c406495762/article/details/70306795
https://blog.csdn.net/light169/article/details/58135135
https://blog.csdn.net/column/details/15390.html
https://blog.csdn.net/qq_27923041/article/details/54139887
https://blog.csdn.net/cham_3/article/details/72141753

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值