美文网首页
Ubuntu下Caffe安装

Ubuntu下Caffe安装

作者: sixfold_yuan | 来源:发表于2017-02-20 15:18 被阅读0次

简易方法

下载sh脚本文件Easy Install by@zeakey

只安装opencv:bash install-opencv.sh
安装caffe(cpu_only)+opencv:bash install-caffe.sh

如果安装GPU版本,则修改如下

#!/bin/bash
# install common deps
set -e
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake make
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install python-dev
# install OpenCV
if [[ "$(which opencv_version)" == '' ]]; then
    echo "Installing OpenCV ..."
    sudo bash install-opencv.sh
fi
# install python deps
if [[ "$(which pip)" == '' ]]; then
    # curl https://bootstrap.pypa.io/get-pip.py
    # alternative link for CN users
    curl http://zhaok-data.oss-cn-shanghai.aliyuncs.com/service/get-pip.py | sudo -H python
else
    sudo -H pip install --upgrade pip
fi
sudo -H pip install numpy scipy Cython
if [ ! -d /usr/lib/python2.7/dist-packages/numpy ]; then
    sudo ln -s /usr/local/lib/python2.7/dist-packages/numpy /usr/lib/python2.7/dist-packages/numpy
fi
echo '#numpy include path' >> ~/.bashrc
echo 'export CPATH=/usr/local/lib/python2.7/dist-packages/numpy/core/include:$CPP_INCLUDE_PATH' >> ~/.bashrc
echo 'export CPATH=/usr/local/lib/python2.7/dist-packages/numpy/core/include:$C_INCLUDE_PATH' >> ~/.bashrc
. ~/.bashrc
sudo apt-get install python-tk  # tkinter cannot install with pip
sudo -H pip install scikit-image scikit-learn
sudo -H pip install matplotlib
sudo -H pip install ipython jupyter
sudo -H pip install protobuf
sudo -H pip install h5py leveldb lmdb
sudo -H pip install networkx nose
sudo -H pip install pandas
sudo -H pip install python-dateutil
sudo -H pip install python-gflags pyyaml Pillow six pyzmq singledispatch
sudo -H pip install backports_abc certifi jsonschema graphviz  qtawesome pydot
# clone latest caffe source code
cd ~/ && git clone https://github.com/BVLC/caffe --depth 1 && cd caffe
mkdir build
cd build
cmake ..
make all
make install
make runtest
## some other cmake examples ##
# build with cuda, cudnn and nccl
# cmake -USE_NCCL=ON -DNCCL_INCLUDE_DIR=/pkg/nccl/include -DNCCL_LIBRARIES=/pkg/nccl/lib \
# -DCUDNN_INCLUDE=/usr/local/cudnn/include -DCUDNN_LIBRARY=/usr/local/cudnn/lib64 ..

echo "Done! Built caffe source at '~/caffe'"

# try caffe MNIST example:
# cd ~/caffe
# bash data/mnist/get_mnist.sh
# bash examples/mnist/create_mnist.sh
# bash examples/mnist/train_lenet.sh

次选方法

官网指引
注意:装Caffe前先安装OpenCV

OpenCV安装

下载opencv源码,opencv.zip和opencv_contirb.zip下载解压,放在根目录下
opencv官网

第一步:安装源码前先安装好需要的第三方环境

[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

第二步:使用cmake编译源码(包括opencv_contrib部分)

~$ cd opencv
~/opencv$ mkdir build
~/opencv$ cd build
~/opencv/build$ cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contirb/modules/ -D CMAKE_INSTALL_PREFIX=/usr/local ..
常见问题

解决方法:把需要的文件从百度网盘源码资料中替换到对应的目录(<opencv目录>/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz)重新编译

第三步:编译安装

make -j7
sudo make install
ls /usr/local/lib
sudo vim /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
/usr/local/lib

:wq!退出

sudo ldconfig

测试代码

vim test_opencv.cpp

:q!退出

g++ -o test_opencv test_opencv.cpp -lopencv_core -lopencv_highgui -lopencv_imgcodecs
./test_opencv
显示图片

Caffe选择Github上的主分支,下载解压到某个位置

General dependencies

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

BLAS

sudo apt-get install libatlas-base-dev

Remaining dependencies, 14.04

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

CMake Build

在caffe的根目录下

mkdir build
cd build
cmake ..
make all
make install
make runtest

如果是CPU模式,cmake ..加上

cmake -DCMAKE_BUILD_TYPE=Release -DCPU_ONLY=ON ..

-D表示参数定义


安装成功

相关文章

网友评论

      本文标题:Ubuntu下Caffe安装

      本文链接:https://www.haomeiwen.com/subject/rxlewttx.html