0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

強化学習8 ChainerUIを使ってみる

0
Last updated at Posted at 2019-11-14

強化学習7までが終了していいることが前提です。
強化学習をしていくには、その学習過程を見たくなります。
Chainerの可視化・実験管理ツールである「ChainerUI」を使います。

ChainerUI
https://github.com/chainer/chainerui
https://research.preferred.jp/2017/12/chainerui-release/

ChainerUIをインストールします。

pip install chainerui
chainerui db create
chainerui db upgrade

親ディレクトリーに移動してから、プロジェクトを作ります。

chainerui project create -d CartPole
chainerui server

そして、Webブラウザでhttp://localhost:5000/にアクセスします。
このあたりの順番重要です。

scores.txtは、読み込んでくれません。
そこで、以下のコードをtrain.pyに書き足すか、別コードで実行します。

convert.py
import pandas as pd
import json
import codecs
import numpy as np

scores = pd.read_table('result/scores.txt')
columns = scores.columns  # header情報

data_list = []
for column in columns:
    data_list.append([column, ''])
data_hash = dict(data_list) # 各station dataのhashの雛形

log_json = []
for score in np.array(scores):
    score_hash = data_hash.copy()
    for i in range(columns.size):
        score_hash[columns[i]] = score[i]
    log_json.append(score_hash)

print(log_json)
f = codecs.open('result/log', 'w', 'utf-8')
json.dump(log_json, f, indent=4, ensure_ascii=False)
f.close

print(log_json)は不要に思えますが、jupyter notebookで実行すると、入れておかないとlogファイルの末尾がおかしくなりました。
これで、chainerUIでグラフを見ることができます。

ChainerUIはグラフのX軸が"epoch", "iteration", "episode", "step", "elapsed_time"の5つ固定です。
scores.txtは微妙に違うので、ChainerUIを魔改造します。
連載9回目で魔改造。

まず、ファイルの位置ですが、個人フォルダー内にanaconda3があります。
ここの中を探します。
userFolder/anaconda3/envs/chainer/lib/python3.7/site-packages/chainerui
ここにプログラムが入っています。
userFolder/anaconda3/envs/chainer/lib/python3.7/site-packages/chainerui/static/dist/chainerui.js
このファイルを開きます。
このファイルの中の、
T = ["epoch", "iteration", "episode", "step", "elapsed_time"],
を、
T = ["epoch", "iteration", "episode", "step", "elapsed_time","steps","episodes","elapsed"],
に書き換えます。
これで、X軸をstepsなどに指定できます。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?