[機械学習] PythonライブラリのDeelをインストールして写真判定

2017年2月9日

AI Python テクノロジー プログラミング

深層学習を勉強し始めたわけだが、とりあえず、参考書を買ってチュートリアルをやっていくのが手っ取り早いでしょ。 [amazonjs asin="4774185345" locale="JP" title="はじめての深層学習(ディープラーニング)プログラミング"] とりあえずAmazonで初心者向きという事だったので、「はじめての深層学習(ディープラーニング)プログラミング」を購入してみた。 この本は序盤は環境構築を細かく書いてくれているんだが、やはりpythonやらpipやら他にも各種モジュールのマイナーバージョンまで少し違うとインストールが途端にエラーになって進まなくなる。 これまで少しやっていた記事も参考にしながら勧めます。 ディープラーニングの環境構築の為に「chainer」をインストール ディープラーニングの環境構築の為にMacBookAirに「OpenCV」をインストール

Deelのインストール作業

Chainerを簡単に使う事ができるツールの「Deel」ですが、本に書かれている通り、Githubからcloneしてきただけでは、うまく動作せず、実行エラーを履いていたので、その解決までの道程を書き留めておきます。 まず本に書いていた内容としては、Chainerをインストールしたあとで、DeelをGithubからcloneするだけだったのだが、いくつかの手順が抜けていた。 ※Chainerのインストールは、ディープラーニングの環境構築の為に「chainer」をインストールを参考に入れてください。

DeelをGithubから取得してインストール

$ git clone https://github.com/uei/deel.git $ cd deel/misc/ $ ./getPretrainedModels.sh 本に書かれていた内容は上記でその後実行だったのだが、普通にエラー発生 from deel import * from deel.network import * from deel.network.googlenet import * from deel.commands import * deel = Deel() CNN = GoogLeNet() CNN.Input("deel.png") CNN.classify() ShowLabels() 実行してみる。 $ python tyny.py Traceback (most recent call last): File "tyny_2.py", line 2, in <module> from deel.network import * File "/Users/yugeta.koji1/web/study/python/dl/deel/deel/network/__init__.py", line 7, in <module> from deel.tensor import * File "/Users/yugeta.koji1/web/study/python/dl/deel/deel/tensor.py", line 15, in <module> from PIL import Image ImportError: No module named PIL なんだかモジュールが足りていないエラーが出ている。

README.mdの通りインストールしてみる

$ git clone https://github.com/uei/deel.git $ cd deel $ python setup.py install $ cd deel/data $ ./getCaltech101.sh $ cd ../misc $ ./getPretrainedModels.sh $ cd .. $ python test.py やはり何だか途中を抜かしてますね。 抜けてる箇所は以下のところでした。 $ python setup.py install $ cd deel/data $ ./getCaltech101.sh ここまで完了して実行しても同じエラーが出ていた・・・

モジュール不足エラーを元にググってみた

人工生命サンプル実行成功。 このページを参考にして下記ライブラリをbrewインストールしてみた。 brew install libjpeg libjpeg-turbo libpng ・・・まだだめ・・・

pipでもインストールしてみる

とりあえず、なんとなくダメ元で、deelをpipモジュールとしてインストールしてみる。 $ pip install deel

一応成功!!!

