def test_dfs():
    """Test dfs for lane graph

    Lane Graph:
                9629626
               /       \
              /         \
          9620336    9632589
          (10.77)     (8.33)
             |          |
             |          |
          9628835    9621228
           (31.9)    (31.96)
             |          |
             |          |
          9629406    9626257
           (7.9)      (7.81)

    """

    lane_id = 9629626
    city_name = "MIA"
    dist = 0.0
    threshold = 30.0
    extend_along_predecessor = False

    avm = ArgoverseMap()
    lane_seq = avm.dfs(lane_id, city_name, dist, threshold,
                       extend_along_predecessor)

    expected_lane_seq = [[9629626, 9620336, 9628835],
                         [9629626, 9632589, 9621228]]
    assert np.array_equal(lane_seq,
                          expected_lane_seq), "dfs over lane graph failed!"
def write_tf_record(args: Any) -> None:
    print("Loading map...")
    avm = ArgoverseMap()
    fomv = ForecastingOnMapVisualizer(
        dataset_dir=args.dataset_dir,
        convert_tf_record=True,
        overwrite_rendered_file=args.overwrite_rendered_file)

    if not Path(f"{args.dataset_dir}../{args.prefix_tf_record}").exists():
        os.makedirs(f"{args.dataset_dir}../{args.prefix_tf_record}")

    print("Start rendering...")
    for i in range(args.starting_frame_ind, fomv.num):
        # for i in range(91648, 102400):
        if (i + 1) % 64 == 0:
            print(f"Processing {i}th frame")
        if i % FRAME_IN_SHARD == 0:
            shard_ind = int(i / FRAME_IN_SHARD)
            writer = tf.io.TFRecordWriter(
                f"{args.dataset_dir}/../{args.prefix_tf_record}/{shard_ind}_tf_record"
            )

        past_traj, future_traj, center_lines, surr_past_pos = fomv.plot_log_one_at_a_time(
            avm, log_num=i)
        example = convert_to_example(past_traj, future_traj, center_lines,
                                     surr_past_pos)
        writer.write(example.SerializeToString())

        if (i - shard_ind * FRAME_IN_SHARD) % (FRAME_IN_SHARD - 1) == 0 and (
                not i == shard_ind * FRAME_IN_SHARD):
            print(f"the {shard_ind}th shard has been done!")
            writer.close()
    writer.close()
Exemple #3
0
    def __init__(self,
                 every_n_steps,
                 output_dir,
                 width=100,
                 height=100,
                 scale=10,
                 mode='train',
                 source_dir='/workspace/datasets/argo/forecasting/val/data/'):
        self._every_n_steps = every_n_steps
        self.last_epoch = -1

        self.source_dir = source_dir
        self.avm = ArgoverseMap()
        self.seq_lane_props = {}
        self.seq_lane_props['PIT'] = self.avm.city_lane_centerlines_dict['PIT']
        self.seq_lane_props['MIA'] = self.avm.city_lane_centerlines_dict['MIA']
        self.afl = ArgoverseForecastingLoader(source_dir)
        self.seq_file = None

        self._width = width
        self._height = height
        self._min_alpha = 0.1

        self._output_dir = Path(output_dir)
        if not self._output_dir.exists():
            self._output_dir.mkdir(parents=True)

        self.mode = mode

        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111)
Exemple #4
0
    def __init__(self, data_dict: Dict[str, Any], args: Any, mode: str):
        """Initialize the Dataset.

        Args:
            data_dict: Dict containing all the data
            args: Arguments passed to the baseline code
            mode: train/val/test mode

        """
        self.data_dict = data_dict
        self.args = args
        self.mode = mode

        # Get input
        self.input_data = data_dict["{}_input".format(mode)]
        if mode != "test":
            self.output_data = data_dict["{}_output".format(mode)]
        self.data_size = self.input_data.shape[0]

        # Get helpers
        self.helpers = self.get_helpers()
        self.helpers = list(zip(*self.helpers))

        from argoverse.map_representation.map_api import ArgoverseMap

        self.avm = ArgoverseMap()
        self.mf = MapFeaturesUtils()
