1. Caffe 安装

1.1. Step 1 - CUDA安装

要结合使用 Caffe 和 NVIDIA GPU,需要安装 CUDA 工具包

1.2. Step 2 - cuDNN 安装

[1] - 下载适用于Linux的cuDNN库,这里需要注册加速计算开发人员计划;

[2] - 下载后,解压缩文件并将其复制到CUDA目录, 以cuDNN v5.1 为例:

tar zvxf  cudnn-8.0-linux-x64-v5.1.tgz 
cd cuda/
sudo cp lib64/lib* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/

[3] - 建立软链接,并更新:

cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5
sudo ln -s libcudnn.so.5.1.10 libcudnn.so.5
sudo ln -s libcudnn.so.5 libcudnn.so
sudo ldconfig -v

注:cuDNN在很多工程中兼容性较差,可能需要安装特定的历史版本,只需对如上命令中的版本进行修改.
查看caffe 是否成功使用cuDNN v5:

ldd ./build/tools/caffe.bin  | grep cudnn

1.3. Step 3 - 安装依赖项

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev 
sudo apt-get install protobuf-compiler git 
sudo apt-get install --no-install-recommends libboost-all-dev 
sudo apt-get install libatlas-base-dev # 安装 ATLAS
sudo apt-get install libopenblas-dev # 安装OpenBLAS
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

1.4. Step 4 - 安装 NCCL库

多GPUs进行并行计算,Caffe自带实现.

在多个 GPU 上运行 Caffe 需要使用 NVIDIA NCCL.

git clone https://github.com/NVIDIA/nccl.git
cd nccl
sudo make install -j4
sudo ldconfig

NCCL 库和文件头将安装在 /usr/local/lib/usr/local/include 中.
NCCL主要是为了加速在多GPU环境,同时用多块GPU做training的时候,它做出一个同步,或者说 Reduction 时候,加速 collective的过程。
它的最核心思想是什么呢?在做数据传输的时候,把大块数据切成小块,同时利用系统里面的多条链路,比如现在是PCI-E链路,同时利用PCI-E的上行和下行,尽量去避免不同的数据同时用某一个上行或者下行通道,可能会造成数据的contention,大大降低传输效率.

1.5. Step 5 - 编译Caffe

[1] - 下载 Caffe

git clone https://github.com/BVLC/caffe.git
cd caffe/
cp Makefile.config.example Makefile.config

[2] - 编辑 Makefile.config,进行修改:

取消 USE_CUDNN := 1 的注释,启用 cuDNN 加速;
取消 USE_NCCL := 1 的注释,启用在多个 GPU 上运行 Caffe 所需的 NCCL 库

[3] - 编译安装 Caffe

make all -j8
make test -j8
make pycaffe  # python API 
make matcaffe # matlab API,需定义matlab路径

完成安装,即可在 build/tools/caffe 中获得 Caffe 二进制文件.

1.6. 查看 Caffe 库版本信息

ldd build/tools/caffe # 查看所有的库
ldd build/tools/caffe | grep cudnn # 查看cudnn 版本信息
ldd build/tools/caffe | grep openblas # 查看 openblas 库信息

2. Caffe 实例测试

2.1. Step1 - 准备图像数据库

测试 Caffe 的训练性能需要使用图像数据库作为输入资源.

Caffe 自带多个模型,可使用来自 ILSVRC12 挑战赛(“ImageNet”)的图像.
原始图像文件可从 http://image-net.org/download-images 下载(将需要开通帐户并同意其条款.)
下载原始图像文件并解压,假设原始图像存储方式如下:

/path/to/imagenet/train/n01440764/n01440764_10026.JPEG
/path/to/imagenet/val/ILSVRC2012_val_00000001.JPEG

2.2. Step2 - 下载辅助数据

 ./data/ilsvrc12/get_ilsvrc_aux.sh

2.3. Step3 - 创建数据集

