极智AI | ubuntu cudnn8 源码编译caffe

​  本教程详细记录了cudnn7环境编译caffe(原生caffe要求的环境),与cudnn8环境编译caffe(潮流caffe要求的环境)的方法。


原生caffe源码编译(with cudnn7)

1、下载caffe包

​ 官方github网址:BVLC/caffe

​ 下载解压,将caffe-master重命名为caffe


2、安装依赖

sudo apt-get install libprotobuf-dev libleveldb-dev  libblas-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler 
sudo apt-get install --no-install-recommends libboost-all-dev 
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev 
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev 
sudo apt-get install git cmake build-essential 

3、编译配置

​  Step1:备份makefile.config

cp Makefile.config.example Makefile.config

Step2:根据自己的路径 对Makefile.config进行相应修改

# 设置cuda算力 
CUDA_ARCH := -gencode arch=compute_75,code=sm_75            

# 因为使用的是OpenCV3,所以需要取消注释  
# Uncomment if you're using OpenCV 3  
OPENCV_VERSION := 3    

# 设置CUDA路径,若编译CPU版,则需要打开CPU_ONLY选项  
# CUDA directory contains bin/ and lib/ directories that we need.  
CUDA_DIR := /usr/local/cuda    

# 设置Python头文件路径,主要是Python.h和numpy头文件  
# We need to be able to find Python.h and numpy/arrayobject.h.  
PYTHON_INCLUDE := /root/anaconda3/include \ 	 
				/root/anaconda3/include/python3.7m \ 	 
				/root/anaconda3/lib/python3.7/site-packages/numpy/core/include  
				
# 设置Python库目录  
# We need to be able to find libpythonX.X.so or .dylib.  
PYTHON_LIB := /root/anaconda3/lib    

# 设置其他依赖包的头文件路径和库目录  
# Whatever else you find you need goes here.  
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial /home/0_env/opencv/include LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial /home/0_env/opencv/lib                          
LIBRARIES += glog gflags protobuf leveldb snappy \ 	
			lmdb boost_system hdf5_hl hdf5 m\ 	
			opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs  

​  Step3:Makefile进行相应修改

 # 在LIBRARIES后添加 opencv_imgcodecs 
 LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs 

4、编译

make all -j8 
make test -j8 
make runtest -j8 
make pycaffe  # 编译python接口

vim ~/.bashrc 

# 加入如下,路径根据实际修改
export PYTHONPATH=$PYTHONPATH:/home/0_env/caffe/python 

source ~/.bashrc


潮流caffe源码编译(with cudnn8)

  原生的caffe只有在cudnn7.x的环境工作,从cuda11.x以来,开始替换到了cudnn8.x,所以想要让caffe继续work,需要改一些caffe的源码。

1、下载caffe-cudnn8包

  caffe-cudnn8 github网址:Jeremy-J-J/caffe-cudnn8


2、安装依赖 (如上)

sudo apt-get install libprotobuf-dev libleveldb-dev  libblas-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler 
sudo apt-get install --no-install-recommends libboost-all-dev 
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev 
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev 
sudo apt-get install git cmake build-essential 
sudo pip install graphviz

3、编译配置(如上)

  配置Makefile.config和Makefile的方法可参考上面的原生caffe的编译步骤。当然,我的github里放的代码是非常友好的,已经帮你都准备好了修改的文件,所以你要做的只是跳过这一步。


4、编译

make all -j8 
make test -j8 
make runtest -j8 
make pycaffe  # 编译python接口

vim ~/.bashrc 

# 加入如下,路径根据实际修改
export PYTHONPATH=$PYTHONPATH:/home/0_env/caffe/python 

source ~/.bashrc

  关于caffe-cudnn8的相关细节可以参考我github(Jeremy-J-J/caffe-cudnn8)里的README,欢迎 Star~

  收工~
  如果疑问或报错请联系我。



扫描下方二维码即可关注我的微信公众号【极智视界】,获取更多AI经验分享,让我们用极致+极客的心态来迎接AI !

你可能感兴趣的:(极智AI,caffe,ubuntu,cudnn,深度学习,github)