Exemple #5
0
def visualize_30hz_benchmark_data_on_map(args: Any) -> None:
    """
    """
    domv = DatasetOnMapVisualizer(args.dataset_dir, args.experiment_prefix,
                                  args.tf_record_prefix)
    avm = ArgoverseMap()
    # get all log id
    foldernames = sorted(glob.glob(args.dataset_dir + "/*"))

    num = 1
    for foldername in foldernames:
        log_id = os.path.basename(foldername)
        # log_id = "0ef28d5c-ae34-370b-99e7-6709e1c4b929"

        domv.set_log_id(log_id=log_id)

        logger.info(f"the {num}th log")
        num += 1

        # Plotting does not work on AWS! The figure cannot be refreshed properly
        # Thus, plotting must be performed locally.
        domv.plot_log_one_at_a_time(avm=avm,
                                    log_id=log_id,
                                    save_img=args.save_img,
                                    convert_tf_record=args.convert_tf_record,
                                    is_training=args.is_training)
    def __init__(self, info_path, root_path, class_names, num_point_features,
                 target_assigner, feature_map_size, prep_func):
        #with open(info_path, 'rb') as f:
        #    infos = pickle.load(f)
        self._root_path = root_path
        self.argoverse_loader = ArgoverseTrackingLoader(root_path)
        self.am = ArgoverseMap()

        self.inform = info_path
        self._num_point_features = num_point_features
        self.class_names = class_names
        #print("remain number of infos:", len(self._kitti_infos))
        # generate anchors cache
        # [352, 400]
        ret = target_assigner.generate_anchors(feature_map_size)
        anchors = ret["anchors"]
        anchors = anchors.reshape([-1, 7])
        matched_thresholds = ret["matched_thresholds"]
        unmatched_thresholds = ret["unmatched_thresholds"]
        anchors_bv = box_np_ops.rbbox2d_to_near_bbox(anchors[:,
                                                             [0, 1, 3, 4, 6]])
        anchor_cache = {
            "anchors": anchors,
            "anchors_bv": anchors_bv,
            "matched_thresholds": matched_thresholds,
            "unmatched_thresholds": unmatched_thresholds,
        }

        self._prep_func = partial(prep_func, anchor_cache=anchor_cache)
def get_drivable_area_compliance(
    forecasted_trajectories: Dict[int, List[np.ndarray]],
    city_names: Dict[int, str],
    max_n_guesses: int,
) -> float:
    """Compute drivable area compliance metric.

    Args:
        forecasted_trajectories: Predicted top-k trajectory dict with key as seq_id and value as list of trajectories.
                Each element of the list is of shape (pred_len x 2).
        city_names: Dict mapping sequence id to city name.
        max_n_guesses: Maximum number of guesses allowed.

    Returns:
        Mean drivable area compliance

    """
    avm = ArgoverseMap()

    dac_score = []

    for seq_id, trajectories in forecasted_trajectories.items():
        city_name = city_names[seq_id]
        num_dac_trajectories = 0
        n_guesses = min(max_n_guesses, len(trajectories))
        for trajectory in trajectories[:n_guesses]:
            raster_layer = avm.get_raster_layer_points_boolean(trajectory, city_name, "driveable_area")
            if np.sum(raster_layer) == raster_layer.shape[0]:
                num_dac_trajectories += 1

        dac_score.append(num_dac_trajectories / n_guesses)

    return sum(dac_score) / len(dac_score)
Exemple #8
0
def get_lanes(df: pd.DataFrame, city_name: str, avm: Optional[ArgoverseMap] = None) -> list:
    
    # Get API for Argo Dataset map
    avm = ArgoverseMap() if avm is None else avm
    seq_lane_bbox = avm.city_halluc_bbox_table[city_name]
    seq_lane_props = avm.city_lane_centerlines_dict[city_name]
    
    x_min = min(df["X"])
    x_max = max(df["X"])
    y_min = min(df["Y"])
    y_max = max(df["Y"])

    lane_centerlines = []
    
    # Get lane centerlines which lie within the range of trajectories
    for lane_id, lane_props in seq_lane_props.items():

        lane_cl = lane_props.centerline

        if (
            np.min(lane_cl[:, 0]) < x_max
            and np.min(lane_cl[:, 1]) < y_max
            and np.max(lane_cl[:, 0]) > x_min
            and np.max(lane_cl[:, 1]) > y_min
        ):
            lane_centerlines.append(lane_cl)
    
    return lane_centerlines
