-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
|
||
from metadrive.component.sensors.semantic_camera import SemanticCamera | ||
from metadrive.envs.metadrive_env import MetaDriveEnv | ||
|
||
blackbox_test_configs = dict( | ||
standard=dict(stack_size=3, width=256, height=128, rgb_clip=True), | ||
small=dict(stack_size=1, width=64, height=32, rgb_clip=False), | ||
large=dict(stack_size=5, width=800, height=600, rgb_clip=True), | ||
no_clip=dict(stack_size=3, width=800, height=600, rgb_clip=False), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("config", list(blackbox_test_configs.values()), ids=list(blackbox_test_configs.keys())) | ||
def test_semantic_cam(config, render=False): | ||
""" | ||
Test the output shape of Semantic camera. This can NOT make sure the correctness of rendered image but only for | ||
checking the shape of image output and image retrieve pipeline | ||
Args: | ||
config: test parameter | ||
render: render with cv2 | ||
Returns: None | ||
""" | ||
env = MetaDriveEnv( | ||
{ | ||
"num_scenarios": 1, | ||
"traffic_density": 0.1, | ||
"map": "S", | ||
"start_seed": 4, | ||
"stack_size": config["stack_size"], | ||
"vehicle_config": dict(image_source="camera"), | ||
"sensors": { | ||
"camera": (SemanticCamera, config["width"], config["height"]) | ||
}, | ||
"interface_panel": ["dashboard", "camera"], | ||
"image_observation": True, # it is a switch telling metadrive to use rgb as observation | ||
"rgb_clip": config["rgb_clip"], # clip rgb to range(0,1) instead of (0, 255) | ||
} | ||
) | ||
env.reset() | ||
try: | ||
import cv2 | ||
for i in range(1, 10): | ||
o, r, tm, tc, info = env.step([0, 1]) | ||
assert env.observation_space.contains(o) | ||
# Reverse | ||
assert o["image"].shape == (config["height"], config["width"], 4, config["stack_size"]) | ||
if render: | ||
cv2.imshow('img', o["image"][..., -1]) | ||
cv2.waitKey(1) | ||
finally: | ||
env.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
test_semantic_cam(config=blackbox_test_configs["small"], render=True) |