Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
学習済み Caffe モデルを移植してみた
Search
ohtysk
December 19, 2015
1
65k
学習済み Caffe モデルを移植してみた
ohtysk
December 19, 2015
Tweet
Share
More Decks by ohtysk
See All by ohtysk
20170408_cvsaisentan_39_ohtysk
ohtysk
0
1.2k
20161203_cvsaisentan_ECCV2016
ohtysk
0
610
Featured
See All Featured
The Language of Interfaces
destraynor
158
25k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Speed Design
sergeychernyshev
32
1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
The World Runs on Bad Software
bkeepers
PRO
69
11k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
Designing for humans not robots
tammielis
253
25k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Transcript
学習済み Caffe モデルを 移植して使ってみた 2015/12/19 @ohtysk 1
自己紹介 • twitter id: @ohtysk • メーカ勤務 研究・開発 ソフトウエアエンジニア 画像処理
• python, DNN, Chainer 初心者(勉強中) • 「人工知能は人間を越えるか」「深層学習」読了 2
背景 • 動機:実績のある学習済みモデルを使って CNN の性能を向上したい • Chainer には学習済み Caffe モデルを利用するしくみがある
• しかし上記の仕組みは個人的には以下のような課題がある • 記述が独自で学習コストとコード量が増大する • Caffe モデルの読み込みに時間がかかる => そこで Caffe モデルを Chainer モデルに移植して使ってみた 3
移植のステップ ① caffemodel/prototxt をダウンロード a. 「caffe modelzoo」でぐぐると出てくる ② caffemodel ファイルから
hdf5 ファイルを作成(詳細は後述) ③ caffemodel に対応する Chain クラスを作成(詳細は後述) a. ここが少し手間なので将来的には自動生成できるとうれしいですね! b. alexnet, googlenet などについては chainer/examples/imagenet に既にある! ④ 作成した Chain オブジェクトに hdf5 データをロード(詳細は後述) 4
全体像 5 Caffe Model Zoo alexnet.caffemodel train.prototxt deply.prototxt local machine
alexnet.caffemodel train.prototxt deply.prototxt ①download alexnet.h5 alex.py ②convert internet network.png ③visualize network ③create ③create ④load
②caffemodel ファイルから hdf5 ファイルを作成 import chainer.functions.caffe as c import chainer.serializers
as s func = c.CaffeFunction(“alexnet.caffemodel”) # caffemodel 読み込み。遅い! s.save_hdf5(“alexnet.h5”, func) # hdf5 ファイルに保存。簡単! 6
• 右図のような Chain クラスを定義 • __init__ で link を定義 •
__call__で link, function を接続 • ヒント • ②の func を調べる • prototxt を読む • ネットワーク図を見る(caffe/python/draw_net.py で作成可能) ③caffemodel に対応する Chain クラスを定義 7 図1Chain クラス例 図2 ネットワーク図例 ex) dir(func) func.layers func.forwards func[‘conv1’]
④作成した Chain オブジェクトにデータをロード import alex # caffemodelに対応した Chain クラスをインポート import
chainer.serializers as s model = alex.Alex() # Chain オブジェクトを作成 s.load_hdf5(“alexnet.h5”, model) # 学習済みデータをロード。早い! (中略) s.save_hdf5(“alexnet2.h5”, model) # 必要なら再学習済みのデータを保存 8
結果 9 • bvlc_alexnet を移植して再学習した結果 • 記述が統一され学習コストとコード量増大を抑制 • 読み込み時間短縮 182sec
-> 2.7sec • ゼロからの学習と再学習の比較結果 • 再学習の方が学習が進みやすい傾向 • 再学習の方が正解率が高まる傾向 • chainer/examples/imagenet/alex.py と若干の差異が見つかった
まとめ • Caffe モデルの Chainer 移植方法について説明 • 実際に移植した結果、移植の利点を実感 • 今後
caffemodel/prototxt から Chain クラスを自動生成できるといいですね 学習済み Caffe モデルを移植して Happy Chainer Life を! 10