本を読み始めたのはいいが、とりあえず動かしたい
ゼロから作るDeep Learningをちびちび読んでいるのですが。
ちびちびすぎて、まだ4章。
先が長すぎる。
とりあえず動かしてみよう。
ってことで。
ml5.jsのLSTMのサンプルプログラムを動かしてみようと思い立ちました。
LSTMって何?っていう疑問はとりあえず脇に置いておいて。
日本語のデータ作って、動かすぞ。
というのをゴールにすることにします。
Local環境で動かす
とりあえず、ここから一式持ってきました。
https://github.com/ml5js/ml5-examples
で。これがLocalで動くことを確認。
https://github.com/ml5js/ml5-examples/tree/master/p5js/LSTM/LSTM_Text
ここまでは順調。
次はデータ作成。
tensorflowをインストールする
とりあえずここだけを見て。
https://www.tensorflow.org/install/?hl=ja
えい。1
2
3
4
5
6c:\work\ml5js\training-lstm>pip install tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
You are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
だめだった。
言われた通り、pipをupgrade。1
2
3
4
5
6
7
8
9c:\work\ml5js\training-lstm>python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 4.6MB/s
Installing collected packages: pip
Found existing installation: pip 18.0
Uninstalling pip-18.0:
Successfully uninstalled pip-18.0
Successfully installed pip-18.1
もういっかい。えい。1
2
3
4c:\work\ml5js>pip install tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
だめだった。
しかたがないので。
ちゃんとインストールガイドを見ることに。
https://www.tensorflow.org/install/pip?hl=ja
ここまでたどり着いた。1
2
3
4
5
6
7
8c:\work\ml5js>python --version
Python 3.6.5
c:\work\ml5js>pip --version
pip 18.1 from c:\users\nahok\appdata\local\programs\python\python36-32\lib\site-packages\pip (python 3.6)
c:\work\ml5js>virtualenv --version
16.2.0
しかしインストールできない。
URL指定でもやってみた。1
2C:\work\ml5js>pip3 install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl
tensorflow-1.12.0-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
だめだった。
そして気づく。
おや。ぼくのPython、32bit?1
2
3C:\work\ml5js>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
PC自体が64bitなのは知っていたのでノーケアだった。
もはや。
いつ、どうやってpythonをインストールしたのか定かではない。
Pythonには32bitと64bitがあるのか。そうか。そうなのか。
入れなおした。(追加して入れた。Pathは入れてから環境変数直した)1
2
3
4C:\work\ml5js>python
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
えい。1
2
3C:\work\ml5js>pip3 install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp36-cp36m-win_amd64.whl
(中略)
Successfully installed tensorflow-1.12.0
やっと成功した。
virtualenvいれたのに普通にインストールしちゃった。
気にしない。
チュートリアルTraining a LSTM
やっと本題。
このチュートリアルをすすめます。
https://ml5js.org/docs/training-lstm
- トレーニング用のリポジトリから一式持ってくる
gitでcloneしてくるだけ。
1 | C:\work\ml5js>git clone https://github.com/ml5js/training-lstm.git |
- データを持ってくる
さて。どうしよう。青空文庫でいっか。
こちらを参考に。(というかそのまま実行)
【Python】MeCabを使って青空文庫を簡単に分かち書きする方法
GoogleColabって初めて知りました。
すごいですね。
ここでゲットした「吾輩は猫である」の分かち書きテキストを。
トレーニングのインプットにするべく。
mydataフォルダを作って、input.txtという名前で保存。
- トレーニング!!
1 | c:\work\ml5js\training-lstm>python train.py --data_dir=.\mydata |
終わった!!
どれくらい時間かかったかわからないんですが。
0.6秒 × 10500 = 105分
くらいでしょうか。
4.自分のデータを使う
LSTM_Textのmodelsフォルダにフォルダごと放り込む。
sketch.jsのデータ指定しているところを変更する。1
2
3// Create the LSTM Generator passing it the model directory
//charRNN = ml5.charRNN('./models/woolf/', modelReady);
charRNN = ml5.charRNN('./models/mydata/', modelReady);
index.htmlも、ちょろちょろ見た目を修正して。
できたー。
まとめ
だから、何?という感じ。
せっかくなのでアップしてみた。
http://rissoku.net/petitapp/LSTM_Text/
さ。
ゼロから作るDeep Learningの続き読もっと。