【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)

前端之家收集整理的这篇文章主要介绍了【CPU + GPU版】Ubuntu16.04 + caffe + Anaconda2 + OpenCV3.x(附:问题集锦+测试案例)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


cpu版】Ubuntu + caffe + Anaconda2 + OpenCV3.x


2017.06.02:整理出第一个版本。

2018.01.05:整理libhdf5_hl.so.100和libopencv_highgui.so等两个问题。

2018.01.05:Ubuntu 16.04中使用Matlab R2016b编译Caffe接口出错的解决方法


一、本文目的

本文基于上一篇博文《Ubuntu 常用软件安装:Matlab + XX-net + ... + TeamViewer + Tensorflow + Caffe》中的caffe环境的搭建部分进行完善,更详细的进行整理,主要贡献如下:

1、根据本人实践过程进行记录,更加完善记录整个“caffe环境搭建”的过程。

2、归纳总结问题集锦:caffe环境的搭建过程确实很多细节需要处理,本文尽可能收集一些相关的参考资料。

3、本文会尽可能详细的列出每个步骤,图文结合,并附上参考网址。

4、贴出【cpu版本】和【GPU版本】的Makefile.configure配置文件

5、总结归纳测试案例。


参考网址:


1)caffe的配置过程:http://blog.csdn.net/brightming/article/details/51106629

2)【深度学习】 Ubuntu16.04 caffe Opencv2.4.13 GPU环境配置:http://blog.csdn.net/sinat_17196995/article/details/53466524

3)Ubuntu 常用软件安装:Matlab + XX-net + ... + TeamViewer + Tensorflow + Caffe

4)caffe安装:http://www.jb51.cc/article/p-hgkqqphr-qh.html



新增参考网址(20180105)


3D - caffe:https://github.com/faustomilletari/3D-Caffe.git

@H_502_187@深度学习之常用软件(ubuntu):http://blog.csdn.net/houchaoqun_xmu/article/details/78869052

@H_502_187@发表过CVPR-2017的作者的博客http://zongweiz.leanote.com/post/Install-caffe-in-Ubuntu

cuda-8.0 + cudnn-5.1 的安装步骤请参考这里:OpenCV-3.3.0(Ubuntu-16.06)请参考这里:http://blog.csdn.net/houchaoqun_xmu/article/details/78565




二、GPU版caffe配置过程


1、更新安装必要的软件包,去除不必要的包

[plain] view plain copy
  1. sudoapt-getupdate
  2. sudoapt-getupgrade
  3. sudoapt-getinstallbuild-essential
  4. sudoapt-getautoremove

2、查看系统GPU信息:lspci | grep -i nvidia

[plain] view plain copy
  1. hcq@hcq-To-be-filled-by-O-E-M:~$lspci|grep-invidia
  2. 01:00.0VGAcompatiblecontroller:NVIDIACorporationGM206[GeForceGTX960](reva1)
  3. 01:00.1Audiodevice:NVIDIACorporationDevice0fba(reva1)

注:如果当前系统尚未安装NVIDIA驱动,需先进行安装,可参考这里

3、安装并配置CUDA8.0

1)下载对应版本的CUDA安装包(.deb文件):https://developer.nvidia.com/cuda-downloads

2)cd到文件所在路径,并执行如下命令:

3)sudo dpkg -i cuda-repo-<distro>_<version>_<architecture>.deb
4)sudo apt-get update
5)sudo apt-get install cuda

=== 配置环境变量 ===

1)export PATH=“/usr/local/cuda-8.0/bin:$PATH”
2)export LD_LIBRARY_PATH=”/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH“

3)配置环境变量和动态链接库,在命令行输入【sudo gedit /etc/profile】在文件末尾加入【export PATH = “/usr/local/cuda/bin:$PATH”】,保存后关闭文件

4)保存之后,创建链接文件,输入【sudo gedit /etc/ld.so.conf.d/cuda.conf】在打开的文件添加如下语句【/usr/local/cuda/lib64】执行【sudo ldconfig】。

5)查看显卡的驱动版本: cat /proc/driver/nvidia/version

6)查看nvcc编译器的版本: nvcc -V

=== 编译CUDA Sample(可选) ===

1)参考网址:http://blog.csdn.net/sinat_17196995/article/details/53466524
2)【cd/usr/local/cuda-8.0/samples/bin/x86_64/linux/release】,然后执行【sudo ./deviceQuery】,出现如下信息,表示成功

[plain] view plain copy
  1. sudo./deviceQuery
  2. [sudo]hcq的密码:
  3. ./deviceQueryStarting...
  4. CUDADeviceQuery(RuntimeAPI)version(CUDARTstaticlinking)
  5. Detected1CUDACapabledevice(s)
  6. Device0:"GeForceGTX960"
  7. CUDADriverVersion/RuntimeVersion8.0/8.0
  8. CUDACapabilityMajor/Minorversionnumber:5.2
  9. Totalamountofglobalmemory:1993MBytes(2090270720bytes)
  10. (8)Multiprocessors,(128)CUDACores/MP:1024CUDACores
  11. GPUMaxClockrate:1178MHz(1.18GHz)
  12. MemoryClockrate:3505Mhz
  13. MemoryBusWidth:128-bit
  14. L2CacheSize:1048576bytes
  15. MaximumTextureDimensionSize(x,y,z)1D=(65536),2D=(65536,65536),3D=(4096,4096,4096)
  16. MaximumLayered1DTextureSize,(num)layers1D=(16384),2048layers
  17. MaximumLayered2DTextureSize,(num)layers2D=(16384,16384),2048layers
  18. Totalamountofconstantmemory:65536bytes
  19. Totalamountofsharedmemoryperblock:49152bytes
  20. Totalnumberofregistersavailableperblock:65536
  21. Warpsize:32
  22. Maximumnumberofthreadspermultiprocessor:2048
  23. Maximumnumberofthreadsperblock:1024
  24. Maxdimensionsizeofathreadblock(x,z):(1024,1024,64)
  25. Maxdimensionsizeofagridsize(x,z):(2147483647,65535,65535)
  26. Maximummemorypitch:2147483647bytes
  27. Texturealignment:512bytes
  28. Concurrentcopyandkernelexecution:Yeswith2copyengine(s)
  29. Runtimelimitonkernels:Yes
  30. IntegratedGPUsharingHostMemory:No
  31. Supporthostpage-lockedmemorymapping:Yes
  32. AlignmentrequirementforSurfaces:Yes
  33. DevicehasECCsupport:Disabled
  34. DevicesupportsUnifiedAddressing(UVA):Yes
  35. DevicePCIDomainID/BusID/locationID:0/1/0
  36. ComputeMode:
  37. <Default(multiplehostthreadscanuse::cudaSetDevice()withdevicesimultaneously)>
  38. deviceQuery,CUDADriver=CUDART,CUDADriverVersion=8.0,CUDARuntimeVersion=8.0,NumDevs=1,Device0=GeForceGTX960
  39. Result=PASS

4、安装Anaconda2


1)到官网下载安装包(此处选择for Linux):https://www.continuum.io/downloads/

2)cd到安装包文件所在的目录下并执行:bash Anaconda2-4.3.1-Linux-x86_64.sh

3)配置环境变量:

== sudo gedit ~/.bashrc

== export PATH="/home/hcq/anaconda2/bin:$PATH"

== source ~/.bashrc


