-
Notifications
You must be signed in to change notification settings - Fork 6
/
animations.jl
81 lines (69 loc) · 1.43 KB
/
animations.jl
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using OpenAIGym
import Random
using Statistics
using Flux
using StatsBase
using PyCall
env = GymEnv("CartPole-v1")
s = reset!(env)
a = 1
r,sdash = step!(env,a)
frame = render(env, mode=:rgb_array)
f = convert(Array,frame)
zs = zeros(255,255,255)
frame[1]
env = GymEnv("LunarLander-v2")
s = reset!(env)
frame = render(env, mode=:rgb_array)
size(frame)
env.pyenv
convert(Array, frame)
using Plots
using Images
using ImageView
pyenv = env.pyenv
gym = pyimport("gym")
np = pyimport("numpy")
f = np.array(pyenv.render(mode="rgb_array")) ./255f0
colorview(RGB, permutedims(f, [3,1,2]))
Plots.plot(f)
py"""
import numpy as np
def get_frame(env):
f = env.render(mode="rgb_array")
print(type(f))
"""
Int(rand() > 0.5)
py"get_frame"(pyenv)
env
env = GymEnv("CartPole-v1")
pyenv = env.pyenv
sample(OpenAIGym.actionset(env.pyenv))
Plots.plot([1,2,3])
frames = []
s = reset!(env)
for i in 1:100
println("$i")
a = Int(rand() > 0.5)
r,sdash = step!(env, a)
f = np.array(pyenv.render(mode="rgb_array")) ./255f0
push!(frames, convert(Array{Float32},f))
end
frames
frames[1]
Plots.plot(colorview(RGB, permutedims(frames[56], [3,1,2])))
cols = []
for bib in frames
col = colorview(RGB, permutedims(bib, [3,1,2]))
push!(cols, col)
end
cols
Plots.plot(cols[1])
frame = 0
@gif for col in cols
Plots.plot(col)
end
@gif for bib in frames
Plots.plot(colorview(RGB, permutedims(bib, [3,1,2])))
end
gif(anim, "test_cartpole.gif", fps=30)