torchというディープラーニングのライブラリが有ります。Luaで書かれているようであまり馴染みがなかったのですが、論文を読んでいて、サンプルをどうしても動かしたくてデバッグできる環境の構築を行った時のメモです
環境
- MacOS Seirra 10.12.4
- eclipse 4.6.3
こちらにubuntuの場合の設定方法があるのですが、Macではちょっと違いました。
luaインストール
1 | brew install lua |
これだけです
torchインストール
公式の手順通りにやれば問題なく終了します。
1 2 3 | git clone https://github.com/torch/distro.git ~/torch --recursive cd ~/torch; bash install-deps; ./install.sh |
eclipseプラグイン
下記URLからLuaプラグインをインストールします。1.4.1が最新でした
http://download.eclipse.org/ldt/releases/milestones/
eclipseの設定
これが一番ハマりました。
環境設定 > Lua > Interpreters で Addで追加します。
Interpreter type | Lua JIT 2.0 |
Interpreter executable | /Users/yourname/torch/install/bin/luajit |
Interpreter name | Lua JIT |
interpreter arguments | -lenv -e “io.stdout:setvbuf(‘no’); if os.getenv(‘DEBUG_MODE’) then require ‘debugger’ ; require ‘debugger.plugins.ffi’end” |
Linked Execution Environment | lua-5.1 |
また、Import…で/Users/yourname/torch/install/bin/torch-activateをインポートし環境変数を追加します
実行
こちらのサンプルを動かしてみます。
EclipseでLuaプロジェクトを作成し、srcディレクトリ内にファイルを作成します。
ここでポイントは、ファイルのパスをコード中に記述する際にはプロジェクトのトップからの相対パスを書きます。
download.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | print '==> downloading dataset' -- Here we download dataset files. -- Note: files were converted from their original LUSH format -- to Torch's internal format. -- The SVHN dataset contains 3 files: -- + train: training data -- + test: test data tar = 'http://torch7.s3-website-us-east-1.amazonaws.com/data/mnist.t7.tgz' if not paths.dirp('mnist.t7') then os.execute('wget ' .. tar) os.execute('tar xvf ' .. paths.basename(tar)) end train_file = 'src/mnist.t7/train_32x32.t7' test_file = 'src/mnist.t7/test_32x32.t7' ---------------------------------------------------------------------- print '==> loading dataset' -- We load the dataset from disk, it's straightforward trainData = torch.load(train_file,'ascii') testData = torch.load(test_file,'ascii') print('Training Data:') print(trainData) print() print('Test Data:') print(testData) print() ---------------------------------------------------------------------- print '==> visualizing data' -- Visualization is quite easy, using itorch.image(). if itorch then print('training data:') itorch.image(trainData.data[{ {1,256} }]) print('test data:') itorch.image(testData.data[{ {1,256} }]) end |
右クリックのRunで実行できます