GithubHelp home page GithubHelp logo

Comments (5)

praveen-palanisamy avatar praveen-palanisamy commented on July 20, 2024

Hi Ali,

The error is because in your code snipped, action is a 3 dimensional array instead of an integer.
As documented here , when "discrete_actions" is set to true (the default), the action space of the Carla-v0 environment is Discrete(9).

Therefore, you can simplify your pick action function something like below:

def pick_random_discrete_action(t, current_action):
#     a = env.action_space.sample()
#     return a
    if t < 60:
        return np.array(3)  # Go forward
    
    if t % 5 > 0:
        return current_action

    rn = random.randint(0,9)
   return rn

To see what each discrete action means, please refer to the table here.

If you want to use the continuous action space, you can set the "discrete_actions": False here:

# Default environment configuration
ENV_CONFIG = {
"discrete_actions": True,

and then provide a 2 dimensional action (example: np.array([0, 1]) ) to the env.step(...) function. The definitions for the continuous action space is listed here.

Hope that helps.

from hands-on-intelligent-agents-with-openai-gym.

AliBaheri avatar AliBaheri commented on July 20, 2024

Thanks Praveen,

In fact, In my dataset, I have 3 dimensional control action in the form of [steer, gas, break]. One quick hack may be change this part in carla-env.py:

def step_env(self, action):
        if self.config["discrete_actions"]:
            action = DISCRETE_ACTIONS[int(action)]
        assert len(action) == 3, "Invalid action {}".format(action)
        throttle = float(np.clip(action[0], 0, 1))
        brake = float(np.abs(np.clip(action[0], -1, 0)))
        steer = float(np.clip(action[1], -1, 1))
        reverse = False
        hand_brake = False

where I changed assert len(action) == 2 to assert len(action) == 3. It solves the problem, but it turns out this is not good for driving policy as it is pointless to accelerate while braking. In fact, as we already discussed, it is good idea to concatenate gas and brake into a single [-1 , 1], which indicates [-1 , 0) for brake and (0, 1] for gas. However, I do not know how can I modify the code or dataset to take into account this? Is there any way to resolve the issue without modifying or
re-collecting the dataset? In other words, is there any way to keep the size of the control action as 3?

from hands-on-intelligent-agents-with-openai-gym.

praveen-palanisamy avatar praveen-palanisamy commented on July 20, 2024

@AliBaheri : Sorry for the delay. I was just able to get to this.

You could use a 3 dimensional control action in this form [steer, gas, brake] with the Carla Gym environment implementation.
In that case, you can use a modified step function in place of the the original step function in carla_env.py or for quick experiments, you can replace the following lines:

def step_env(self, action):
if self.config["discrete_actions"]:
action = DISCRETE_ACTIONS[int(action)]
assert len(action) == 2, "Invalid action {}".format(action)
throttle = float(np.clip(action[0], 0, 1))
brake = float(np.abs(np.clip(action[0], -1, 0)))
steer = float(np.clip(action[1], -1, 1))

with

def step_env(self, action):  # action: [ steer, gas, brake]
    steer = float(np.clip(action[0], -1, 1))
    throttle = float(np.clip(action[1], 0, 1))
    brake = float(np.clip[action[2], 0, 1))

from hands-on-intelligent-agents-with-openai-gym.

praveen-palanisamy avatar praveen-palanisamy commented on July 20, 2024

@AliBaheri: Is your question answered?

from hands-on-intelligent-agents-with-openai-gym.

githubce avatar githubce commented on July 20, 2024

Author provided the solution. Reopen if you want to continue discussion.

from hands-on-intelligent-agents-with-openai-gym.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.