#更改 examples/imagenet/create_imagenet.sh 脚本中的 TRAIN_DATA_ROOT 和 VAL_DATA_ROOT 为解压后的原始图像路径
#设置 RESIZE=true 以便在将图像添加到数据库之前将其调整到适当大小
#创建图像数据库
./examples/imagenet/create_imagenet.sh
创建所需的图像均值文件
./examples/imagenet/make_imagenet_mean.sh

2.4. 训练模型

编辑 models/bvlc_alexnet/solver.prototxt 文件
./build/tools/caffe train –solver=models/bvlc_alexnet/solver.prototxt –gpu 0
#可以通过指定多个设备 ID(例如 0、1、2、3)或,
#指定“-gpu all”以使用系统中所有可用的 GPU,在多个 GPU 上进行训练. 

3. 问题及解决

3.1. 问题1 - python 库相关项安装

sudo apt-get install python-numpy \
                     python-scipy \
                     python-matplotlib \
                     python-sklearn \
                     python-skimage \
                     python-h5py \
                     python-protobuf \
                     python-leveldb \
                     python-networkx \
                     python-nose \
                     python-pandas \
                     python-gflags \
                     Cython \
                     ipython 
sudo apt-get install python-pip wget
sudo pip install ipython --upgrade # 升级 pip 安装的 python 库

也可以采用 pip install 安装 Python 相关库,如:

sudo pip install ipython matplotlib numpy 

3.2. 问题2 - No module named lmdb

sudo apt-get install liblmdb-dev
# 或
sudo pip install lmdb

3.3. 问题3 - No module named cv2

sudo conda install opencv #  for Anaconda 
# 或
sudo apt-get install python-opencv
# 或
sudo pip install opencv-python

3.4. 问题4 - can not find module skimage.io

sudo apt-get install python-skimage 
# 或
sudo pip install scikit-image

3.5. 问题5 - No module named _caffe

# 设置环境变量
sudo  gedit /etc/profile
# 添加环境变量:
    export PYTHONPATH=${HOME}/caffe-master/distribute/python:$PYTHONPATH
    export LD_LIBRARY_PATH=${HOME}/caffe-master/build/lib:$LD_LIBRARY_PATH
source /etc/profile # 使环境变量生效
echo $<环境变量名>  # 查看环境变量

3.6. 问题6 - Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python

或者出现的错误是:

_caffe.so: undefined symbol: _ZN5caffe4mtx_E
Uncomment to support layers written in Python (will link against Python libs)

打开caffe目录下的 Makefile.config 文件,找到 WITH_PYTHON_LAYER := 1这一行,将前面的#去掉,重新编译.

3.7. 问题7 - No module named easydict

sudo pip install easydict

3.8. 问题8 - ImportError: No module named google.protobuf错误

下载 protobuf:

wget  https://code.google.com/p/protobuf/wiki/Download?tm=2

解压缩文件,并进入文件夹,编译安装:

./configure
make
make check
make install
./configure 
make 
cd python
python setup.py test 
python setup.py install

引用1:http://code.google.com/p/protobuf/issues/detail?id=235
引用2:http://blog.csdn.net/qinglu000/article/details/17242011

3.9. 问题9 - ImportError: No module named google.protobuf.internal

sudo apt-get install python-protobuf
# 或
使用新立得软件包搜索“python-protobuf”安装
# 或
手工编译

手工编译:

# 下载protobuf-2.5.0:  
wget http://protobuf.googlecode.com/files/protobuf-2.5.0.zip
unzip protobuf-2.5.0
cd protobuf-2.5.0
chmod 777 configure
./configure
make -j4
make check -j4
make install    

# 编译python接口   
cd ./python 
python setup.py build 
python setup.py test 
python setup.py install
protoc -version  # 验证使用命令 

>>> import google.protobuf

3.10. 问题10 - “fatal error: hdf5.h: 没有那个文件或目录”

[1] - Step 1: 在Makefile.config 文件的第85行,添加 /usr/include/hdf5/serial/INCLUDE_DIRS,也就是把下面第一行代码改为第二行代码:

# 修改前:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include

# 修改后:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

[2] - Step 2: 在Makefile文件的第173行,把 hdf5_hlhdf5修改为hdf5_serial_hlhdf5_serial,也就是把下面第一行代码改为第二行代码

