1,创建anaconda3下面的虚拟环境:
conda create -n caffe2_py3 python=3.6
source activate caffe2_py
官网安装
ubuntu16.04.5 cuda9.0 cudnn7_7.1.4
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
git \
libgoogle-glog-dev \
libgtest-dev \
libiomp-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libopenmpi-dev \
libsnappy-dev \
libprotobuf-dev \
openmpi-bin \
openmpi-doc \
protobuf-compiler \
python-dev \
python-pip
pip install --user \
future \
numpy \
protobuf \
typing \
hypothesis
sudo apt-get install -y --no-install-recommends \
libgflags-dev \
cmake
git clone https://github.com/pytorch/pytorch.git && cd pytorch
git submodule update --init --recursive
python setup.py install
2,安装python需要的包
conda install -y future
conda install -y gflags
conda install -y leveldb
conda install -y mkl
conda install -y mkl-include
conda install -y numpy
conda install -y opencv
conda install -y protobuf
conda install -y six
conda install -y lmdb
conda install -y matplotlib
conda install -y flask
conda install -y graphviz
conda install -y hypothesis
conda install -y jupyter
conda install -y pydot
conda install -y pyyaml
conda install -y requests
conda install -y scikit-image
conda install -y scipy
conda install -y setuptools
conda install -y tornado
conda install -c menpo opencv3
conda install -y cython ipython h5py nose pandas protobuf
conda install -y spyder
3,下载caffe2 编译
cd ~
git clone --recursive https://github.com/pytorch/pytorch.git
cd pytorch
git submodule update --init
mkdir build && cd build
cmake -DCMAKE_PREFIX_PATH=~/anaconda3/envs/caffe2_py3 -DCMAKE_INSTALL_PREFIX=~/anaconda3/envs/caffe2_py3 -DUSE_NATIVE_ARCH=ON ..
make
caffe2的好处是: Makefile中会根据你的库进行make,省去了makefile.config的设置步骤。
make install
4,测试:
cd /home/xxxxx/Downloads/caffe/pytorch/build
1)python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
2)执行 python
import caffe2.python.core #导入这个包,看看是否成功,如果没报错,就OK了。