5、安装、编译OpenCV3.x


1)sudo git clonehttps://github.com/jayrambhia/Install-OpenCV

2)在Install-OpenCV/Ubuntu目录下:

== 先执行命令:sudo chmod +x *

== 然后执行sudo ./opencv_latest.sh(此过程需要一段时间,最后出现OpenCV 3.2.0 ready to be used表示成功)

3)cd/home/hcq/Install-OpenCV/Ubuntu/OpenCV/opencv-3.2.0

4)sudo mkdirrelease

5)cd release

6)sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

7)sudo make(编译过程需要一段时间,要到100%才算是是成功)

8)sudo make install

编译完,环境也自动加上了。

===== 配置文件 =====

1)sudo gedit /etc/ld.so.conf.d/opencv.conf #配置相关文件

2)复制如下代码加入到文件

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

3)source /etc/bash.bashrc



6、安装依赖项


1)安装google-glog:参考这里

== 下载地址:https://pan.baidu.com/s/1slpjjeH
== 将glog‐0.3.3.tar.gz这个文件拷贝到主文件夹下,即/home/yourname 文件夹下,点击鼠标右键,选择提取到此处(也就是解压该文件)解压后在终端输入如下命令:

[plain] view plain copy
  1. cd/home/yourname/glog-0.3.3
  2. ./configure
  3. make
  4. sudomakeinstall

2)安装其他依赖项:

[plain] view plain copy
  1. sudoapt-getinstalllibatlas-base-devlibprotobuf-devlibleveldb-devlibsnappy-devlibopencv-dev
  2. sudoapt-getinstalllibboost-all-devlibhdf5-serial-devlibgflags-devlibgoogle-glog-devliblmdb-devprotobuf-compiler

3)安装OpenBLAS

[plain] view plain copy
  1. gitclonehttps://github.com/xianyi/OpenBLAS.git
  2. cdOpenBLAS
  3. make-j$(($(nproc)+1))
  4. makeinstall

参考网址:https://github.com/xianyi/OpenBLAS#set-the-number-of-threads-with-environment-variables

注:如果在sudo make runtest 的时候出现错误【libopenblas.so.0: cannot open shared object file: No such file or directory】,第四部分有介绍解决方案。

7、安装其他所需工具(可能导致错误的一些安装,建议读者先跳过本节的安装,遇到问题后再进行安装,印象会比较深刻)

1)conda install libgcc 参考网址:http://www.jb51.cc/article/p-vyhrkbir-yc.html

2)sudo apt install ffmpeg 参考网址:http://f.dataguru.cn/thread-738610-1-1.html


8、安装并配置CUDNN一定要看好对应的版本!!否则后面一些链接库会出错):https://developer.nvidia.com/rdp/cudnn-download

====================== cudnn-5.1-8.0 ========================
1)切换到安装包所在的目录下:sudo tar xvf cudnn-8.0-linux-x64-v5.1.tgz
2)切换到 cuda/lib64 目录下:sudo cp lib* /usr/local/cuda-8.0/lib64/
3)切换到 cuda/include 目录下:sudo cp *.h /usr/local/cuda-8.0/include/
4)切换到 /usr/local/lib 目录下:sudo chmod +r libcudnn.so.5.1.10 && sudo ln -sf libcudnn.so.5.1.10 libcudnn.so.5 && sudo ln -sf libcudnn.so.5 libcudnn.so && sudo ldconfig


9、下载caffe源码、配置、编译:

=== 下载caffe源码 ===

1)cd到home/hcq/目录,下载caffe源码:sudo git clone https://github.com/BVLC/caffe.git


=== 配置相关文件 ===

1)cd到home/hcq/caffe,复制配置文件:sudo cp Makefile.config.example Makefile.config

2)配置Makefile.config文件:sudo geditMakefile.config,去掉注释并修改的部分如下所示:

[python] view plain copy
  1. #cuDNNaccelerationswitch(uncommenttobuildwithcuDNN).
  2. USE_CUDNN:=1
  3. #Uncommentifyou'reusingOpenCV3
  4. OPENCV_VERSION:=3
  5. #openforOpenBlas
  6. BLAS:=open
  7. #(whichshouldwork)!
  8. BLAS_INCLUDE:=/opt/OpenBLAS/include
  9. BLAS_LIB:=/opt/OpenBLAS/lib
  10. ANACONDA_HOME:=/home/hcq/anaconda2
  11. PYTHON_INCLUDE:=$(ANACONDA_HOME)/include\
  12. $(ANACONDA_HOME)/include/python2.7\
  13. $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
  14. PYTHON_LIB:=$(ANACONDA_HOME)/lib
  15. #Whateverelseyoufindyouneedgoeshere.
  16. INCLUDE_DIRS:=$(PYTHON_INCLUDE)/usr/local/include/usr/include/hdf5/serial
  17. LIBRARY_DIRS:=$(PYTHON_LIB)/usr/local/lib/usr/lib/usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial
  18. #N.B.bothbuildanddistributedirsareclearedon`makeclean`
  19. BUILD_DIR:=build
  20. DISTRIBUTE_DIR:=distribute
  21. #TheIDoftheGPUthat'makeruntest'willusetorununittests.
  22. TEST_GPUID:=0
  23. #enableprettybuild(commenttoseefullcommands)
  24. Q?=@

3)修改Makefile文件sudo geditMakefile,进行如下修改

[plain] view plain copy
  1. NVCCFLAGS+=-ccbin=$(CXX)-Xcompiler-fPIC$(COMMON_FLAGS)#这行去掉
  2. NVCCFLAGS+=-D_FORCE_INLINES-ccbin=$(CXX)-Xcompiler-fPIC$(COMMON_FLAGS)#添加这行

4)进入/usr/lib/x86_64-linux-gnu目录下,执行如下命令(否则会提示:/usr/bin/ld: 找不到 -lhdf5_hl 和 /usr/bin/ld: 找不到 -lhdf5

[plain] view plain copy
  1. sudolnlibhdf5_serial.so.10.1.0libhdf5.so
  2. sudolnlibhdf5_serial_hl.so.10.0.2libhdf5_hl.so
  3. sudoldconfig#使连接生效

5)caffe源码中,python的一些必要安装:

[plain] view plain copy
  1. cd/home/hcq/caffe/python
  2. forreqin$(catrequirements.txt);dopipinstall$req;done

注:如果需要执行权限问题,就改变caffe文件的执行权限 sudo chown -R 'hcq' xxx

=== 编译caffe(期间遇到问题可以到第四部分查看是否有相关的解决方案)===

1)cd /home/hcq/caffe:进入caffe的根目录下

2)sudo make clean

3)sudo make all -j4 (-j4表示使用4核处理器执行当前指令)

4)sudomake test -j4(最好加上sudo防止有些文件的访问权限不够)

5)sudomake runtest-j4

6)sudo make pycaffe -j4(配置pycaffe)


=== 效果图展示 ===

1)sudo make all 成功后的效果图,如下所示:


2)sudo make runtest 成功后的效果图,如下所示:

[python] view plain copy
  1. [OK]ArgMaxLayerTest/1.TestcpuMaxVal(1ms)
  2. [RUN]ArgMaxLayerTest/1.TestSetupMaxVal
  3. [OK]ArgMaxLayerTest/1.TestSetupMaxVal(1ms)
  4. [RUN]ArgMaxLayerTest/1.TestSetupAxis
  5. [OK]ArgMaxLayerTest/1.TestSetupAxis(0ms)
  6. [RUN]ArgMaxLayerTest/1.TestcpuTopK
  7. [OK]ArgMaxLayerTest/1.TestcpuTopK(1ms)
  8. [----------]12testsfromArgMaxLayerTest/1(48mstotal)
  9. [----------]4testsfromContrastiveLossLayerTest/1,whereTypeParam=caffe::cpuDevice<double>
  10. [RUN]ContrastiveLossLayerTest/1.TestGradientLegacy
  11. [OK]ContrastiveLossLayerTest/1.TestGradientLegacy(125ms)
  12. [RUN]ContrastiveLossLayerTest/1.TestForward
  13. [OK]ContrastiveLossLayerTest/1.TestForward(0ms)
  14. [RUN]ContrastiveLossLayerTest/1.TestGradient
  15. [OK]ContrastiveLossLayerTest/1.TestGradient(136ms)
  16. [RUN]ContrastiveLossLayerTest/1.TestForwardLegacy
  17. [OK]ContrastiveLossLayerTest/1.TestForwardLegacy(0ms)
  18. [----------]4testsfromContrastiveLossLayerTest/1(261mstotal)
  19. [----------]Globaltestenvironmenttear-down
  20. [==========]1106testsfrom150testcasesran.(43894mstotal)
  21. [PASSED]1106tests.
  22. hcq@hcq-To-be-filled-by-O-E-M:~/caffe$

10、caffe的测试案例

参考网址:http://caffe.berkeleyvision.org/gathered/examples/mnist.html

1)import caffe,输入如下命令:

== cd /home/hcq/caffe

== python

== import caffe

== 第一次成功后如下所示:

[plain] view plain copy
  1. hcq@ubuntu:~/caffe/python$python
  2. Python2.7.13|Anacondacustom(64-bit)|(default,Dec202016,23:09:15)
  3. [GCC4.4.720120313(RedHat4.4.7-1)]onlinux2
  4. Type"help","copyright","credits"or"license"formoreinformation.
  5. AnacondaisbroughttoyoubyContinuumAnalytics.
  6. Pleasecheckout:http://continuum.io/thanksandhttps://anaconda.org
  7. >>>importcaffe
  8. /home/hcq/anaconda2/lib/python2.7/site-packages/matplotlib/font_manager.py:280:UserWarning:Matplotlibisbuildingthefontcacheusingfc-list.Thismaytakeamoment.
  9. 'Matplotlibisbuildingthefontcacheusingfc-list.'

2)MNIST 模型

==cd/home/hcq/caffe(确保当前目录是caffe目录),执行如下命令:

== sudo ./data/mnist/get_mnist.sh

== sudo ./examples/mnist/create_mnist.sh

==sudo./examples/mnist/train_lenet.sh

== 训练完成后如下所示:

[plain] view plain copy
  1. I060113:09:21.12908329215solver.cpp:447]Snapshottingtobinaryprotofileexamples/mnist/lenet_iter_10000.caffemodel
  2. I060113:09:21.13408929215sgd_solver.cpp:273]Snapshottingsolverstatetobinaryprotofileexamples/mnist/lenet_iter_10000.solverstate
  3. I060113:09:21.16399029215solver.cpp:310]Iteration10000,loss=0.00275877
  4. I060113:09:21.16401329215solver.cpp:330]Iteration10000,Testingnet(#0)
  5. I060113:09:25.22633729217data_layer.cpp:73]Restartingdataprefetchingfromstart.
  6. I060113:09:25.39416729215solver.cpp:397]Testnetoutput#0:accuracy=0.991
  7. I060113:09:25.39420929215solver.cpp:397]Testnetoutput#1:loss=0.0280903(*1=0.0280903loss)
  8. I060113:09:25.39421529215solver.cpp:315]OptimizationDone.
  9. I060113:09:25.39423429215caffe.cpp:259]OptimizationDone.

3)Cifar-10 模型

== cd /home/hcq/caffe #cd到caffe源码的根目录下

== sudo ./data/cifar10/get_cifar10.sh #该脚本会下载二进制的cifar,并解压,会在/data/cifar10中出现很多batch文件

== sudo ./examples/cifar10/create_cifar10.sh #运行后将会在examples中出现数据集./cifar10_xxx_lmdb和数据集图像均值./mean.binaryproto

注:CIFAR-10的卷积神经网络模型由卷积层,pooling层,ReLU,非线性变换层,局部对比归一化线性分类器组成。该模型定义在CAFFE_ROOT/examples/cifar10/cifar10_quick_train_test.prototxt中。

== sudo./examples/cifar10/train_quick.sh #先以0.001的学习率迭代4000次,再以0.01的学习率接着再迭代1000次,共5000次

注:同理可以训练full模型,full模型比quick模型迭代次数多,一共迭代70000次,前60000次学习率是0.001,中间5000次学习率是0.0001,最后5000次学习率是0.00001。full模型的网络层数也比quick模型多,输入如下命令训练full模型

== sudo./examples/cifar10/train_full.sh

参考网址:

== caffe示例实现之1在CIFAR-10数据集上训练与测试Caffe:http://blog.csdn.net/liumaolincycle/article/details/47258937

== caffe官网http://caffe.berkeleyvision.org/

训练成功后,提示如下所示,以sudo./examples/cifar10/train_quick.sh为例:

[plain] view plain copy
  1. I060117:15:20.21963532594solver.cpp:237]Trainnetoutput#0:loss=0.550304(*1=0.550304loss)
  2. I060117:15:20.21964232594sgd_solver.cpp:105]Iteration4700,lr=0.0001
  3. I060117:16:15.67182332594solver.cpp:218]Iteration4800(1.80336iter/s,55.452s/100iters),loss=0.403176
  4. I060117:16:15.67189132594solver.cpp:237]Trainnetoutput#0:loss=0.403176(*1=0.403176loss)
  5. I060117:16:15.67189832594sgd_solver.cpp:105]Iteration4800,lr=0.0001
  6. I060117:17:10.76178532594solver.cpp:218]Iteration4900(1.81524iter/s,55.089s/100iters),loss=0.466545
  7. I060117:17:10.76190332594solver.cpp:237]Trainnetoutput#0:loss=0.466545(*1=0.466545loss)
  8. I060117:17:10.76190732594sgd_solver.cpp:105]Iteration4900,lr=0.0001
  9. I060117:18:02.53276432595data_layer.cpp:73]Restartingdataprefetchingfromstart.
  10. I060117:18:04.70677932594solver.cpp:457]SnapshottingtoHDF5fileexamples/cifar10/cifar10_quick_iter_5000.caffemodel.h5
  11. I060117:18:04.70835332594sgd_solver.cpp:283]SnapshottingsolverstatetoHDF5fileexamples/cifar10/cifar10_quick_iter_5000.solverstate.h5
  12. I060117:18:04.92949232594solver.cpp:310]Iteration5000,loss=0.451509
  13. I060117:18:04.92952232594solver.cpp:330]Iteration5000,Testingnet(#0)
  14. I060117:18:26.00878632597data_layer.cpp:73]Restartingdataprefetchingfromstart.
  15. I060117:18:26.88809732594solver.cpp:397]Testnetoutput#0:accuracy=0.7575
  16. I060117:18:26.88812332594solver.cpp:397]Testnetoutput#1:loss=0.737631(*1=0.737631loss)
  17. I060117:18:26.88814132594solver.cpp:315]OptimizationDone.
  18. I060117:18:26.88814432594caffe.cpp:259]OptimizationDone.

4)使用训练的模型来分类新数据:

== 确保 sudo make pycaffe 已经编译成功。

== 打开终端,在caffe源码的根目录下,执行如下命令:

[python] view plain copy
  1. pythonpython/classify.pyexamples/images/cat.jpgfoo#直接用一下别人的模型分类试一下:(默认用的ImageNet的模型)

[python] view plain copy
  1. hcq@hcq-To-be-filled-by-O-E-M:~/caffe$pythonpython/classify.pyexamples/images/cat.jpgfoo
  2. cpumode
  3. WARNING:LoggingbeforeInitGoogleLogging()iswrittentoSTDERR
  4. W060211:25:53.5616469707_caffe.cpp:139]DEPRECATIONWARNING-deprecateduSEOfPythoninterface
  5. W060211:25:53.5616989707_caffe.cpp:140]Usethisinstead(withthenamed"weights"parameter):
  6. W060211:25:53.5617099707_caffe.cpp:142]Net('python/../models/bvlc_reference_caffenet/deploy.prototxt',1,weights='python/../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel')
  7. Traceback(mostrecentcalllast):
  8. File"python/classify.py",line138,in<module>
  9. main(sys.argv)
  10. File"python/classify.py",line110,inmain
  11. channel_swap=channel_swap)
  12. File"/home/hcq/caffe/python/caffe/classifier.py",line26,in__init__
  13. caffe.Net.__init__(self,model_file,pretrained_file,caffe.TEST)
  14. RuntimeError:Couldnotopenfilepython/../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
上面这句话的意思是,使用cifar10_quick.prototxt网络 + cifar10_quick_iter_4000.caffemodel.h5模型,对examples/images/cat.jpg图片进行分类

错误原因

解决方

1)cd/home/hcq/caffe/script

2)python download_model_binary.py /home/hcq/caffe/models/bvlc_reference_caffenet

参考网址http://blog.csdn.net/u011636440/article/details/52441519

解决上述问题后,又出现新问题提示如下所示:

[plain] view plain copy
  1. I060211:51:24.16338910753upgrade_proto.cpp:53]AttemptingtoupgradeinputfilespecifiedusingdeprecatedV1LayerParameter:python/../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
  2. I060211:51:24.36864610753upgrade_proto.cpp:61]SuccessfullyupgradedfilespecifiedusingdeprecatedV1LayerParameter
  3. I060211:51:24.43614910753net.cpp:744]Ignoringsourcelayerloss
  4. Traceback(mostrecentcalllast):
  5. File"python/classify.py",line138,in<module>
  6. main(sys.argv)
  7. File"python/classify.py",line110,inmain
  8. channel_swap=channel_swap)
  9. File"/home/hcq/caffe/python/caffe/classifier.py",line34,in__init__
  10. self.transformer.set_mean(in_,mean)
  11. File"/home/hcq/caffe/python/caffe/io.py",line259,inset_mean
  12. raiseValueError('Meanshapeincompatiblewithinputshape.')
  13. ValueError:Meanshapeincompatiblewithinputshape.
错误原因:ValueError: Mean shape incompatible with input shape. 是因为‘mean’与‘input’的尺寸不同造成的。

解决方修改了 ./python/caffe/io.py 文件,如下

将:

[plain] view plain copy
  1. ifms!=self.inputs[in_][1:]:
  2. raiseValueError('Meanshapeincompatiblewithinputshape.')

修改为:

[python] view plain copy
  1. ifms!=self.inputs[in_][1:]:
  2. print(self.inputs[in_])
  3. in_shape=self.inputs[in_][1:]
  4. m_min,m_max=mean.min(),mean.max()
  5. normal_mean=(mean-m_min)/(m_max-m_min)
  6. mean=resize_image(normal_mean.transpose((1,2,0)),
  7. in_shape[1:]).transpose((2,0,1))*\
  8. (m_max-m_min)+m_min
  9. #raiseValueError('Meanshapeincompatiblewithinputshape.')

参考网址http://blog.csdn.net/gzljss/article/details/45849013
运行成功后,提示如下所示:

[python] view plain copy
  1. I060212:00:07.86424810953net.cpp:200]conv1doesnotneedbackwardcomputation.
  2. I060212:00:07.86425110953net.cpp:200]datadoesnotneedbackwardcomputation.
  3. I060212:00:07.86425410953net.cpp:242]Thisnetworkproducesoutputprob
  4. I060212:00:07.86426610953net.cpp:255]Networkinitializationdone.
  5. I060212:00:07.98715710953upgrade_proto.cpp:44]Attemptingtoupgradeinputfilespecifiedusingdeprecatedtransformationparameters:python/../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
  6. I060212:00:07.98719010953upgrade_proto.cpp:47]Successfullyupgradedfilespecifiedusingdeprecateddatatransformationparameters.
  7. W060212:00:07.98719510953upgrade_proto.cpp:49]NotethatfutureCaffereleaseswillonlysupporttransform_parammessagesfortransformationfields.
  8. I060212:00:07.98719810953upgrade_proto.cpp:53]AttemptingtoupgradeinputfilespecifiedusingdeprecatedV1LayerParameter:python/../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel
  9. I060212:00:08.21731310953upgrade_proto.cpp:61]SuccessfullyupgradedfilespecifiedusingdeprecatedV1LayerParameter
  10. I060212:00:08.28918610953net.cpp:744]Ignoringsourcelayerloss
  11. (10,3,227,227)
  12. Loadingfile:examples/images/cat.jpg
  13. Classifying1inputs.
  14. Donein0.43s.
  15. Savingresultsintofoo

== 使用cifar10_quick_iter_4000.caffemodel.h5模型:

[python] view plain copy
  1. pythonpython/classify.py--model_defexamples/cifar10/cifar10_quick.prototxt--pretrained_modelexamples/cifar10/cifar10_quick_iter_4000.caffemodel.h5--center_onlyexamples/images/cat.jpgfoo#指定自己的模型进行分类

== 错误提示如下:

[python] view plain copy
  1. hcq@hcq-To-be-filled-by-O-E-M:~/caffe$pythonpython/classify.py--model_defexamples/cifar10/cifar10_quick.prototxt--pretrained_modelexamples/cifar10/cifar10_quick_iter_4000.caffemodel.h5--center_onlyexamples/images/cat.jpgfoo
  2. cpumode
  3. WARNING:LoggingbeforeInitGoogleLogging()iswrittentoSTDERR
  4. W060211:27:22.8577199729_caffe.cpp:139]DEPRECATIONWARNING-deprecateduSEOfPythoninterface
  5. W060211:27:22.8577569729_caffe.cpp:140]Usethisinstead(withthenamed"weights"parameter):
  6. W060211:27:22.8577599729_caffe.cpp:142]Net('examples/cifar10/cifar10_quick.prototxt',weights='examples/cifar10/cifar10_quick_iter_4000.caffemodel.h5')
  7. Traceback(mostrecentcalllast):
  8. File"python/classify.py",caffe.TEST)
  9. RuntimeError:Couldnotopenfileexamples/cifar10/cifar10_quick_iter_4000.caffemodel.h5
原因:在目录/home/hcq/caffe/examples/cifar10下,确实不存在 cifar10_quick_iter_4000.caffemodel.h5这个模型,运行结果必然错误

解决方案:到目录/home/hcq/caffe/examples/cifar10下查看已有的模型,然后把指定的模型换成已有的模型,已有的模型如下所示(因人而异):

[html] view plain copy
  1. hcq@hcq-To-be-filled-by-O-E-M:~/caffe/examples/cifar10$ls-lrt
  2. 总用量6788
  3. -rwxrwxr-x1hcqhcq3385月2711:55train_quick.sh
  4. -rwxrwxr-x1hcqhcq1395月2711:55train_full_sigmoid.sh
  5. -rwxrwxr-x1hcqhcq1425月2711:55train_full_sigmoid_bn.sh
  6. -rwxrwxr-x1hcqhcq5245月2711:55train_full.sh
  7. -rw-rw-r--1hcqhcq52435月2711:55readme.md
  8. -rwxrwxr-x1hcqhcq4675月2711:55create_cifar10.sh
  9. -rw-rw-r--1hcqhcq36775月2711:55convert_cifar_data.cpp
  10. -rw-rw-r--1hcqhcq19215月2711:55cifar10_quick.prototxt
  11. -rw-rw-r--1hcqhcq31225月2711:55cifar10_full_train_test.prototxt
  12. -rw-rw-r--1hcqhcq28795月2711:55cifar10_full_sigmoid_train_test.prototxt
  13. -rw-rw-r--1hcqhcq31925月2711:55cifar10_full_sigmoid_train_test_bn.prototxt
  14. -rw-rw-r--1hcqhcq21745月2711:55cifar10_full.prototxt
  15. drwxr--r--2hcqroot40966月115:38cifar10_train_lmdb
  16. drwxr--r--2hcqroot40966月115:38cifar10_test_lmdb
  17. -rw-r--r--1hcqroot122996月115:38mean.binaryproto
  18. -rw-rw-r--1hcqhcq30886月115:39cifar10_quick_train_test.prototxt
  19. -rw-rw-r--1hcqhcq8596月116:25cifar10_quick_solver.prototxt
  20. -rw-rw-r--1hcqhcq9446月116:25cifar10_full_solver_lr1.prototxt
  21. -rw-rw-r--1hcqhcq8826月116:26cifar10_quick_solver_lr1.prototxt
  22. -rw-rw-r--1hcqhcq9446月116:26cifar10_full_solver.prototxt
  23. -rw-rw-r--1hcqhcq9596月116:26cifar10_full_sigmoid_solver_bn.prototxt
  24. -rw-rw-r--1hcqhcq9536月116:26cifar10_full_sigmoid_solver.prototxt
  25. -rw-rw-r--1hcqhcq9456月116:26cifar10_full_solver_lr2.prototxt
  26. -rw-r--r--1hcqroot3660486月201:37cifar10_full_iter_10000.solverstate.h5
  27. -rw-r--r--1hcqroot3757526月201:37cifar10_full_iter_10000.caffemodel.h5
  28. -rw-r--r--1hcqroot3660486月202:34cifar10_full_iter_20000.solverstate.h5
  29. -rw-r--r--1hcqroot3757526月202:34cifar10_full_iter_20000.caffemodel.h5
  30. -rw-r--r--1hcqroot3660486月203:30cifar10_full_iter_30000.solverstate.h5
  31. -rw-r--r--1hcqroot3757526月203:30cifar10_full_iter_30000.caffemodel.h5
  32. -rw-r--r--1hcqroot3660486月204:27cifar10_full_iter_40000.solverstate.h5
  33. -rw-r--r--1hcqroot3757526月204:27cifar10_full_iter_40000.caffemodel.h5
  34. -rw-r--r--1hcqroot3660486月205:24cifar10_full_iter_50000.solverstate.h5
  35. -rw-r--r--1hcqroot3757526月205:24cifar10_full_iter_50000.caffemodel.h5
  36. -rw-r--r--1hcqroot3660486月206:21cifar10_full_iter_60000.solverstate.h5
  37. -rw-r--r--1hcqroot3757526月206:21cifar10_full_iter_60000.caffemodel.h5
  38. -rw-r--r--1hcqroot5824966月216:40cifar10_quick_iter_4000.solverstate
  39. -rw-r--r--1hcqroot5833016月216:40cifar10_quick_iter_4000.caffemodel
  40. -rw-r--r--1hcqroot5900646月216:44cifar10_quick_iter_5000.solverstate.h5
  41. -rw-r--r--1hcqroot6000326月216:44cifar10_quick_iter_5000.caffemodel.h5

== 选择【cifar10_quick_iter_5000.caffemodel.h5】作为指定模型,再次运行如下命令:

[python] view plain copy
  1. pythonpython/classify.py--model_defexamples/cifar10/cifar10_quick.prototxt--pretrained_modelexamples/cifar10/cifar10_quick_iter_5000.caffemodel.h5--center_onlyexamples/images/cat.jpgfoo
== 运行成功后,提示如下所示:

[html] view plain copy
  1. cpumode
  2. WARNING:LoggingbeforeInitGoogleLogging()iswrittentoSTDERR
  3. W060216:48:24.26168312766_caffe.cpp:139]DEPRECATIONWARNING-deprecateduSEOfPythoninterface
  4. W060216:48:24.26173212766_caffe.cpp:140]Usethisinstead(withthenamed"weights"parameter):
  5. W060216:48:24.26173512766_caffe.cpp:142]Net('examples/cifar10/cifar10_quick.prototxt',1,weights='examples/cifar10/cifar10_quick_iter_5000.caffemodel.h5')
  6. I060216:48:24.26283012766net.cpp:51]Initializingnetfromparameters:
  7. name:"CIFAR10_quick_test"
  8. state{
  9. phase:TEST
  10. level:0
  11. }
  12. layer{
  13. ...
  14. ...
  15. I060216:48:24.26377412766net.cpp:242]Thisnetworkproducesoutputprob
  16. I060216:48:24.26378212766net.cpp:255]Networkinitializationdone.
  17. I060216:48:24.26453912766net.cpp:798]Ignoringsourcelayercifar
  18. I060216:48:24.26462712766hdf5.cpp:32]Datatypeclass:H5T_FLOAT
  19. I060216:48:24.26504812766net.cpp:798]Ignoringsourcelayerloss
  20. (1,3,32,32)
  21. Loadingfile:examples/images/cat.jpg
  22. Classifying1inputs.
  23. Donein0.03s.
  24. Savingresultsintofoo

注:默认的classify脚本不会直接输出结果,而是会把结果输入到foo文件里,不太直观,网上有一个修改版,添加了一些参数,可以输出概率最高的分类

替换Python/classify.py,下载地址:

这个脚本添加了两个参数,可以指定labels_file,然后可以直接把分类结果输出出来:

[python] view plain copy
  1. pythonpython/classify.py--print_results--model_defexamples/cifar10/cifar10_quick.prototxt--pretrained_modelexamples/cifar10/cifar10_quick_iter_5000.caffemodel.h5--labels_filedata/cifar10/cifar10_words.txt--center_onlyexamples/images/cat.jpgfoo


Caffe学习资料:

1、Classification: Instant Recognition with Caffe:http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb

三、cpu版caffe环境配置过程


1、cpu和GPU版本的一些区别:

1)cpu版本的话,不需要NVIDIA驱动,不需要安装CUDA,不需要配置CUDNN

2)caffe目录下的Makefile.configure配置不一样

3)配置模型的时候,solver_mode: cpu,变成cpu(如果没改的话会报错),如下所示:


2、cpu版本的Makefile.configure配置,未注释掉的部分,如下所示:

[python] view plain copy
  1. #cpu-onlyswitch(uncommenttobuildwithoutGPUsupport).
  2. cpu_ONLY:=1
  3. #Uncommentifyou'reusingOpenCV3
  4. OPENCV_VERSION:=3
  5. #openforOpenBlas
  6. BLAS:=open
  7. #(whichshouldwork)!
  8. BLAS_INCLUDE:=/opt/OpenBLAS/include
  9. BLAS_LIB:=/opt/OpenBLAS/lib
  10. ANACONDA_HOME:=/home/hcq/anaconda2
  11. PYTHON_INCLUDE:=$(ANACONDA_HOME)/include\
  12. $(ANACONDA_HOME)/include/python2.7\
  13. $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
  14. PYTHON_LIB:=$(ANACONDA_HOME)/lib
  15. #Whateverelseyoufindyouneedgoeshere.
  16. INCLUDE_DIRS:=$(PYTHON_INCLUDE)/usr/local/include/usr/include/hdf5/serial
  17. LIBRARY_DIRS:=$(PYTHON_LIB)/usr/local/lib/usr/lib/usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial
  18. #N.B.bothbuildanddistributedirsareclearedon`makeclean`
  19. BUILD_DIR:=build
  20. DISTRIBUTE_DIR:=distribute
  21. #TheIDoftheGPUthat'makeruntest'willusetorununittests.
  22. TEST_GPUID:=0
  23. #enableprettybuild(commenttoseefullcommands)
  24. Q?=@

3、测试案例跟GPU的类似,只不过需要把solver_mode: cpu改为cpu

四、问题集锦

1、sudo make all 编译过程遇到的错误,【conda install libgcc】安装libgcc即可,错误提示如下所示:

[plain] view plain copy
  1. /usr/local/lib/libglog.so:对‘std::__cxx11::basic_ostringstream<char,std::char_traits<char>,std::allocator<char>>::~basic_ostringstream()@GLIBCXX_3.4.21’未定义的引用
  2. /usr/lib/x86_64-linux-gnu/libgflags.so:对‘std::__cxx11::basic_string<char,std::allocator<char>>::find(charconst*,unsignedlong,unsignedlong)const@GLIBCXX_3.4.21’未定义的引用
  3. .build_release/lib/libcaffe.so:对‘std::out_of_range::out_of_range(std::__cxx11::basic_string<char,std::allocator<char>>const&)’未定义的引用
  4. .build_release/lib/libcaffe.so:对‘std::__cxx11::basic_string<char,std::allocator<char>>::_M_replace_aux(unsignedlong,char)’未定义的引用
  5. /usr/local/lib/libopencv_core.so:对‘std::basic_istream<char,std::char_traits<char>>&std::getline<char,std::allocator<char>>(std::basic_istream<char,std::char_traits<char>>&,std::__cxx11::basic_string<char,std::allocator<char>>&,char)@GLIBCXX_3.4.21’未定义的引用
  6. .build_release/lib/libcaffe.so:对‘std::__cxx11::basic_string<char,std::allocator<char>>::compare(unsignedlong,charconst*)const’未定义的引用
  7. /usr/lib/x86_64-linux-gnu/libprotobuf.so:对‘std::__cxx11::basic_string<char,std::allocator<char>>::swap(std::__cxx11::basic_string<char,std::allocator<char>>&)@GLIBCXX_3.4.21’未定义的引用
  8. /usr/local/lib/libglog.so:对‘vtableforstd::__cxx11::basic_stringbuf<char,std::allocator<char>>@GLIBCXX_3.4.21’未定义的引用
  9. /usr/local/lib/libopencv_core.so:对‘std::__cxx11::basic_stringbuf<char,std::allocator<char>>::str()const@GLIBCXX_3.4.21’未定义的引用
  10. collect2:error:ldreturned1exitstatus
  11. Makefile:629:recipefortarget'.build_release/tools/upgrade_solver_proto_text.bin'Failed
  12. make:***[.build_release/tools/upgrade_solver_proto_text.bin]Error1

或者如下所示:

[plain] view plain copy
  1. AR-o.build_release/lib/libcaffe.a
  2. LD-o.build_release/lib/libcaffe.so.1.0.0
  3. CXX/LD-o.build_release/tools/upgrade_solver_proto_text.bin
  4. CXX/LD-o.build_release/tools/test_net.bin
  5. CXX/LD-o.build_release/tools/upgrade_net_proto_text.bin
  6. CXX/LD-o.build_release/tools/finetune_net.bin
  7. .build_release/tools/test_net.o:Infunction`boost::system::system_error::what()const':
  8. test_net.cpp:(.text._ZNK5boost6system12system_error4whatEv[_ZNK5boost6system12system_error4whatEv]+0x74):undefinedreferenceto`std::__cxx11::basic_string<char,std::allocator<char>>::_M_replace(unsignedlong,charconst*,unsignedlong)'
  9. test_net.cpp:(.text._ZNK5boost6system12system_error4whatEv[_ZNK5boost6system12system_error4whatEv]+0xa1):undefinedreferenceto`std::__cxx11::basic_string<char,std::allocator<char>>::_M_append(charconst*,unsignedlong)'
  10. test_net.cpp:(.text._ZNK5boost6system12system_error4whatEv[_ZNK5boost6system12system_error4whatEv]+0xe3):undefinedreferenceto`std::__cxx11::basic_string<char,unsignedlong)'
  11. /usr/local/lib/libglog.so:undefinedreferenceto`std::__cxx11::basic_string<char,std::allocator<char>>::_M_create(unsignedlong&,unsignedlong)@GLIBCXX_3.4.21'
  12. /usr/local/lib/libglog.so:undefinedreferenceto`std::__cxx11::basic_string<char,char)@GLIBCXX_3.4.21'
  13. ...
  14. ...
  15. ...
  16. .build_release/lib/libcaffe.so:undefinedreferenceto`std::out_of_range::out_of_range(std::__cxx11::basic_string<char,std::allocator<char>>const&)'
  17. .build_release/lib/libcaffe.so:undefinedreferenceto`std::__cxx11::basic_string<char,char)'
  18. /usr/local/lib/libopencv_core.so:undefinedreferenceto`std::basic_istream<char,char)@GLIBCXX_3.4.21'
  19. .build_release/lib/libcaffe.so:undefinedreferenceto`std::__cxx11::basic_string<char,charconst*)const'
  20. /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libprotobuf.so:undefinedreferenceto`std::__cxx11::basic_string<char,std::allocator<char>>&)@GLIBCXX_3.4.21'
  21. /usr/local/lib/libglog.so:undefinedreferenceto`vtableforstd::__cxx11::basic_stringbuf<char,std::allocator<char>>@GLIBCXX_3.4.21'
  22. /usr/local/lib/libopencv_core.so:undefinedreferenceto`std::__cxx11::basic_stringbuf<char,std::allocator<char>>::str()const@GLIBCXX_3.4.21'
  23. collect2:error:ldreturned1exitstatus
  24. Makefile:629:recipefortarget'.build_release/tools/upgrade_net_proto_text.bin'Failed
  25. make:***[.build_release/tools/upgrade_net_proto_text.bin]Error1

2、sudo make runtest 时遇到的错误,【sudo apt install ffmpeg】安装ffmpeg即可,错误提示如下所示:

[plain] view plain copy
  1. hcq@ubuntu:~/caffe$sudomakeruntest
  2. .build_release/tools/caffe
  3. .build_release/tools/caffe:errorwhileloadingsharedlibraries:libopencv_core.so.3.2:cannotopensharedobjectfile:Nosuchfileordirectory
  4. Makefile:538:recipefortarget'runtest'Failed
  5. make:***[runtest]Error127

3、sudo make runtest 时遇到的错误,缺失一些相关的so链接

[plain] view plain copy
  1. hcq@hcq-To-be-filled-by-O-E-M:~/caffe$sudomakeruntest-j4
  2. .build_release/tools/caffe
  3. .build_release/tools/caffe:errorwhileloadingsharedlibraries:libhdf5_hl.so.10:cannotopensharedobjectfile:Nosuchfileordirectory
  4. Makefile:536:recipefortarget'runtest'Failed
  5. make:***[runtest]Error127
以及

[plain] view plain copy
  1. hcq@hcq-To-be-filled-by-O-E-M:~/caffe$sudomakeruntest-j4
  2. .build_release/tools/caffe
  3. .build_release/tools/caffe:errorwhileloadingsharedlibraries:libhdf5.so.10:cannotopensharedobjectfile:Nosuchfileordirectory
  4. Makefile:536:recipefortarget'runtest'Failed
  5. make:***[runtest]Error127

原因:目录/usr/lib/x86_64-linux-gnu下确实是找不到【libhdf5_hl.so.10】和【libhdf5.so.10】这两个文件,如下图所示:


解决方案:根据相应的文件,创建所需的软连接,如下所示:

[plain] view plain copy
  1. sudolnlibhdf5_serial_hl.so.10libhdf5_hl.so.10
  2. sudolnlibhdf5_serial.so.10libhdf5.so.10
4、Makefile.configure配置中,关于nvcc warning的一些警告,注释掉相关的配置代码即可,提示如下所示:

[plain] view plain copy
  1. NVCCsrc/caffe/layers/mvn_layer.cu
  2. nvccwarning:The'compute_20','sm_20',and'sm_21'architecturesaredeprecated,andmayberemovedinafuturerelease(Use-Wno-deprecated-gpu-targetstosuppresswarning).
  3. nvccwarning:The'compute_20',andmayberemovedinafuturerelease(Use-Wno-deprecated-gpu-targetstosuppresswarning).
  4. NVCCsrc/caffe/layers/filter_layer.cu
  5. nvccwarning:The'compute_20',andmayberemovedinafuturerelease(Use-Wno-deprecated-gpu-targetstosuppresswarning).
  6. nvccwarning:The'compute_20',andmayberemovedinafuturerelease(Use-Wno-deprecated-gpu-targetstosuppresswarning).
5、Check Failed: status == CUDNN_STATUS_SUCCESS (3 vs. 0) CUDNN_STATUS_BAD_PARAM

[plain] view plain copy
  1. F060110:03:16.68394028607cudnn.hpp:122]CheckFailed:status==CUDNN_STATUS_SUCCESS(3vs.0)CUDNN_STATUS_BAD_PARAM
  2. ***Checkfailurestacktrace:***
  3. @0x7f52e7de2e3dgoogle::LogMessage::Fail()
  4. @0x7f52e7de4bc0google::LogMessage::SendToLog()
  5. @0x7f52e7de2a23google::LogMessage::Flush()
  6. @0x7f52e7de558egoogle::LogMessageFatal::~LogMessageFatal()
  7. @0x7f52e313c5f8caffe::CuDNNConvolutionLayer<>::Reshape()
  8. @0x7f52e325ed37caffe::Net<>::Init()
  9. @0x7f52e326146ecaffe::Net<>::Net()
  10. @0x888f2ccaffe::NetTest<>::InitNetFromProtoString()
  11. @0x88e1d1caffe::NetTest_TestReshape_Test<>::TestBody()
  12. @0x91e4b3testing::internal::HandleExceptionsInMethodIfSupported<>()
  13. @0x917acatesting::Test::Run()
  14. @0x917c18testing::TestInfo::Run()
  15. @0x917cf5testing::TestCase::Run()
  16. @0x918fcftesting::internal::UnitTestImpl::RunAllTests()
  17. @0x9192f3testing::UnitTest::Run()
  18. @0x46d44dmain
  19. @0x7f52e2443830(unknown)
  20. @0x474f69_start
  21. Makefile:536:recipefortarget'runtest'Failed
  22. make:***[runtest]已放弃(coredumped)

原因:初步断定是NVIDIA的显存不够,本文所使用的机器是GeForce GTX 960 2GB的显存。本人做了如下探究:

1)据同学介绍,他使用的机器显存有8GB,就不会出现这样的问题。

2)本人还尝试使用cpu( 物理内存8GB )运行sudo make runtest -j4,也不会出现这样的问题。

解决方案:

1)从机器层面入手,扩大硬件性能(主要是显存

2)改用cpu跑程序,不过最后使用GPU的话还是需要使用好一点的设备(显卡、显卡)

参考网址:http://www.cnblogs.com/penguinliong/p/6351215.html


6、build_release/tools/caffe: error while loading shared libraries: libopenblas.so.0: cannot open shared object file: No such file or directory

描述:Makefile.configure配置好了,相应的引用位置也有libopenblas.so.0 该文件,make runtest的时候仍然出错。

解决方案:将openblas 的库所在位置添加到系统环境变量 LD_LIBRARY_PATH,export LD_LIBRARY_PATH=/opt/OpenBLAS/lib/ sudo ldconfig。打开终端,输入如下命令:

1)export LD_LIBRARY_PATH=/opt/OpenBLAS/lib/

2sudo ldconfig

参考网址:

1)http://www.jb51.cc/article/p-hgkqqphr-qh.html

2)http://www.jb51.cc/article/p-mxwdsawn-ek.html

3)https://github.com/sermanet/OverFeat/issues/10

配置成功后的提示如下所示:

[plain] view plain copy
  1. [OK]ArgMaxLayerTest/1.TestcpuMaxVal(1ms)
  2. [RUN]ArgMaxLayerTest/1.TestSetupMaxVal
  3. [OK]ArgMaxLayerTest/1.TestSetupMaxVal(1ms)
  4. [RUN]ArgMaxLayerTest/1.TestSetupAxis
  5. [OK]ArgMaxLayerTest/1.TestSetupAxis(0ms)
  6. [RUN]ArgMaxLayerTest/1.TestcpuTopK
  7. [OK]ArgMaxLayerTest/1.TestcpuTopK(1ms)
  8. [----------]12testsfromArgMaxLayerTest/1(48mstotal)
  9. [----------]4testsfromContrastiveLossLayerTest/1,whereTypeParam=caffe::cpuDevice<double>
  10. [RUN]ContrastiveLossLayerTest/1.TestGradientLegacy
  11. [OK]ContrastiveLossLayerTest/1.TestGradientLegacy(125ms)
  12. [RUN]ContrastiveLossLayerTest/1.TestForward
  13. [OK]ContrastiveLossLayerTest/1.TestForward(0ms)
  14. [RUN]ContrastiveLossLayerTest/1.TestGradient
  15. [OK]ContrastiveLossLayerTest/1.TestGradient(136ms)
  16. [RUN]ContrastiveLossLayerTest/1.TestForwardLegacy
  17. [OK]ContrastiveLossLayerTest/1.TestForwardLegacy(0ms)
  18. [----------]4testsfromContrastiveLossLayerTest/1(261mstotal)
  19. [----------]Globaltestenvironmenttear-down
  20. [==========]1106testsfrom150testcasesran.(43894mstotal)
  21. [PASSED]1106tests.
  22. hcq@hcq-To-be-filled-by-O-E-M:~/caffe$

7、Check Failed: fd != -1 (-1 vs. -1) File not found: examples/cifar10/cifar10_full_iter_60000.solverstate

描述:执行【sudo./examples/cifar10/train_full.sh】报错。

解决方案:


相似问题:Check Failed: fd != -1 (-1 vs. -1) File not found: deploy.prototxt

原因:因为没有把deploy.prototxt文件复制到demo下。

解决方案:把caffe/models/bvlc_reference_caffnnet/deploy.prototxt复制到demo下即可。

参考网址:http://www.jb51.cc/article/p-fwfghnpr-qq.html


8、error while loading shared libraries: libhdf5_hl.so.100

[html] view plain copy
  1. build_release/tools/caffe:errorwhileloadingsharedlibraries:libhdf5_hl.so.100:cannotopensharedobjectfile:Nosuchfileordirectory
  2. Makefile:470:recipefortarget'runtest'Failed
参考网址: http://www.jb51.cc/article/p-qixhtjny-bpx.html

9、Makefile:567: recipe for target '.build_release/examples/cifar10/convert_cifar_data.bin' Failed

[html] view plain copy
  1. Makefile:567:recipefortarget'.build_release/examples/mnist/convert_mnist_data.bin'Failed
  2. make:***[.build_release/examples/mnist/convert_mnist_data.bin]Error1
  3. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFReadRGBAStrip@LIBTIFF_4.0'
  4. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFIsTiled@LIBTIFF_4.0'
  5. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFWriteScanline@LIBTIFF_4.0'
  6. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFGetField@LIBTIFF_4.0'
  7. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFScanlineSize@LIBTIFF_4.0'
  8. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFReadEncodedTile@LIBTIFF_4.0'
  9. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFReadRGBATile@LIBTIFF_4.0'
  10. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFClose@LIBTIFF_4.0'
  11. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFRGBAImageOK@LIBTIFF_4.0'
  12. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFOpen@LIBTIFF_4.0'
  13. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFReadEncodedStrip@LIBTIFF_4.0'
  14. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFSetField@LIBTIFF_4.0'
  15. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFSetWarningHandler@LIBTIFF_4.0'
  16. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFSetErrorHandler@LIBTIFF_4.0'
  17. collect2:error:ldreturned1exitstatus
  18. Makefile:567:recipefortarget'.build_release/examples/cifar10/convert_cifar_data.bin'Failed
  19. make:***[.build_release/examples/cifar10/convert_cifar_data.bin]Error1
reference: https://www.cnblogs.com/whu-zeng/p/6874307.html

9、Ubuntu 16.04中使用Matlab R2016b编译Caffe接口出错的解决方法

[html] view plain copy
  1. MEX-file'caffe/matlab/+caffe/private/caffe_.mexa64'无效:
  2. caffe/matlab/+caffe/private/caffe_.mexa64:undefined
  3. symbol:_ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERSt6vectorIhSaIhEERKSB_IiSaIiEE。
  4. 出错caffe.set_mode_cpu(line5)
  5. caffe_('set_mode_cpu');
  6. 出错caffe.run_tests(line6)
  7. caffe.set_mode_cpu();
reference: https://github.com/BVLC/caffe/issues/3934


10、gcc 降级后的问题

[html] view plain copy
  1. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFGetField@LIBTIFF_4.0'
  2. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFScanlineSize@LIBTIFF_4.0'
  3. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::internal::NameOfEnum(google::protobuf::EnumDescriptorconst*,int)'
  4. .build_release/lib/libcaffe.so:undefinedreferenceto`cv::imread(std::stringconst&,int)'
  5. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFReadEncodedTile@LIBTIFF_4.0'
  6. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFReadRGBATile@LIBTIFF_4.0'
  7. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFClose@LIBTIFF_4.0'
  8. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::DescriptorPool::FindFileByName(std::stringconst&)const'
  9. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFRGBAImageOK@LIBTIFF_4.0'
  10. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*,std::string*)'
  11. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::internal::StringTypeHandlerBase::Delete(std::string*)'
  12. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFOpen@LIBTIFF_4.0'
  13. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::MessageFactory::InternalRegisterGeneratedFile(charconst*,void(*)(std::stringconst&))'
  14. .build_release/lib/libcaffe.so:undefinedreferenceto`leveldb::DB::Open(leveldb::Optionsconst&,std::stringconst&,leveldb::DB**)'
  15. .build_release/lib/libcaffe.so:undefinedreferenceto`cv::imencode(std::stringconst&,cv::_InputArrayconst&,std::vector<unsignedchar,std::allocator<unsignedchar>>&,std::vector<int,std::allocator<int>>const&)'
  16. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFReadEncodedStrip@LIBTIFF_4.0'
  17. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFSetField@LIBTIFF_4.0'
  18. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::internal::StringTypeHandlerBase::New()'
  19. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(int,google::protobuf::io::CodedOutputStream*)'
  20. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFSetWarningHandler@LIBTIFF_4.0'
  21. /usr/lib/x86_64-linux-gnu/libopencv_highgui.so:undefinedreferenceto`TIFFSetErrorHandler@LIBTIFF_4.0'
  22. .build_release/lib/libcaffe.so:undefinedreferenceto`leveldb::Status::ToString()const'
  23. .build_release/lib/libcaffe.so:undefinedreferenceto`google::protobuf::internal::WireFormatLite::WriteString(int,google::protobuf::io::CodedOutputStream*)'
  24. collect2:error:ldreturned1exitstatus
  25. Makefile:567:recipefortarget'.build_release/examples/cifar10/convert_cifar_data.bin'Failed
  26. make:***[.build_release/examples/cifar10/convert_cifar_data.bin]Error1

reference: http://www.jb51.cc/article/p-vyhrkbir-yc.html



其他相关的参考网址:

1、解决/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found问题:http://www.jb51.cc/article/p-dncvgnde-ey.html

2、Caffe搭建:常见问题解决办法和ubuntu使用中遇到问题(持续更新):http://www.cnblogs.com/empty16/p/4828476.html

3、安装python caffe过程中遇到的一些问题以及对应的解决方案:http://www.cnblogs.com/TiBAi/p/6848307.html

4、安装caffe总结:http://blog.csdn.net/csoldiers/article/details/51685179

5、caffe+cuda7.0+opencv3.0.0+mkl ubuntu14.04配置:http://www.th7.cn/system/lin/201504/103304.shtml

6、Caffe 环境搭建中应注意的问题:http://www.jb51.cc/article/p-evvodmjx-gt.html

7、caffe cpu版 Anaconda3 python 接口安装:http://www.jb51.cc/article/p-xoksgxry-bcx.html

猜你在找的Ubuntu相关文章