From cf0ec7347495f1a00dc3f412a7ac9e4873bb2b1f Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Fri, 3 Jun 2022 19:11:34 -0400 Subject: [PATCH 01/10] Unpin numpy. --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 2f85e4d8..25ab7379 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,7 +24,7 @@ install_requires = matplotlib nox numba - numpy>=1.21.5 + numpy opencv-python pandas pyarrow From 1a315c53dd2eec5a6d09bc692fab74b632b2b25d Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Fri, 3 Jun 2022 21:32:18 -0400 Subject: [PATCH 02/10] Remove ignore comments. --- .../motion_forecasting/eval/metrics.py | 8 +++--- .../motion_forecasting/eval/submission.py | 2 +- .../datasets/sensor/av2_sensor_dataloader.py | 6 ++--- src/av2/evaluation/detection/eval.py | 4 +-- src/av2/evaluation/detection/utils.py | 20 +++++++------- src/av2/geometry/camera/pinhole_camera.py | 10 +++---- src/av2/geometry/geometry.py | 2 +- src/av2/geometry/infinity_norm_utils.py | 2 +- src/av2/geometry/interpolate.py | 16 ++++++------ src/av2/geometry/mesh_grid.py | 2 +- src/av2/geometry/polyline_utils.py | 8 +++--- src/av2/geometry/sim2.py | 4 +-- src/av2/map/map_api.py | 4 +-- src/av2/rendering/color.py | 4 +-- src/av2/rendering/map.py | 6 ++--- src/av2/rendering/vector.py | 2 +- src/av2/utils/depth_map_utils.py | 4 +-- src/av2/utils/io.py | 2 +- .../motion_forecasting/eval/test_metrics.py | 8 +++--- .../eval/test_submission.py | 2 +- tests/evaluation/detection/test_eval.py | 6 ++--- tests/geometry/test_geometry.py | 12 ++++----- tests/geometry/test_pinhole_camera.py | 26 +++++++++---------- tests/map/test_map_api.py | 8 +++--- tests/utils/test_raster.py | 2 +- tests/utils/test_sim2.py | 2 +- tutorials/generate_egoview_overlaid_lidar.py | 10 +++---- ...ate_forecasting_scenario_visualizations.py | 2 +- .../generate_sensor_dataset_visualizations.py | 2 +- tutorials/map_teaser_notebook.py | 12 ++++----- 30 files changed, 99 insertions(+), 99 deletions(-) diff --git a/src/av2/datasets/motion_forecasting/eval/metrics.py b/src/av2/datasets/motion_forecasting/eval/metrics.py index 961ecf75..95491dee 100644 --- a/src/av2/datasets/motion_forecasting/eval/metrics.py +++ b/src/av2/datasets/motion_forecasting/eval/metrics.py @@ -16,7 +16,7 @@ def compute_ade(forecasted_trajectories: NDArrayNumber, gt_trajectory: NDArrayNu Returns: (K,) Average displacement error for each of the predicted trajectories. """ - displacement_errors = np.linalg.norm(forecasted_trajectories - gt_trajectory, axis=2) # type: ignore + displacement_errors = np.linalg.norm(forecasted_trajectories - gt_trajectory, axis=2) ade: NDArrayFloat = np.mean(displacement_errors, axis=1) return ade @@ -32,8 +32,8 @@ def compute_fde(forecasted_trajectories: NDArrayNumber, gt_trajectory: NDArrayNu (K,) Final displacement error for each of the predicted trajectories. """ # Compute final displacement error for all K trajectories - fde_vector = (forecasted_trajectories - gt_trajectory)[:, -1] # type: ignore - fde: NDArrayFloat = np.linalg.norm(fde_vector, axis=-1) # type: ignore + fde_vector = (forecasted_trajectories - gt_trajectory)[:, -1] + fde: NDArrayFloat = np.linalg.norm(fde_vector, axis=-1) return fde @@ -53,7 +53,7 @@ def compute_is_missed_prediction( (K,) Bools indicating whether prediction missed by more than specified threshold. """ fde = compute_fde(forecasted_trajectories, gt_trajectory) - is_missed_prediction = fde > miss_threshold_m # type: ignore + is_missed_prediction = fde > miss_threshold_m return is_missed_prediction diff --git a/src/av2/datasets/motion_forecasting/eval/submission.py b/src/av2/datasets/motion_forecasting/eval/submission.py index dab295c9..dbfdc92d 100644 --- a/src/av2/datasets/motion_forecasting/eval/submission.py +++ b/src/av2/datasets/motion_forecasting/eval/submission.py @@ -91,7 +91,7 @@ def from_parquet(cls, submission_file_path: Path) -> ChallengeSubmission: submission_df.sort_values(by="probability", inplace=True, ascending=False) # From serialized data, build scenario-track mapping for predictions - submission_dict: Dict[str, ScenarioPredictions] = defaultdict(lambda: defaultdict(dict)) # type: ignore + submission_dict: Dict[str, ScenarioPredictions] = defaultdict(lambda: defaultdict(dict)) for (scenario_id, track_id), track_df in submission_df.groupby(["scenario_id", "track_id"]): predicted_trajectories_x = np.stack(track_df.loc[:, "predicted_trajectory_x"].values.tolist()) predicted_trajectories_y = np.stack(track_df.loc[:, "predicted_trajectory_y"].values.tolist()) diff --git a/src/av2/datasets/sensor/av2_sensor_dataloader.py b/src/av2/datasets/sensor/av2_sensor_dataloader.py index 7204e36a..5de58873 100644 --- a/src/av2/datasets/sensor/av2_sensor_dataloader.py +++ b/src/av2/datasets/sensor/av2_sensor_dataloader.py @@ -362,7 +362,7 @@ def get_colored_sweep(self, log_id: str, lidar_timestamp_ns: int) -> NDArrayByte lidar_timestamp_ns=lidar_timestamp_ns, log_id=log_id, ) - uv_valid = np.round(uv[is_valid]).astype(np.int64) # type: ignore + uv_valid = np.round(uv[is_valid]).astype(np.int64) u = uv_valid[:, 0] v = uv_valid[:, 1] img = io_utils.read_img(img_fpath, channel_order="RGB") @@ -412,8 +412,8 @@ def get_depth_map_from_lidar( if is_valid_points is None or is_valid_points.sum() == 0: return None - u = np.round(uv[:, 0][is_valid_points]).astype(np.int32) # type: ignore - v = np.round(uv[:, 1][is_valid_points]).astype(np.int32) # type: ignore + u = np.round(uv[:, 0][is_valid_points]).astype(np.int32) + v = np.round(uv[:, 1][is_valid_points]).astype(np.int32) z = points_cam[:, 2][is_valid_points] depth_map: NDArrayFloat = np.zeros((height_px, width_px), dtype=np.float32) diff --git a/src/av2/evaluation/detection/eval.py b/src/av2/evaluation/detection/eval.py index 7d95ff36..051a9de0 100644 --- a/src/av2/evaluation/detection/eval.py +++ b/src/av2/evaluation/detection/eval.py @@ -169,8 +169,8 @@ def evaluate( dts_list, gts_list = zip(*outputs) METRIC_COLUMN_NAMES = cfg.affinity_thresholds_m + TP_ERROR_COLUMNS + ("is_evaluated",) - dts_metrics: NDArrayFloat = np.concatenate(dts_list) # type: ignore - gts_metrics: NDArrayFloat = np.concatenate(gts_list) # type: ignore + dts_metrics: NDArrayFloat = np.concatenate(dts_list) + gts_metrics: NDArrayFloat = np.concatenate(gts_list) dts.loc[:, METRIC_COLUMN_NAMES] = dts_metrics gts.loc[:, METRIC_COLUMN_NAMES] = gts_metrics diff --git a/src/av2/evaluation/detection/utils.py b/src/av2/evaluation/detection/utils.py index 412e8428..502fa63a 100644 --- a/src/av2/evaluation/detection/utils.py +++ b/src/av2/evaluation/detection/utils.py @@ -159,7 +159,7 @@ def accumulate( gts_augmented[is_evaluated_gts, :-1] = gts_assignments # Permute the detections according to the original ordering. - outputs: Tuple[NDArrayInt, NDArrayInt] = np.unique(permutation, return_index=True) # type: ignore + outputs: Tuple[NDArrayInt, NDArrayInt] = np.unique(permutation, return_index=True) _, inverse_permutation = outputs dts_augmented = dts_augmented[inverse_permutation] return dts_augmented, gts_augmented @@ -198,10 +198,10 @@ def assign(dts: NDArrayFloat, gts: NDArrayFloat, cfg: DetectionCfg) -> Tuple[NDA # The affinity matrix is an N by M matrix of the detections and ground truth labels respectively. # We want to take the corresponding affinity for each of the initial assignments using `gt_matches`. # The following line grabs the max affinity for each detection to a ground truth label. - affinities: NDArrayFloat = np.take_along_axis(affinity_matrix.transpose(), idx_gts, axis=0)[0] # type: ignore + affinities: NDArrayFloat = np.take_along_axis(affinity_matrix.transpose(), idx_gts, axis=0)[0] # Find the indices of the _first_ detection assigned to each GT. - assignments: Tuple[NDArrayInt, NDArrayInt] = np.unique(idx_gts, return_index=True) # type: ignore + assignments: Tuple[NDArrayInt, NDArrayInt] = np.unique(idx_gts, return_index=True) idx_gts, idx_dts = assignments T, E = len(cfg.affinity_thresholds_m), 3 @@ -313,7 +313,7 @@ def compute_average_precision( precision = interpolate_precision(precision) # Evaluate precision at different recalls. - precision_interpolated: NDArrayFloat = np.interp(recall_interpolated, recall, precision, right=0) # type: ignore + precision_interpolated: NDArrayFloat = np.interp(recall_interpolated, recall, precision, right=0) average_precision: float = np.mean(precision_interpolated) return average_precision, precision_interpolated @@ -334,7 +334,7 @@ def distance(dts: NDArrayFloat, gts: NDArrayFloat, metric: DistanceType) -> NDAr NotImplementedError: If the distance type is not supported. """ if metric == DistanceType.TRANSLATION: - translation_errors: NDArrayFloat = np.linalg.norm(dts - gts, axis=1) # type: ignore + translation_errors: NDArrayFloat = np.linalg.norm(dts - gts, axis=1) return translation_errors elif metric == DistanceType.SCALE: scale_errors: NDArrayFloat = 1 - iou_3d_axis_aligned(dts, gts) @@ -397,14 +397,14 @@ def compute_evaluated_dts_mask( if len(xyz_m_ego) == 0: is_evaluated = np.zeros((0,), dtype=bool) return is_evaluated - norm: NDArrayFloat = np.linalg.norm(xyz_m_ego, axis=1) # type: ignore + norm: NDArrayFloat = np.linalg.norm(xyz_m_ego, axis=1) is_evaluated = norm < cfg.max_range_m cumsum: NDArrayInt = np.cumsum(is_evaluated) max_idx_arr: NDArrayInt = np.where(cumsum > cfg.max_num_dts_per_category)[0] if len(max_idx_arr) > 0: max_idx = max_idx_arr[0] - is_evaluated[max_idx:] = False # type: ignore + is_evaluated[max_idx:] = False return is_evaluated @@ -431,7 +431,7 @@ def compute_evaluated_gts_mask( if len(xyz_m_ego) == 0: is_evaluated = np.zeros((0,), dtype=bool) return is_evaluated - norm: NDArrayFloat = np.linalg.norm(xyz_m_ego, axis=1) # type: ignore + norm: NDArrayFloat = np.linalg.norm(xyz_m_ego, axis=1) is_evaluated = np.logical_and(norm < cfg.max_range_m, num_interior_pts > 0) return is_evaluated @@ -471,8 +471,8 @@ def groupby(names: List[str], values: NDArrayFloat) -> Dict[str, NDArrayFloat]: Returns: Dictionary mapping the group name to the corresponding group. """ - outputs: Tuple[NDArrayInt, NDArrayInt] = np.unique(names, return_index=True) # type: ignore + outputs: Tuple[NDArrayInt, NDArrayInt] = np.unique(names, return_index=True) unique_items, unique_items_indices = outputs - dts_groups: List[NDArrayFloat] = np.split(values, unique_items_indices[1:]) # type: ignore + dts_groups: List[NDArrayFloat] = np.split(values, unique_items_indices[1:]) uuid_to_groups = {unique_items[i]: x for i, x in enumerate(dts_groups)} return uuid_to_groups diff --git a/src/av2/geometry/camera/pinhole_camera.py b/src/av2/geometry/camera/pinhole_camera.py index 4e52d928..b43673d8 100644 --- a/src/av2/geometry/camera/pinhole_camera.py +++ b/src/av2/geometry/camera/pinhole_camera.py @@ -261,7 +261,7 @@ def right_clipping_plane(self) -> NDArrayFloat: (4,) tuple of Hessian normal coefficients. """ a, b, c, d = -self.intrinsics.fx_px, 0.0, self.width_px / 2.0, 0.0 - coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) # type: ignore + coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) return coeffs @cached_property @@ -272,7 +272,7 @@ def left_clipping_plane(self) -> NDArrayFloat: (4,) tuple of Hessian normal coefficients. """ a, b, c, d = self.intrinsics.fx_px, 0.0, self.width_px / 2.0, 0.0 - coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) # type: ignore + coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) return coeffs @cached_property @@ -283,7 +283,7 @@ def top_clipping_plane(self) -> NDArrayFloat: (4,) tuple of Hessian normal coefficients. """ a, b, c, d = 0.0, self.intrinsics.fx_px, self.height_px / 2.0, 0.0 - coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) # type: ignore + coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) return coeffs @cached_property @@ -294,7 +294,7 @@ def bottom_clipping_plane(self) -> NDArrayFloat: (4,) tuple of Hessian normal coefficients. """ a, b, c, d = 0.0, -self.intrinsics.fx_px, self.height_px / 2.0, 0.0 - coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) # type: ignore + coeffs: NDArrayFloat = np.array([a, b, c, d]) / np.linalg.norm([a, b, c]) return coeffs def near_clipping_plane(self, near_clip_m: float) -> NDArrayFloat: @@ -402,7 +402,7 @@ def compute_pixel_ray_directions(self, uv: Union[NDArrayFloat, NDArrayInt]) -> N ray_dirs[:, 2] = fx # elementwise multiplication of scalars requires last dim to match - ray_dirs = ray_dirs / np.linalg.norm(ray_dirs, axis=1, keepdims=True) # type: ignore + ray_dirs = ray_dirs / np.linalg.norm(ray_dirs, axis=1, keepdims=True) if ray_dirs.shape[1] != 3: raise RuntimeError("Ray directions must be (N,3)") return ray_dirs diff --git a/src/av2/geometry/geometry.py b/src/av2/geometry/geometry.py index 8865765a..44eceac1 100644 --- a/src/av2/geometry/geometry.py +++ b/src/av2/geometry/geometry.py @@ -285,7 +285,7 @@ def compute_interior_points_mask(points_xyz: NDArrayFloat, cuboid_vertices: NDAr sim_uvw_ref = uvw @ ref_vertex # (3,) # Only care about the diagonal. - sim_uvw_vertices: NDArrayFloat = np.diag(uvw @ vertices.transpose()) # type: ignore # (3,) + sim_uvw_vertices: NDArrayFloat = np.diag(uvw @ vertices.transpose()) # (3,) # Check 6 conditions (2 for each of the 3 orthogonal directions). # Refer to the linked reference for additional information. diff --git a/src/av2/geometry/infinity_norm_utils.py b/src/av2/geometry/infinity_norm_utils.py index 959a65a4..a6f2ddd9 100644 --- a/src/av2/geometry/infinity_norm_utils.py +++ b/src/av2/geometry/infinity_norm_utils.py @@ -38,5 +38,5 @@ def has_pts_in_infinity_norm_radius(points: NDArrayFloat, window_center: NDArray # reshape just in case was given column vector window_center = window_center.reshape(1, 2) - dists = np.linalg.norm(points - window_center, ord=np.inf, axis=1) # type: ignore + dists = np.linalg.norm(points - window_center, ord=np.inf, axis=1) return bool(dists.min() < window_sz) diff --git a/src/av2/geometry/interpolate.py b/src/av2/geometry/interpolate.py index 8b0af1bb..7bf4ad10 100644 --- a/src/av2/geometry/interpolate.py +++ b/src/av2/geometry/interpolate.py @@ -35,7 +35,7 @@ def compute_lane_width(left_even_pts: NDArrayFloat, right_even_pts: NDArrayFloat raise ValueError( f"Shape of left_even_pts {left_even_pts.shape} did not match right_even_pts {right_even_pts.shape}" ) - lane_width = float(np.mean(np.linalg.norm(left_even_pts - right_even_pts, axis=1))) # type: ignore + lane_width = float(np.mean(np.linalg.norm(left_even_pts - right_even_pts, axis=1))) return lane_width @@ -57,7 +57,7 @@ def compute_mid_pivot_arc(single_pt: NDArrayFloat, arc_pts: NDArrayFloat) -> Tup """ num_pts = len(arc_pts) # form ladder with equal number of vertices on each side - single_pt_tiled = np.tile(single_pt, (num_pts, 1)) # type: ignore + single_pt_tiled = np.tile(single_pt, (num_pts, 1)) # compute midpoint for each rung of the ladder centerline_pts = (single_pt_tiled + arc_pts) / 2.0 lane_width = compute_lane_width(single_pt_tiled, arc_pts) @@ -111,7 +111,7 @@ def compute_midpoint_line( left_even_pts = interp_arc(num_interp_pts, points=left_ln_boundary) right_even_pts = interp_arc(num_interp_pts, points=right_ln_boundary) - centerline_pts = (left_even_pts + right_even_pts) / 2.0 # type: ignore + centerline_pts = (left_even_pts + right_even_pts) / 2.0 lane_width = compute_lane_width(left_even_pts, right_even_pts) return centerline_pts, lane_width @@ -151,7 +151,7 @@ def interp_arc(t: int, points: NDArrayFloat) -> NDArrayFloat: # Compute the chordal arclength of each segment. # Compute differences between each x coord, to get the dx's # Do the same to get dy's. Then the hypotenuse length is computed as a norm. - chordlen: NDArrayFloat = np.linalg.norm(np.diff(points, axis=0), axis=1) # type: ignore + chordlen: NDArrayFloat = np.linalg.norm(np.diff(points, axis=0), axis=1) # Normalize the arclengths to a unit total chordlen = chordlen / np.sum(chordlen) # cumulative arclength @@ -160,10 +160,10 @@ def interp_arc(t: int, points: NDArrayFloat) -> NDArrayFloat: cumarc[1:] = np.cumsum(chordlen) # which interval did each point fall in, in terms of eq_spaced_points? (bin index) - tbins: NDArrayInt = np.digitize(eq_spaced_points, bins=cumarc).astype(int) # type: ignore + tbins: NDArrayInt = np.digitize(eq_spaced_points, bins=cumarc).astype(int) # #catch any problems at the ends - tbins[np.where((tbins <= 0) | (eq_spaced_points <= 0))] = 1 # type: ignore + tbins[np.where((tbins <= 0) | (eq_spaced_points <= 0))] = 1 tbins[np.where((tbins >= n) | (eq_spaced_points >= 1))] = n - 1 s = np.divide((eq_spaced_points - cumarc[tbins - 1]), chordlen[tbins - 1]) @@ -198,8 +198,8 @@ def linear_interpolation( interval = t1 - t0 t = (query_timestamp - t0) / interval - vec = key_translations[1] - key_translations[0] # type: ignore - translation_interp = key_translations[0] + vec * t # type: ignore + vec = key_translations[1] - key_translations[0] + translation_interp = key_translations[0] + vec * t return translation_interp diff --git a/src/av2/geometry/mesh_grid.py b/src/av2/geometry/mesh_grid.py index 275d3a80..8fb24621 100644 --- a/src/av2/geometry/mesh_grid.py +++ b/src/av2/geometry/mesh_grid.py @@ -33,7 +33,7 @@ def get_mesh_grid_as_point_cloud( ny = max_y - min_y x = np.linspace(min_x, max_x, math.ceil(nx / downsample_factor) + 1) y = np.linspace(min_y, max_y, math.ceil(ny / downsample_factor) + 1) - x_grid, y_grid = np.meshgrid(x, y) # type: ignore + x_grid, y_grid = np.meshgrid(x, y) x_grid = x_grid.flatten() y_grid = y_grid.flatten() diff --git a/src/av2/geometry/polyline_utils.py b/src/av2/geometry/polyline_utils.py index e3cf9b8e..7e212941 100644 --- a/src/av2/geometry/polyline_utils.py +++ b/src/av2/geometry/polyline_utils.py @@ -30,8 +30,8 @@ def get_polyline_length(polyline: NDArrayFloat) -> float: """ if polyline.shape[1] not in [2, 3]: raise RuntimeError("Polyline must have shape (N,2) or (N,3)") - offsets = np.diff(polyline, axis=0) # type: ignore - return float(np.linalg.norm(offsets, axis=1).sum()) # type: ignore + offsets = np.diff(polyline, axis=0) + return float(np.linalg.norm(offsets, axis=1).sum()) def interp_polyline_by_fixed_waypt_interval(polyline: NDArrayFloat, waypt_interval: float) -> Tuple[NDArrayFloat, int]: @@ -130,12 +130,12 @@ def centerline_to_polygon( Numpy array of shape (2N+1,2) or (2N+1,3), with duplicate first and last vertices. """ # eliminate duplicates - _, inds = np.unique(centerline, axis=0, return_index=True) # type: ignore + _, inds = np.unique(centerline, axis=0, return_index=True) # does not return indices in sorted order inds = np.sort(inds) centerline = centerline[inds] - grad: NDArrayFloat = np.gradient(centerline, axis=0) # type: ignore + grad: NDArrayFloat = np.gradient(centerline, axis=0) dx = grad[:, 0] dy = grad[:, 1] diff --git a/src/av2/geometry/sim2.py b/src/av2/geometry/sim2.py index 8a8f71d4..b496b7a7 100644 --- a/src/av2/geometry/sim2.py +++ b/src/av2/geometry/sim2.py @@ -71,7 +71,7 @@ def theta_deg(self) -> float: def __repr__(self) -> str: """Return a human-readable string representation of the class.""" - trans = np.round(self.t, 2) # type: ignore + trans = np.round(self.t, 2) return f"Angle (deg.): {self.theta_deg:.1f}, Trans.: {trans}, Scale: {self.s:.1f}" def __eq__(self, other: object) -> bool: @@ -132,7 +132,7 @@ def compose(self, S: Sim2) -> Sim2: # fmt: off return Sim2( R=self.R @ S.R, - t=self.R @ S.t + ((1.0 / S.s) * self.t), # type: ignore + t=self.R @ S.t + ((1.0 / S.s) * self.t), s=self.s * S.s ) # fmt: on diff --git a/src/av2/map/map_api.py b/src/av2/map/map_api.py index f0436924..9226e8c9 100644 --- a/src/av2/map/map_api.py +++ b/src/av2/map/map_api.py @@ -130,7 +130,7 @@ def from_file(cls, log_map_dirpath: Path) -> GroundHeightLayer: raise RuntimeError("Sim(2) mapping from city to image coordinates is missing") # load the file with rasterized values - ground_height_array: NDArrayFloat = np.load(ground_height_npy_fpaths[0]) # type: ignore + ground_height_array: NDArrayFloat = np.load(ground_height_npy_fpaths[0]) array_Sim2_city = Sim2.from_json(Sim2_json_fpaths[0]) @@ -221,7 +221,7 @@ def from_vector_data(cls, drivable_areas: List[DrivableArea]) -> DrivableAreaMap da_polygons_img = [] for da_polygon_city in drivable_areas: da_polygon_img = array_Sim2_city.transform_from(da_polygon_city.xyz[:, :2]) - da_polygon_img = np.round(da_polygon_img).astype(np.int32) # type: ignore + da_polygon_img = np.round(da_polygon_img).astype(np.int32) da_polygons_img.append(da_polygon_img) da_mask = raster_utils.get_mask_from_polygons(da_polygons_img, img_h, img_w) diff --git a/src/av2/rendering/color.py b/src/av2/rendering/color.py index f5b62ba7..8dee746b 100644 --- a/src/av2/rendering/color.py +++ b/src/av2/rendering/color.py @@ -51,7 +51,7 @@ def create_range_map(points_xyz: NDArrayFloat) -> NDArrayByte: (N,3) RGB colormap. """ range = points_xyz[..., 2] - range = np.round(range).astype(int) # type: ignore + range = np.round(range).astype(int) color = plt.get_cmap("turbo")(np.arange(0, range.max() + 1)) color = color[range] range_cmap: NDArrayByte = (color * 255.0).astype(np.uint8) @@ -71,4 +71,4 @@ def create_colormap(color_list: Sequence[str], n_colors: int) -> NDArrayFloat: cmap = LinearSegmentedColormap.from_list(name="dummy_name", colors=color_list) colorscale: NDArrayFloat = np.array([cmap(k * 1 / n_colors) for k in range(n_colors)]) # ignore the 4th alpha channel - return colorscale[:, :3] # type: ignore + return colorscale[:, :3] diff --git a/src/av2/rendering/map.py b/src/av2/rendering/map.py index 50c898ec..990a677f 100644 --- a/src/av2/rendering/map.py +++ b/src/av2/rendering/map.py @@ -210,8 +210,8 @@ def render_polyline_egoview( if is_valid_points.sum() == 0: return - u: NDArrayInt = np.round(uv[:, 0][is_valid_points]).astype(np.int32) # type: ignore - v: NDArrayInt = np.round(uv[:, 1][is_valid_points]).astype(np.int32) # type: ignore + u: NDArrayInt = np.round(uv[:, 0][is_valid_points]).astype(np.int32) + v: NDArrayInt = np.round(uv[:, 1][is_valid_points]).astype(np.int32) lane_z = points_cam[:, 2][is_valid_points] @@ -252,7 +252,7 @@ def draw_visible_polyline_segments_cv2( color: Tuple of shape (3,) with a BGR format color thickness_px: thickness (in pixels) to use when rendering the polyline. """ - line_segments_arr_int: NDArrayInt = np.round(line_segments_arr).astype(int) # type: ignore + line_segments_arr_int: NDArrayInt = np.round(line_segments_arr).astype(int) for i in range(len(line_segments_arr_int) - 1): if (not valid_pts_bool[i]) or (not valid_pts_bool[i + 1]): diff --git a/src/av2/rendering/vector.py b/src/av2/rendering/vector.py index 8ea7edac..67893089 100644 --- a/src/av2/rendering/vector.py +++ b/src/av2/rendering/vector.py @@ -130,7 +130,7 @@ def draw_line_frustum( # After clipping the line segment to the view frustum in the camera coordinate frame, we obtain # the final set of line segment vertices, and then project these into the image. uv, _, _ = cam_model.project_cam_to_img(clipped_points) - uv_int: NDArrayInt = np.round(uv).astype(int) # type: ignore + uv_int: NDArrayInt = np.round(uv).astype(int) p1, p2 = uv_int[0], uv_int[1] img = draw_line_in_img(img, p1, p2, color=color, thickness=thickness, line_type=line_type) return img diff --git a/src/av2/utils/depth_map_utils.py b/src/av2/utils/depth_map_utils.py index 55726253..110f4a4d 100644 --- a/src/av2/utils/depth_map_utils.py +++ b/src/av2/utils/depth_map_utils.py @@ -29,7 +29,7 @@ def compute_allowed_noise_per_point(points_cam: NDArrayFloat) -> NDArrayFloat: Returns: array of shape (N,) representing allowed amount of noise, in meters, for entries in a depth map. """ - dists_away: NDArrayFloat = np.linalg.norm(points_cam, axis=1) # type: ignore + dists_away: NDArrayFloat = np.linalg.norm(points_cam, axis=1) max_dist_away = dists_away.max() max_dist_away = max(max_dist_away, MIN_DISTANCE_AWAY_M) @@ -68,4 +68,4 @@ def vis_depth_map( plt.subplot(1, 2, 1) plt.imshow(img_rgb) plt.subplot(1, 2, 2) - plt.imshow((depth_map * 3).astype(np.uint8), cmap="inferno") # type: ignore + plt.imshow((depth_map * 3).astype(np.uint8), cmap="inferno") diff --git a/src/av2/utils/io.py b/src/av2/utils/io.py index 633f498b..b06fdd8a 100644 --- a/src/av2/utils/io.py +++ b/src/av2/utils/io.py @@ -201,7 +201,7 @@ def write_img(img_path: Path, img: NDArrayByte, channel_order: str = "RGB") -> N raise ValueError("Unsupported channel order (must be BGR or RGB).") if channel_order == "RGB": - img: NDArrayByte = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) # type: ignore + img: NDArrayByte = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) cv2.imwrite(str(img_path), img) diff --git a/tests/datasets/motion_forecasting/eval/test_metrics.py b/tests/datasets/motion_forecasting/eval/test_metrics.py index 4ffd4afa..c26efd08 100644 --- a/tests/datasets/motion_forecasting/eval/test_metrics.py +++ b/tests/datasets/motion_forecasting/eval/test_metrics.py @@ -32,7 +32,7 @@ expected_fde_straight_k1 = np.full((1,), test_N - 1) # Case 4: K=6 forecasts in straight line on X axis -forecasted_trajectories_straight_k6: NDArrayFloat = np.concatenate( # type: ignore +forecasted_trajectories_straight_k6: NDArrayFloat = np.concatenate( [forecasted_trajectories_straight_k1] * 6, axis=0 ) # 6xNx2 expected_ade_straight_k6 = np.full((6,), np.arange(test_N).mean()) @@ -63,7 +63,7 @@ def test_compute_ade(forecasted_trajectories: NDArrayNumber, expected_ade: NDArr expected_ade: Expected average displacement error. """ ade = metrics.compute_ade(forecasted_trajectories, _STATIONARY_GT_TRAJ) - np.testing.assert_allclose(ade, expected_ade) # type: ignore + np.testing.assert_allclose(ade, expected_ade) @pytest.mark.parametrize( @@ -183,7 +183,7 @@ def test_compute_brier_ade( ], ) def test_compute_brier_ade_data_validation( - forecast_probabilities: NDArrayNumber, normalize: bool, expectation: AbstractContextManager # type: ignore + forecast_probabilities: NDArrayNumber, normalize: bool, expectation: AbstractContextManager ) -> None: """Test that test_compute_brier_ade raises the correct errors when inputs are invalid. @@ -247,7 +247,7 @@ def test_compute_brier_fde( ], ) def test_compute_brier_fde_data_validation( - forecast_probabilities: NDArrayNumber, normalize: bool, expectation: AbstractContextManager # type: ignore + forecast_probabilities: NDArrayNumber, normalize: bool, expectation: AbstractContextManager ) -> None: """Test that test_compute_brier_fde raises the correct errors when inputs are invalid. diff --git a/tests/datasets/motion_forecasting/eval/test_submission.py b/tests/datasets/motion_forecasting/eval/test_submission.py index a60a88bd..886ec6a4 100644 --- a/tests/datasets/motion_forecasting/eval/test_submission.py +++ b/tests/datasets/motion_forecasting/eval/test_submission.py @@ -39,7 +39,7 @@ ids=["valid", "wrong_shape_trajectory", "mismatched_trajectory_probability_shape"], ) def test_challenge_submission_data_validation( - test_submission_dict: Dict[str, ScenarioPredictions], expectation: AbstractContextManager # type: ignore + test_submission_dict: Dict[str, ScenarioPredictions], expectation: AbstractContextManager ) -> None: """Test that validation of submitted trajectories works as expected during challenge submission initialization. diff --git a/tests/evaluation/detection/test_eval.py b/tests/evaluation/detection/test_eval.py index 58c9ece8..25154d3d 100644 --- a/tests/evaluation/detection/test_eval.py +++ b/tests/evaluation/detection/test_eval.py @@ -287,7 +287,7 @@ def test_compute_evaluated_dts_mask() -> None: detection_cfg = DetectionCfg(categories=("REGULAR_VEHICLE",), eval_only_roi_instances=False) dts_mask = compute_evaluated_dts_mask(dts, detection_cfg) dts_mask_: NDArrayBool = np.array([True, False, False, True]) - np.testing.assert_array_equal(dts_mask, dts_mask_) # type: ignore + np.testing.assert_array_equal(dts_mask, dts_mask_) def test_compute_evaluated_dts_mask_2() -> None: @@ -317,7 +317,7 @@ def test_compute_evaluated_gts_mask() -> None: gts_mask = compute_evaluated_gts_mask(gts_xyz_ego, num_interior_pts, detection_cfg) gts_mask_: NDArrayBool = np.array([True, False, False, False]) - np.testing.assert_array_equal(gts_mask, gts_mask_) # type: ignore + np.testing.assert_array_equal(gts_mask, gts_mask_) def test_compute_objects_in_roi_mask() -> None: @@ -350,4 +350,4 @@ def test_compute_objects_in_roi_mask() -> None: sweep_annotations.loc[:, ORDERED_CUBOID_COL_NAMES].to_numpy(), timestamped_city_SE3_egoposes[timestamp_ns], avm ) mask_: NDArrayBool = np.array([True, False, True]) - np.testing.assert_array_equal(mask, mask_) # type: ignore + np.testing.assert_array_equal(mask, mask_) diff --git a/tests/geometry/test_geometry.py b/tests/geometry/test_geometry.py index a6330b8e..637a37fa 100644 --- a/tests/geometry/test_geometry.py +++ b/tests/geometry/test_geometry.py @@ -207,8 +207,8 @@ def test_crop_points( """ cropped_xyz, mask = geometry_utils.crop_points(points_xyz, lower_bound_inclusive, upper_bound_exclusive) - np.testing.assert_array_equal(expected_crop_points, cropped_xyz) # type: ignore - np.testing.assert_array_equal(expected_mask, mask) # type: ignore + np.testing.assert_array_equal(expected_crop_points, cropped_xyz) + np.testing.assert_array_equal(expected_mask, mask) @pytest.mark.parametrize( @@ -395,7 +395,7 @@ def test_xyz_to_mat_matrix() -> None: [0.5000000, 0.8535534, -0.1464466], [-0.7071068, 0.5000000, 0.5000000], ] - np.testing.assert_allclose(rotation_matrix, rotation_matrix_expected) # type: ignore + np.testing.assert_allclose(rotation_matrix, rotation_matrix_expected) def test_xyz_to_mat_round_trip() -> None: @@ -403,7 +403,7 @@ def test_xyz_to_mat_round_trip() -> None: tait_bryan_angles: NDArrayFloat = np.deg2rad([45.0, 45.0, 45.0]) rotation_matrix = xyz_to_mat(tait_bryan_angles) tait_bryan_angles_ = mat_to_xyz(rotation_matrix) - np.testing.assert_allclose(tait_bryan_angles, tait_bryan_angles_) # type: ignore + np.testing.assert_allclose(tait_bryan_angles, tait_bryan_angles_) def test_mat_to_xyz_round_trip() -> None: @@ -417,7 +417,7 @@ def test_mat_to_xyz_round_trip() -> None: ) tait_bryan_angles = mat_to_xyz(rotation_matrix) rotation_matrix_ = xyz_to_mat(tait_bryan_angles) - np.testing.assert_allclose(rotation_matrix, rotation_matrix_, atol=1e-10) # type: ignore + np.testing.assert_allclose(rotation_matrix, rotation_matrix_, atol=1e-10) def test_mat_to_xyz_constrained() -> None: @@ -435,7 +435,7 @@ def test_mat_to_xyz_constrained() -> None: xyz_expected = np.deg2rad([0, 0, 90]) # [45, 0, 90] -> constrain roll to zero -> [0, 0, 90]. mat_constrained_expected = xyz_to_mat(xyz_expected) - np.testing.assert_allclose(mat_constrained, mat_constrained_expected) # type: ignore + np.testing.assert_allclose(mat_constrained, mat_constrained_expected) def RzRyRx(x: float, y: float, z: float) -> NDArrayFloat: diff --git a/tests/geometry/test_pinhole_camera.py b/tests/geometry/test_pinhole_camera.py index b1a16667..8a6a8c2c 100644 --- a/tests/geometry/test_pinhole_camera.py +++ b/tests/geometry/test_pinhole_camera.py @@ -45,12 +45,12 @@ def _fit_plane_to_point_cloud(points_xyz: NDArrayFloat) -> Tuple[float, float, f (4,) Plane coefficients. Defining ax + by + cz = d for the plane. """ center_xyz: NDArrayFloat = np.mean(points_xyz, axis=0) - out: Tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat] = np.linalg.svd(points_xyz - center_xyz) # type: ignore + out: Tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat] = np.linalg.svd(points_xyz - center_xyz) vh = out[2] # Get the unitary normal vector a, b, c = float(vh[2, 0]), float(vh[2, 1]), float(vh[2, 2]) - d: float = -np.dot([a, b, c], center_xyz) # type: ignore + d: float = -np.dot([a, b, c], center_xyz) return (a, b, c, d) @@ -308,10 +308,10 @@ def test_frustum_planes_ring_cam() -> None: bottom_plane_expected: NDArrayFloat = np.array([0.0, -fx_px, height_px / 2.0, 0.0]) top_plane_expected: NDArrayFloat = np.array([0.0, fx_px, height_px / 2.0, 0.0]) - assert np.allclose(left_plane, left_plane_expected / np.linalg.norm(left_plane_expected)) # type: ignore - assert np.allclose(right_plane, right_plane_expected / np.linalg.norm(right_plane_expected)) # type: ignore - assert np.allclose(bottom_plane, bottom_plane_expected / np.linalg.norm(bottom_plane_expected)) # type: ignore - assert np.allclose(top_plane, top_plane_expected / np.linalg.norm(top_plane_expected)) # type: ignore + assert np.allclose(left_plane, left_plane_expected / np.linalg.norm(left_plane_expected)) + assert np.allclose(right_plane, right_plane_expected / np.linalg.norm(right_plane_expected)) + assert np.allclose(bottom_plane, bottom_plane_expected / np.linalg.norm(bottom_plane_expected)) + assert np.allclose(top_plane, top_plane_expected / np.linalg.norm(top_plane_expected)) assert np.allclose(near_plane, near_plane_expected) @@ -346,10 +346,10 @@ def test_generate_frustum_planes_stereo() -> None: bottom_plane_expected: NDArrayFloat = np.array([0.0, -fx_px, height_px / 2.0, 0.0]) top_plane_expected: NDArrayFloat = np.array([0.0, fx_px, height_px / 2.0, 0.0]) - assert np.allclose(left_plane, left_plane_expected / np.linalg.norm(left_plane_expected)) # type: ignore - assert np.allclose(right_plane, right_plane_expected / np.linalg.norm(right_plane_expected)) # type: ignore - assert np.allclose(bottom_plane, bottom_plane_expected / np.linalg.norm(bottom_plane_expected)) # type: ignore - assert np.allclose(top_plane, top_plane_expected / np.linalg.norm(top_plane_expected)) # type: ignore + assert np.allclose(left_plane, left_plane_expected / np.linalg.norm(left_plane_expected)) + assert np.allclose(right_plane, right_plane_expected / np.linalg.norm(right_plane_expected)) + assert np.allclose(bottom_plane, bottom_plane_expected / np.linalg.norm(bottom_plane_expected)) + assert np.allclose(top_plane, top_plane_expected / np.linalg.norm(top_plane_expected)) assert np.allclose(near_plane, near_plane_expected) @@ -422,7 +422,7 @@ def test_compute_pixel_ray_directions_vectorized() -> None: ray_dirs = pinhole_camera.compute_pixel_ray_directions(uv) gt_ray_dir: NDArrayFloat = np.array([2, -3, 10.0]) - gt_ray_dir /= np.linalg.norm(gt_ray_dir) # type: ignore + gt_ray_dir /= np.linalg.norm(gt_ray_dir) for i in range(4): assert np.allclose(gt_ray_dir, ray_dirs[i]) @@ -483,7 +483,7 @@ def test_compute_pixel_rays() -> None: ray_dir = _compute_pixel_ray_direction(u, v, fx, fy, img_w, img_h) gt_ray_dir: NDArrayFloat = np.array([2.0, -3.0, 10.0]) - gt_ray_dir /= np.linalg.norm(gt_ray_dir) # type: ignore + gt_ray_dir /= np.linalg.norm(gt_ray_dir) assert np.allclose(gt_ray_dir, ray_dir) @@ -536,7 +536,7 @@ def _compute_pixel_ray_direction(u: float, v: float, fx: float, fy: float, img_w y_center_offs = v - py ray_dir: NDArrayFloat = np.array([x_center_offs, y_center_offs, fx]) - ray_dir /= np.linalg.norm(ray_dir) # type: ignore + ray_dir /= np.linalg.norm(ray_dir) return ray_dir diff --git a/tests/map/test_map_api.py b/tests/map/test_map_api.py index 1e1e16d1..5a35a2f8 100644 --- a/tests/map/test_map_api.py +++ b/tests/map/test_map_api.py @@ -190,7 +190,7 @@ def test_get_lane_segment_polygon(self, dummy_static_map: ArgoverseStaticMap) -> [874.01, -105.15, -19.58], ] ) - np.testing.assert_allclose(ls_polygon, expected_ls_polygon) # type: ignore + np.testing.assert_allclose(ls_polygon, expected_ls_polygon) def test_get_lane_segment_centerline(self, dummy_static_map: ArgoverseStaticMap) -> None: """Ensure lane segment centerlines can be inferred and fetched properly.""" @@ -213,7 +213,7 @@ def test_get_lane_segment_centerline(self, dummy_static_map: ArgoverseStaticMap) [890.435, -102.41, -19.62], ] ) - np.testing.assert_allclose(centerline, expected_centerline) # type: ignore + np.testing.assert_allclose(centerline, expected_centerline) def test_get_scenario_lane_segments(self, dummy_static_map: ArgoverseStaticMap) -> None: """Ensure that all LaneSegment objects in the local map can be returned as a list.""" @@ -275,7 +275,7 @@ def test_get_scenario_vector_drivable_areas(self, dummy_static_map: ArgoverseSta assert vector_da.xyz.shape == (172, 3) # compare first and last vertex, for equality - np.testing.assert_allclose(vector_da.xyz[0], vector_da.xyz[171]) # type: ignore + np.testing.assert_allclose(vector_da.xyz[0], vector_da.xyz[171]) # fmt: off # compare first 4 vertices @@ -285,7 +285,7 @@ def test_get_scenario_vector_drivable_areas(self, dummy_static_map: ArgoverseSta [904.64, -137.25, -19.28], [904.37, -132.55, -19.32]]) # fmt: on - np.testing.assert_allclose(vector_da.xyz[:4], expected_first4_vertices) # type: ignore + np.testing.assert_allclose(vector_da.xyz[:4], expected_first4_vertices) def test_get_ground_height_at_xy(self, dummy_static_map: ArgoverseStaticMap) -> None: """Ensure that ground height at (x,y) locations can be retrieved properly.""" diff --git a/tests/utils/test_raster.py b/tests/utils/test_raster.py index f379d15b..8a8d929b 100644 --- a/tests/utils/test_raster.py +++ b/tests/utils/test_raster.py @@ -187,6 +187,6 @@ def test_blend_images() -> None: img_b: NDArrayByte = np.zeros((H, W, 3), dtype=np.uint8) img_b[:, :, :3] = np.array([2, 4, 8]) # column 0 has uniform intensity - blended_img_expected: NDArrayByte = np.round(img_a * alpha + img_b * beta + gamma).astype(np.uint8) # type: ignore + blended_img_expected: NDArrayByte = np.round(img_a * alpha + img_b * beta + gamma).astype(np.uint8) blended_img = raster_utils.blend_images(img_a, img_b, alpha=alpha) assert np.array_equal(blended_img, blended_img_expected) diff --git a/tests/utils/test_sim2.py b/tests/utils/test_sim2.py index 47730e23..ec3e0e45 100644 --- a/tests/utils/test_sim2.py +++ b/tests/utils/test_sim2.py @@ -184,7 +184,7 @@ def test_matrix_homogenous_transform() -> None: world_pts_h: NDArrayFloat = np.hstack([world_pts, np.ones((4, 1))]) # multiply each (3,1) homogeneous point vector w/ transform matrix - img_pts_h = (imgSw.matrix @ world_pts_h.T).T # type: ignore + img_pts_h = (imgSw.matrix @ world_pts_h.T).T # divide (x,y,s) by s img_pts = img_pts_h[:, :2] / img_pts_h[:, 2].reshape(-1, 1) assert np.allclose(expected_img_pts, img_pts) diff --git a/tutorials/generate_egoview_overlaid_lidar.py b/tutorials/generate_egoview_overlaid_lidar.py index 8e91a8aa..37366a35 100644 --- a/tutorials/generate_egoview_overlaid_lidar.py +++ b/tutorials/generate_egoview_overlaid_lidar.py @@ -53,8 +53,8 @@ def generate_egoview_overlaid_lidar( # repeat red to green colormap every 50 m. colors_arr_rgb = color_utils.create_colormap(color_list=[RED_HEX, GREEN_HEX], n_colors=NUM_RANGE_BINS) - colors_arr_rgb = (colors_arr_rgb * 255).astype(np.uint8) # type: ignore - colors_arr_bgr: NDArrayByte = np.fliplr(colors_arr_rgb) # type: ignore + colors_arr_rgb = (colors_arr_rgb * 255).astype(np.uint8) + colors_arr_bgr: NDArrayByte = np.fliplr(colors_arr_rgb) for _, cam_name in enumerate(list(RingCameras)): cam_im_fpaths = loader.get_ordered_log_cam_fpaths(log_id, cam_name) @@ -104,10 +104,10 @@ def generate_egoview_overlaid_lidar( if is_valid_points.sum() == 0: continue - uv_int: NDArrayInt = np.round(uv[is_valid_points]).astype(np.int32) # type: ignore + uv_int: NDArrayInt = np.round(uv[is_valid_points]).astype(np.int32) points_cam = points_cam[is_valid_points] - pt_ranges: NDArrayFloat = np.linalg.norm(points_cam[:, :3], axis=1) # type: ignore - color_bins: NDArrayInt = np.round(pt_ranges).astype(np.int32) # type: ignore + pt_ranges: NDArrayFloat = np.linalg.norm(points_cam[:, :3], axis=1) + color_bins: NDArrayInt = np.round(pt_ranges).astype(np.int32) # account for moving past 100 meters, loop around again color_bins = color_bins % NUM_RANGE_BINS uv_colors_bgr = colors_arr_bgr[color_bins] diff --git a/tutorials/generate_forecasting_scenario_visualizations.py b/tutorials/generate_forecasting_scenario_visualizations.py index f94de042..bf285c50 100644 --- a/tutorials/generate_forecasting_scenario_visualizations.py +++ b/tutorials/generate_forecasting_scenario_visualizations.py @@ -47,7 +47,7 @@ def generate_scenario_visualizations( scenario_file_list = ( all_scenario_files[:num_scenarios] if selection_criteria == SelectionCriteria.FIRST - else np.random.choice(all_scenario_files, size=num_scenarios).tolist() # type: ignore + else np.random.choice(all_scenario_files, size=num_scenarios).tolist() ) # Ignoring type here because type of "choice" is partially unknown. # Build inner function to generate visualization for a single scenario. diff --git a/tutorials/generate_sensor_dataset_visualizations.py b/tutorials/generate_sensor_dataset_visualizations.py index caa9a515..e1a3d7a3 100644 --- a/tutorials/generate_sensor_dataset_visualizations.py +++ b/tutorials/generate_sensor_dataset_visualizations.py @@ -70,7 +70,7 @@ def generate_sensor_dataset_visualizations( city_SE3_ego_lidar_t=city_SE3_ego_lidar_t, ) - uv_int: NDArrayInt = np.round(uv[is_valid_points]).astype(int) # type: ignore + uv_int: NDArrayInt = np.round(uv[is_valid_points]).astype(int) colors = create_range_map(points_cam[is_valid_points, :3]) img = draw_points_xy_in_img( cam.img, uv_int, colors=colors, alpha=0.85, diameter=5, sigma=1.0, with_anti_alias=True diff --git a/tutorials/map_teaser_notebook.py b/tutorials/map_teaser_notebook.py index d37fc942..344a9aae 100644 --- a/tutorials/map_teaser_notebook.py +++ b/tutorials/map_teaser_notebook.py @@ -110,7 +110,7 @@ def visualize_raster_layers(data_root: Path, log_id: str, save_figures: bool) -> height_array = avm.raster_ground_height_layer.array ax = plt.subplot() plt.title("Ground surface height (@ 30 centimeter resolution).") - img = plt.imshow(np.flipud(height_array)) # type: ignore + img = plt.imshow(np.flipud(height_array)) divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) @@ -122,17 +122,17 @@ def visualize_raster_layers(data_root: Path, log_id: str, save_figures: bool) -> fig = plt.figure(figsize=(10, 10)) plt.subplot(1, 3, 1) - plt.imshow(np.flipud(height_array)) # type: ignore + plt.imshow(np.flipud(height_array)) plt.title("Ground Surface Height") plt.subplot(1, 3, 2) da_array = avm.raster_drivable_area_layer.array - plt.imshow(np.flipud(da_array)) # type: ignore + plt.imshow(np.flipud(da_array)) plt.title("Drivable Area (rasterized \nfrom vector polygons)") plt.subplot(1, 3, 3) roi_array = avm.raster_roi_layer.array - plt.imshow(np.flipud(roi_array)) # type: ignore + plt.imshow(np.flipud(roi_array)) plt.title("Region of Interest (ROI)") fig.tight_layout() @@ -294,12 +294,12 @@ def visualize_ego_pose_and_lane_markings(data_root: Path, log_id: str, save_figu traj_ns = loader.get_subsampled_ego_trajectory(log_id, sample_rate_hz=1e9) # now, sample @ 1 Hz traj_1hz = loader.get_subsampled_ego_trajectory(log_id, sample_rate_hz=1.0) - med: NDArrayFloat = np.median(traj_ns, axis=0) # type: ignore + med: NDArrayFloat = np.median(traj_ns, axis=0) med_x, med_y = med # Derive plot area from trajectory (with radius defined in infinity norm). # A larger distance traveled during trajectory means we should have a larger viewing window size. - view_radius_m: float = float(np.linalg.norm(traj_ns[-1] - traj_ns[0])) + 20 # type: ignore + view_radius_m: float = float(np.linalg.norm(traj_ns[-1] - traj_ns[0])) + 20 xlims = [med_x - view_radius_m, med_x + view_radius_m] ylims = [med_y - view_radius_m, med_y + view_radius_m] From 44b88db5856ad01338aba8f30207428a8155d380 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Mon, 6 Jun 2022 10:46:51 -0400 Subject: [PATCH 03/10] Fix typing. --- src/av2/evaluation/detection/utils.py | 4 ++-- src/av2/map/map_api.py | 2 +- src/av2/rendering/ops/draw.py | 4 ++-- src/av2/rendering/rasterize.py | 3 ++- src/av2/structures/cuboid.py | 6 +++--- src/av2/structures/ndgrid.py | 6 +++--- src/av2/utils/io.py | 2 +- tests/evaluation/detection/test_eval.py | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/av2/evaluation/detection/utils.py b/src/av2/evaluation/detection/utils.py index 502fa63a..26da37fb 100644 --- a/src/av2/evaluation/detection/utils.py +++ b/src/av2/evaluation/detection/utils.py @@ -142,7 +142,7 @@ def accumulate( is_evaluated_gts &= compute_objects_in_roi_mask(gts, city_SE3_ego, avm) is_evaluated_dts &= compute_evaluated_dts_mask(dts[..., :3], cfg) - is_evaluated_gts &= compute_evaluated_gts_mask(gts[..., :3], gts[..., -1], cfg) + is_evaluated_gts &= compute_evaluated_gts_mask(gts[..., :3], gts[..., -1].astype(int), cfg) # Initialize results array. dts_augmented: NDArrayFloat = np.zeros((N, T + E + 1)) @@ -193,7 +193,7 @@ def assign(dts: NDArrayFloat, gts: NDArrayFloat, cfg: DetectionCfg) -> Tuple[NDA affinity_matrix = compute_affinity_matrix(dts[..., :3], gts[..., :3], cfg.affinity_type) # Get the GT label for each max-affinity GT label, detection pair. - idx_gts = affinity_matrix.argmax(axis=1)[None] + idx_gts: NDArrayInt = affinity_matrix.argmax(axis=1)[None] # The affinity matrix is an N by M matrix of the detections and ground truth labels respectively. # We want to take the corresponding affinity for each of the initial assignments using `gt_matches`. diff --git a/src/av2/map/map_api.py b/src/av2/map/map_api.py index 9226e8c9..d7c21eab 100644 --- a/src/av2/map/map_api.py +++ b/src/av2/map/map_api.py @@ -134,7 +134,7 @@ def from_file(cls, log_map_dirpath: Path) -> GroundHeightLayer: array_Sim2_city = Sim2.from_json(Sim2_json_fpaths[0]) - return cls(array=ground_height_array.astype(np.float32), array_Sim2_city=array_Sim2_city) + return cls(array=ground_height_array.astype(float), array_Sim2_city=array_Sim2_city) def get_ground_points_boolean(self, points_xyz: NDArrayFloat) -> NDArrayBool: """Check whether each 3d point is likely to be from the ground surface. diff --git a/src/av2/rendering/ops/draw.py b/src/av2/rendering/ops/draw.py index 11c845d6..c4ef9e08 100644 --- a/src/av2/rendering/ops/draw.py +++ b/src/av2/rendering/ops/draw.py @@ -11,7 +11,7 @@ from av2.utils.constants import NAN from av2.utils.typing import NDArrayByte, NDArrayFloat, NDArrayInt, NDArrayNumber -UINT8_MAX: Final[np.uint8] = np.iinfo(np.uint8).max +UINT8_MAX: Final[np.uint8] = np.uint8(np.iinfo(np.uint8).max) UINT8_BITS: Final[np.uint8] = np.log2(UINT8_MAX + 1).astype(np.uint8) @@ -138,7 +138,7 @@ def draw_points_kernel( @nb.njit(nogil=True) -def clip_line_frustum(p1: NDArrayNumber, p2: NDArrayNumber, planes: NDArrayFloat) -> NDArrayFloat: +def clip_line_frustum(p1: NDArrayFloat, p2: NDArrayFloat, planes: NDArrayFloat) -> NDArrayFloat: """Iterate over the frustum planes and intersect them with the segment. We exploit the fact that in a camera frustum, all plane normals point inside the frustum volume. diff --git a/src/av2/rendering/rasterize.py b/src/av2/rendering/rasterize.py index 746ba82b..1f21a40f 100644 --- a/src/av2/rendering/rasterize.py +++ b/src/av2/rendering/rasterize.py @@ -54,8 +54,9 @@ def xyz_to_bev( # If only xyz are provided, then assume intensity is 1.0. # Otherwise, use the provided intensity. + intensity: NDArrayByte if xyz.shape[-1] == 3: - intensity: NDArrayByte = np.ones_like(xyz.shape[0], np.uint8) + intensity = np.ones_like(xyz.shape[0], np.uint8) else: intensity = xyz[..., -1].copy() diff --git a/src/av2/structures/cuboid.py b/src/av2/structures/cuboid.py index c23640d6..eadff004 100644 --- a/src/av2/structures/cuboid.py +++ b/src/av2/structures/cuboid.py @@ -162,9 +162,9 @@ def from_numpy( Returns: Constructed cuboid. """ - translation = params[:3] - length_m, width_m, height_m = params[3:6] - quat_wxyz = params[6:10] + translation: NDArrayFloat = params[:3].astype(float) + length_m, width_m, height_m = params[3:6].astype(float) + quat_wxyz = params[6:10].astype(float) rotation = geometry_utils.quat_to_mat(quat_wxyz) ego_SE3_object = SE3(rotation=rotation, translation=translation) diff --git a/src/av2/structures/ndgrid.py b/src/av2/structures/ndgrid.py index 0bab67d9..69d616a2 100644 --- a/src/av2/structures/ndgrid.py +++ b/src/av2/structures/ndgrid.py @@ -141,12 +141,12 @@ def points_to_bev_img( raise ValueError("Points must be at least 2d!") points_xy = points[..., :2].copy() # Prevent modifying input. - indices = self.transform_to_grid_coordinates(points_xy) - indices_int, _ = crop_points(indices, lower_bound_inclusive=(0.0, 0.0), upper_bound_exclusive=self.dims) + indices_int = self.transform_to_grid_coordinates(points_xy) + indices, _ = crop_points(indices_int, lower_bound_inclusive=(0.0, 0.0), upper_bound_exclusive=self.dims) # Construct uv coordinates. H, W = (self.dims[0], self.dims[1]) - uv = indices_int[..., :2] + uv = indices[..., :2].astype(int) C = len(color) shape = (H, W, C) diff --git a/src/av2/utils/io.py b/src/av2/utils/io.py index b06fdd8a..d1d7daba 100644 --- a/src/av2/utils/io.py +++ b/src/av2/utils/io.py @@ -201,7 +201,7 @@ def write_img(img_path: Path, img: NDArrayByte, channel_order: str = "RGB") -> N raise ValueError("Unsupported channel order (must be BGR or RGB).") if channel_order == "RGB": - img: NDArrayByte = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) + img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) cv2.imwrite(str(img_path), img) diff --git a/tests/evaluation/detection/test_eval.py b/tests/evaluation/detection/test_eval.py index 25154d3d..afa19e6a 100644 --- a/tests/evaluation/detection/test_eval.py +++ b/tests/evaluation/detection/test_eval.py @@ -313,7 +313,7 @@ def test_compute_evaluated_gts_mask() -> None: ) detection_cfg = DetectionCfg(categories=("REGULAR_VEHICLE",), eval_only_roi_instances=False) gts_xyz_ego = gts[..., :3] - num_interior_pts = gts[..., -1] + num_interior_pts = gts[..., -1].astype(int) gts_mask = compute_evaluated_gts_mask(gts_xyz_ego, num_interior_pts, detection_cfg) gts_mask_: NDArrayBool = np.array([True, False, False, False]) From 7f4e259323be5132502a94f187cad7bc054e56d2 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Fri, 12 Aug 2022 18:46:00 -0700 Subject: [PATCH 04/10] Fix typing. --- .../motion_forecasting/eval/metrics.py | 26 +++++++++---------- .../motion_forecasting/eval/submission.py | 4 +-- src/av2/rendering/rasterize.py | 2 +- .../motion_forecasting/eval/test_metrics.py | 20 +++++++------- .../eval/test_submission.py | 2 +- ...ate_forecasting_scenario_visualizations.py | 3 ++- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/av2/datasets/motion_forecasting/eval/metrics.py b/src/av2/datasets/motion_forecasting/eval/metrics.py index 95491dee..e3ebf34d 100644 --- a/src/av2/datasets/motion_forecasting/eval/metrics.py +++ b/src/av2/datasets/motion_forecasting/eval/metrics.py @@ -3,10 +3,10 @@ import numpy as np -from av2.utils.typing import NDArrayBool, NDArrayFloat, NDArrayNumber +from av2.utils.typing import NDArrayBool, NDArrayFloat -def compute_ade(forecasted_trajectories: NDArrayNumber, gt_trajectory: NDArrayNumber) -> NDArrayFloat: +def compute_ade(forecasted_trajectories: NDArrayFloat, gt_trajectory: NDArrayFloat) -> NDArrayFloat: """Compute the average displacement error for a set of K predicted trajectories (for the same actor). Args: @@ -21,7 +21,7 @@ def compute_ade(forecasted_trajectories: NDArrayNumber, gt_trajectory: NDArrayNu return ade -def compute_fde(forecasted_trajectories: NDArrayNumber, gt_trajectory: NDArrayNumber) -> NDArrayFloat: +def compute_fde(forecasted_trajectories: NDArrayFloat, gt_trajectory: NDArrayFloat) -> NDArrayFloat: """Compute the final displacement error for a set of K predicted trajectories (for the same actor). Args: @@ -38,8 +38,8 @@ def compute_fde(forecasted_trajectories: NDArrayNumber, gt_trajectory: NDArrayNu def compute_is_missed_prediction( - forecasted_trajectories: NDArrayNumber, - gt_trajectory: NDArrayNumber, + forecasted_trajectories: NDArrayFloat, + gt_trajectory: NDArrayFloat, miss_threshold_m: float = 2.0, ) -> NDArrayBool: """Compute whether each of K predicted trajectories (for the same actor) missed by more than a distance threshold. @@ -58,9 +58,9 @@ def compute_is_missed_prediction( def compute_brier_ade( - forecasted_trajectories: NDArrayNumber, - gt_trajectory: NDArrayNumber, - forecast_probabilities: NDArrayNumber, + forecasted_trajectories: NDArrayFloat, + gt_trajectory: NDArrayFloat, + forecast_probabilities: NDArrayFloat, normalize: bool = False, ) -> NDArrayFloat: """Compute a probability-weighted (using Brier score) ADE for K predicted trajectories (for the same actor). @@ -82,9 +82,9 @@ def compute_brier_ade( def compute_brier_fde( - forecasted_trajectories: NDArrayNumber, - gt_trajectory: NDArrayNumber, - forecast_probabilities: NDArrayNumber, + forecasted_trajectories: NDArrayFloat, + gt_trajectory: NDArrayFloat, + forecast_probabilities: NDArrayFloat, normalize: bool = False, ) -> NDArrayFloat: """Compute a probability-weighted (using Brier score) FDE for K predicted trajectories (for the same actor). @@ -106,8 +106,8 @@ def compute_brier_fde( def _compute_brier_score( - forecasted_trajectories: NDArrayNumber, - forecast_probabilities: NDArrayNumber, + forecasted_trajectories: NDArrayFloat, + forecast_probabilities: NDArrayFloat, normalize: bool = False, ) -> NDArrayFloat: """Compute Brier score for K predicted trajectories. diff --git a/src/av2/datasets/motion_forecasting/eval/submission.py b/src/av2/datasets/motion_forecasting/eval/submission.py index dbfdc92d..ca1eb8d5 100644 --- a/src/av2/datasets/motion_forecasting/eval/submission.py +++ b/src/av2/datasets/motion_forecasting/eval/submission.py @@ -7,7 +7,7 @@ from collections import defaultdict from dataclasses import dataclass from pathlib import Path -from typing import Dict, Final, List, Tuple +from typing import Any, Dict, Final, List, Tuple import numpy as np import pandas as pd @@ -91,7 +91,7 @@ def from_parquet(cls, submission_file_path: Path) -> ChallengeSubmission: submission_df.sort_values(by="probability", inplace=True, ascending=False) # From serialized data, build scenario-track mapping for predictions - submission_dict: Dict[str, ScenarioPredictions] = defaultdict(lambda: defaultdict(dict)) + submission_dict: Dict[str, Any] = defaultdict(lambda: defaultdict(dict)) for (scenario_id, track_id), track_df in submission_df.groupby(["scenario_id", "track_id"]): predicted_trajectories_x = np.stack(track_df.loc[:, "predicted_trajectory_x"].values.tolist()) predicted_trajectories_y = np.stack(track_df.loc[:, "predicted_trajectory_y"].values.tolist()) diff --git a/src/av2/rendering/rasterize.py b/src/av2/rendering/rasterize.py index 1f21a40f..33d9e7f0 100644 --- a/src/av2/rendering/rasterize.py +++ b/src/av2/rendering/rasterize.py @@ -58,7 +58,7 @@ def xyz_to_bev( if xyz.shape[-1] == 3: intensity = np.ones_like(xyz.shape[0], np.uint8) else: - intensity = xyz[..., -1].copy() + intensity = xyz[..., -1].copy().astype(np.uint8) # Grab the Cartesian coordinates (xyz). cart = xyz[..., :-1].copy() diff --git a/tests/datasets/motion_forecasting/eval/test_metrics.py b/tests/datasets/motion_forecasting/eval/test_metrics.py index c26efd08..fb9782e3 100644 --- a/tests/datasets/motion_forecasting/eval/test_metrics.py +++ b/tests/datasets/motion_forecasting/eval/test_metrics.py @@ -10,7 +10,7 @@ import pytest import av2.datasets.motion_forecasting.eval.metrics as metrics -from av2.utils.typing import NDArrayFloat, NDArrayNumber +from av2.utils.typing import NDArrayFloat # Build stationary GT trajectory at (0, 0) test_N: Final[int] = 10 @@ -55,7 +55,7 @@ ], ids=["stationary_k1", "stationary_k6", "straight_k1", "straight_k6", "diagonal_k1"], ) -def test_compute_ade(forecasted_trajectories: NDArrayNumber, expected_ade: NDArrayFloat) -> None: +def test_compute_ade(forecasted_trajectories: NDArrayFloat, expected_ade: NDArrayFloat) -> None: """Test that compute_ade returns the correct output with valid inputs. Args: @@ -77,7 +77,7 @@ def test_compute_ade(forecasted_trajectories: NDArrayNumber, expected_ade: NDArr ], ids=["stationary_k1", "stationary_k6", "straight_k1", "straight_k6", "diagonal_k1"], ) -def test_compute_fde(forecasted_trajectories: NDArrayNumber, expected_fde: NDArrayFloat) -> None: +def test_compute_fde(forecasted_trajectories: NDArrayFloat, expected_fde: NDArrayFloat) -> None: """Test that compute_fde returns the correct output with valid inputs. Args: @@ -100,7 +100,7 @@ def test_compute_fde(forecasted_trajectories: NDArrayNumber, expected_fde: NDArr ids=["stationary_k1", "stationary_k6", "straight_below_threshold", "straight_above_threshold", "diagonal"], ) def test_compute_is_missed_prediction( - forecasted_trajectories: NDArrayNumber, miss_threshold_m: float, expected_is_missed_label: bool + forecasted_trajectories: NDArrayFloat, miss_threshold_m: float, expected_is_missed_label: bool ) -> None: """Test that compute_is_missed_prediction returns the correct output with valid inputs. @@ -150,8 +150,8 @@ def test_compute_is_missed_prediction( ], ) def test_compute_brier_ade( - forecasted_trajectories: NDArrayNumber, - forecast_probabilities: NDArrayNumber, + forecasted_trajectories: NDArrayFloat, + forecast_probabilities: NDArrayFloat, normalize: bool, expected_brier_ade: NDArrayFloat, ) -> None: @@ -183,7 +183,7 @@ def test_compute_brier_ade( ], ) def test_compute_brier_ade_data_validation( - forecast_probabilities: NDArrayNumber, normalize: bool, expectation: AbstractContextManager + forecast_probabilities: NDArrayFloat, normalize: bool, expectation: AbstractContextManager[None] ) -> None: """Test that test_compute_brier_ade raises the correct errors when inputs are invalid. @@ -214,8 +214,8 @@ def test_compute_brier_ade_data_validation( ], ) def test_compute_brier_fde( - forecasted_trajectories: NDArrayNumber, - forecast_probabilities: NDArrayNumber, + forecasted_trajectories: NDArrayFloat, + forecast_probabilities: NDArrayFloat, normalize: bool, expected_brier_fde: NDArrayFloat, ) -> None: @@ -247,7 +247,7 @@ def test_compute_brier_fde( ], ) def test_compute_brier_fde_data_validation( - forecast_probabilities: NDArrayNumber, normalize: bool, expectation: AbstractContextManager + forecast_probabilities: NDArrayFloat, normalize: bool, expectation: AbstractContextManager[None] ) -> None: """Test that test_compute_brier_fde raises the correct errors when inputs are invalid. diff --git a/tests/datasets/motion_forecasting/eval/test_submission.py b/tests/datasets/motion_forecasting/eval/test_submission.py index 886ec6a4..327eb07b 100644 --- a/tests/datasets/motion_forecasting/eval/test_submission.py +++ b/tests/datasets/motion_forecasting/eval/test_submission.py @@ -39,7 +39,7 @@ ids=["valid", "wrong_shape_trajectory", "mismatched_trajectory_probability_shape"], ) def test_challenge_submission_data_validation( - test_submission_dict: Dict[str, ScenarioPredictions], expectation: AbstractContextManager + test_submission_dict: Dict[str, ScenarioPredictions], expectation: AbstractContextManager[None] ) -> None: """Test that validation of submitted trajectories works as expected during challenge submission initialization. diff --git a/tutorials/generate_forecasting_scenario_visualizations.py b/tutorials/generate_forecasting_scenario_visualizations.py index bf285c50..06cbbba5 100644 --- a/tutorials/generate_forecasting_scenario_visualizations.py +++ b/tutorials/generate_forecasting_scenario_visualizations.py @@ -3,6 +3,7 @@ from enum import Enum, unique from pathlib import Path +from random import choices from typing import Final import click @@ -47,7 +48,7 @@ def generate_scenario_visualizations( scenario_file_list = ( all_scenario_files[:num_scenarios] if selection_criteria == SelectionCriteria.FIRST - else np.random.choice(all_scenario_files, size=num_scenarios).tolist() + else choices(all_scenario_files, k=num_scenarios) ) # Ignoring type here because type of "choice" is partially unknown. # Build inner function to generate visualization for a single scenario. From f3b922cf0f3e4fb011c536ce2e83c59c69bce665 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Wed, 24 Aug 2022 11:57:55 -0700 Subject: [PATCH 05/10] Update setup.cfg --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 25ab7379..2f85e4d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,7 +24,7 @@ install_requires = matplotlib nox numba - numpy + numpy>=1.21.5 opencv-python pandas pyarrow From 76e8f6bd02bff7c66d5622b8703f87df4150ff56 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Thu, 25 Aug 2022 22:25:05 -0700 Subject: [PATCH 06/10] Update test_metrics.py --- tests/datasets/motion_forecasting/eval/test_metrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/datasets/motion_forecasting/eval/test_metrics.py b/tests/datasets/motion_forecasting/eval/test_metrics.py index fb9782e3..7237ddc9 100644 --- a/tests/datasets/motion_forecasting/eval/test_metrics.py +++ b/tests/datasets/motion_forecasting/eval/test_metrics.py @@ -183,7 +183,7 @@ def test_compute_brier_ade( ], ) def test_compute_brier_ade_data_validation( - forecast_probabilities: NDArrayFloat, normalize: bool, expectation: AbstractContextManager[None] + forecast_probabilities: NDArrayFloat, normalize: bool, expectation: AbstractContextManager # type: ignore ) -> None: """Test that test_compute_brier_ade raises the correct errors when inputs are invalid. @@ -247,7 +247,7 @@ def test_compute_brier_fde( ], ) def test_compute_brier_fde_data_validation( - forecast_probabilities: NDArrayFloat, normalize: bool, expectation: AbstractContextManager[None] + forecast_probabilities: NDArrayFloat, normalize: bool, expectation: AbstractContextManager # type: ignore ) -> None: """Test that test_compute_brier_fde raises the correct errors when inputs are invalid. From 05febada6f3d6122e55e2a0a91039915900b50ba Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Fri, 26 Aug 2022 05:27:50 +0000 Subject: [PATCH 07/10] Relax versioning. --- conda/environment.yml | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conda/environment.yml b/conda/environment.yml index 23a11300..d152ff7c 100644 --- a/conda/environment.yml +++ b/conda/environment.yml @@ -8,7 +8,7 @@ dependencies: - matplotlib-base - nox - numba - - numpy>=1.21.5 + - numpy - opencv - pandas - pip diff --git a/setup.cfg b/setup.cfg index 2f85e4d8..25ab7379 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,7 +24,7 @@ install_requires = matplotlib nox numba - numpy>=1.21.5 + numpy opencv-python pandas pyarrow From a3f6a8aa2d98f6e409ba087e76b15ad22f5371fe Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Fri, 26 Aug 2022 05:49:11 +0000 Subject: [PATCH 08/10] Ignore types. --- tests/datasets/motion_forecasting/eval/test_submission.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets/motion_forecasting/eval/test_submission.py b/tests/datasets/motion_forecasting/eval/test_submission.py index 327eb07b..89f49619 100644 --- a/tests/datasets/motion_forecasting/eval/test_submission.py +++ b/tests/datasets/motion_forecasting/eval/test_submission.py @@ -39,7 +39,7 @@ ids=["valid", "wrong_shape_trajectory", "mismatched_trajectory_probability_shape"], ) def test_challenge_submission_data_validation( - test_submission_dict: Dict[str, ScenarioPredictions], expectation: AbstractContextManager[None] + test_submission_dict: Dict[str, ScenarioPredictions], expectation: AbstractContextManager # type: ignore ) -> None: """Test that validation of submitted trajectories works as expected during challenge submission initialization. From 22a3bf7bcd7e71e2d8f4e669f85c25011e5df1b7 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Fri, 26 Aug 2022 06:05:04 +0000 Subject: [PATCH 09/10] Shorten docstring. --- tutorials/map_teaser_notebook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/map_teaser_notebook.py b/tutorials/map_teaser_notebook.py index 344a9aae..f1756bae 100644 --- a/tutorials/map_teaser_notebook.py +++ b/tutorials/map_teaser_notebook.py @@ -40,7 +40,7 @@ def single_log_teaser(data_root: Path, log_id: str, save_figures: bool) -> None: - """For a single log, render all local lane segments in green, and pedestrian crossings in purple, in a bird's eye view. + """Render all local lane segments in green, and pedestrian crossings in purple, in a bird's eye view. Args: data_root: path to where the AV2 logs live. From 7044b763cc192d804a080408ae9efdb573f4bc15 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Fri, 26 Aug 2022 06:25:02 +0000 Subject: [PATCH 10/10] Add types. --- tests/rendering/ops/test_draw.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/rendering/ops/test_draw.py b/tests/rendering/ops/test_draw.py index 0feb5a05..3916eef8 100644 --- a/tests/rendering/ops/test_draw.py +++ b/tests/rendering/ops/test_draw.py @@ -113,7 +113,7 @@ def test_draw_points_kernel_9x9_aliased() -> None: def test_benchmark_draw_points_kernel_aliased(benchmark: Callable[..., Any]) -> None: """Benchmark the draw points kernel _without_ anti-aliasing.""" img: NDArrayByte = np.zeros((2048, 2048, 3), dtype=np.uint8) - points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)) + points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)).astype(np.int64) colors: NDArrayByte = np.random.randint(low=0, high=255, size=(60000, 3)).astype(np.uint8) diameter = 10 benchmark(draw_points_kernel, img, points_xy, colors, diameter) @@ -122,7 +122,7 @@ def test_benchmark_draw_points_kernel_aliased(benchmark: Callable[..., Any]) -> def test_benchmark_draw_points_kernel_anti_aliased(benchmark: Callable[..., Any]) -> None: """Benchmark the draw points kernel _with_ anti-aliasing.""" img: NDArrayByte = np.zeros((2048, 2048, 3), dtype=np.uint8) - points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)) + points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)).astype(np.int64) colors: NDArrayByte = np.random.randint(low=0, high=255, size=(60000, 3)).astype(np.uint8) diameter = 10 benchmark(draw_points_kernel, img, points_xy, colors, diameter, with_anti_alias=True) @@ -131,7 +131,7 @@ def test_benchmark_draw_points_kernel_anti_aliased(benchmark: Callable[..., Any] def test_benchmark_draw_points_cv2_aliased(benchmark: Callable[..., Any]) -> None: """Benchmark the draw points method from OpenCV _without_ anti-aliasing.""" img: NDArrayByte = np.zeros((2048, 2048, 3), dtype=np.uint8) - points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)) + points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)).astype(np.int64) colors: NDArrayByte = np.random.randint(low=0, high=255, size=(60000, 3)).astype(np.uint8) radius = 10 benchmark(_draw_points_cv2, img, points_xy, colors, radius, with_anti_alias=False) @@ -140,7 +140,7 @@ def test_benchmark_draw_points_cv2_aliased(benchmark: Callable[..., Any]) -> Non def test_benchmark_draw_points_cv2_anti_aliased(benchmark: Callable[..., Any]) -> None: """Benchmark the draw points method from OpenCV _with_ anti-aliasing.""" img: NDArrayByte = np.zeros((2048, 2048, 3), dtype=np.uint8) - points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)) + points_xy: NDArrayInt = np.random.randint(low=0, high=2048, size=(60000, 2)).astype(np.int64) colors: NDArrayByte = np.random.randint(low=0, high=255, size=(60000, 3)).astype(np.uint8) radius = 10 benchmark(_draw_points_cv2, img, points_xy, colors, radius, with_anti_alias=True)