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

Fix get ann ids #36

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 27 additions & 24 deletions faster_coco_eval/core/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,40 +174,43 @@ def getAnnIds(self, imgIds=[], catIds=[], areaRng=[], iscrowd=None):
:return: ids (int array) : integer array of ann ids

"""
imgIds = imgIds if _isArrayLike(imgIds) else [imgIds]
catIds = catIds if _isArrayLike(catIds) else [catIds]

anns = []
check_area = len(areaRng) > 0
check_crowd = iscrowd is not None
check_cat = len(catIds) > 0
check_img = len(imgIds) > 0

if len(imgIds) != 0:
for img_id in imgIds:
anns.extend(self.img_ann_map[img_id])
else:
if not (check_area and check_crowd and check_cat and check_img):
anns = self.dataset["annotations"]
else:
anns = []

# return early if no more filtering required
if (len(catIds) == 0) and (len(areaRng) == 0) and (iscrowd is None):
return [_ann["id"] for _ann in anns]
if check_img:
for img_id in imgIds:
anns.extend(self.img_ann_map[img_id])
else:
anns = self.dataset["annotations"]

cat_ids = set(catIds)
if check_cat:
anns = [ann for ann in anns if ann["category_id"] in catIds]

if len(areaRng) == 0:
areaRng = [0, float("inf")]
if check_area:
areaRng = [0, float("inf")]

imgIds = imgIds if _isArrayLike(imgIds) else [imgIds]
catIds = catIds if _isArrayLike(catIds) else [catIds]
anns = [
ann
for ann in anns
if ann["area"] > areaRng[0] and ann["area"] < areaRng[1]
]

if iscrowd is None:
iscrowd = False
if check_crowd:
anns = [ann for ann in anns if ann["iscrowd"] == iscrowd]

ann_ids = [
_ann["id"]
for _ann in anns
if _ann["category_id"] in cat_ids
and _ann["area"] > areaRng[0]
and _ann["area"] < areaRng[1]
and int(_ann.get("iscrowd", 0)) == int(iscrowd)
]
ids = [ann["id"] for ann in anns]

return ann_ids
return ids

def getCatIds(self, catNms=[], supNms=[], catIds=[]):
"""Filtering parameters.
Expand Down
13 changes: 4 additions & 9 deletions faster_coco_eval/core/cocoeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,10 @@ def _prepare(self):

# set ignore flag
for gt in gts:
if "ignore" not in gt:
gt["ignore"] = 0

if ("iscrowd" in gt) and (gt["ignore"] != 0):
gt["ignore"] = gt["iscrowd"]

if p.iouType == "keypoints" and (gt["ignore"] == 0):
gt["ignore"] = int(gt.get("num_keypoints", 0) == 0)

gt["ignore"] = gt["ignore"] if "ignore" in gt else 0
gt["ignore"] = "iscrowd" in gt and gt["iscrowd"]
if p.iouType == "keypoints":
gt["ignore"] = (gt.get("num_keypoints") == 0) or gt["ignore"]
self._gts = defaultdict(list) # gt for evaluation
self._dts = defaultdict(list) # dt for evaluation
img_pl = defaultdict(
Expand Down
2 changes: 1 addition & 1 deletion faster_coco_eval/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.5.6"
__version__ = "1.5.7"
__author__ = "MiXaiLL76"
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# history

## v1.5.7

- [x] Compare COCOEval bug fix.

## v1.5.6

- [x] Replace CED MSE curve with MAE (px) curve
Expand Down