PacktPublishing / Hands-On-Intelligent-Agents-with-OpenAI-Gym

Code for Hands On Intelligent Agents with OpenAI Gym book to get started and learn to build deep reinforcement learning agents using PyTorch
https://www.packtpub.com/big-data-and-business-intelligence/hands-intelligent-agents-openai-gym
MIT License
366 stars 149 forks source link

about 'Carla_env.py' #9

Closed AliBaheri closed 5 years ago

AliBaheri commented 5 years ago

I have two questions about carla_env.py:

1 - I am interested to try other senarios such as turn or navigation. However when I change the following part:

"scenarios": [scenario_config["Lane_Keep_Town2"]],

to:

"scenarios": [scenario_config["Curve_Poses_Town2"]],

I face with the error. I have also changed the scenario in the json file to the following:

 "Curve_Poses_Town2": {
    "city": "Town02",
    "start_pos_id": 8,
    "end_pos_id": 24,
    "num_vehicles": 25,
    "num_pedestrians": 30,
    "weather_distribution": [0],
    "max_steps": 200
  },

2- If I wanted to save the observations in, for example, 64x64x3 should I modify the carla_env.py to the following:

    "framestack": 1,  # note: only [1, 2] currently supported
    "enable_planner": True,
    "use_depth_camera": False,
    "early_terminate_on_collision": True,
    "verbose": False,
    "render" : True,  # Render to display if true
    "render_x_res": 1800,
    "render_y_res": 1600,
    "x_res": 64,
    "y_res": 64,
    "seed": 1
}.

Particularity, dose the meaning of frame-stack is the same as RGB channel?

I am asking this question because when I gather some observations in numpy and convert them to RGB image, I get some meaningless images, which are not the images from the road.

praveen-palanisamy commented 5 years ago
  1. With "scenarios": [scenario_config["Curve_Poses_Town2"]] what error do you get?

  2. Yes. That's right. changing x_res and y_res will change the observation size. With the configuration you listed above, you will get an observation of shape 64x64x3 which is one frame of the environment. If you set "framestack": 2, you will get an observation of shape 64x64x6 which is two frames stacked along the channels. What do you mean by "meaningless images"? If you are trying to visualize the image, be sure to use the correct channel order (BGR vs RGB). You can display the observations using the following lines of code:

    import cv2
    # Assuming obs is the observation returned by the env
    cv2.imshow("obs", obs)
    cv2.waitKey(0)
AliBaheri commented 5 years ago

With "scenarios": [scenario_config["Curve_Poses_Town2"]] I get the following error:

Clearing Carla server state ERROR:Initializing new Carla server... Error during reset: Traceback (most recent call last): File "carla_env.py", line 223, in reset return self.reset_env() File "carla_env.py", line 247, in reset_env assert self.scenario["city"] == self.city, (self.scenario, self.city) TypeError: list indices must be integers, not str

Are you able to run with other scenarios?

AliBaheri commented 5 years ago
   What do you mean by "meaningless images"? If you are trying to visualize the image, be sure to use the correct channel order (BGR vs RGB).
   You can display the observations using the following lines of code:
import cv2
# Assuming obs is the observation returned by the env
cv2.imshow("obs", obs)
cv2.waitKey(0)

I will get something like this image:

image

Which is not clearly the road image. Are you able to get actual road image from that code snippet?

praveen-palanisamy commented 5 years ago

With "scenarios": [scenario_config["Curve_Poses_Town2"]] I get the following error: Clearing Carla server state ERROR:Initializing new Carla server... Error during reset: Traceback (most recent call last): File "carla_env.py", line 223, in reset return self.reset_env() File "carla_env.py", line 247, in reset_env assert self.scenario["city"] == self.city, (self.scenario, self.city) TypeError: list indices must be integers, not str

It is because you are using "Curve_Poses_Town2" which is defined to be: https://github.com/PacktPublishing/Hands-On-Intelligent-Agents-with-OpenAI-Gym/blob/df9ab3984237b3a02998e2c3d3df482f557945f9/ch8/environment/carla_gym/envs/scenarios.json#L75-L81

You should probably change the key name in your code.

If you want to create a scenario in Town2 where the vehicle is driving along some curves, you can add the following to scenarios.json:

"Curve1_Town2": {
    "city": "Town02",
    "start_pos_id": 8,
    "end_pos_id": 24,
    "num_vehicles": 25,
    "num_pedestrians": 30,
    "weather_distribution": [0],
    "max_steps": 200
  },

And then change this line: https://github.com/PacktPublishing/Hands-On-Intelligent-Agents-with-OpenAI-Gym/blob/df9ab3984237b3a02998e2c3d3df482f557945f9/ch8/environment/carla_gym/envs/carla_env.py#L75

to

"scenarios": [scenario_config["Curve1_Town2"]],

I have also add this explanation to the wiki here for future references.

githubce commented 5 years ago

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