Caffe 网络结构可视化

可以利用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 update
sudo apt-get install python-dev
  • 1
  • 2

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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

wget https://bootstrap.pypa.io/get-pip.py  --no-check-certificate
sudo python get-pip.py
  • 1
  • 2

或者直接更新pip:

pip install -U pip
  • 1

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
  • 1
  • 2

2.编译 pycaffe

cd ${CAFFE_ROOT}
make clean
make
make pycaffe
  • 1
  • 2
  • 3
  • 4

3.绘制网络结构图

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

这里写图片描述

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值