File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 10461046 (torch/save (py. critic state_dict) " critic.pt" )
10471047 (System/exit 0 )))
10481048
1049+ ; ; ## Visualisation of Actor Output
1050+
1051+ ; ; We can use [dtype-next](https://cnuernber.github.io/dtype-next/) to visualise the output of the actor.
1052+ ; ; First we need to load additional modules.
1053+ (require '[tech.v3.datatype :as dtype]
1054+ '[tech.v3.tensor :as dtt]
1055+ '[tech.v3.libs.buffered-image :as bufimg]
1056+ '[tech.v3.datatype.functional :as dfn])
1057+
1058+ ; ; Here we load a pre-trained model and visualise the output of the actor.
1059+ (def actor (Actor 3 64 1 ))
1060+ (py. actor load_state_dict (torch/load " src/ppo/actor.pt" ))
1061+
1062+ (let [angle-values (torch/linspace (- PI) PI 854 )
1063+ speed-values (torch/linspace 1.0 -1.0 480 )
1064+ grid (torch/meshgrid speed-values angle-values :indexing " ij" )
1065+ cos-angle (torch/cos (last grid))
1066+ sin-angle (torch/sin (last grid))
1067+ observations (torch/stack [(py. cos-angle ravel)
1068+ (py. sin-angle ravel)
1069+ (py. (first grid) ravel)]
1070+ :axis 1 )
1071+ actions (without-gradient (py. (py. (py. actor deterministic_act observations) reshape 480 854 ) numpy))
1072+ actions-tensor (dtype/elemwise-cast (dtt/ensure-tensor (py/->jvm actions)) :float32 )]
1073+ (bufimg/tensor->image (dfn/* actions-tensor 255 )))
1074+
10491075; ; ## Automated Pendulum
10501076; ;
10511077; ; The pendulum implementation can now be updated to use the actor instead of the mouse position as motor input when the mouse button is pressed.
You can’t perform that action at this time.
0 commit comments