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

Initial streaming support. #89

Merged
merged 128 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
9d33045
Add evaluation.
Mar 24, 2022
f7d708d
Small fixes.
Mar 24, 2022
74d0eb0
Add unit tests + eval mask fixes.
Mar 25, 2022
5589bf5
Update detection unit tests.
Mar 25, 2022
244100d
Fix typing + update pyproject.
Mar 25, 2022
5314ee4
Run autoflake.
Mar 25, 2022
4c0e6bb
Add ROI pruning.
Mar 26, 2022
8e59867
Remove arg.
Mar 26, 2022
343c219
Fix typo.
Mar 26, 2022
6a34f5b
Speed up argoverse maps.
Mar 28, 2022
23b2fec
Speed up evaluation.
Mar 28, 2022
ae42718
Small fixes.
Mar 28, 2022
a02e45c
Fix lint.
Mar 28, 2022
2f208d5
Small lint fixes.
Mar 28, 2022
c7797a5
Fix filtering.
benjaminrwilson Mar 29, 2022
0b15248
Small fixes.
benjaminrwilson Mar 29, 2022
c7a66de
Fix enums.
benjaminrwilson Mar 29, 2022
957e016
Remove unused lines.
benjaminrwilson Mar 29, 2022
b8ab038
Mypy fixes.
benjaminrwilson Mar 29, 2022
ceff8fa
Fix click mypy error.
benjaminrwilson Mar 29, 2022
c314775
Pytype fixes.
benjaminrwilson Mar 30, 2022
2e7af38
Fix pytype.
benjaminrwilson Mar 30, 2022
43f938a
Remove pytype.
benjaminrwilson Mar 30, 2022
90c791f
Small typing fixes.
benjaminrwilson Mar 30, 2022
515c6f2
Add unit tests.
benjaminrwilson Mar 31, 2022
8c5d1bc
Fix typing.
benjaminrwilson Mar 31, 2022
e7f2925
Remove click typing issue.
benjaminrwilson Mar 31, 2022
14f1141
Fix mypy.
benjaminrwilson Mar 31, 2022
7d4139c
Detection eval speed up.
benjaminrwilson Apr 2, 2022
c9de7cb
Rewrite detection eval for major speedup.
benjaminrwilson Apr 2, 2022
59a65f8
Typing fixes.
benjaminrwilson Apr 2, 2022
4327278
Typing fixes.
benjaminrwilson Apr 2, 2022
df479b9
Switch from record arrays to numpy arrays.
benjaminrwilson Apr 2, 2022
4c40a5f
Temp changes.
benjaminrwilson Apr 2, 2022
eccd4f0
Improve readability.
benjaminrwilson Apr 2, 2022
72dc702
Add comments.
benjaminrwilson Apr 2, 2022
fddd899
Modularize evaluate.
benjaminrwilson Apr 2, 2022
faa8317
Additional speedups.
benjaminrwilson Apr 3, 2022
f81ae17
Cleanup code.
benjaminrwilson Apr 3, 2022
d49105a
Additional speedup.
benjaminrwilson Apr 3, 2022
195b46a
Add roi pruning back.
benjaminrwilson Apr 3, 2022
dc2a954
Add multiprocessing.
benjaminrwilson Apr 3, 2022
06e2e96
Add verbosity.
benjaminrwilson Apr 3, 2022
54901b2
Mypy fixes.
benjaminrwilson Apr 3, 2022
856b4d4
Update cuboid fields.
benjaminrwilson Apr 3, 2022
be5a89c
Lint fixes.
benjaminrwilson Apr 3, 2022
5cb43ea
Fix map tutorial issues.
benjaminrwilson Apr 3, 2022
5214d9d
Merge branch 'map_notebook-fixes'
benjaminrwilson Apr 3, 2022
967cc39
Add test log.
benjaminrwilson Apr 3, 2022
ae8aeb5
Revert strings.
benjaminrwilson Apr 3, 2022
d8a0ae9
Remove outputs.
benjaminrwilson Apr 3, 2022
a343292
Merge branch 'map_notebook-fixes'
benjaminrwilson Apr 3, 2022
87239c3
Address missing detection edge cases.
benjaminrwilson Apr 4, 2022
9a2acc6
Address jhony comments.
benjaminrwilson Apr 5, 2022
ba6c337
Update docstring.
benjaminrwilson Apr 5, 2022
aa036aa
Clean docstrings.
benjaminrwilson Apr 5, 2022
a6b345d
Change roi method.
benjaminrwilson Apr 5, 2022
e725147
Clean up roi method.
benjaminrwilson Apr 5, 2022
ce896f0
Update roi returns.
benjaminrwilson Apr 5, 2022
aeea617
Autoflake.:
benjaminrwilson Apr 5, 2022
da897c1
Fix lint.
benjaminrwilson Apr 5, 2022
c459c26
Fix lint.
benjaminrwilson Apr 5, 2022
ca5d644
Update detection limiting logic.
Apr 7, 2022
375aaba
Fix indexing.
Apr 7, 2022
5113202
Fix tuple return.
Apr 7, 2022
97235a0
Merge https://github.com/argoai/av2-api into main
Apr 7, 2022
5a4c76d
Update CI.
Apr 7, 2022
07d3fbf
Add ROI unit tests.
Apr 9, 2022
0cd98f9
Remove val identity.
Apr 9, 2022
0ef221b
Fix import.
Apr 9, 2022
0b00475
Remove unused import.
Apr 9, 2022
82da97f
Update column names.
Apr 9, 2022
548ea93
Update eval.py
benjaminrwilson Apr 11, 2022
d83f8eb
Add README.md.
benjaminrwilson Apr 12, 2022
89163fa
Update README.
benjaminrwilson Apr 12, 2022
a7ea318
Update README.
benjaminrwilson Apr 12, 2022
8cbcb48
Update README.md
benjaminrwilson Apr 12, 2022
5753fc6
Update README.
benjaminrwilson Apr 12, 2022
db85849
Update README.
benjaminrwilson Apr 12, 2022
37d63ac
Update README.
benjaminrwilson Apr 12, 2022
94fb9de
Update README.
benjaminrwilson Apr 12, 2022
bc12db8
Update README.
benjaminrwilson Apr 12, 2022
f803216
Update README.md
benjaminrwilson Apr 12, 2022
2abf31c
Update README.md
benjaminrwilson Apr 12, 2022
f3d3f4d
Update README.md
benjaminrwilson Apr 12, 2022
b7c04f0
Updates.
Apr 15, 2022
c7c4026
Merge.
benjaminrwilson May 7, 2022
55fbff5
Merge branch 'argoai:main' into main
benjaminrwilson May 17, 2022
8eb4935
Merge branch 'argoai:main' into main
benjaminrwilson Jul 20, 2022
e9b141e
Streaming test.
benjaminrwilson Jul 20, 2022
f3bdf43
Add streaming support.
benjaminrwilson Jul 20, 2022
29ace45
Updates.
benjaminrwilson Jul 20, 2022
ab2d361
Updates.
benjaminrwilson Jul 20, 2022
2f37df2
Updates.
benjaminrwilson Jul 20, 2022
6249c87
Update upath.
Aug 8, 2022
9a06e2c
Remove file.
Aug 8, 2022
22eb6f9
Bump package.
Aug 8, 2022
6e295e7
Update upaths.
Aug 8, 2022
e6184b3
Add additional upath.
Aug 8, 2022
e2109bf
Add upaths.
Aug 8, 2022
40194b8
Updates.
Aug 8, 2022
21a3140
Autoflake.
Aug 8, 2022
7eed4a7
Small updates.
Aug 9, 2022
ae9ef75
Add range breakdown.
Aug 15, 2022
2eed914
Reorder indices.
Aug 15, 2022
38afd16
Update multiprocessing.
Aug 16, 2022
3897a79
Switch to threading
Aug 16, 2022
1d155f5
Small fixes.
Aug 17, 2022
cb33dbf
Merge.
Aug 26, 2022
072e596
Remove comments.
Aug 26, 2022
3fef470
Revert eval.
benjaminrwilson Aug 27, 2022
f915243
Update eval.py
benjaminrwilson Aug 28, 2022
2baa02f
Fix lint.
benjaminrwilson Aug 28, 2022
dc68a70
Fix lint.
benjaminrwilson Sep 3, 2022
af69cb1
Merge.
benjaminrwilson Sep 22, 2022
2e6d394
Fix lint.
benjaminrwilson Sep 22, 2022
0f7e248
Try numpy bound.
benjaminrwilson Sep 23, 2022
6765828
ci 3.10 pin to 3.10.6: https://github.com/python/mypy/issues/13627
benjaminrwilson Sep 25, 2022
d9e6245
Remove pin.
benjaminrwilson Sep 25, 2022
0f6f2ec
mypy fix attempt #2.
benjaminrwilson Sep 25, 2022
d1203f6
Update nox.
benjaminrwilson Sep 25, 2022
09ccefa
Updates.
benjaminrwilson Sep 25, 2022
b956b3e
Try 3.10.5
benjaminrwilson Sep 25, 2022
2e8f021
Pin numpy.
benjaminrwilson Sep 25, 2022
6eddb08
Upper bound numpy.
benjaminrwilson Sep 25, 2022
3516586
3.10.6
benjaminrwilson Sep 25, 2022
a131956
Update ci.yml
benjaminrwilson Sep 28, 2022
47aaa48
Update noxfile.py
benjaminrwilson Sep 28, 2022
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
Prev Previous commit
Next Next commit
Temp changes.
  • Loading branch information
