centos7自带python2.7,建议不要采用python3.4+,踩了好多坑。。。用自带的2.7很简单。
一定要先安装 epel-release!,因为这个权威的yum源会帮你找到很多包,装起来就简单了。
1、TensorFlow
tf安装很容易,其实按照官网装就可以,但是总有人不愿意看官网。。
我安装的是tf1.2,稳定版,基于virtualenv(可以创建一个独立的python环境)
安装步骤(我是root。。。):
yum install python-pip python-dev python-virtualenv
virtualenv --system-site-packages tensorflow (最后这个tensorflow指的你想存放的路径,我就放在~/这个下面了)
source ~/tensorflow/bin/activate (每次使用tf都要执行这句话!)
pip install --upgrade tensorflow==1.2(指定版本,只是cpu,如果是gpu模式。则执行pip install --upgrade tensorflow-gpu)
安装完毕,,,这个过程我没遇到什么错误。。。接下来测试
先执行
source ~/tensorflow/bin/activate
运行你的程序。。
当你不使用tf就执行deactivate ,game over。
2、caffe
yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel (如果你没有安装epel-release,会提示找不到leveldb-devel和hdf5-devel)
yum install gflags-devel glog-devel lmdb-devel (如果你没有安装epel-release,会提示找不到这三个包,惊喜不惊喜。。节省好多时间)
yum install atlas-devel
然后下载caffe源码
git clone https://github.com/BVLC/caffe.git
cp Makefile.config.example Makefile.config
然后修改Makefile.config,别着急,慢慢来,
我这里把CPU_ONLY=1前面的注释删掉,把与GPU和CUDA有关的全都注释掉,写明atlas相关地址,我的是:
BLAS_INCLUDE := /usr/include/atlas
BLAS_LIB := /usr/lib64/atlas
我的opencv是2.4.5, 所以要将USE_OPENCV := 1前面的注释删掉(默认选择3.0+)
然后make all
make test
make runtest
make pycaffe
这个过程会遇到错误,因机器环境而异
我遇到
错误1:LD -o .build_release/lib/libcaffe.so.1.0.0
/bin/ld: cannot find -lcblas
/bin/ld: cannot find -latlas
collect2: error: ld returned 1 exit status
make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1
解决办法:先确定Makefile.config里面是否有配置了 BLAS_LIB 和BLAS_INCLUDE ,去掉前面的#号。如果还是有这个问题是因为 ATLAS现在的名称变了,要新建一下软连
ln -sv libsatlas.so.3.10 libcblas.so
ln -sv libsatlas.so.3.10 libatlas.so
错误2:还遇到了ImportError: No module named google.protobuf.internal
解决办法:pip install protobuf
错误3:ImportError: No module named caffe
解决办法:在~/.bashrc中添加export PYTHONPATH=~/caffe/python:$PYTHONPATH,然后source ~/.bashrc (其实在脚本中sys.path.insert(0, caffe_root + 'python')就可以,但如果你想在python环境中,就要像刚才那样添加)
测试http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb
这个例子,发现图像不能显示,因为我是用XShell链接测试机的,先下载X-ming,然后设置Xshell属性-》隧道-》选择X-DISPLAY,记得将/etc/ssh/sshd_config中UseLogin no和X11Forwarding yes前面的#删除。