Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection eval max boxes fix #227

Merged
merged 12 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions argoverse/evaluation/detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,7 @@ def rank(dts: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
ranked_scores = scores[ranks]

# Ensure the number of boxes considered per class is at most `MAX_NUM_BOXES`.
if ranked_dts.shape[0] > MAX_NUM_BOXES:
ranked_dts = ranked_dts[:MAX_NUM_BOXES]
ranked_scores = ranked_scores[:MAX_NUM_BOXES]
return ranked_dts, ranked_scores
return ranked_dts[:MAX_NUM_BOXES], ranked_scores[:MAX_NUM_BOXES]


def interp(prec: np.ndarray, method: InterpType = InterpType.ALL) -> np.ndarray:
Expand Down
2 changes: 1 addition & 1 deletion argoverse/map_representation/map_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ArgoverseMap:
"""

def __init__(self, root: _PathLike = ROOT) -> None:
""" Initialize the Argoverse Map. """
"""Initialize the Argoverse Map."""
self.root = root

self.city_name_to_city_id_dict = {"PIT": PITTSBURGH_ID, "MIA": MIAMI_ID}
Expand Down
2 changes: 1 addition & 1 deletion argoverse/utils/make_att_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def compute_v_a(traj: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:


def make_att_files(root_dir: str) -> None:
""" Write a .pkl file with difficulty attributes per track """
"""Write a .pkl file with difficulty attributes per track"""
path_output_vis = "vis_output"
filename_output = "att_file.npy"

Expand Down
2 changes: 1 addition & 1 deletion argoverse/utils/sim2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class Sim2:
""" Implements the Similarity(2) class."""
"""Implements the Similarity(2) class."""

def __init__(self, R: np.ndarray, t: np.ndarray, s: Union[int, float]) -> None:
"""Initialize from rotation R, translation t, and scale s.
Expand Down
4 changes: 2 additions & 2 deletions argoverse/utils/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def quat_argo2scipy(q: np.ndarray) -> np.ndarray:


def quat_argo2scipy_vectorized(q: np.ndarray) -> np.ndarray:
""""Re-order Argoverse's scalar-first [w,x,y,z] quaternion order to Scipy's scalar-last [x,y,z,w]"""
"""Re-order Argoverse's scalar-first [w,x,y,z] quaternion order to Scipy's scalar-last [x,y,z,w]"""
return q[..., [1, 2, 3, 0]]


def quat_scipy2argo_vectorized(q: np.ndarray) -> np.ndarray:
""""Re-order Scipy's scalar-last [x,y,z,w] quaternion order to Argoverse's scalar-first [w,x,y,z]."""
""" "Re-order Scipy's scalar-last [x,y,z,w] quaternion order to Argoverse's scalar-first [w,x,y,z]."""
return q[..., [3, 0, 1, 2]]
2 changes: 1 addition & 1 deletion argoverse/visualization/visualization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def draw_box(


def show_image_with_boxes(img: np.ndarray, objects: Iterable[ObjectLabelRecord], calib: Calibration) -> np.ndarray:
""" Show image with 2D bounding boxes """
"""Show image with 2D bounding boxes"""
img1 = np.copy(img)
K = calib.K
d = calib.d
Expand Down
2 changes: 1 addition & 1 deletion demo_usage/visualize_30hz_benchmark_data_on_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def render_front_camera_on_axis(self, ax: plt.Axes, timestamp: int, log_id: str)


def visualize_30hz_benchmark_data_on_map(args: Any) -> None:
""""""
"""Function to render lidar, imagery, and map elements overlaid on both a bird's-eye-view and egoview."""
benjaminrwilson marked this conversation as resolved.
Show resolved Hide resolved
domv = DatasetOnMapVisualizer(
args.dataset_dir,
args.experiment_prefix,
Expand Down
12 changes: 6 additions & 6 deletions integration_tests/test_map_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def add_lane_segment_to_ax(
ax: plt.axes.Axis,
ax: plt.Axes,
lane_centerline: np.ndarray,
lane_polygon: np.ndarray,
patch_color: str,
Expand All @@ -25,14 +25,14 @@ def add_lane_segment_to_ax(
ymin: float,
ymax: float,
) -> None:
""""""
"""Utility function to add a lane segment to an Matplotlib axis."""
plot_lane_segment_patch(lane_polygon, ax, color=patch_color, alpha=0.3)


def find_lane_segment_bounds_in_table(
avm: ArgoverseMap, city_name: str, lane_segment_id: int
) -> Tuple[float, float, float, float]:
""""""
""" """
benjaminrwilson marked this conversation as resolved.
Show resolved Hide resolved
match_found = False
# find the lane segment inside the table
for table_idx, table_lane_id in avm.city_halluc_tableidx_to_laneid_map[city_name].items():
Expand All @@ -47,7 +47,7 @@ def find_lane_segment_bounds_in_table(


def verify_halluc_lane_extent_index(enable_lane_boundaries: bool = False) -> None:
""""""
""" """
avm = ArgoverseMap()

city_names = ["MIA", "PIT"]
Expand Down Expand Up @@ -209,7 +209,7 @@ def verify_halluc_lane_extent_index(enable_lane_boundaries: bool = False) -> Non


def verify_point_in_polygon_for_lanes() -> None:
""""""
""" """
avm = ArgoverseMap()

# ref_query_x = 422.
Expand Down Expand Up @@ -252,7 +252,7 @@ def plot_nearby_halluc_lanes(
patch_color: str = "r",
radius: float = 20.0,
) -> None:
""""""
""" """
nearby_lane_ids = avm.get_lane_ids_in_xy_bbox(query_x, query_y, city_name, radius)
for nearby_lane_id in nearby_lane_ids:
halluc_lane_polygon = avm.get_lane_segment_polygon(nearby_lane_id, city_name)
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/test_plane_visualization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@

@skip_if_mayavi_missing # type: ignore
def test_plot_frustum_planes_and_normals() -> None:
""""""
""" """

assert planes is not None
plot_frustum_planes_and_normals(planes, cuboid_verts=None, near_clip_dist=0.5)


@skip_if_mayavi_missing # type: ignore
def test_populate_frustum_voxels() -> None:
""""""
""" """
fig, axis_pair = plt.subplots(1, 1, figsize=(20, 15))

assert planes is not None
Expand All @@ -56,6 +56,6 @@ def test_populate_frustum_voxels() -> None:

@skip_if_mayavi_missing # type: ignore
def test_get_perpendicular() -> None:
""""""
""" """
n = [0, 1, 1]
result = get_perpendicular(n)
2 changes: 1 addition & 1 deletion tests/test_cuboid_interior.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_scenario_1() -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:


def test_extract_pc_in_box3d_hull() -> None:
""""""
""" """
pc_raw, bbox_3d, gt_segment, gt_is_valid = get_scenario_1()
segment, is_valid = extract_pc_in_box3d_hull(pc_raw, bbox_3d)

Expand Down
103 changes: 92 additions & 11 deletions tests/test_eval_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
interp,
iou_aligned_3d,
plot,
rank,
remove_duplicate_instances,
wrap_angle,
)
Expand Down Expand Up @@ -215,8 +216,26 @@ def test_accumulate() -> None:
cls_to_accum["VEHICLE"]
== np.array(
[
[1.0, 1.0, 1.0, 1.0, expected_ATE, expected_ASE, expected_AOE, expected_AP],
[1.0, 1.0, 1.0, 1.0, expected_ATE, expected_ASE, expected_AOE, expected_AP],
[
benjaminrwilson marked this conversation as resolved.
Show resolved Hide resolved
1.0,
1.0,
1.0,
1.0,
expected_ATE,
expected_ASE,
expected_AOE,
expected_AP,
],
[
1.0,
1.0,
1.0,
1.0,
expected_ATE,
expected_ASE,
expected_AOE,
expected_AP,
],
]
)
).all()
Expand Down Expand Up @@ -389,7 +408,7 @@ def test_orientation_error(metrics_identity: DataFrame, metrics: DataFrame) -> N
assert metrics.AOE.loc["Average Metrics"] == expected_result_det


def test_remove_duplicate_instances():
def test_remove_duplicate_instances() -> None:
"""Ensure a duplicate ground truth cuboid can be filtered out correctly."""
instances = [
SimpleNamespace(**{"translation": np.array([1, 1, 0])}),
Expand All @@ -407,7 +426,7 @@ def test_remove_duplicate_instances():
assert np.allclose(unique_instances[2].translation, np.array([2, 2, 0]))


def test_remove_duplicate_instances_ground_truth():
def test_remove_duplicate_instances_ground_truth() -> None:
"""Ensure that if an extra duplicate cuboid is present in ground truth, it would be ignored."""
dt_fpath = TEST_DATA_LOC / "remove_duplicates_detections"
gt_fpath = TEST_DATA_LOC / "remove_duplicates_ground_truth"
Expand All @@ -420,14 +439,23 @@ def test_remove_duplicate_instances_ground_truth():
assert metrics.AP.loc["Pedestrian"] == 1.0


def test_filter_objs_to_roi():
""" Use the map to filter out an object that lies outside the ROI in a parking lot """
def test_filter_objs_to_roi() -> None:
"""Use the map to filter out an object that lies outside the ROI in a parking lot."""
avm = ArgoverseMap()

# should be outside of ROI
outside_obj = {
"center": {"x": -14.102872067388489, "y": 19.466695178746022, "z": 0.11740010190455852},
"rotation": {"x": 0.0, "y": 0.0, "z": -0.038991328555453404, "w": 0.9992395490058831},
"center": {
benjaminrwilson marked this conversation as resolved.
Show resolved Hide resolved
"x": -14.102872067388489,
"y": 19.466695178746022,
"z": 0.11740010190455852,
},
"rotation": {
"x": 0.0,
"y": 0.0,
"z": -0.038991328555453404,
"w": 0.9992395490058831,
},
"length": 4.56126567460171,
"width": 1.9370055686754908,
"height": 1.5820081349372281,
Expand All @@ -438,8 +466,17 @@ def test_filter_objs_to_roi():

# should be inside the ROI
inside_obj = {
"center": {"x": -20.727430239506702, "y": 3.4488006757501353, "z": 0.4036619561689685},
"rotation": {"x": 0.0, "y": 0.0, "z": 0.0013102003738908123, "w": 0.9999991416871218},
"center": {
"x": -20.727430239506702,
"y": 3.4488006757501353,
"z": 0.4036619561689685,
},
"rotation": {
"x": 0.0,
"y": 0.0,
"z": 0.0013102003738908123,
"w": 0.9999991416871218,
},
"length": 4.507580779458834,
"width": 1.9243189627993598,
"height": 1.629934978730058,
Expand All @@ -464,7 +501,7 @@ def test_filter_objs_to_roi():


def test_AP_on_filtered_instances() -> None:
""" """
"""Test AP calculation on instances filtered on region-of-interest."""
dt_fpath = TEST_DATA_LOC / "remove_nonroi_detections"
gt_fpath = TEST_DATA_LOC / "remove_nonroi_ground_truth"
fig_fpath = TEST_DATA_LOC / "test_figures"
Expand All @@ -474,3 +511,47 @@ def test_AP_on_filtered_instances() -> None:
metrics = evaluator.evaluate()

assert metrics.AP.loc["Vehicle"] == 1.0


def test_rank() -> None:
benjaminrwilson marked this conversation as resolved.
Show resolved Hide resolved
"""Test ranking of detections and scores during detection evaluation."""
dts: np.ndarray = np.array(
[
ObjectLabelRecord(
quaternion=np.array([1, 0, 0, 0]),
translation=np.array([0, 0, 0]),
length=5.0,
width=5.0,
height=5.0,
occlusion=0,
score=0.7,
track_id="0",
),
ObjectLabelRecord(
quaternion=np.array([1, 0, 0, 0]),
translation=np.array([10, 10, 10]),
length=5.0,
width=5.0,
height=5.0,
occlusion=0,
score=0.9,
track_id="1",
),
ObjectLabelRecord(
quaternion=np.array([1, 0, 0, 0]),
translation=np.array([20, 20, 20]),
length=5.0,
width=5.0,
height=5.0,
occlusion=0,
score=0.8,
track_id="2",
),
]
)

ranked_dts, ranked_scores = rank(dts)
track_ids = np.array([dt.track_id for dt in ranked_dts.tolist()])
expected_track_ids = np.array(["1", "2", "0"])
expected_scores = np.array([0.9, 0.8, 0.7])
assert (track_ids == expected_track_ids).all() and (ranked_scores == expected_scores).all()
benjaminrwilson marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions tests/test_ffmpeg_utils_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


def test_ffmpeg_seq_frame_vid_smokescreen() -> None:
""""""
""" """
benjaminrwilson marked this conversation as resolved.
Show resolved Hide resolved
image_prefix = "imgs_%d.jpg"
output_prefix = "out"
write_video(image_prefix, output_prefix)


def test_ffmpeg_nonseq_frame_vid_smokescreen() -> None:
""""""
""" """
img_wildcard = "imgs_%*.jpg"
output_fpath = "out.mp4"
fps = 10
Expand Down
2 changes: 1 addition & 1 deletion tests/test_manhattan_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def polygons_and_gt_bboxes() -> Tuple[List[np.ndarray], List[np.ndarray]]:
def test_find_all_polygon_bboxes_overlapping_query_bbox(
polygons_and_gt_bboxes: Tuple[List[np.ndarray], List[np.ndarray]]
) -> None:
"""Test for correctness of """
"""Test for correctness of finding polygons which overlap with the query bbox."""
poly_bboxes = np.array([compute_point_cloud_bbox(poly) for poly in polygons_and_gt_bboxes[0]])

query_bbox = np.array([-1.5, 0.5, 1.5, 1.5])
Expand Down
10 changes: 5 additions & 5 deletions tests/test_mpl_plotting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def test_draw_polygon_mpl_smokescreen_nolinewidth() -> None:
""""""
""" """
ax = plt.axes([1, 1, 1, 1])
# polygon: Numpy array of shape (N,2) or (N,3)
polygon = np.array([[0, 0], [1, 1], [1, 0], [0, 0]])
Expand All @@ -22,7 +22,7 @@ def test_draw_polygon_mpl_smokescreen_nolinewidth() -> None:


def test_draw_polygon_mpl_smokescreen_with_linewidth() -> None:
""""""
""" """
ax = plt.axes([1, 1, 1, 1])
# polygon: Numpy array of shape (N,2) or (N,3)
polygon = np.array([[0, 0], [1, 1], [1, 0], [0, 0]])
Expand All @@ -33,7 +33,7 @@ def test_draw_polygon_mpl_smokescreen_with_linewidth() -> None:


def test_plot_lane_segment_patch_smokescreen() -> None:
""""""
""" """
ax = plt.axes([1, 1, 1, 1])
polygon_pts = np.array([[-1, 0], [1, 0], [0, 1]])
color = "r"
Expand All @@ -43,7 +43,7 @@ def test_plot_lane_segment_patch_smokescreen() -> None:


def test_plot_nearby_centerlines_smokescreen() -> None:
""""""
""" """
ax = plt.axes([1, 1, 1, 1])
# lane_centerlines: Python dictionary where key is lane ID, value is
# object describing the lane
Expand All @@ -63,7 +63,7 @@ def test_plot_nearby_centerlines_smokescreen() -> None:


def test_animate_polyline_smokescreen() -> None:
""""""
""" """
polyline = np.array([[0, 0], [1, 1], [2, 0], [0, 2]])
axes_margin = 2
animate_polyline(polyline, axes_margin, show_plot=False)
Expand Down
Loading