# 修改前:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
# 修改后:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

3.11. 问题11 - nccl.hpp:5:18: fatal error: nccl.h: No such file or directory

# 在多个 GPU 上运行 Caffe 需要使用 NVIDIA NCCL
git clone https://github.com/NVIDIA/nccl.git
cd nccl
sudo make install -j4
# NCCL 库和文件头将安装在 /usr/local/lib 和 /usr/local/include 中
sudo  ldconfig 
# 该命令不执行会出现错误: 
#  error while loading shared libraries: 
#  libnccl.so.1: cannot open shared object file: No such file or directory 

3.12. 问题12 - No module named google.prototxt

sudo apt-get install python-protobuf
# 或   
可以先下载安装包,自行编译和安装

可参考:http://blog.csdn.net/paynetiger/article/details/8197326
建议使用第一种方法,下面是关键:
如果使用Anaconda,而以上两种方法无论哪一种都会将prototxt相关文件安装到/usr/local/lib/python2.7/dist-packages, 需要将相关文件复制到Anaconda/lib/python2.7/site-packages下,才能正常使用.

3.13. 问题13 - No module named pydot

sudo apt-get install graphviz # 安装graphviz
sudo pip install pydot # 安装pydot

如果使用Anaconda,需要将相关文件从/usr/local/lib/python2.7/dist-packages复制到Anaconda/lib/python2.7/site-packages下.

3.14. 问题14 - ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory (CUDA7.5)

sudo ldconfig /usr/local/cuda/lib64
sudo ldconfig /usr/local/cuda-7.5/lib64

3.15. 问题15 - Failed to compile cuda_ndarray.cu: libcublas.so.7.5: cannot open shared object file(CUDA7.5)

sudo ldconfig /usr/local/cuda-7.5/lib64

3.16. 问题16 - libcudart.so.7.5 cannot open shared object file: No such file or directory(CUDA7.5)

# 检查环境变量设置  
echo $PATH
echo $LD_LIBRARY_PATH 
# 将一些文件复制到/usr/local/lib文件夹下:
sudo cp /usr/local/cuda-7.5/lib64/libcudart.so.7.5 /usr/local/lib/libcudart.so.7.5 && sudo ldconfig
sudo cp /usr/local/cuda-7.5/lib64/libcublas.so.7.5 /usr/local/lib/libcublas.so.7.5 && sudo ldconfig
sudo cp /usr/local/cuda-7.5/lib64/libcurand.so.7.5 /usr/local/lib/libcurand.so.7.5 && sudo ldconfig

3.17. 问题17 - ImportError: No module named caffe

可能是 caffe 库路径问题:

import sys
sys.path.append("/path/to/caffe-master/python")
sys.path.append("/path/to/caffe-master/python/caffe")
import caffe

