-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
58 lines (40 loc) · 1.89 KB
/
utils.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
51
52
53
54
55
56
57
58
from IPython import display as ipythondisplay
from pyvirtualdisplay import Display
from gym.wrappers import Monitor
from pathlib import Path
import base64
# display = Display(visible=0, size=(1400, 900))
# display.start()
def record_videos(env, path="videos"):
return Monitor(env, path, force=True, video_callable=lambda episode: True)
# def show_videos(path="videos"):
# html = []
# for mp4 in Path(path).glob("*.mp4"):
# video_b64 = base64.b64encode(mp4.read_bytes())
# html.append('''<video alt="{}" autoplay
# loop controls style="height: 400px;">
# <source src="data:video/mp4;base64,{}" type="video/mp4" />
# </video>'''.format(mp4, video_b64.decode('ascii')))
# ipythondisplay.display(ipythondisplay.HTML(data="<br>".join(html)))
def capture_intermediate_frames(env):
env.unwrapped.automatic_rendering_callback = env.video_recorder.capture_frame
# from IPython import display as ipythondisplay
# from pyvirtualdisplay import Display
# from gym.wrappers import Monitor
# from pathlib import Path
# import base64
# display = Display(visible=0, size=(1400, 900))
# display.start()
# def record_videos(env, path="videos"):
# return Monitor(env, path, force=True, video_callable=lambda episode: True)
# def show_videos(path="videos"):
# html = []
# for mp4 in Path(path).glob("*.mp4"):
# video_b64 = base64.b64encode(mp4.read_bytes())
# html.append('''<video alt="{}" autoplay
# loop controls style="height: 400px;">
# <source src="data:video/mp4;base64,{}" type="video/mp4" />
# </video>'''.format(mp4, video_b64.decode('ascii')))
# ipythondisplay.display(ipythondisplay.HTML(data="<br>".join(html)))
# def capture_intermediate_frames(env):
# env.unwrapped.automatic_rendering_callback = env.video_recorder.capture_frame