caffe 安装

环境:

基于OpenCV3.4,Anaconda python3.7,cuda11.1。

安装库

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libatlas-base-dev libboost-all-dev libgflags-dev libgoogle-glog-dev liblmdb-dev

修改Makefile.config

这里只显示未注释部分,如下所示:

USE_CUDNN := 1
USE_OPENCV := 1
USE_LEVELDB := 1
USE_LMDB := 1
USE_HDF5 := 1
OPENCV_VERSION := 3
CUDA_DIR := /usr/local/cuda
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
		-gencode arch=compute_35,code=sm_35 \
		-gencode arch=compute_50,code=sm_50 \
		-gencode arch=compute_52,code=sm_52 \
		-gencode arch=compute_60,code=sm_60 \
		-gencode arch=compute_61,code=sm_61 \
		-gencode arch=compute_61,code=compute_61
BLAS := atlas
ANACONDA_HOME := /opt/conda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		 $(ANACONDA_HOME)/include/python3.7m \
		 $(ANACONDA_HOME)/lib/python3.7/site-packages/numpy/core/include
PYTHON_LIBRARIES := boost_python3 python3.6m
PYTHON_LIB := $(ANACONDA_HOME)/lib
WITH_PYTHON_LAYER := 1
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial 

#如发现conda中的lib库与系统安装库存在冲突,可以去掉下面的$(PYTHON_LIB) 
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial 
USE_NCCL := 1
USE_PKG_CONFIG := 1
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
TEST_GPUID := 0
Q ?= @

修改Makefile

将
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m
替换为
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

将
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
替换为
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)

修改CMakeLists.txt

添加如下信息:

# ---[ Includes
set(${CMAKE_CXX_FLAGS} "-D_FORCE_INLINES ${CMAKE_CXX_FLAGS}")

编译caffe

make all -j $(($(nproc) + 1))
make pycaffe

添加pycaffe路径

vim ~/.bashrc

添加如下:

export PYTHONPATH=/path/to/caffe-master/python:$PYTHONPATH

保存后执行如下更新:

source ~/.bashrc

参考资料

https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-Installation-Guide

你可能感兴趣的:(Ubuntu,深度学习,人工智能,caffe)