OpenAI Gym CarRacing

1.6k Views Asked by At

I want to create a reinforcement learning model using stable-baselines3 PPO that can drive OpenAI Gym Car racing environment and I have been having a lot of errors and package compatibility issues. I have currently this code just for random actions

import gym 
from stable_baselines3 import PPO

environment_name = "CarRacing-v0"
env = gym.make(environment_name)

episodes = 5
for episode in range(1, episodes+1):
    state = env.reset()
    done = False
    score = 0 
    
    while not done:
        env.render()
        action = env.action_space.sample()
        n_state, reward, done, info = env.step(action)
        score+=reward
    print('Episode:{} Score:{}'.format(episode, score))
env.close()

Runnning on Ubuntu 20.04, in VSCode Jupyter notebook. With these packages in a conda env enter image description here

Even with random actions I am currently getting an error on state = env.reset() enter image description here

I tried different versions of gym and other packages and none seem to work flawlessly. Could anyone please help me, my only requirement is to make it work (firstly random and then with PPO) no matter what versions of packages.

Thank you

1

There are 1 best solutions below

0
Thiroshan Suthakar On

Hello there seems like environment has error

change environment_name = "CarRacing-v0" to as environment_name = "CarRacing-v2" it might fix erorr

and if doesnt work uninstall and install again

pip uninstall stable-baselines3[extra] 

or

pip uninstall stable-baselines3

after you uninstall it install it again

pip install stable-baselines3[extra]

and remember,

you need to install Pytorch if you didn't it might be the problem https://pytorch.org/get-started/locally/

(Sorry for late answer)