metadriverse / scenarionet

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

Problem about format mismatch between ScenarioNet/MetaDrive (v0.4.2.3) and TrafficGen #89

Open RyukeLXC opened 2 months ago

RyukeLXC commented 2 months ago

Hello ScenarioNet team!Thank you for your great work!

I am interested in the Visualization of Scenario Embeddings with Scenario Generation Model (4.2 section in your paper) and noticed that you had processed some PG data based on TrafficGen, as noted in Appendix A.

However, when I tried to convert data exported from MetaDriveEnv and ScenarioEnv into the input vector v for Encoder, I found some format mismatches between data and processing scripts (Maybe because of the update in ScenarioNet scenario format?).

Would you please explain the meaning of the strings like "('>', '>>', 0)__0" , "('->>>', '->>', 2)", "('>>>', '1X20', 0)"

And do you have a script for converting the new format scenario data to vector v?

If not, would you please give me some advice on how to modify the convert script now (I use trafficgen/utils/get_md_data.py currently)?

Thanks again for your great work! Looking foward to your replay! (This problem really bothers me recently.)

The details are as follows: I tried to convert scenario data with _trafficgen/utils/get_mddata.py However, in __extractmap method, I found that _map_featsid in the following line 33, is a string"('>', '>>', 0)", therefore I modified a few to let the code run.

def _extract_map(map_feats, sample_num):

    lanes = []

    center_infos = {}

    for map_feat_id, map_feat in map_feats.items():

        if map_feat["type"] == "DRIVEWAY":
            # TODO: The driveway is not supported in the current version of TrafficGen.
            continue

        if "polyline" not in map_feat:
            if "polygon" in map_feat:
                map_feat['polyline'] = map_feat['polygon'] #[np.newaxis]
            else:
                map_feat['polyline'] = map_feat['position'][np.newaxis]

        poly_unsampled = map_feat['polyline'][:, :2]

        # TODO(PZH): Revisit the down sampling function. It seems quite werid to me.
        poly = _down_sampling(poly_unsampled, sample_num=sample_num)

        a_lane = np.zeros([len(poly), 4], dtype=object)

        # try:
        #     a_lane_id = str(map_feat_id[-2])  # ('>', '>>', 0)
        # except:
        #     a_lane_id = str(map_feat_id[-4])  # ('>', '>>', 0)_0

        a_lane[:, :2] = np.array(poly)
        a_lane[:, 2] = METADRIVE_TYPE_TO_INT[map_feat['type']]
        a_lane[:, 3] = map_feat_id  #"('>', '>>', 0)"   original str(map_feat_id)

        lanes.append(a_lane)

        if "LANE" in map_feat["type"]:
            center_info = extract_center(map_feat)
            center_infos[map_feat_id] = center_info  #center_infos[str(map_feat_id)]

extract_center

def extract_center(lane):
      ...
      center['left_boundaries'] = extract_boundaries(lane["left_boundaries"])

      center['right_boundaries'] = extract_boundaries(lane["right_boundaries"])

      center['left_neighbor'] = extract_neighbors(lane["left_neighbor"])

      center['right_neighbor'] = extract_neighbors(lane["right_neighbor"])

But input data didn't contain ["left_boundaries"] or ["right_boundaries"].

When it went into _extractneighbors method, I found that fb was only a list like: ["('>', '>>', 1)", "('>', '>>', 2)"] but not a dict list required in the following method.

def extract_neighbors(fb):
    nbs = []
    for k in range(len(fb)):
        nb = dict()
        nb['id'] = fb[k]["feature_id"]
        nb['indexes'] = [
            fb[k]["self_start_index"], fb[k]["self_end_index"], fb[k]["neighbor_start_index"], fb[k]["neighbor_end_index"]
        ]
        nb['indexes'] = [
            fb[k]["self_start_index"], fb[k]["self_end_index"], fb[k]["neighbor_start_index"], fb[k]["neighbor_end_index"]
        ]
        nb['boundaries'] = extract_boundaries(fb[k]["boundaries"])
        nb['id'] = fb[k]["feature_id"]
        nbs.append(nb)
    return nbs

Scenario data was exported with _base_env.exportscenarios. Envs were defined as follows:

env = MetaDriveEnv(dict(map="X",
                        # This policy setting simplifies the task
                        discrete_action=False,
                        horizon=1000,
                        use_render=False,
                        random_traffic=True,
                        # scenario setting
                        random_spawn_lane_index=False,
                        num_scenarios=1,
                        start_seed=5,
                        traffic_density=0.2,  # 0.2
                        accident_prob=0,  # 0
                        use_lateral_reward=True,
                        log_level=50,
                        ))

I first exported data from metadriveEnv. Then I saved ScnearioEnv data by replaying scenario from metadrive dataset above in ScnearioEnv.

env = ScenarioEnv(
    dict(
        agent_policy=ReplayEgoCarPolicy,
        data_directory=load_dir,
        use_render=True,
        num_scenarios=num_scenarios
    )
)