Caffe 网络结构可视化

来源:互联网 发布:企业站如何优化 编辑:程序博客网 时间:2024/06/11 12:44

可以利用python接口实现网络结构的可视化,便于直观理解。

最近安装了tensorflow,发现caffe的draw_net脚本不好用了(AttributeError: ‘google.protobuf.pyext._message.RepeatedScalarConta’ object has no attribute ‘_values’),原因是二者的protobuf版本不兼容。caffe不支持高于3.0.0版本的protobuf.

解决方法:
卸载当前protobuf。(pip uninstall protobuf)
再指定安装低版本的,这里用的是2.5.0(pip install protobuf==2.5.0)
可以用virtualenv创建独立的Python环境

在线网页绘制caffe网络结构图的方法,其实更简洁方便:
http://ethereon.github.io/netscope/#/editor

注:主要参考《21天实战caffe》

1.准备Python环境

1.1安装Python

sudo apt-get updatesudo apt-get install python-dev

1.2安装Python包管理器:pip
这里建议通过源码安装,如果通过命令 sudo apt-get install python-pip 安装,可能会出现类似下面的错误,主要原因是上述方式安装的pip版本较老。

Exception:Traceback (most recent call last):  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main    status = self.run(options, args)  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1260, in prepare_files    )[0]IndexError: list index out of range

源码安装pip方式如下(参考:http://www.cnblogs.com/ajianbeyourself/p/4214398.html):

wget https://bootstrap.pypa.io/get-pip.py  --no-check-certificatesudo python get-pip.py

或者直接更新pip:

pip install -U pip

1.3通过pip安装依赖包
这里caffe已经列出了依赖包及版本号,在caffe源码根目录下的 /python/requirement.txt 中:
Cython>=0.19.2
numpy>=1.7.1
scipy>=0.13.2
scikit-image>=0.9.3
matplotlib>=1.3.1
ipython>=3.0.0
h5py>=2.2.0
leveldb>=0.191
networkx>=1.8.1
nose>=1.3.0
pandas>=0.12.0
python-dateutil>=1.4,<2
protobuf>=2.5.0
python-gflags>=2.0
pyyaml>=3.10
Pillow>=2.3.0
six>=1.1.0

sudo apt-get install python-numpy #之前以为和下面pip安装的重复了,但是不安装编译时会报numpy的错误。sudo pip install -r ${CAFFE_ROOT}/python/requirement.txt

2.编译 pycaffe

cd ${CAFFE_ROOT}make cleanmakemake pycaffe

3.绘制网络结构图

cd ${CAFFE_ROOT}python ./python/draw_net.py ./models/bvlc_reference_caffenet/train_val.prototxt ~/Desktop/caffenet.png

这里写图片描述

4.“dot” not found in path 的问题

2016.12.01添加:

先安装graphviz否则会出现类似:“dot” not found in path 的问题
安装graphviz不要用pip install安装,否则还是会找不到可执行程序
安装:sudo apt-get insall graphviz
然后安装pydot:pip install pydot
其中pyparsing会自动安装

摘自:pydot 安装 用于caffe画图

0 0
原创粉丝点击