Skip to content

Commit

Permalink
Fix image source config (#468)
Browse files Browse the repository at this point in the history
* fix setting

* add anotation

* update script

* format
  • Loading branch information
QuanyiLi committed Jul 9, 2021
1 parent be4bdbd commit 2e84d33
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
2 changes: 0 additions & 2 deletions pgdrive/envs/pgdrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@

# ===== use image =====
image_source="rgb_cam", # take effect when only when use_image == True
# use_image=False,
# rgb_clip=True,

# ===== vehicle spawn =====
spawn_lane_index=(FirstBlock.NODE_1, FirstBlock.NODE_2, 0),
Expand Down
8 changes: 6 additions & 2 deletions pgdrive/scene_manager/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
from typing import Dict

from gym.spaces import Box
from gym.spaces import Box, Dict

from pgdrive.scene_creator.vehicle.base_vehicle import BaseVehicle


Expand Down Expand Up @@ -112,7 +113,10 @@ def init(self, pg_world, config_dict: Dict):

obs_space = self._init_observation_spaces[agent_id]
self.observation_spaces[vehicle.name] = obs_space
assert isinstance(obs_space, Box)
if not vehicle.vehicle_config["use_image"]:
assert isinstance(obs_space, Box)
else:
assert isinstance(obs_space, Dict), "Multi-agent observation should be gym.Dict"
action_space = self._init_action_spaces[agent_id]
self.action_spaces[vehicle.name] = action_space
assert isinstance(action_space, Box)
Expand Down
5 changes: 2 additions & 3 deletions pgdrive/tests/vis_funtionality/vis_depth_cam_ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ def __init__(self):
"environment_num": 1,
"traffic_density": 0.1,
"start_seed": 4,
"image_source": "depth_cam",
"manual_control": True,
"use_render": True,
"use_image": True,
"rgb_clip": True,
"vehicle_config": dict(depth_cam=(200, 88, True)),
"vehicle_config": dict(depth_cam=(200, 88, True), image_source="depth_cam"),
"pg_world_config": {
"headless_image": False,
},
Expand All @@ -31,7 +30,7 @@ def __init__(self):
if __name__ == "__main__":

def get_image(env):
env.vehicle.image_sensors[env.config["image_source"]].save_image()
env.vehicle.image_sensors[env.vehicle.vehicle_config["image_source"]].save_image()
env.pg_world.screenshot()

env = TestEnv()
Expand Down
5 changes: 2 additions & 3 deletions pgdrive/tests/vis_funtionality/vis_depth_cam_no_ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ def __init__(self):
"environment_num": 1,
"traffic_density": 0.1,
"start_seed": 4,
"image_source": "depth_cam",
"manual_control": True,
"use_render": True,
"use_image": True,
"rgb_clip": True,
"vehicle_config": dict(depth_cam=(200, 88, False)),
"vehicle_config": dict(depth_cam=(200, 88, False), image_source="depth_cam"),
"pg_world_config": {
"headless_image": False,
},
Expand All @@ -31,7 +30,7 @@ def __init__(self):
if __name__ == "__main__":
env = TestEnv()
env.reset()
env.pg_world.accept("m", env.vehicle.image_sensors[env.config["image_source"]].save_image)
env.pg_world.accept("m", env.vehicle.image_sensors[env.vehicle.vehicle_config["image_source"]].save_image)

for i in range(1, 100000):
o, r, d, info = env.step([0, 1])
Expand Down
12 changes: 4 additions & 8 deletions pgdrive/tests/vis_funtionality/vis_rgb_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@ def __init__(self):
"environment_num": 1,
"traffic_density": 0.1,
"start_seed": 4,
"image_source": "rgb_cam",
"manual_control": True,
"use_render": True,
"use_image": True,
"rgb_clip": True,
# "vehicle_config": dict(rgb_cam=(200, 88)),
"pg_world_config": {
"headless_image": False
}
"use_image": True, # it is a switch telling pgdrive to use rgb as observation
"rgb_clip": True, # clip rgb to range(0,1) instead of (0, 255)
}
)


if __name__ == "__main__":
env = TestEnv()
env.reset()
env.pg_world.accept("m", env.vehicle.image_sensors[env.config["image_source"]].save_image)
# print m to capture rgb observation
env.pg_world.accept("m", env.vehicle.image_sensors[env.vehicle.vehicle_config["image_source"]].save_image)

for i in range(1, 100000):
o, r, d, info = env.step([0, 1])
Expand Down

0 comments on commit 2e84d33

Please sign in to comment.