Skip to content

Instantly share code, notes, and snippets.

@juniorprincewang
Last active April 30, 2020 02:20
Show Gist options
  • Save juniorprincewang/8bb5c28267e9d153e1fe4e1633f5e191 to your computer and use it in GitHub Desktop.
Save juniorprincewang/8bb5c28267e9d153e1fe4e1633f5e191 to your computer and use it in GitHub Desktop.
Caffe installation steps in Ubuntu 16.04 or 18.04 with CUDA 9.1 & CUDA 10.0

cifar10

cd $CAFFE_ROOT
./data/cifar10/get_cifar10.sh
./examples/cifar10/create_cifar10.sh
./examples/cifar10/train_quick.sh

mnist

cd $CAFFE_ROOT
./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh
./examples/mnist/train_lenet.sh

Check failed: registry.count(type) == 1 (0 vs. 1) Unknown solver type: SGD (known types: )

重新编译即可。

make clean
make all -j8

caffe

prerequisites:

  • CUDA

  • boost > 1.5

sudo apt-get install libboost-all-dev
  • cuDNN

/sbin/ldconfig.real: /usr/local/cuda/lib64/libcudnn.so.7 is not a symbolic link

sudo ln -s libcudnn.so.7.1.3 libcudnn.so.7
sudo ln -s libcudnn.so.7 libcudnn.so
  • Atlas
sudo apt-get install libatlas-base-dev
  • OpenBLAS
sudo apt-get install libopenblas-dev

General Dependencies

如果不安装依赖包,会出现各种编译问题

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

fatal error: opencv2/core/core.hpp caffe framework installation
但是通过 sudo apt-get install libopencv-dev 安装的是 opencv 3 ,可以通过 dpkg -l | grep libopencv 得出来, 因此需要在 Makefile.config 中取消 OPENCV_VERSION=3 的注释。参见caffe fails with error undefined reference to cv::imread(cv::String const&, int)' and undefined reference to cv::imdecode(cv::_InputArray const&, int)

caffe

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

Makefile.config

cp Makefile.config.example Makefile.config

将 Makefile.config 中以下条目修改。

USE_CUDNN := 1
WITH_PYTHON_LAYER := 1
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 /usr/lib/x86_64-linux-gnu/hdf5/serial

For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.

build and test

make all -j8
make test -j8
make runtest -j8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment