环境:
ubuntu16.04 cuda8.0 cudnn5.0
已安装过caffe1.0 tensorflow1.2
编辑过程中出现问题尽量到这里面搜一下:https://github.com/BVLC/caffe/issues
教程 https://github.com/weiliu89/caffe/tree/ssd
Installation
- Get the code. We will call the directory that you cloned Caffe into
$CAFFE_ROOT
git clone https://github.com/weiliu89/caffe.git
cd caffe
git checkout ssd
- Build the code. Please follow Caffe instruction to install all necessary packages and build it.
# Modify Makefile.config according to your Caffe installation.
cp Makefile.config.example Makefile.config
make -j8
# Make sure to include $CAFFE_ROOT/python to your PYTHONPATH.
make py
make test -j8
# (Optional)
make runtest -j8 问题:此处参考了别的教程使用了make all -j8出现问题(一定看官方教程)问题描述:
This file was generated by an older version of protoc which is incompatible with your Protocol Buffer headers. Please regenerate this file with a newer version of protoc.
原因是系统中装tensorflow时装有了多个版本的protobuf,造成版本冲突。将protobuf卸载后,按照此教程重新安装https://www.cnblogs.com/luoxn28/p/5303517.html
tar -xvf protobuf cd protobuf ./configure --prefix=/usr/local/protobuf make make check make install
按照上边的还有问题,加上这部分
去https://developers.google.com/protocol-buffers/docs/downloads下载*.tar.tz压缩包,解压,
命令行进入解压后目录,依次执行如下
./configure
make
创建文件 /etc/ld.so.conf.d/libprotobuf.conf 写入内容:/usr/local/lib
输入命令 sudo ldconfig
注:protobuf的默认安装路径是/usr/local/lib,而/usr/local/lib 不在Ubuntu体系默认的 LD_LIBRARY_PATH 里,后面install找不到该lib 然后sudo make install 安装后,输入protoc --version 验证是否安装成功
如果还有问题,参考:https://my.oschina.net/ifraincoat/blog/406339
然后输入protoc --version查看是否安装成功,报错:protoc: error while loading shared libraries: libprotoc.so.8: cannot open shared object file: No such file or directory
解决办法: export LD_LIBRARY_PATH=/usr/local/lib/ (这个可能需要写到环境变量里,否则会不会下次启动就不能用了)
装完一定要清理一下,一定要清理一下!! make clean!!!
install libhdf5-dev add patch to libhdf5 in Makefile.config. example: INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
参考:https://askubuntu.com/questions/629654/building-caffe-failed-to-see-hdf5-h
继续编译,新的问题gcc版本过高, /usr/local/cuda/include/host_config.h::: error: #error -- unsupported GNU version! gcc versions
解决方案:降低gcc与g++版本到5,参考https://blog.csdn.net/qq_31175231/article/details/77774971
gcc --verison查看gcc
()设置gcc的默认版本
设置之前可以先输入命令ls /usr/bin/gcc* 查看gcc .8版本是否安装成功
然后输入下面的命令设置默认版本:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8
最后的数字为优先级(越大越高),因为只有一个4.8版本作为alternatives,可以不要纠结数字,这样设就行了
()然后可以输入以下命令查看设置结果(非必须)
sudo update-alternatives --config gcc
因为只设置了一个,所以显示结果为:"链接组 gcc (提供 /usr/bin/gcc)中只有一个候选项:/usr/bin/gcc-4.8
无需配置.",如果有多个则会显示一个按优先级的列表.
()最后再次输入命令gcc -version查看gcc的版本已经变成4.8啦...就成功啦.
现在默认版本已经是4.8版本,如果想用6.2版本,则gcc-6.2 这样指定就好啦
g++ 等其他软件也是这样设置进行版本升级/降级. ps: ()当以上设置不需要的时候输入以下命令删除: sudo update-alternatives --remove gcc /usr/bin/gcc-4.8
---------------------
作者:帝江VII
来源:CSDN
原文:https://blog.csdn.net/qq_31175231/article/details/77774971
版权声明:本文为博主原创文章,转载请附上博文链接!
继续编译,出现问题
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_videoio
collect2: error: ld returned exit status
Makefile:: recipe for target ‘.build_release/lib/libcaffe.so.1.0.-rc3’ failed
make: * [.build_release/lib/libcaffe.so.1.0.-rc3] Error
首先更新Makefile,不知道管没管用,参考https://blog.csdn.net/sunshinezhihuo/article/details/79427093
然后修改Makefile 文件(注意不是)Makefile.config 将里面的 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
然后还是原问题,根据https://github.com/BVLC/caffe/issues/5308安装库
Did you apt-get install libopenblas-base libopenblas-dev
?
继续编译,出现问题: .build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::set(int, double)' .build_r
solution: add "opencv_imgcodecs" in Makefile.(LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs)
If you input "make all",the problem is the same again.But if you delete all the file in build(rm -rf ./build/*) before "make all"(I use make clean ),you will success.I just success github 讨论帖:https://github.com/BVLC/caffe/issues/2348
参考链接:https://www.douban.com/note/568788483/
另外opencv_videoio也要加上。
继续编译新问题出现 .build_release/lib/libcaffe.so: undefined reference to `boost::filesystem::detail::status(boost::fil
解决方式:再加一个库boost_filesystem
第一步编译成功
二:make py
问题:
python/caffe/_caffe.cpp::: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
Makefile:: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error
解决方式:
如果还是不行,可以试试: import numpy as np
np.get_include()
得到:
/usr/local/lib/python2./dist-packages/numpy/core/include 在Makefile.config找到PYTHON_INCLUDE,发现有点不同: PYTHON_INCLUDE := /usr/include/python2. \
/usr/lib/python2./dist-packages/numpy/core/include 要加一个local,变成: PYTHON_INCLUDE := /usr/include/python2. \
/usr/local/lib/python2./dist-packages/numpy/core/include
再make pycaffe就ok了
参考:https://blog.csdn.net/wuzuyu365/article/details/52430657
三:
不要随便make clean 否则会出现 make: .build_release/tools/caffe: Command not found
解决方式:make all 参考:https://blog.csdn.net/xunan003/article/details/72997028
问题: Makefile:: recipe for target 'runtest' failed make: *** [runtest] Segmentation fault
解决方案:sf@ubuntu:~/caffe$ export MKL_CBWR=AUTO
不要make clean,然后重新make runtest
这个问题没有解决,但是看网上资料说这个不用全部运行成功也可以,就没有继续调试
然后在python环境下imoprt python,报错 ImportError: No module named caffe
solution:
A.把环境变量路径放到 ~/.bashrc文件中,打开文件
sudo vim ~/.bashrc 在文件下方写入
export PYTHONPATH=~/caffe/python:$PYTHONPATH 上述语句中 “~” 号表示caffe 所在的根目录。 B.关闭文件,在终端写入下面语句,使环境变量生效
source ~/.bashrc
---------------------
作者:修炼打怪的小乌龟
来源:CSDN
原文:https://blog.csdn.net/u010417185/article/details/53559107
版权声明:本文为博主原创文章,转载请附上博文链接!
继续import,报错 ImportError: No module named google.protobuf.internal
solution: sudo pip install protobuf