metadriverse / scenarionet

ScenarioNet: Scalable Traffic Scenario Management System for Autonomous Driving
Apache License 2.0
142 stars 21 forks source link

Ego Vehicle Behavior Not Responding to Varied Inputs in ScenarioNet Simulator #70

Closed kevin647 closed 3 months ago

kevin647 commented 3 months ago

Issue Summary:

When conducting experiments with the ScenarioNet simulator, I encountered an issue where the ego vehicle's movement does not change in response to different input commands. This behavior is inconsistent with my experiences using MetaDriveEnv and SafeMetaDriveEnv, where the ego vehicle appropriately reacts to varied inputs.

Environment:

Followed the official guide to install

My code:

from metadrive.engine.engine_utils import close_engine close_engine() from metadrive.pull_asset import pull_asset pull_asset(False)

from metadrive.engine.asset_loader import AssetLoader from metadrive.policy.replay_policy import ReplayEgoCarPolicy from metadrive.envs.scenario_env import ScenarioEnv import os import sys sys.path.append(r'~/LGM/scnet/scenarionet') from metadrive import SafeMetaDriveEnv

from IPython.display import Image as IImage import pygame import numpy as np from PIL import Image

nuplan_data = "/home/hermes/nuplan/database"

from scenarionet import read_dataset_summary, read_scenario

dataset_summary, scenario_ids, mapping = read_dataset_summary(dataset_path=nuplan_data)

scenario_file_name = scenario_ids[0]

scenario = read_scenario(dataset_path=nuplan_data, mapping=mapping, scenario_file_name=scenario_file_name)

print(scenario.keys())

scenario.sanity_check(scenario)

scenario.to_dict()

threeD_render=True

=============================================================env setting start====================================================================

env = ScenarioEnv( { "manual_control": False, "reactive_traffic": False, "use_render": threeD_render, "agent_policy": ReplayEgoCarPolicy, "data_directory": nuplan_data, "num_scenarios": 10 } )

env = SafeMetaDriveEnv(dict(use_render=True))#, environment_num=50, start_seed=1000, horizon=1000))

=============================================================env setting start====================================================================

from stable_baselines3 import PPO from stable_baselines3.common.env_util import make_vec_env

model = PPO('MlpPolicy', env, verbose=1)

model.learn(total_timesteps=(1e+6))

model.save("scenarioenv")

model.load('')

o, _ = env.reset(seed=0) frames = [] for i in range(1, 1000): a = env.action_space.sample()

print(a)

o, r, tm, tc, info = env.step([0, 1])
env.render()
#frames.append(env.render(mode="top_down",film_size=(1200, 1200)))
if tm or tc:
    break

print(info) env.close()

Expected Behavior:

The ego vehicle should modify its movement based on the inputs provided, similar to how it functions within MetaDriveEnv and SafeMetaDriveEnv.

Actual Behavior:

Regardless of the input variations provided, the ego vehicle continues to move in the same manner without any noticeable adjustments.

It seems like there is a problem in the ScenarioNet env. I would greatly appreciate any insights or guidance on resolving this issue to ensure the ego vehicle responds dynamically to different inputs as expected. Thank you in advance for your support.

kevin647 commented 3 months ago

My bad. Setting "agent_policy": ReplayEgoCarPolicy was the problem. I shouldn't have set it or set to EnvInputPolicy(default).