2

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

Din
  • 61
  • 8
  • `Discrete` can mean it needs integer values but game uses float values but I don't know if it can be converted. – furas Mar 31 '22 at 05:25
  • maybe you should ask on similar portal for [DataScience](https://datascience.stackexchange.com/) – furas Mar 31 '22 at 05:25
  • 1
    Could you please add which versions of libraries you used and your working PPO code? – Yunnosch Sep 12 '22 at 11:54

2 Answers2

0

Unfortunately stable-baselines DQN implementation doesn't support continuous actions. Refer to this table to check which algorithms match your action space!

0

DQN does not support the Box continuous action space as seen here https://stable-baselines3.readthedocs.io/en/master/guide/algos.html but you could tweek the environment to use Discrete instead of Box. Check this website for a remade CarRacing env with Discrete action space https://github.com/NotAnyMike/gym

brownie
  • 121
  • 9