Caffe+Matlab的坑

Posted ariel-dreamland

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Caffe+Matlab的坑相关的知识,希望对你有一定的参考价值。

1、安装依赖库也能出问题

命令行输入:

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

出现错误:

Could not find /boot/grub/menu.lst file. Would you like /boot/grub/menu.lst generated for you? (y/N) /usr/sbin/update-grub: 第 1094 行: read: 读错误: 0: 错误的文件描述符
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: 处理软件包 linux-image-4.15.0-29-generic (--configure)时出错:
 子进程 已安装 post-installation 脚本 返回错误状态 1
在处理时有错误发生:
 linux-image-4.15.0-29-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

解决办法:

cd /boot/grub

之后:

sudo update-grub

再安装依赖库就可以了。

 

2、Caffe倒是很容易配置好,编译matcaffe的时候,出现问题:

make mattest时报错:

1 Invalid 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 
5 Error in caffe.set_mode_cpu (line 5)
6 caffe_(set_mode_cpu);
7 
8 Error in caffe.run_tests (line 6)
9 caffe.set_mode_cpu();

有些说法是要执行如下命令:

1 export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4:/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libfreetype.so.6
2 export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6

但是再次运行make mattest时会有新错误:

1 malloc: unknown:0: assertion botched
2 free: called with unallocated block argument
3 last command: (null)
4 Aborting...find: ‘bash’ terminated by signal 6

虽然最后还是能运行成功,但发现在运行bash指令时无法成功执行,纠结了好久发现是这里没有彻底解决问题,解决方法是:

将 libopencv_imgproc.so.2.4, libopencv_core.so.2.4, libopencv_highgui.so.2.4三个文件拷贝到/usr/local/MATLAB/R2016b/bin/glnxa64/中

sudo mv /usr/local/MATLAB/R2016a/bin/glnxa64/libopencv_imgproc.so.2.4.9 /usr/local/MATLAB/R2016a/bin/glnxa64/libopencv_imgproc.so.2.4.old
sudo cp /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4 /usr/local/MATLAB/R2016a/bin/glnxa64/

sudo mv /usr/local/MATLAB/R2016a/bin/glnxa64/libopencv_core.so.2.4.9 /usr/local/MATLAB/R2016a/bin/glnxa64/libopencv_core.so.2.4.old
sudo cp /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4 /usr/local/MATLAB/R2016a/bin/glnxa64/

sudo mv /usr/local/MATLAB/R2016a/bin/glnxa64/libopencv_highgui.so.2.4.9 /usr/local/MATLAB/R2016a/bin/glnxa64/libopencv_highgui.so.2.4.old
sudo cp /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4 /usr/local/MATLAB/R2016a/bin/glnxa64/

注:上面是我的matlab、opencv版本以及路径。

再执行:

1 export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6

bash指令没有问题了,搞定。

以上是关于Caffe+Matlab的坑的主要内容,如果未能解决你的问题,请参考以下文章

Caffe初学者第一部:Ubuntu14.04上安装caffe(CPU)+Python的详细过程 (亲测成功, 20180524更新)

ubuntu17.10 caffe 编译安装的坑

安装caffe碰到的坑(各种.so未找到)

ubuntu下 编译Caffe的Matlab接口

python Caffe片段

caffe-windows caffe-master 之 matlab接口配置