File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ import torch as th
2
+ import gym_torcs
3
+ import gym
4
+ import sys
5
+ import os
6
+
7
+ from stable_baselines3 import A2C
8
+
9
+ #env = gym.make('CartPole-v1')
10
+ env = gym_torcs .TorcsEnv ()
11
+ policy_kwargs = dict (activation_fn = th .nn .ReLU ,
12
+ net_arch = [dict (pi = [128 , 128 ], vf = [128 , 128 ])])
13
+
14
+ if os .path .exists ('a2c_torcs.zip' ):
15
+ print ('Using saved model' )
16
+ model = A2C .load ('a2c_torcs' , env = env )
17
+ else :
18
+ model = A2C ('MlpPolicy' , env , policy_kwargs = policy_kwargs , verbose = 1 )
19
+ model .learn (total_timesteps = 1000 , log_interval = 5 )
20
+ print ('Learning done' )
21
+ model .save ('a2c_torcs' )
22
+ env .end ()
23
+ sys .exit ()
24
+ obs = env .reset ()
25
+ for i in range (1000 ):
26
+ action , _state = model .predict (obs , deterministic = True )
27
+ obs , reward , done , info = env .step (action )
28
+ env .render ()
29
+ if done :
30
+ obs = env .reset ()
You can’t perform that action at this time.
0 commit comments