def leave_only_roi_region(lidar_pts: np.ndarray,
                          egovehicle_to_city_se3: np.ndarray,
                          ground_removal_method: str,
                          city_name: str = "MIA") -> np.ndarray:
    """Return points that are on driveable area, and (optionally) are not ground.

    Args:
        lidar_pts: The lidar points
        egovehicle_to_city_se3: Transformation from vehicle to map (city) frame
        ground_removal_method: "map" is only supported value currently, otherwise will not run ground removal
        city_name: city name, either 'PIT' or 'MIA'

    Returns:
        Modified point cloud reduced by driveable area and ground.

    """

    avm = ArgoverseMap()

    driveable_area_pts = copy.deepcopy(lidar_pts)
    driveable_area_pts = egovehicle_to_city_se3.transform_point_cloud(
        driveable_area_pts)  # put into city coords

    driveable_area_pts = avm.remove_non_roi_points(driveable_area_pts,
                                                   city_name)

    if ground_removal_method == "map":
        driveable_area_pts = avm.remove_ground_surface(driveable_area_pts,
                                                       city_name)
    driveable_area_pts = egovehicle_to_city_se3.inverse_transform_point_cloud(
        driveable_area_pts)  # put back into ego-vehicle coords
    return driveable_area_pts
Exemple #10
0
    def rebuild_centerline(self):
        '''rebuild centerline and save data'''
        save_path_shapely = self.save_path + '/' + self.city + '_shapely'
        save_path_array = self.save_path + '/' + self.city + '_array'
        try:
            f = open(save_path_shapely, 'rb')
            line_set_shapely = pickle.load(f)
            f.close()

            f = open(save_path_array, 'rb')
            line_set_array = pickle.load(f)
            f.close()
        except:
            am = ArgoverseMap()
            line_set_shapely = {}
            line_set_array = {}
            centerline_ind = am.build_centerline_index()[
                self.city]  # 生成全部centerline
            for ctlID, ctlinfo in centerline_ind.items():
                line_set_shapely[ctlID] = LineString(ctlinfo.centerline)
                line_set_array[ctlID] = ctlinfo.centerline
            # 保存
            f = open(save_path_shapely, 'wb')
            pickle.dump(line_set_shapely, f)
            f.close()

            f = open(save_path_array, 'wb')
            pickle.dump(line_set_array, f)
            f.close()

        self.line_set_shapely = line_set_shapely
        self.line_set_array = line_set_array
Exemple #11
0
 def __init__(
         self,
         dt_root_fpath: Path,
         gt_root_fpath: Path,
         figs_fpath: Path,
         cfg: DetectionCfg = DetectionCfg(),
         num_procs: int = -1,
 ) -> None:
     """
     Args:
         dt_fpath_root: Path to the folder which contains the detections.
         gt_fpath_root: Path to the folder which contains the split of logs.
         figs_fpath: Path to the folder which will contain the output figures.
         cfg: Detection configuration settings.
         num_procs: Number of processes among which to subdivide work.
             Specifying -1 will use one process per available core
     """
     self.dt_root_fpath = dt_root_fpath
     self.gt_root_fpath = gt_root_fpath
     self.figs_fpath = figs_fpath
     self.cfg = cfg
     self.num_procs = os.cpu_count() if num_procs == -1 else num_procs
     self.avm = (
         ArgoverseMap(self.cfg.map_root)
         if self.cfg.eval_only_roi_instances else None
     )  # map is only required if using Region of Interest (ROI) information to filter objects
