강화 학습 34 연속적인 Agent의 동영상을 만든다
강화 학습 28을 종료하고 있는 것이 전제입니다.
강화 학습의 도중에, 예를 들면 10000 스텝마다 agent를 보존하고,
그것을 한 번씩 연속해서 재생하고 싶습니다.
이렇게 하면 학습의 성장 과정이 보기 쉬울까.
Youtube등으로 보는, 점점 능숙해져 가는 녀석입니다.
chokozainerRL로 강화 학습을 하면, 이런 느낌으로 폴더가 만들어집니다.

이것을, 순서대로 나란히 읽어들이는 것은, 이하와 같이 합니다.
import os
import re
testdir='mydrive/OpenAI/CartPole/result_dqn_choko'
files = os.listdir(testdir)
files_dir = [f for f in files if os.path.isdir(os.path.join(testdir, f))]
agentList=[]
for f in files_dir:
if re.search('_',f):
f2=f.split('_')
agentList.append([int(f2[0]),f])
agentList.sort()
Google 드라이브가 탑재된 상태로 진행합니다.
그대로 sort 하면(자) , 캐릭터 라인으로서의 소트가 되므로 , 이상한 순서가 됩니다. 그러므로, 전방의 수치만을 꺼내 소트가 걸리도록 합니다.
env와 agent가 정의되어 있다면 다음과 같이 할 수 있습니다.
from matplotlib import animation
import matplotlib.pyplot as plt
frames = []
for item in agentList:
agent.load(testdir+'/'+item[1])
obs = env.reset()
done = False
R = 0
t = 0
while not done and t < 200:
frames.append(env.render(mode = 'rgb_array'))
action = agent.act(obs)
obs, r, done, _ = env.step(action)
R += r
t += 1
print('test episode:', item[1], 'R:', R)
agent.stop_episode()
env.close()
from IPython.display import HTML
plt.figure(figsize=(frames[0].shape[1]/72.0, frames[0].shape[0]/72.0),dpi=72)
patch = plt.imshow(frames[0])
plt.axis('off')
def animate(i):
patch.set_data(frames[i])
anim = animation.FuncAnimation(plt.gcf(), animate, frames=len(frames),interval=50)
anim.save(testdir+"grouth.mp4")
HTML(anim.to_jshtml())
Reference
이 문제에 관하여(강화 학습 34 연속적인 Agent의 동영상을 만든다), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/chokozainer/items/137d8e4317850485a593텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)