参考链接:https://blog.youkuaiyun.com/u014525760/article/details/79862218
https://blog.youkuaiyun.com/weixin_37251044/article/details/82259230
这里我使用系统自带的python2.7对于caffe2进行安装,因为
系统自带的python2.7的环境变量设置:
alias python='/usr/bin/python2.7'
cmake要大于等于3.5,protobuf的版本需要时2.6.1,太高不支持
最后的环境变量需要设置为:
#这个需要注意:在环境变量当中只能有一个PYTHONPATH,多了的需要注释掉
export PYTHONPATH=pytorch根目录/build:$PYTHONPATH
一,依赖项安装
-
sudo apt-get update
-
sudo apt-get install -y --no-install-recommends \
-
build-essential \
-
cmake \
-
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
-
sudo pip install \
-
future \
-
numpy \
-
protobuf
Note libgflags2
is for Ubuntu 14.04. libgflags-dev
is for Ubuntu 16.04.
-
# for Ubuntu 14.04
-
sudo apt-get install -y --no-install-recommends libgflags2
-
# for Ubuntu 16.04
-
sudo apt-get install -y --no-install-recommends libgflags-dev
二,caffe2安装
-
# Clone Caffe2's source code from our Github repository
-
git clone --recursive https://github.com/pytorch/pytorch.git && cd pytorch
-
git submodule update --init
-
# Create a directory to put Caffe2's build files in
-
mkdir build && cd build
-
# Configure Caffe2's build
-
# This looks for packages on your machine and figures out which functionality
-
# to include in the Caffe2 installation. The output of this command is very
-
# useful in debugging.
-
#指定python路径
-
sudo cmake .. -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DUSE_MPI=OFF.
-
# Compile, link, and install Caffe2
-
sudo make install
三,测试
cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
If this fails, then get a better error message by running Python in your home directory and then running from caffe2.python import core
inside Python.
If this fails with a message about not finding caffe2.python or not finding libcaffe2.so, please see this info on how Caffe2 installs in Python.
If you installed with GPU support, test that the GPU build was a success with this command (run from the top level pytorch directory). You will get a test output either way, but it will warn you at the top of the output if CPU was used instead of GPU, along with other errors such as missing libraries.
python caffe2/python/operator_test/relu_op_test.py
错误总结
1), #error "Caffe2 requires Eigen to be at least 3.3.0.";
The solution is:
- Check the Eigen version with:
cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h | grep VERSION
- It will show some version variable values like below:
EIGEN_WORLD_VERSION 3
EIGEN_MAJOR_VERSION 2
EIGEN_MINOR_VERSION 192
These values are telling your problem directly. Your Eigen version is 3.2.192 instead of 3.3.0. So we need to upgrade this package.
-
Install the latest version of eigen from http://eigen.tuxfamily.org/index.php?title=Main_Page .
-
Extract the file wherever you want and rename it to
eigen3
. -
cd /usr/include
-
sudo rm -rf eigen3/
-
Place the file you just extracted with
sudo mv path/of/eigen3 /usr/include/
-
Lastly check the version again with
cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h | grep VERSION
You should see these variables:
EIGEN_WORLD_VERSION 3
EIGEN_MAJOR_VERSION 3
EIGEN_MINOR_VERSION 4
You can run sudo make install
again in the caffe2
directory and you will see that everything will be installed succesfully!