Exemple #12
0
def visualize_ground_lidar_pts(log_id: str, dataset_dir: str,
                               experiment_prefix: str):
    """Process a log by drawing the LiDAR returns that are classified as belonging
    to the ground surface in a red to green colormap in the image.

    Args:
        log_id: The ID of a log
        dataset_dir: Where the dataset is stored
        experiment_prefix: Output prefix
    """
    sdb = SynchronizationDB(dataset_dir, collect_single_log_id=log_id)

    city_info_fpath = f"{dataset_dir}/{log_id}/city_info.json"
    city_info = read_json_file(city_info_fpath)
    city_name = city_info["city_name"]
    avm = ArgoverseMap()

    ply_fpaths = sorted(glob.glob(f"{dataset_dir}/{log_id}/lidar/PC_*.ply"))

    for i, ply_fpath in enumerate(ply_fpaths):
        if i % 500 == 0:
            print(f"\tOn file {i} of {log_id}")
        lidar_timestamp_ns = ply_fpath.split("/")[-1].split(".")[0].split(
            "_")[-1]

        pose_fpath = f"{dataset_dir}/{log_id}/poses/city_SE3_egovehicle_{lidar_timestamp_ns}.json"
        if not Path(pose_fpath).exists():
            continue

        pose_data = read_json_file(pose_fpath)
        rotation = np.array(pose_data["rotation"])
        translation = np.array(pose_data["translation"])
        city_to_egovehicle_se3 = SE3(rotation=quat2rotmat(rotation),
                                     translation=translation)

        lidar_pts = load_ply(ply_fpath)

        lidar_timestamp_ns = int(lidar_timestamp_ns)
        draw_ground_pts_in_image(
            sdb,
            lidar_pts,
            city_to_egovehicle_se3,
            avm,
            log_id,
            lidar_timestamp_ns,
            city_name,
            dataset_dir,
            experiment_prefix,
        )

    for camera_name in CAMERA_LIST:
        if "stereo" in camera_name:
            fps = 5
        else:
            fps = 10
        cmd = f"ffmpeg -r {fps} -f image2 -i '{experiment_prefix}_ground_viz/{log_id}/{camera_name}/%*.jpg' {experiment_prefix}_ground_viz/{experiment_prefix}_{log_id}_{camera_name}_{fps}fps.mp4"

        print(cmd)
        run_command(cmd)
        def map_features_helper(locations,
                                dfs_threshold_multiplier=2.0,
                                save_str="",
                                avm=None,
                                mfu=None,
                                rotation=None,
                                translation=None,
                                generate_candidate_centerlines=0,
                                compute_all=False):
            # Initialize map utilities if not provided
            if avm is None:
                avm = ArgoverseMap()
            if mfu is None:
                mfu = MapFeaturesUtils()

            # Get best-fitting (oracle) centerline for current vehicle
            heuristic_oracle_centerline = mfu.get_candidate_centerlines_for_trajectory(
                locations,
                city,
                avm=avm,
                viz=False,
                max_candidates=generate_candidate_centerlines,
                mode='train')[0]  # NOQA
            features = {
                "HEURISTIC_ORACLE_CENTERLINE" + save_str:
                heuristic_oracle_centerline,
                "HEURISTIC_ORACLE_CENTERLINE_NORMALIZED" + save_str:
                normalize_xy(heuristic_oracle_centerline,
                             translation=translation,
                             rotation=rotation)[0]  # NOQA
            }

            # Get top-fitting candidate centerlines for current vehicle (can beused at test time)
            if compute_all:
                if generate_candidate_centerlines > 0:
                    test_candidate_centerlines = mfu.get_candidate_centerlines_for_trajectory(
                        locations,
                        city,
                        avm=avm,
                        viz=False,
                        max_candidates=generate_candidate_centerlines,
                        mode='test')  # NOQA
                    features["TEST_CANDIDATE_CENTERLINES" +
                             save_str] = test_candidate_centerlines

                # Apply rotation and translation normalization if specified
                if rotation is not None or translation is not None:
                    if generate_candidate_centerlines > 0:
                        features['TEST_CANDIDATE_CENTERLINE_NORMALIZED' +
                                 save_str] = [
                                     normalize_xy(test_candidate_centerline,
                                                  translation=translation,
                                                  rotation=rotation)[0]
                                     for test_candidate_centerline in
                                     test_candidate_centerlines
                                 ]  # NOQA
            return features
