caffe环境搭建 踩坑历程

参考链接:https://www.cnblogs.com/go-better/p/7160615.html

操作系统:ubuntu 16.04

 

1.编写并执行,1_install_caffe_depends.sh:

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
4sudo apt-get install libatlas-base-dev
sudo apt-get install python-dev

#少了编译会报错:make all
#fatal error: cblas.h: No such file or directory
sudo apt-get install libblas-dev

#少了编译会报错:make all
#/usr/bin/ld: cannot find -lcblas
#/usr/bin/ld: cannot find -latlas

sudo apt-get install libatlas-base-dev

 

2.编写并执行,2_download_caffe.sh:

sudo apt-get install git
git clone https://github.com/BVLC/caffe.git

 

3.编写并执行,3_compile_caffe.sh:

cd caffe
#sudo test -e Makefile.config.example && echo Yes || echo No

echo Copy File Makefile.config...

#拷贝配置文件Makefile.config
sudo cp Makefile.config.example Makefile.config

echo Modifying Makefile.config...
#修改配置文件Makefile.config
sudo find . -name "Makefile.config" | xargs sed -i 's/# CPU_ONLY := 1/ CPU_ONLY := 1/g'
sudo find . -name "Makefile.config" | xargs sed -i 's/INCLUDE_DIRS := $(PYTHON_INCLUDE) \/usr\/local\/include/INCLUDE_DIRS := $(PYTHON_INCLUDE) \/usr\/local\/include \/usr\/include\/hdf5\/serial/g'
sudo find . -name "Makefile.config" | xargs sed -i 's/LIBRARY_DIRS := $(PYTHON_LIB) \/usr\/local\/lib \/usr\/lib/LIBRARY_DIRS := $(PYTHON_LIB) \/usr\/local\/lib \/usr\/lib \/usr\/lib\/x86_64-linux-gnu \/usr\/lib\/x86_64-linux-gnu\/hdf5\/serial/g'

echo make clean...
sudo make clean

echo make all...
sudo make all -j4

echo make test...
sudo make test -j4

echo make runtest...
sudo make runtest -j4

echo finish
 

4.编写并执行,4_compile_pycaffe.sh:

cd caffe

#报错:You are using pip version 8.1.1, however version 18.1 is available.
echo pip upgrade...
sudo pip install --upgrade pip

#安装somthing
echo preinstall pycaffe...
sudo apt-get install python-pip
sudo apt-get install gfortran

#make pycaffe报错:#fatal error: numpy/arrayobject.h
sudo apt-get install python-numpy

cd python

#备份requirements.txt
sudo test -e requirements_bak.txt && sudo cp requirements_bak.txt requirements.txt || sudo cp requirements.txt requirements_bak.txt

#报错:
#修改requirements.txt
#pandas 0.23.4 has requirement python-dateutil>=2.5.0, but you'll have python-dateutil 1.5 which is incompatible.
#matplotlib 2.2.3 has requirement python-dateutil>=2.1, but you'll have python-dateutil 1.5 which is incompatible.
#直接2.5.0
sudo find . -name "requirements.txt" | xargs sed -i 's/python-dateutil>=1.4,<2/python-dateutil==2.5.0/g'

#AttributeError: 'numpy.ufunc' object has no attribute '__module__'
#numpy版本问题,试了一些,直接1.14.5
sudo find . -name "requirements.txt" | xargs sed -i 's/numpy>=1.7.1/numpy==1.14.5/g'

#安装requirements.txt中的包
echo install pycaffe requirements...
sudo pip install -r requirements.txt

#回到caffe
cd ..

#compile pycaffe
echo make pycaffe...
sudo make pycaffe -j4

#添加路径
cat ~/.bashrc | grep "export PYTHONPATH=" && echo export PYTHONPATH exists || echo export PYTHONPATH=$(pwd)/python:'$'PYTHONPATH>>~/.bashrc
#pwd
#sudo gedit ~/.bashrc 
#sudo find . -name "~/.bashrc" | xargs sed -i 's/python-dateutil>=1.4,<2/python-dateutil==2.5.0/g'
#应用修改
source ~/.bashrc 

#回到脚本所在目录
cd ..
#test pycaffe
echo test pycaffe...
python test_pycaffe.py
echo finish

 

另外test_pycaffe.py内容:

import caffe

 

跑完不报错就成功了

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页