可以先用make -j8 && make pycaffe来查看目前有啥问题
问题1:
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_videoio
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target ‘.build_release/lib/libcaffe.so.1.0.0-rc3’ failed
make: * [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
解决方法:
CXX src/caffe/solver.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target ‘.build_release/lib/libcaffe.so.1.0.0-rc3’ failedmake: * [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
参考:http://blog.csdn.net/oyjxer/article/details/51824254安装,
然后修改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
但注意,这里由于cannot find 的内容不同,所以这样改是错的。不必要动这块儿。
2.接着make -j8 && make pycaffe(这里没有make clean)
然后还是报上面的错误。
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_videoio
collect2: error: ld returned 1 exit status
Makefile:566: recipe for target ‘.build_release/lib/libcaffe.so.1.0.0-rc3’ failed
make: * [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
实际上是opencv的问题。
解决方法:安装opencv
sudo apt install git
git clone https://github.com/jayrambhia/Install-OpenCV
cd Install-OpenCV/Ubuntu/
chmod +x *
./opencv_latest.sh
3.make -j8 && make pycaffe
正确的情况是:
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3 CXX/LD -o
.build_release/tools/train_net.bin CXX/LD -o
.build_release/tools/net_speed_benchmark.bin CXX/LD -o
.build_release/tools/create_label_map.bin CXX/LD -o
.build_release/tools/convert_annoset.bin CXX/LD -o
.build_release/tools/finetune_net.bin CXX/LD -o
.build_release/tools/upgrade_solver_proto_text.bin CXX/LD -o
.build_release/tools/extract_features.bin CXX/LD -o
.build_release/tools/caffe.bin CXX/LD -o
.build_release/tools/compute_image_mean.bin CXX/LD -o
.build_release/tools/test_net.bin CXX/LD -o
.build_release/tools/convert_imageset.bin CXX/LD -o
.build_release/tools/get_image_size.bin CXX/LD -o
.build_release/tools/device_query.bin CXX/LD -o
.build_release/tools/upgrade_net_proto_binary.bin CXX/LD -o
.build_release/tools/upgrade_net_proto_text.bin CXX/LD -o
.build_release/examples/siamese/convert_mnist_siamese_data.bin CXX/LD
-o .build_release/examples/ssd/ssd_detect.bin CXX/LD -o .build_release/examples/cifar10/convert_cifar_data.bin CXX/LD -o
.build_release/examples/mnist/convert_mnist_data.bin CXX/LD -o
.build_release/examples/cpp_classification/classification.bin CXX/LD
-o python/caffe/_caffe.so python/caffe/_caffe.cpp touch python/caffe/proto/init.py PROTOC (python)
src/caffe/proto/caffe.proto
当再一次执行make pycaffe时,显示:
make: Nothing to be done for ‘pycaffe’. 证明是没有问题的
4.bash ./data/mnist/get_mnist.sh
正常
./examples/mnist/create_mnist.sh
正常
./examples/mnist/train_lenet_adam.sh
发现执行这个命令时出错了。
E0302 13:16:16.531128 6895 common.cpp:113] Cannot create Cublas handle. Cublas won’t be available.
F0302 13:16:18.103356 6887 cudnn_conv_layer.cpp:53] Check failed: status == **CUDNN**_STATUS_SUCCESS (4 vs. 0) CUDNN_STATUS_INTERNAL_ERROR
./examples/mnist/train_lenet.sh
当执行这个命令时,同样出错了。
E0302 13:16:26.964674 6908 common.cpp:113] Cannot create Cublas handle. Cublas won’t be available.
F0302 13:16:27.254376 6900 cudnn_conv_layer.cpp:53] Check failed: status == **CUDNN**_STATUS_SUCCESS (4 vs. 0) CUDNN_STATUS_INTERNAL_ERROR
而在此时,make -j8 && make pycaffe 显示:
make: Nothing to be done for ‘all’.
make: Nothing to be done for ‘pycaffe’.
编译是通过了啊,这是怎么回事呢?
好吧,在Makefile.config文件中把cudnn关了,make clean,重新来过。make -j8 && make pycaffe
OK,好吧,运行正常,显示:
touch python/caffe/proto/init.py
PROTOC (python) src/caffe/proto/caffe.proto
再执行
./examples/mnist/train_lenet.sh
这次错误是:
F0302 13:23:22.642010 18584 math_functions.cu:26] Check failed: status == CUBLAS_STATUS_SUCCESS (1 vs. 0) CUBLAS_STATUS_NOT_INITIALIZED
好吧,可能是cuda的问题。
安装cuda
# 注意:安装过程中不要选择安装显卡驱动,其他选择yes即可。
sudo sh cuda_8.0.44_linux.run --no-opengl-libs
reboot
# 添加环境变量
sudo gedit ~/.bashrc
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
source ~/.bashrc
验证cuda
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
安装CUDNN,并把Makefile.config中的开关打开:USE_CUDNN := 1
下载cudnn,并且拷贝到/usr/local路径下:
sudo cp /home/qi/cudnn-8.0-linux-x64-v5.0-ga.tgz /usr/local
解压,执行:
sudo tar -zxvf cudnn-8.0-linux-x64-v5.0-ga.tgz
解压后,执行:
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
5.
make clean
make -j8 && make pycaffe
./examples/mnist/train_lenet.sh
然后依然显示:
E0302 13:43:02.388759 30003 common.cpp:113] Cannot create Cublas handle. Cublas won’t be available.
F0302 13:43:02.431520 29995 cudnn_conv_layer.cpp:53] Check failed: status == CUDNN_STATUS_SUCCESS (4 vs. 0) CUDNN_STATUS_INTERNAL_ERROR
解决方法:加sudo
sudo ./examples/mnist/train_lenet.sh
运行终于正常了。
再试一个
sudo ./examples/mnist/train_lenet_adam.sh
正常
终于装好了~
有几个命令:
卸载anaconda
rm -rf anaconda2/
打开环境变量管理:sudo gedit ~/.bashrc
在这里有几个需要注意的地方:
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export PYTHONPATH=/home/qi/caffe/python:$PYTHONPATH
让配置立即生效:
source ~/.bashrc
查看显存占用情况:
nvidia-smi
查看Python版本
python -V
在Python下查看opencv版本
python
import cv2
cv2.__version__
关于caffe的安装推荐一篇博文:http://www.cnblogs.com/peiyuYang/p/7784787.html