Exemple #14
0
def get_lane_direction(pos, city, am):
    if am is None:
        from argoverse.map_representation.map_api import ArgoverseMap
        am = ArgoverseMap()
    else:
        pass
    drct_conf = np.array([np.append(*am.get_lane_direction(p[:2], city)) for p in pos])
    
    return drct_conf
Exemple #15
0
def get_all_lanes(city_name: str, avm: Optional[ArgoverseMap] = None) -> list:
    
    # Get API for Argo Dataset map
    avm = ArgoverseMap() if avm is None else avm
    seq_lane_bbox = avm.city_halluc_bbox_table[city_name]
    seq_lane_props = avm.city_lane_centerlines_dict[city_name]

    lane_centerlines = [lane.centerline for lane in seq_lane_props.values()]
    
    return lane_centerlines
def visualize_forecating_data_on_map(args: Any) -> None:
    print("Loading map...")
    avm = ArgoverseMap()
    fomv = ForecastingOnMapVisualizer(
        dataset_dir=args.dataset_dir,
        save_img=args.save_image,
        overwrite_rendered_file=args.overwrite_rendered_file)
    for i in range(fomv.num):
        print(f"Processing the file: {fomv.filenames[i]}")
        fomv.plot_log_one_at_a_time(avm, log_num=i)
def verify_manhattan_search_functionality():
    """
        Minimal example where we
        """
    adm = ArgoverseMap()
    # query_x = 254.
    # query_y = 1778.

    ref_query_x = 422.0
    ref_query_y = 1005.0

    city_name = "PIT"  # 'MIA'
    for trial_idx in range(10):
        query_x = ref_query_x + (np.random.rand() - 0.5) * 10
        query_y = ref_query_y + (np.random.rand() - 0.5) * 10

        # query_x,query_y = (3092.49845414,1798.55426805)
        query_x, query_y = (3112.80160113, 1817.07585338)

        lane_segment_ids = avm.get_lane_ids_in_xy_bbox(query_x, query_y,
                                                       city_name, 5000)

        fig = plt.figure(figsize=(22.5, 8))
        ax = fig.add_subplot(111)
        # ax.scatter([query_x], [query_y], 500, color='k', marker='.')

        plot_lane_segment_patch(pittsburgh_bounds, ax, color="m", alpha=0.1)

        if len(lane_segment_ids) > 0:
            for i, lane_segment_id in enumerate(lane_segment_ids):
                patch_color = "y"  # patch_colors[i % 4]
                lane_centerline = avm.get_lane_segment_centerline(
                    lane_segment_id, city_name)

                test_x, test_y = lane_centerline.mean(axis=0)
                inside = point_inside_polygon(n_poly_vertices,
                                              pittsburgh_bounds[:, 0],
                                              pittsburgh_bounds[:, 1], test_x,
                                              test_y)

                if inside:
                    halluc_lane_polygon = avm.get_lane_segment_polygon(
                        lane_segment_id, city_name)
                    xmin, ymin, xmax, ymax = find_lane_segment_bounds_in_table(
                        adm, city_name, lane_segment_id)
                    add_lane_segment_to_ax(ax, lane_centerline,
                                           halluc_lane_polygon, patch_color,
                                           xmin, xmax, ymin, ymax)

        ax.axis("equal")
        plt.show()
        datetime_str = generate_datetime_string()
        plt.savefig(f"{trial_idx}_{datetime_str}.jpg")
        plt.close("all")
