From 4299277d99a190f0706a7cfa36b1f2d03ed8b024 Mon Sep 17 00:00:00 2001 From: lzh <2536890272@qq.com> Date: Mon, 26 Feb 2024 19:23:21 +0800 Subject: [PATCH 1/2] fix expert bug, cover side_detector and lane_line_detector setting --- metadrive/examples/ppo_expert/numpy_expert.py | 8 ++++---- metadrive/examples/ppo_expert/torch_expert.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/metadrive/examples/ppo_expert/numpy_expert.py b/metadrive/examples/ppo_expert/numpy_expert.py index 3419a87d5..35f3ccac9 100644 --- a/metadrive/examples/ppo_expert/numpy_expert.py +++ b/metadrive/examples/ppo_expert/numpy_expert.py @@ -41,12 +41,12 @@ def expert(vehicle, deterministic=False, need_obs=False): global _expert_observation expert_obs_cfg = dict( lidar=dict(num_lasers=240, distance=50, num_others=4, gaussian_noise=0.0, dropout_prob=0.0), + side_detector=dict(num_lasers=0, distance=50, gaussian_noise=0.0, dropout_prob=0.0), + lane_line_detector=dict(num_lasers=0, distance=20, gaussian_noise=0.0, dropout_prob=0.0), random_agent_model=False ) - origin_obs_cfg = dict( - lidar=dict(num_lasers=240, distance=50, num_others=0, gaussian_noise=0.0, dropout_prob=0.0), - random_agent_model=False - ) + origin_obs_cfg = vehicle.config.copy() + # TODO: some setting in origin cfg will not be covered, then they may change the obs shape if _expert_weights is None: _expert_weights = np.load(ckpt_path) diff --git a/metadrive/examples/ppo_expert/torch_expert.py b/metadrive/examples/ppo_expert/torch_expert.py index a244b8583..fc572f1d3 100644 --- a/metadrive/examples/ppo_expert/torch_expert.py +++ b/metadrive/examples/ppo_expert/torch_expert.py @@ -50,12 +50,12 @@ def torch_expert(vehicle, deterministic=False, need_obs=False): global _expert_observation expert_obs_cfg = dict( lidar=dict(num_lasers=240, distance=50, num_others=4, gaussian_noise=0.0, dropout_prob=0.0), + side_detector=dict(num_lasers=0, distance=50, gaussian_noise=0.0, dropout_prob=0.0), + lane_line_detector=dict(num_lasers=0, distance=20, gaussian_noise=0.0, dropout_prob=0.0), random_agent_model=False ) - origin_obs_cfg = dict( - lidar=dict(num_lasers=240, distance=50, num_others=0, gaussian_noise=0.0, dropout_prob=0.0), - random_agent_model=False - ) + origin_obs_cfg = vehicle.config.copy() + # TODO: some setting in origin cfg will not be covered, then they may change the obs shape with torch.no_grad(): # Disable gradient computation if _expert_weights is None: _expert_weights = numpy_to_torch(np.load(ckpt_path), device) From baa2901d0a9523e26688bf1457261c06b7ea01aa Mon Sep 17 00:00:00 2001 From: lzh <2536890272@qq.com> Date: Mon, 20 May 2024 15:26:29 +0800 Subject: [PATCH 2/2] add ego car color in top down view --- metadrive/constants.py | 3 +++ metadrive/engine/top_down_renderer.py | 6 +++++- metadrive/type.py | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/metadrive/constants.py b/metadrive/constants.py index 00f5cc5bd..e98e055c5 100644 --- a/metadrive/constants.py +++ b/metadrive/constants.py @@ -459,6 +459,9 @@ def get_color(type): # vehicle elif MetaDriveType.is_vehicle(type): ret = np.array([224, 177, 67]) + # self vehicle + elif MetaDriveType.is_ego_vehicle(type): + ret = np.array([67, 177, 224]) # construction object elif MetaDriveType.is_traffic_object(type): ret = np.array([67, 143, 224]) diff --git a/metadrive/engine/top_down_renderer.py b/metadrive/engine/top_down_renderer.py index 841614e4b..e425a1e61 100644 --- a/metadrive/engine/top_down_renderer.py +++ b/metadrive/engine/top_down_renderer.py @@ -409,10 +409,14 @@ def _append_frame_objects(objects): """ frame_objects = [] for name, obj in objects.items(): + obj_type = obj.metadrive_type if hasattr(obj, "metadrive_type") else MetaDriveType.OTHER + if obj_type == MetaDriveType.VEHICLE: + obj_type = 'EGO_VEHICLE' if obj.class_name == 'DefaultVehicle' else MetaDriveType.VEHICLE + frame_objects.append( history_object( name=name, - type=obj.metadrive_type if hasattr(obj, "metadrive_type") else MetaDriveType.OTHER, + type=obj_type, heading_theta=obj.heading_theta, WIDTH=obj.top_down_width, LENGTH=obj.top_down_length, diff --git a/metadrive/type.py b/metadrive/type.py index 00f9fdd1a..7af0d865f 100644 --- a/metadrive/type.py +++ b/metadrive/type.py @@ -62,6 +62,7 @@ class MetaDriveType: # ===== Agent type ===== UNSET = "UNSET" VEHICLE = "VEHICLE" + EGO_VEHICLE = "EGO_VEHICLE" # currently for top-down view PEDESTRIAN = "PEDESTRIAN" CYCLIST = "CYCLIST" OTHER = "OTHER" @@ -177,6 +178,10 @@ def is_crosswalk(cls, type): def is_vehicle(cls, type): return type == cls.VEHICLE + @classmethod + def is_ego_vehicle(cls, type): + return type == cls.EGO_VEHICLE + @classmethod def is_pedestrian(cls, type): return type == cls.PEDESTRIAN