いつもの作業の備忘録

作業を忘れがちな自分のためのブログ

【Caffe】ネットワークを可視化する

前回(【Caffe】特徴量抽出を行いSVMで物体識別する - いつもの作業の備忘録)使用したネットワークを可視化する

1.描画用Pydotインストール

以下の二つのコマンドを実行したが、apt-getはなくても動くかもしれない

$ sudo apt-get install python-pydot
$ pip install pydot2

2.描画コマンド実行

以下のコマンドでネットワークを描画し、deploy.jpgで保存する

$ cd $CAFFE_HOME
$ python/draw_net.py models/bvlc_reference_caffenet/deploy.prototxt deploy.jpg

可視化結果が下図
f:id:whg_res:20160304132046j:plain
赤が畳み込み層、緑が活性化関数、オレンジがプーリング、青が正規化、グレーがデータらしい

もし、エラーが出る場合は以下のように対応

  • AttributeError: 'module' object has no attribute 'bool_'

これは、import caffeした際に出るかもしれない。

$ cd $CAFFE_HOME/python
$ aftfile="caffe_io"
$ for file in `find . -name "*.py"`; do cat $file | sed -e "s/import [\w\.]*io/import $aftfile/g" | sed -e "s/caffe\.io/caffe\.$aftfile/g" > $file".tmp";mv $file".tmp" $file; done
$ mv "caffe/io.py" "caffe/"$aftfile".py"
  • Couldn't import dot_parser, loading of dot files will not be possible.
$ pip uninstall pyparsing
$ pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz#md5=9be0fcdcc595199c646ab317c1d9a709
$ pip install pydot

※参考
http://www.installion.co.uk/ubuntu/precise/universe/p/python-pydot/install/index.html
http://stackoverflow.com/questions/15951748/pydot-and-graphviz-error-couldnt-import-dot-parser-loading-of-dot-files-will
https://groups.google.com/forum/#!topic/caffe-users/4r5dxoFpWxk
http://qiita.com/CORDEA/items/9fad27ae024928b6a7b1
http://wiki.ruka-f.net/index.php?Pydot