-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAM2 AMG example mIoU, perf numbers and more SAM2 model annotations (#…
- Loading branch information
Showing
7 changed files
with
345 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import fire | ||
import torch | ||
import json | ||
from sam2.utils.amg import rle_to_mask | ||
|
||
""" | ||
Script to calculate mIoU given two lists of rles from upload_rle endpoint | ||
of server. | ||
""" | ||
|
||
|
||
def iou(mask1, mask2): | ||
assert mask1.dim() == 2 | ||
assert mask2.dim() == 2 | ||
intersection = torch.logical_and(mask1, mask2) | ||
union = torch.logical_or(mask1, mask2) | ||
return (intersection.sum(dim=(-1, -2)) / union.sum(dim=(-1, -2))) | ||
|
||
|
||
def main(path0, path1): | ||
fail_count = 0 | ||
miou_sum = 0.0 | ||
miou_count = 0 | ||
with open(path0, 'r') as f0, open(path1, 'r') as f1: | ||
for line0, line1 in zip(f0, f1): | ||
masks0 = json.loads(line0) | ||
masks1 = json.loads(line1) | ||
if masks0.keys() != masks1.keys(): | ||
fail_count += 1 | ||
continue | ||
for mask0, mask1 in zip(masks0.values(), masks1.values()): | ||
mask0 = torch.from_numpy(rle_to_mask(mask0)) | ||
mask1 = torch.from_numpy(rle_to_mask(mask1)) | ||
miou_sum += iou(mask0, mask1).item() | ||
miou_count += 1 | ||
|
||
print(f"fail_count: {fail_count} mIoU: {miou_sum / miou_count}") | ||
|
||
|
||
if __name__ == "__main__": | ||
fire.Fire(main) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.