gym car racing v0 using DQN

I am currently learning reinforcement learning and wanted to use it on the car racing-v0 environment. I have successfully made it using PPO algorithm and now I want to use a DQN algorithm but when I want to train the model it gives me this error:

AssertionError: The algorithm only supports (class 'gym.spaces.discrete.Discrete',) as action spaces but Box([-1. 0. 0.], [1. 1. 1.], (3,), float32) was provided

Here is my code:

import os
import gym
from stable_baselines3 import DQN
from stable_baselines3.common.vec_env import DummyVecEnv
from stable_baselines3.common.evaluation import evaluate_policy

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

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

env = gym.make(environment_name)
env = DummyVecEnv([lambda: env])

log_path = os.path.join('Training', 'Logs')
model = DQN('CnnPolicy', env, verbose=1, tensorboard_log = log_path)

I am using jupyter notebook for this project

Topic dqn openai-gym jupyter reinforcement-learning python

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.