【深度学习】Caffe2安装 ubuntu16.04

本文提供了Caffe2在Ubuntu 16.04系统上的详细安装步骤,包括依赖库安装、代码下载、编译过程中常见问题及解决方案,适用于已安装CUDA、CUDNN和OPENCV的环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.介绍

一个轻量级的深度学习框架,商用项目上面貌似用的比较多,废话不多说,看看怎么装

2.安装

应为官网流程很详细,直接给出官网链接,针对一些有问题的地方给予补充(算了,我还是写一下)。我使用的平台式Ubuntu 16.04,CUDA ,CUDNN,OPENCV都已经装好

Caffe2官网

3.先安装依赖库

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

4. 下载代码

由于国内下载很慢,我将下好的代码上传到CSDN,后附链接

# Clone Caffe2's source code from our Github repository
git clone --recursive https://github.com/pytorch/pytorch.git && cd pytorch
git submodule update --init

5. 编译

# 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.
cmake ..
# Compile, link, and install Caffe2
sudo make install

6.编译时候遇到一个的问题

意思是说Eigen的版本太低了

这里写图片描述

#error "Caffe2 requires Eigen to be at least 3.3.0.";
#error "Caffe2 requires Eigen to be at least 3.3.0.";

解决办法:

1.首先检查自己的 Eigen 版本:
cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h | grep VERSION

我的是这个样子,版本低于3.3.0

EIGEN_WORLD_VERSION 3
EIGEN_MAJOR_VERSION 2
EIGEN_MINOR_VERSION 92
2.去下载高版本的Eigen

下载最github上的新版本的,不要下官网上的,项目已经迁移到github上面去了。

被墙下不了的点这个CSDN

如果下的是官网上的可能会下面的报错,应为cuda9需要高版本才能支持

usr/local/cuda-9.0/include/crt/common_functions.h:64:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                    ^
/usr/local/cuda-9.0/include/crt/common_functions.h:64:24: note: in definition of macro '__CUDACC_VER__'
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/cuda-9.0/include/crt/common_functions.h:64:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                    ^
/usr/local/cuda-9.0/include/crt/common_functions.h:64:24: note: in definition of macro '__CUDACC_VER__'
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."

然后解压,重命名为eigen3

3.移除旧的Eigen
cd /usr/include
sudo rm -rf eigen3/
4.移动我们下载加压好的Eigen到原来路径
sudo mv path/of/eigen3 /usr/include/
5.检查下载的 Eigen 版本:
 cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h | grep VERSION

我的是这个样子:

EIGEN_WORLD_VERSION 3
EIGEN_MAJOR_VERSION 3
EIGEN_MINOR_VERSION 90

然后可以继续回去重新编译了sudo make install

问题:

测试是否安装成功:

cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"

如果Failure

WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
WARNING:root:Debug message: /home/username/pytorch/build/caffe2/python/caffe2_pybind11_state_gpu.so: undefined symbol: _Py_ZeroStruct

CRITICAL:root:Cannot load caffe2.python. Error: /home/username/pytorch/build/caffe2/python/caffe2_pybind11_state.so: undefined symbol: _Py_ZeroStruct

/home/username/pytorch/build/caffe2/python/路径下执行下面命令

sudo ldconfig

再次执行测试

Success

更多问题可以去github上查找:https://github.com/caffe2/caffe2/labels/build

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

罗杰海贼团

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值