Exemple #18
0
def get_batch_lane_direction(pos, city, am):
    if am is None:
        from argoverse.map_representation.map_api import ArgoverseMap
        am = ArgoverseMap()
    else:
        pass
    drct_conf = list()
    
    for ps, c in zip(pos, city):
        drct_conf.append(np.array([np.append(*am.get_lane_direction(p[:2], c)) for p in ps]))
    
    return drct_conf
 def __init__(self, train_test_val, root_dir=None, afl=None, avm=None):
     # self.root_dir = '/media/bartosz/hdd1TB/workspace_hdd/datasets/argodataset/argoverse-forecasting/train/data' if root_dir is None else root_dir
     self.root_dir = f"/media/bartosz/hdd1TB/workspace_hdd/datasets/argodataset/argoverse-forecasting/forecasting_{train_test_val}_v1.1/{train_test_val}/data" if root_dir is None else root_dir
     self.pickle_path = "/media/bartosz/hdd1TB/workspace_hdd/SS-LSTM/data/argoverse/ss_lstm_format_argo_forecasting_v11_{train_test_val}.pickle"
     self.pickle_cache_path = "/media/bartosz/hdd1TB/workspace_hdd/SS-LSTM/data/argoverse/cacheio_v11/ss_lstm_format_argo_forecasting_v11_{train_test_val}_{range}.pickle"
     self.img_dataset_dir = "/media/bartosz/hdd1TB/workspace_hdd/SS-LSTM/data/argoverse/imgs_ds_forecasting_v11"
     self.obs, self.pred = 20, 30
     self.afl = ArgoverseForecastingLoader(self.root_dir) if afl is None else afl
     self.avm = ArgoverseMap() if avm is None else avm
     self.scene_input, self.social_input, self.person_input, self.expected_output = None, None, None, None
     self.total_nb_of_segments = len(self.afl)
     self.train_test_val = train_test_val
Exemple #20
0
    def __init__(self, data_dir, obs_len=20, position_downscaling_factor=100):
        """
        Args:
            inp_dir: Directory with all trajectories
            obs_len: length of observed trajectory
        """
        self.data_dir = data_dir
        self.obs_len = obs_len
        self.position_downscaling_factor = position_downscaling_factor

        assert os.path.isdir(data_dir), 'Invalid Data Directory'
        self.afl = ArgoverseForecastingLoader(data_dir)
        self.avm = ArgoverseMap()
Exemple #21
0
def compute_best_candidates(agent_track: np.ndarray, obs_len: int,
                            pred_len: int, raw_data_format: Dict[str, int]):

    agent_obs = agent_track[:obs_len]
    agent_xy_obs = agent_obs[:, [raw_data_format["X"], raw_data_format["Y"]
                                 ]].astype("float")

    xy = agent_xy_obs

    avm = ArgoverseMap()

    city_name = agent_track[0, raw_data_format["CITY_NAME"]]

    candidate_centerlines = avm.get_candidate_centerlines_for_traj(
        xy,
        city_name,
        viz=False,
        max_search_radius=_MAX_SEARCH_RADIUS_CENTERLINES,
    )

    cl_str = []
    cl_turn = []
    for cl in candidate_centerlines:
        if cl.shape[0] <= 10:
            continue
        straight = is_straight(cl)
        if straight == 1:
            cl_str.append(cl)
        else:
            cl_turn.append(cl)

    if len(cl_str) + len(cl_turn) == 0:
        idx_list = np.random.randint(len(candidate_centerlines), size=2)
        best_str = candidate_centerlines[idx_list[0]]
        best_turn = candidate_centerlines[idx_list[1]]

        return best_str, best_turn

    if len(cl_str) != 0:
        best_str = get_oracle_from_candidate_centerlines(cl_str, xy)

    if len(cl_turn) != 0:
        best_turn = get_oracle_from_candidate_centerlines(cl_turn, xy)

    if len(cl_str) == 0:
        best_str = best_turn

    if len(cl_turn) == 0:
        best_turn = best_str

    return best_str, best_turn