$ python tyny.py Loading bvlc_googlenet.caffemodel Converting from bvlc_googlenet.caffemodel data 5 label_data_1_split 22 conv1/7x7_s2 4 conv1/relu_7x7 18 pool1/3x3_s2 17 pool1/norm1 15 conv2/3x3_reduce 4 conv2/relu_3x3_reduce 18 conv2/3x3 4 conv2/relu_3x3 18 conv2/norm2 15 pool2/3x3_s2 17 pool2/3x3_s2_pool2/3x3_s2_0_split 22 inception_3a/1x1 4 inception_3a/relu_1x1 18 inception_3a/3x3_reduce 4 inception_3a/relu_3x3_reduce 18 inception_3a/3x3 4 inception_3a/relu_3x3 18 inception_3a/5x5_reduce 4 inception_3a/relu_5x5_reduce 18 inception_3a/5x5 4 inception_3a/relu_5x5 18 inception_3a/pool 17 inception_3a/pool_proj 4 inception_3a/relu_pool_proj 18 inception_3a/output 3 inception_3a/output_inception_3a/output_0_split 22 inception_3b/1x1 4 inception_3b/relu_1x1 18 inception_3b/3x3_reduce 4 inception_3b/relu_3x3_reduce 18 inception_3b/3x3 4 inception_3b/relu_3x3 18 inception_3b/5x5_reduce 4 inception_3b/relu_5x5_reduce 18 inception_3b/5x5 4 inception_3b/relu_5x5 18 inception_3b/pool 17 inception_3b/pool_proj 4 inception_3b/relu_pool_proj 18 inception_3b/output 3 pool3/3x3_s2 17 pool3/3x3_s2_pool3/3x3_s2_0_split 22 inception_4a/1x1 4 inception_4a/relu_1x1 18 inception_4a/3x3_reduce 4 inception_4a/relu_3x3_reduce 18 inception_4a/3x3 4 inception_4a/relu_3x3 18 inception_4a/5x5_reduce 4 inception_4a/relu_5x5_reduce 18 inception_4a/5x5 4 inception_4a/relu_5x5 18 inception_4a/pool 17 inception_4a/pool_proj 4 inception_4a/relu_pool_proj 18 inception_4a/output 3 inception_4a/output_inception_4a/output_0_split 22 loss1/ave_pool 17 loss1/conv 4 loss1/relu_conv 18 loss1/fc 14 loss1/relu_fc 18 loss1/drop_fc 6 loss1/classifier 14 loss1/loss 21 inception_4b/1x1 4 inception_4b/relu_1x1 18 inception_4b/3x3_reduce 4 inception_4b/relu_3x3_reduce 18 inception_4b/3x3 4 inception_4b/relu_3x3 18 inception_4b/5x5_reduce 4 inception_4b/relu_5x5_reduce 18 inception_4b/5x5 4 inception_4b/relu_5x5 18 inception_4b/pool 17 inception_4b/pool_proj 4 inception_4b/relu_pool_proj 18 inception_4b/output 3 inception_4b/output_inception_4b/output_0_split 22 inception_4c/1x1 4 inception_4c/relu_1x1 18 inception_4c/3x3_reduce 4 inception_4c/relu_3x3_reduce 18 inception_4c/3x3 4 inception_4c/relu_3x3 18 inception_4c/5x5_reduce 4 inception_4c/relu_5x5_reduce 18 inception_4c/5x5 4 inception_4c/relu_5x5 18 inception_4c/pool 17 inception_4c/pool_proj 4 inception_4c/relu_pool_proj 18 inception_4c/output 3 inception_4c/output_inception_4c/output_0_split 22 inception_4d/1x1 4 inception_4d/relu_1x1 18 inception_4d/3x3_reduce 4 inception_4d/relu_3x3_reduce 18 inception_4d/3x3 4 inception_4d/relu_3x3 18 inception_4d/5x5_reduce 4 inception_4d/relu_5x5_reduce 18 inception_4d/5x5 4 inception_4d/relu_5x5 18 inception_4d/pool 17 inception_4d/pool_proj 4 inception_4d/relu_pool_proj 18 inception_4d/output 3 inception_4d/output_inception_4d/output_0_split 22 loss2/ave_pool 17 loss2/conv 4 loss2/relu_conv 18 loss2/fc 14 loss2/relu_fc 18 loss2/drop_fc 6 loss2/classifier 14 loss2/loss 21 inception_4e/1x1 4 inception_4e/relu_1x1 18 inception_4e/3x3_reduce 4 inception_4e/relu_3x3_reduce 18 inception_4e/3x3 4 inception_4e/relu_3x3 18 inception_4e/5x5_reduce 4 inception_4e/relu_5x5_reduce 18 inception_4e/5x5 4 inception_4e/relu_5x5 18 inception_4e/pool 17 inception_4e/pool_proj 4 inception_4e/relu_pool_proj 18 inception_4e/output 3 pool4/3x3_s2 17 pool4/3x3_s2_pool4/3x3_s2_0_split 22 inception_5a/1x1 4 inception_5a/relu_1x1 18 inception_5a/3x3_reduce 4 inception_5a/relu_3x3_reduce 18 inception_5a/3x3 4 inception_5a/relu_3x3 18 inception_5a/5x5_reduce 4 inception_5a/relu_5x5_reduce 18 inception_5a/5x5 4 inception_5a/relu_5x5 18 inception_5a/pool 17 inception_5a/pool_proj 4 inception_5a/relu_pool_proj 18 inception_5a/output 3 inception_5a/output_inception_5a/output_0_split 22 inception_5b/1x1 4 inception_5b/relu_1x1 18 inception_5b/3x3_reduce 4 inception_5b/relu_3x3_reduce 18 inception_5b/3x3 4 inception_5b/relu_3x3 18 inception_5b/5x5_reduce 4 inception_5b/relu_5x5_reduce 18 inception_5b/5x5 4 inception_5b/relu_5x5 18 inception_5b/pool 17 inception_5b/pool_proj 4 inception_5b/relu_pool_proj 18 inception_5b/output 3 pool5/7x7_s1 17 pool5/drop_7x7_s1 6 loss3/classifier 14 loss3/loss3 21 #1 | hook, | 19.4% #2 | face | 16.8% #3 | buckle | 7.7% #4 | loupe, | 3.8% #5 | pretzel | 3.1% #6 | puck, | 2.9% #7 | digital | 2.8% #8 | analog | 2.8% #9 | neck | 2.4% #10 | lipstick, | 1.6% #11 | coffee | 1.4% #12 | toilet | 1.4% #13 | screw | 1.2% #14 | cup | 1.1% #15 | street | 1.0% #16 | guillotine | 1.0% #17 | nematode, | 0.9% #18 | spotlight, | 0.9% #19 | carton | 0.8% #20 | safety | 0.6%

注意点

pythonプログラムに書いてある画像読み込みの指定をちゃんとパスが通る状態で実行しなければ、別のエラーが出るので、無駄な時間を過ごさないように注意してください。

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。