LoginSignup
6

More than 5 years have passed since last update.

Pylearn2を試してみようと思ってつまづいたこと

Last updated at Posted at 2015-09-02

はじめに

  • MacBookAir(2012)で流行り(?)のDeepLearningとかやってみたくて,いくつかの記事(参考文献)を漁った
  • ほぼ参考文献のサイトの手順をそのままなぞった,その時にいくつかハマった場所もあったので備忘録的として保存
  • スクリプトとか詳しい内容はそちらのサイト
  • とりあえず何枚か画像を読み込ませてそれっぽい画像が表示するところまでやってみた

環境構築

  • Python,git,pip,numpy,scipyをインストールしておく
  • Theanoをインストール
pip install theano
  • Pylearn2をインストール
pip install pillow
pip install PyYAML
pip install IPython
pip install Cython

git clone git://github.com/lisa-lab/pylearn2.git
python setup.py develop

ここまででハマったところ

ImportError: No module named numpy
  • Pylearn2のsetup.pyを実行するとimport numpyが見つからない系?
    • 以下を参考に対処してみたがうまく治らず
    • http://d.hatena.ne.jp/aremokoremo/20140507/1399475248
    • 環境変数(~/.bash_profile)とか確認してpathを確認したりした
    • 応急処置的にとりあえずnumpyが置いてあるsite-packagesのパスを追加
    • 環境変数を再読み込み(source ~/.bash_profile)
===============================
00001   #include <Python.h>
00002   #include "structmember.h"
00003   #include <sys/time.h>
~~~~~~~~~略~~~~~~~~~
Exception: Compilation failed (return status=1): /Users/user-name/.theano/compiledir_Darwin-14.5.0-x86_64-i386-64bit-i386-2.7.8-64/lazylinker_ext/mod.cpp:1:10: fatal error: 'Python.h' file not found. #include <Python.h>.          ^. 1 error generated.. 
  • import theanoでエラー Python.hとかが見つからない系?
    • いよいよ環境が壊れているような気がしてきたのでbrew doctorで確認
    • エラー内容を一つ一つ地道に消す(エラー内容をGoogle先生に聞くと解決策がある
    • ついでにbrew updateとかした

実行

手順

  1. 同じサイズの画像を集めてくる

    • Googleから学習させたい,jpgの画像を拾ってくる(10枚くらい)
  2. スクリプトを使ってグレースケール化 & csvにする

    • サイトにあるimg2csv.pyを実行する
    • Imageモジュールとかが見つからないとか言われたら2行目から4行目を以下に変更
    from PIL import Image
    from PIL import ImageOps
    from PIL import ImageFilter
    
    • サイトの通り以下のコマンドを実行
    python img2csv.py グレースケール変換した.jpgのリスト train.csv
    
    • ここでうまくリストが渡せなかったのでコードを読んで以下で実行
    python img2csv.py "../img/*.jpg" train.csv
    
  3. 学習させる

    • pylearn2/datasets/にサイトのhoge_dataset.pyを入れる
    • 環境変数に以下を設定
      • export PYLEARN2_DATA_PATH=train.csvとgrbm.yamlが置いてあるパス
      • export PYLEARN2_VIEWER_COMMAND="open -Wn"
    • 学習させる

      train.py grbm.yaml
      
  4. 学習の結果を表示する

    • 表示のコマンド

      show_weights.py grbm.pkl
      

ここまででハマったところ

学習時間

  • 思ったよりも時間がかかる
  • 150*150の画像を10枚使って実行して20分ぐらいかかった

学習結果の表示(描画)

  • 学習結果を表示する時に以下のようなエラーが出た

    UserWarning: Unable to import matplotlib. Some features unavailable. Original exception: No module named matplotlib.pyplot
    "Original exception: " + str(matplotlib_exception))
    
  • 以下のコマンドでmatplotlibを追加して無事に動作を確認

    pip install matplotlib
    

参考文献

http://kensuke-mi.xyz/kensuke-mi_diary/2014/11/rbma.html
http://d.hatena.ne.jp/aremokoremo/20140507/1399475248

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6