def compute_map_features(agent_track: np.ndarray, obs_len: int, pred_len: int,
                         raw_data_format: Dict[str, int], mode: str):

    agent_xy = agent_track[:, [raw_data_format["X"], raw_data_format["Y"]
                               ]].astype("float")
    agent_obs = agent_track[:obs_len]
    agent_xy_obs = agent_obs[:, [raw_data_format["X"], raw_data_format["Y"]
                                 ]].astype("float")

    if mode == "test":
        xy = agent_xy_obs
    else:
        xy = agent_xy

    avm = ArgoverseMap()

    city_name = agent_track[0, raw_data_format["CITY_NAME"]]

    candidate_centerlines = avm.get_candidate_centerlines_for_traj(
        xy,
        city_name,
        viz=False,
        max_search_radius=_MAX_SEARCH_RADIUS_CENTERLINES,
    )
    oracle_centerline = get_oracle_from_candidate_centerlines(
        candidate_centerlines, xy)

    oracle_nt_dist = get_nt_distance(xy, oracle_centerline, viz=False)

    oracle_nt_dist_norm = oracle_nt_dist - oracle_nt_dist[0, :]

    delta_ref = copy.deepcopy(oracle_nt_dist[0, :])
    for i in range(xy.shape[0] - 1, 0, -1):
        oracle_nt_dist[i, :] = oracle_nt_dist[i, :] - oracle_nt_dist[i - 1, :]
    oracle_nt_dist[0, :] = 0

    angle_w_cl = np.zeros((xy.shape[0], 1))
    angle_w_cl[1:, 0] = np.arctan2(oracle_nt_dist[1:, 1], oracle_nt_dist[1:,
                                                                         0])
    angle_w_cl[0, :] = angle_w_cl[1, :]
    #    angle_w_cl[np.isnan(angle_w_cl)] = np.pi/2

    map_features = np.concatenate((oracle_nt_dist_norm, angle_w_cl), axis=1)

    if mode == "test":
        map_features = np.concatenate(
            (map_features, np.full([pred_len, 3], None)), axis=0)

    return map_features, oracle_centerline, delta_ref
 def __init__(self,root,train = True,test = False):
     '''
     根据路径获得数据,并根据训练、验证、测试划分数据
     train_data 和 test_data路径分开
     '''
     self.test = test
     afl = ArgoverseForecastingLoader(root)
     self.avm = ArgoverseMap()
     
     if self.test:
         self.afl = afl
     elif train:
         self.afl = afl[:int(0.7*len(afl))]
     else:
         self.afl = afl[int(0.7*len(afl)):]
Exemple #24
0
    def __init__(self, split, config, train=False):

        self.config = config
        self.train = train
        split2 = config['val_split'] if split=='val' else config['test_split']
        split = self.config['preprocess_val'] if split=='val' else self.config['preprocess_test']

        self.avl = ArgoverseForecastingLoader(split2)
        if 'preprocess' in config and config['preprocess']:
            if train:
                self.split = np.load(split, allow_pickle=True)
            else:
                self.split = np.load(split, allow_pickle=True)
        else:
            self.avl = ArgoverseForecastingLoader(split)
            self.am = ArgoverseMap()
Exemple #25
0
    def __init__(self, split, config, train=True):
        self.config = config
        self.train = train
        
        if 'preprocess' in config and config['preprocess']:
            if train:
                self.split = np.load(self.config['preprocess_train'], allow_pickle=True)
            else:
                self.split = np.load(self.config['preprocess_val'], allow_pickle=True)
        else:
            self.avl = ArgoverseForecastingLoader(split)
            self.am = ArgoverseMap()

        if 'raster' in config and config['raster']:
            #TODO: DELETE
            self.map_query = MapQuery(config['map_scale'])
def test_remove_extended_predecessors():
    """Test remove_extended_predecessors() for map_api"""

    lane_seqs = [[9621385, 9619110, 9619209, 9631133],
                 [9621385, 9619110, 9619209], [9619209, 9631133]]
    xy = np.array([[-130.0, 2315.0], [-129.0, 2315.0],
                   [-128.0, 2315.0]])  # 9619209 comntains xy[0]
    city_name = "MIA"

    avm = ArgoverseMap()
    filtered_lane_seq = avm.remove_extended_predecessors(
        lane_seqs, xy, city_name)

    assert np.array_equal(filtered_lane_seq,
                          [[9619209, 9631133], [9619209], [9619209, 9631133]
                           ]), "remove_extended_predecessors() failed!"