import sys
sys.path.insert(0,caffe_root+'python)
import caffe

3.18. 问题18 - ImportError-No module named yaml

sudo apt-get install python-yaml
# 或源码安装,如 PyYAML 3.11 :
wget http://pyyaml.org/download/pyyaml/PyYAML-3.11.tar.gz 
tar -zxvf PyYAML-3.11.tar.gz  
python setup.py install

3.19. 问题19 - autoreconf:not found

sudo apt-get install automake autoconf libtool

3.20. 问题20 - W- GPG error- http--archive-ubuntukylin-com

sudo apt-get update
# 出现错误 - W: GPG error: http://archive.ubuntukylin.com:10006 xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8D5A09DC9B929006
# 是密钥的问题,解决办法:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8D5A09DC9B929006
# 注意提示的密钥和你上述命令中的密钥是一样的,每个人的电脑都不一样

3.21. 问题21 - ImportError--usr-lib-liblapack.so.3- undefined symbol- ATL_chemv

This issue arises when you have libopenblas-base and libatlas3-base installed, but don't have liblapack3 installed. This combination of packages installs conflicting versions of libblas.so (from OpenBLAS) and liblapack.so (from ATLAS).

[1] - Solution 1 (my favorite): You can keep both OpenBLAS and ATLAS on your machine if you also install liblapack3.

sudo apt-get install liblapack3

[2] - Solution 2: Uninstall ATLAS (this will actually install liblapack3 for you automatically because of some deb package shenanigans)

sudo apt-get uninstall libatlas3-base

[3] - Solution 3: Uninstall OpenBLAS

sudo apt-get uninstall libopenblas-base

Bad configuration

dpkg -l | grep 'openblas\|atlas\|lapack'

输出如:

#ii  libatlas3-base 3.10.1-4 amd64 Automatically Tuned #Linear Algebra Software, generic shared
#liblapack.so.3 auto  /usr/lib/atlas-base/atlas/liblapack.so.3
python -c 'import numpy'

出现:

#Traceback (most recent call last):
#  File "<string>", line 1, in <module>
#  File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
#    from . import add_newdocs
#  File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
#    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.py", line 19, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/__init__.py", line 50, in <module>
    from .linalg import *
  File "/usr/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: /usr/lib/liblapack.so.3: undefined symbol: ATL_chemv
dpkg -l | grep 'openblas\|atlas\|lapack'

输出如:

#ii  libatlas3-base                                        3.10.1-4                                            amd64        Automatically Tuned Linear Algebra Software, generic shared
#ii  liblapack3                                            3.5.0-2ubuntu1                                      amd64        Library of linear algebra routines 3 - shared version
#ii  libopenblas-base                                      0.2.8-6ubuntu1                                      amd64        Optimized BLAS (linear algebra) library based on GotoBLAS2
update-alternatives --get-selections | grep 'blas\|lapack'

输出如:

#libblas.so.3                   auto     /usr/lib/openblas-base/libblas.so.3
#liblapack.so.3                 auto     /usr/lib/lapack/liblapack.so.3

测试:

python -c 'import numpy'

3.22. 问题22 - ubuntu常见错误--Could not get lock

# 通过终端安装程序sudo apt-get install xxx时出错:
#  E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
#  E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it
# 出现这个问题可能是有另外一个程序正在运行,导致资源被锁不可用。而导致资源被锁的原因可能是上次运行安装或更新时没有正常完成,进而出现此状况,解决的办法:
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

3.23. 问题23 - Ubuntu服务器的NVIDIA驱动自动更新所引起的问题及解决方法

问题描述:
服务器为Ubuntu14.04,NVIDIA驱动由352.39自动升级到352.63,导致显卡不能使用,错误为:运行nvidia-smi指令,得到的信息为“Failed to initialize NVML: GPU access blocked by the operating sestem”
系统:Ubuntu14.04
cuda:7.5

解决方案
[1]. 首先关闭系统包括的所有更新

sudo vim /etc/apt/apt.conf.d/50unattended-upgrades
# (注释掉其中的更新部分)

参考链接:http://www.linuxdiyf.com/Linux/15997.html

[2]. 卸载cuda驱动并重新安装

# (1)彻底卸载
sudo apt-get remove --purge nvidia*
sudo apt-get autoremove
sudo apt-get clean
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 

参考链接:
<1> - https://devtalk.nvidia.com/default/topic/900899/cuda-setup-and-installation/unable-to-detect-cuda-capable-device-after-automatic-forced-nvidia-updated/
<2> - http://zhidao.baidu.com/link?url=smwXar3NPdAi1WxnZJ2_sARCEPoNcxLwB0RwmEnDPiqyrbdz64aVCoabN9azod-AQrJP0OjeiL8-y8mFRHZDma

# (2)重装cuda
sudo apt-get install gcc-4.7
cd /usr/bin
sudo mv gcc gcc.bak
sudo ln -s gcc-4.7 gcc
sudo mv g++ g++.bak
sudo ln -s g++-4.7 g++

由于之前系统Ubuntu14.04在配置好caffe环境后,编译matlab接口时将gcc由4.8降级为4.7. 若直接安装cuda,会提示错误,“Unable to find the kernel source tree for the currently running kernel. Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed.If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option.”.如果按照此条路径思索,在尝试添加了“--kernel-source-path”之后,仍存在问题。继续往下走,会提示给系统内核降级。
考虑到之前曾对系统的gcc降级,这导致了上述错误,对gcc升级。

参考链接:http://www.mamicode.com/info-detail-876185.html

然后按照常规方法重装cuda驱动即可解决问题。

转自: http://blog.csdn.net/u012494820/article/details/52289095

3.24. 问题24 - 装nvidia驱动后无法进入系统

# 开机,在 GRUB 选择界面按 E,这时界面变成了一个编辑器。
# 在倒数几行找到 ro quiet splash
# 然后删掉quiet,改成text,接着按F10
# 这时你已进入操作系统(ctrl+alt+F1-F6),输入用户名密码登录。
# 然后输入以下代码:
sudo add-apt-repository ppa:bumblebee/stable
sudo apt-get update
sudo apt-get install bumblebee bumblebee-nvidia

3.25. 问题25 - "libcudart.so.8.0 cannot open shared object file: No such file or directory"

# 解决办法是将一些文件复制到/usr/local/lib文件夹下:
# 注意CUDA版本号
sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/lib/libcublas.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/lib/libcurand.so.8.0 && sudo ldconfig

3.26. 问题26 - matio.h no such file or directory / matio 安装

sudo apt-get install libmatio-dev
# 或源码安装:  
# 下载 matio (https://sourceforge.net/projects/matio/)
tar zxf matio-X.Y.Z.tar.gz
cd matio-X.Y.Z
./configure
make
make check
make install  # 安装
export LD_LIBRARY_PATH=/path/to/libmatio.so.2

在caffe 的 Makefile.config 中的INCLUDE_DIRS 中添加 matio 的 src路径, LIBRARY_DIRS 中添加 src/.libs,如:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include  /path/to/matio-1.5.2/src
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /path/to/matio-1.5.2/src/.libs

参考: http://blog.csdn.net/houqiqi/article/details/46469981

3.27. 问题27 - fast-rcnn 出现问题

# cython_bbox 和cython_nms 问题
cd fast_rcnn_root/lib
python setup.py install

# setup.py安装完成后,
cd python_root/Lib/site-packages/utils
# 可以找到两个文件cython_bbox.so和cython_nms.so,把这两个文件复制到fast_rcnn_root/lib/utils中即可.

参考: http://blog.csdn.net/happynear/article/details/46822109

3.28. 问题28 - CUDA8.0- atomicAdd的重写问题,cuda8中出现了atomicAdd的定义,从而产生bug

将common.cuh 进行如下修改,注意最后的endif.

  1. #ifndef CAFFE_COMMON_CUH_  
  2. #define CAFFE_COMMON_CUH_  
  3.   
  4.   
  5. #include <cuda.h>  
  6. #if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 600  
  7. #else  
  8. // CUDA: atomicAdd is not defined for doubles  
  9. static __inline__ __device__ double atomicAdd(double *address, double val) {  
  10.   unsigned long long int* address_as_ull = (unsigned long long int*)address;  
  11.   unsigned long long int old = *address_as_ull, assumed;  
  12.   if (val==0.0)  
  13.     return __longlong_as_double(old);  
  14.   do {  
  15.     assumed = old;  
  16.     old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val +__longlong_as_double(assumed)));  
  17.   } while (assumed != old);  
  18.   return __longlong_as_double(old);  
  19. }  
  20. #endif  
  21. #endif  

