Skip to content

Commit

Permalink
Fix get ann ids (#36)
Browse files Browse the repository at this point in the history
* fix ignore

* fix getAnnIds

* bump version
  • Loading branch information
MiXaiLL76 authored Jun 20, 2024
1 parent 1430906 commit 5b080c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
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):

This comment has been minimized.

Copy link
@roelKln

roelKln Jul 24, 2024

Pretty sure this should be
if not (check_area or check_crowd or check_cat or check_img)

Right now, it will take all annotations, unless all of the filters are used.

This comment has been minimized.

Copy link
@MiXaiLL76

MiXaiLL76 Jul 25, 2024

Author Owner

Hello! yes, you're right, I already noticed this and corrected it in a new thread.
This will be a big update next month

https://github.com/MiXaiLL76/faster_coco_eval/blob/mask_cpp/faster_coco_eval/core/coco.py#L203

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

0 comments on commit 5b080c4

Please sign in to comment.