benjaminrwilson committed Apr 2, 2022
commit 4c40a5f30aba660574347b929373c33b1a5738d7
49 changes: 33 additions & 16 deletions src/av2/evaluation/detection/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

logger = logging.getLogger(__name__)


@profile
def evaluate(
dts: pd.DataFrame,
gts: pd.DataFrame,
Expand All @@ -84,27 +84,44 @@ def evaluate(
(C+1,K) Table of evaluation metrics where C is the number of classes. Plus a row for their means.
K refers to the number of evaluation metrics.
"""
log_ids: List[str] = gts["log_id"].unique().tolist()
log_id_to_avm: Dict[str, ArgoverseStaticMap] = {}
log_id_to_timestamped_poses: Dict[str, TimestampedCitySE3EgoPoses] = {}
if cfg.eval_only_roi_instances and cfg.dataset_dir is not None:
for log_id in log_ids:
log_dir = cfg.dataset_dir / log_id
avm_dir = log_dir / "map"
avm = ArgoverseStaticMap.from_map_dir(avm_dir, build_raster=True)
log_id_to_avm[log_id] = avm
log_id_to_timestamped_poses[log_id] = read_city_SE3_ego(log_dir)

dts_mapping = {uuid: x for uuid, x in dts.groupby(["log_id", "timestamp_ns"])}
gts_mapping = {uuid: x for uuid, x in gts.groupby(["log_id", "timestamp_ns"])}
# dts_npy = dts.to_numpy()
# gts_npy = gts.to_numpy()
# log_ids: List[str] = gts["log_id"].unique().tolist()
# log_id_to_avm: Dict[str, ArgoverseStaticMap] = {}
# log_id_to_timestamped_poses: Dict[str, TimestampedCitySE3EgoPoses] = {}
# if cfg.eval_only_roi_instances and cfg.dataset_dir is not None:
# for log_id in log_ids:
# log_dir = cfg.dataset_dir / log_id
# avm_dir = log_dir / "map"
# avm = ArgoverseStaticMap.from_map_dir(avm_dir, build_raster=True)
# log_id_to_avm[log_id] = avm
# log_id_to_timestamped_poses[log_id] = read_city_SE3_ego(log_dir)
# dts = dts.sort_values(["log_id", "timestamp_ns"], ascending=True).reset_index(drop=True)
# breakpoint()
# uuids = gts.loc[:, ["log_id", "timestamp_ns"]].drop_duplicates().melt()
# breakpoint()

# dts = dts.set_index(["log_id", "timestamp_ns"]).sort_values("score", ascending=False)
# gts = gts.set_index(["log_id", "timestamp_ns"])
# breakpoint()
dts_mapping = {uuid: x for uuid, x in dts.groupby(["log_id", "timestamp_ns", "category"])}
gts_mapping = {uuid: x for uuid, x in gts.groupby(["log_id", "timestamp_ns", "category"])}
args_list = [(dts_mapping[uuid], sweep_gts, cfg, None, None) for uuid, sweep_gts in gts_mapping.items()]

# Accumulate and gather the processed detections and ground truth annotations.
results = [accumulate(*x) for x in args_list]
dts_list, gts_list = zip(*results)

dts = pd.concat(dts_list).reset_index(drop=True)
gts = pd.concat(gts_list).reset_index(drop=True)
cols = cfg.affinity_thresholds_m + tuple(x.value for x in TruePositiveErrorNames)
dts_npy = np.concatenate(dts_list)
gts_npy = np.concatenate(gts_list)

dts.loc[:len(dts_npy) - 1, cols + ("is_evaluated",)] = dts_npy
gts.loc[:len(gts_npy) - 1, cfg.affinity_thresholds_m + ("is_evaluated",)] = gts_npy
# breakpoint()

# dts = pd.concat(dts_list).reset_index(drop=True)
# gts = pd.concat(gts_list).reset_index(drop=True)

# Compute summary metrics.
metrics = summarize_metrics(dts, gts, cfg)
Expand Down
20 changes: 13 additions & 7 deletions src/av2/evaluation/detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def tp_normalization_terms(self) -> Tuple[float, ...]:
MAX_YAW_RAD_ERROR,
)


@profile
def accumulate(
dts: pd.DataFrame,
gts: pd.DataFrame,
Expand All @@ -115,9 +115,14 @@ def accumulate(
Returns:
The detection and ground truth cuboids augmented with assigment and evaluation fields.
"""
breakpoint()
perm = (-dts["score"]).to_numpy().argsort()
dts = dts.iloc[perm]
# dts = dts[]
# breakpoint()
dts = dts.sort_values("score", ascending=False).reset_index(drop=True)
dts_npy: NDArrayObject = dts[CUBOID_COLS].to_numpy()
gts_npy: NDArrayObject = gts[CUBOID_COLS].to_numpy()
dts_npy: NDArrayFloat = dts[CUBOID_COLS].to_numpy()
gts_npy: NDArrayFloat = gts[CUBOID_COLS].to_numpy()

dts_categories: NDArrayObject = dts["category"].to_numpy()
gts_categories: NDArrayObject = gts["category"].to_numpy()
Expand All @@ -126,6 +131,8 @@ def accumulate(

dt_results: NDArrayFloat = np.zeros((len(dts), 8))
gt_results: NDArrayFloat = np.zeros((len(gts), 5))


for category in cfg.categories:
category_dts_mask: NDArrayBool = dts_categories == category
category_gts_mask: NDArrayBool = gts_categories == category
Expand Down Expand Up @@ -161,10 +168,9 @@ def accumulate(
dt_results[category_dts_idx, :-1] = dts_assignments
gt_results[category_gts_idx, :-1] = gts_assignments

cols = cfg.affinity_thresholds_m + tuple(x.value for x in TruePositiveErrorNames)
dts.loc[:, cols + ("is_evaluated",)] = dt_results
gts.loc[:, cfg.affinity_thresholds_m + ("is_evaluated",)] = gt_results
return dts, gts
_, inv = np.unique(perm, return_index=True)
dt_results = dt_results[inv]
return dt_results, gt_results


def assign(dts: NDArrayFloat, gts: NDArrayFloat, cfg: DetectionCfg) -> Tuple[NDArrayFloat, NDArrayFloat]:
Expand Down
40 changes: 20 additions & 20 deletions tests/evaluation/detection/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ def test_accumulate() -> None:
dts, gts = accumulate(*job)

# Check that there's a true positive under every threshold.
assert np.all(dts.loc[:, cfg.affinity_thresholds_m])
assert np.all(dts[:, :4])

# Check that all error metrics are zero.
assert (dts.loc[:, tuple(x.value for x in TruePositiveErrorNames)] == 0).all(axis=None)
assert (dts[:, 4:7] == 0).all()

# Check that there are 2 regular vehicles.
assert gts["category"].value_counts()["REGULAR_VEHICLE"] == 2
# # Check that there are 2 regular vehicles.
# assert gts["category"].value_counts()["REGULAR_VEHICLE"] == 2

# Check that there are no other labels.
assert gts["category"].value_counts().sum() == 2
# # Check that there are no other labels.
# assert gts["category"].value_counts().sum() == 2


def test_assign() -> None:
Expand Down Expand Up @@ -304,22 +304,22 @@ def test_compute_evaluated_gts_mask() -> None:
np.testing.assert_array_equal(gts_mask, gts_mask_) # type: ignore


# def test_val_identity() -> None:
# root_dir = Path.home() / "data" / "datasets" / "av2" / "sensor" / "val"
# paths = sorted(root_dir.glob("*/annotations.feather"))
def test_val_identity() -> None:
root_dir = Path.home() / "data" / "datasets" / "av2" / "sensor" / "val"
paths = sorted(root_dir.glob("*/annotations.feather"))

# annotations = []
# for p in paths:
# df = pd.read_feather(p)
# df["log_id"] = p.parent.stem
# annotations.append(df)
# annotations = pd.concat(annotations).reset_index(drop=True)
# dts = annotations.copy()
# dts["score"] = 1.0
# annotations["num_interior_pts"] = 1
annotations = []
for p in paths:
df = pd.read_feather(p)
df["log_id"] = p.parent.stem
annotations.append(df)
annotations = pd.concat(annotations).reset_index(drop=True)
dts = annotations.copy()
dts["score"] = 1.0
annotations["num_interior_pts"] = 1

# detection_cfg = DetectionCfg(eval_only_roi_instances=False, max_num_dts_per_category=1000)
# dts_, gts_, metrics_ = evaluate(dts, annotations, detection_cfg)
detection_cfg = DetectionCfg(eval_only_roi_instances=False, max_num_dts_per_category=1000)
dts_, gts_, metrics_ = evaluate(dts, annotations, detection_cfg)


if __name__ == "__main__":
Expand Down