Exemple #27
0
 def __init__(self,
              root_dir='argoverse-data//data',
              avm=None,
              social=False,
              train_seq_size=20,
              cuda=False,
              test=False,
              oracle=False):
     super(Argoverse_LaneCentre_Data,
           self).__init__(root_dir, train_seq_size, cuda, test)
     if avm is None:
         self.avm = ArgoverseMap()
     else:
         self.avm = avm
     self.stationary_threshold = 2.0
     self.oracle = oracle
     print("Done loading map")
Exemple #28
0
    def __init__(self, question_h5, image_feature_h5_path, lidar_feature_h5_path,vocab,load_lidar=True,npoint=1024,normal_channel=True,uniform=False,cache_size=15000,drivable_area=False,
                 mode='prefix', image_h5=None, lidar_h5=None, max_samples=None, question_families=None,
                 image_idx_start_from=None):

        #############read whole question_h5 file in memory#############################
        self.all_questions = question_h5['questions'][:]
        self.all_answers = get_answer_classes(question_h5['answers'][:], vocab)
        self.all_image_idxs = question_h5['image_idxs'][:]
        self.all_video_names = (question_h5['video_names'][:]).astype(str)
        self.questions_length = question_h5['question_length'][:]
        self.image_feature_h5 = image_feature_h5_path
        self.load_lidar=load_lidar

        ############for lidar##########################################################
        if self.load_lidar:
            self.argoverse_loader = ArgoverseTrackingLoader(lidar_feature_h5_path)
            self.am = ArgoverseMap()
            self.drivable_area=drivable_area
def verify_point_in_polygon_for_lanes():
    """
        """
    avm = ArgoverseMap()

    # ref_query_x = 422.
    # ref_query_y = 1005.

    ref_query_x = -662
    ref_query_y = 2817

    city_name = "MIA"
    for trial_idx in range(10):
        query_x = ref_query_x + (np.random.rand() - 0.5) * 10
        query_y = ref_query_y + (np.random.rand() - 0.5) * 10

        fig = plt.figure(figsize=(22.5, 8))
        ax = fig.add_subplot(111)
        ax.scatter([query_x], [query_y], 100, color="k", marker=".")

        occupied_lane_ids = avm.get_lane_segments_containing_xy(
            query_x, query_y, city_name)
        for occupied_lane_id in occupied_lane_ids:
            halluc_lane_polygon = avm.get_lane_segment_polygon(
                occupied_lane_id, city_name)
            plot_lane_segment_patch(halluc_lane_polygon,
                                    ax,
                                    color="y",
                                    alpha=0.3)

        nearby_lane_ids = avm.get_lane_ids_in_xy_bbox(query_x, query_y,
                                                      city_name)
        nearby_lane_ids = set(nearby_lane_ids) - set(occupied_lane_ids)
        for nearby_lane_id in nearby_lane_ids:
            halluc_lane_polygon = avm.get_lane_segment_polygon(
                nearby_lane_id, city_name)
            plot_lane_segment_patch(halluc_lane_polygon,
                                    ax,
                                    color="r",
                                    alpha=0.3)

        ax.axis("equal")
        plt.show()
        plt.close("all")
 def __init__(self,
              root_dir='argoverse-data/forecasting_sample/data',
              train_seq_size=20,
              mode="train",
              save=False,
              load_saved=False,
              avm=None):
     super(Argoverse_Social_Centerline_Data,
           self).__init__(root_dir, train_seq_size)
     # self.agent_rel=agent_rel
     if avm is None:
         self.avm = ArgoverseMap()
     else:
         self.avm = avm
     self.map_features_utils_instance = MapFeaturesUtils()
     self.social_features_utils_instance = SocialFeaturesUtils()
     self.save = save
     self.mode = mode
     self.load_saved = load_saved