3.29. 问题29 - CUDA 查询 nvcc -V not installed 问题

nvcc -V
>> The program 'nvcc' is currently not installed. You can install it by typing:
sudo apt-get install nvidia-cuda-toolkit

但已经安装了cuda,在 /usr/local 能够看到文件夹 cuda-XX. 这需要如下环境变量设置:

sudo gedit ~/.bashrc
# 在最后面,64位的话粘贴以下内容:
export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH

source ~/.bashrc # 使其立即生效即可 

3.30. 问题30 - 使用C++ 11特性的编译问题

问题:

有时在编写caffe代码时为了简便可能会使用C++98之后的一些新特性,如果不对caffe的默认编译选项进行修改则会产生诸如“xxx is not a member of ‘std’”或者某些函数没有匹配声明的错误.

解决方案:

在Makefile中的g++编译命令里添加-std=c++11的flag.
caffe 的 Makefile 中,

 CXXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WRANINGS)

之后添加 -std=c++11

From 在caffe中使用C++ 11特性的编译问题

3.31. 问题31 - 编译时出现undefined reference错误

问题:

../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<boost::shared_ptr<caffe::DataReader::QueuePair> >::size() const'
../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<boost::shared_ptr<caffe::DataReader::QueuePair> >::push(boost::shared_ptr<caffe::DataReader::QueuePair> const&)'
../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<caffe::Datum*>::push(caffe::Datum* const&)'
../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<caffe::Datum*>::BlockingQueue()'
../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<boost::shared_ptr<caffe::DataReader::QueuePair> >::pop(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<caffe::Datum*>::pop(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<caffe::Datum*>::try_pop(caffe::Datum**)'
../lib/libcaffe.so.1.0.0: undefined reference to `caffe::BlockingQueue<boost::shared_ptr<caffe::DataReader::QueuePair> >::BlockingQueue()'

解决方案:

//在blocking_queue.cpp中添加数据类型的泛型实例化的声明
template class BlockingQueue<Datum*>;
template class BlockingQueue<shared_ptr<DataReader::QueuePair> >;

3.32. 问题32 - 安装 scipy 出现错误: error: library dfftpack has Fortran sources but no Fortran compiler found

错误原因是, 没有安装 gfortran 编译器

sudo apt-get install gfortran

3.33. 问题33 - libcudnn.so.7.0: cannot open shared object file: No such file or directory错误

错误原因是, cuda的路径可能设置错了

sudo ldconfig /usr/local/cuda/lib64

3.34. 问题34 - error libGL.so: cannot open shared object file: No such file or directory 错误

运行

import cv2

出现错误:

error libGL.so: cannot open shared object file: No such file or directory

解决方案:

apt-get install libgl1-mesa-dev

3.35. 问题35 - Error: libcudart.so.9.0: cannot open shared object file: No such file or directory 错误

解决方案:
首先,确认环境变量设置:

sudo vim ~/.bashrc

添加 CUDA 环境变量:

export PATH=$PATH:/usr/local/cuda/bin  
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64  
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64  

生效环境变量:

source ~/.bashrc

或在 /etc/profile 中设置环境变量:

export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH

如果仍出现相同错误,尝试以下操作:

sudo cp /usr/local/cuda-9.0/lib64/libcudart.so.9.0 /usr/local/lib/libcudart.so.9.0 && sudo ldconfig  
cp /usr/local/cuda-9.0/lib64/libcublas.so.9.0 /usr/local/lib/libcublas.so.9.0 && sudo ldconfig  
cp /usr/local/cuda-9.0/lib64/libcurand.so.9.0 /usr/local/lib/libcurand.so.9.0 && sudo ldconfig  

如果还是出现相同错误,运行:

sudo ldconfig /usr/local/cuda/lib64  

3.36. 问题36 - undefined reference to `cv::imread(cv::String const&, int)' 错误

OpenCV3.0 版本后,图像读取相关代码在 imgcodes 库中.

编辑 Makefile文件,添加库:

ifeq ($(USE_OPENCV), 1)
    LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs # 

    ifeq ($(OPENCV_VERSION), 3) #
        LIBRARIES += opencv_imgcodecs
    endif

endif

3.37. 问题37 - cannot find -lboost_python3

问题:针对Python3编译caffe时make all的时候出现了如下错误:

cannot find -lboost_python3

解决方案:

cd /usr/lib/x86_64-linux-gnu
ls #查看是否存在python3版本的libboost,如libboost_python35.so
#建立软连接
sudo ln -s libboost_python-py35.so libboost_python3.so

3.38. 问题38 - fatal error: pyconfig.h: No such file or directory

原因是:没有安装对应python的python-dev依赖,导致编译到boost python模块的时候就会出错.

解决方案,如:

sudo apt-get install python2.7-dev 
sudo apt-get install python3.5-dev
Last modification:October 8th, 2020 at 12:24 pm