-
Notifications
You must be signed in to change notification settings - Fork 557
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
Merge release/v1.0.1
to develop
#4894
Changes from 4 commits
f08b8cc
221d807
17e8e53
e416f13
69a89e8
97ccc02
54ce128
ac6f451
35c13f7
a2d26f0
10d303c
e4f1ca4
46c1929
44b6594
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -45,7 +45,7 @@ def add_coco_labels( | |||||||
sample_collection, | ||||||||
label_field, | ||||||||
labels_or_path, | ||||||||
classes, | ||||||||
categories, | ||||||||
label_type="detections", | ||||||||
coco_id_field=None, | ||||||||
include_annotation_id=False, | ||||||||
|
@@ -68,7 +68,7 @@ def add_coco_labels( | |||||||
{ | ||||||||
"id": 1, | ||||||||
"image_id": 1, | ||||||||
"category_id": 2, | ||||||||
"category_id": 1, | ||||||||
"bbox": [260, 177, 231, 199], | ||||||||
# optional | ||||||||
|
@@ -88,7 +88,7 @@ def add_coco_labels( | |||||||
{ | ||||||||
"id": 1, | ||||||||
"image_id": 1, | ||||||||
"category_id": 2, | ||||||||
"category_id": 1, | ||||||||
"bbox": [260, 177, 231, 199], | ||||||||
"segmentation": [...], | ||||||||
|
@@ -109,7 +109,7 @@ def add_coco_labels( | |||||||
{ | ||||||||
"id": 1, | ||||||||
"image_id": 1, | ||||||||
"category_id": 2, | ||||||||
"category_id": 1, | ||||||||
"keypoints": [224, 226, 2, ...], | ||||||||
"num_keypoints": 10, | ||||||||
|
@@ -129,8 +129,14 @@ def add_coco_labels( | |||||||
will be created if necessary | ||||||||
labels_or_path: a list of COCO annotations or the path to a JSON file | ||||||||
containing such data on disk | ||||||||
classes: the list of class label strings or a dict mapping class IDs to | ||||||||
class labels | ||||||||
categories: can be any of the following: | ||||||||
- a list of category dicts in the format of | ||||||||
:meth:`parse_coco_categories` specifying the classes and their | ||||||||
category IDs | ||||||||
- a dict mapping class IDs to class labels | ||||||||
- a list of class labels whose 1-based ordering is assumed to | ||||||||
correspond to the category IDs in the provided COCO labels | ||||||||
label_type ("detections"): the type of labels to load. Supported values | ||||||||
are ``("detections", "segmentations", "keypoints")`` | ||||||||
coco_id_field (None): this parameter determines how to map the | ||||||||
|
@@ -195,10 +201,14 @@ class labels | |||||||
view.compute_metadata() | ||||||||
widths, heights = view.values(["metadata.width", "metadata.height"]) | ||||||||
|
||||||||
if isinstance(classes, dict): | ||||||||
classes_map = classes | ||||||||
if isinstance(categories, dict): | ||||||||
classes_map = categories | ||||||||
elif not categories: | ||||||||
classes_map = {} | ||||||||
elif isinstance(categories[0], dict): | ||||||||
classes_map = {c["id"]: c["name"] for c in categories} | ||||||||
else: | ||||||||
classes_map = {i: label for i, label in enumerate(classes)} | ||||||||
classes_map = {i: label for i, label in enumerate(categories, 1)} | ||||||||
|
||||||||
labels = [] | ||||||||
for _coco_objects, width, height in zip(coco_objects, widths, heights): | ||||||||
|
@@ -563,15 +573,11 @@ def setup(self): | |||||||
self.labels_path, extra_attrs=self.extra_attrs | ||||||||
) | ||||||||
|
||||||||
classes = None | ||||||||
if classes_map is not None: | ||||||||
classes = _to_classes(classes_map) | ||||||||
|
||||||||
if classes is not None: | ||||||||
info["classes"] = classes | ||||||||
info["classes"] = _to_classes(classes_map) | ||||||||
|
||||||||
Comment on lines
+577
to
578
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update In line 578, the code assigns the class mappings to Apply this diff to fix the inconsistency: if classes_map is not None:
- info["classes"] = _to_classes(classes_map)
+ info["categories"] = _to_classes(classes_map) 📝 Committable suggestion
Suggested change
|
||||||||
image_ids = _get_matching_image_ids( | ||||||||
classes, | ||||||||
classes_map, | ||||||||
images, | ||||||||
annotations, | ||||||||
image_ids=self.image_ids, | ||||||||
|
@@ -907,12 +913,11 @@ def export_sample(self, image_or_path, label, metadata=None): | |||||||
|
||||||||
def close(self, *args): | ||||||||
if self._dynamic_classes: | ||||||||
classes = sorted(self._classes) | ||||||||
labels_map_rev = _to_labels_map_rev(classes) | ||||||||
labels_map_rev = _to_labels_map_rev(sorted(self._classes)) | ||||||||
for anno in self._annotations: | ||||||||
anno["category_id"] = labels_map_rev[anno["category_id"]] | ||||||||
else: | ||||||||
classes = self.classes | ||||||||
elif self.categories is None: | ||||||||
labels_map_rev = _to_labels_map_rev(self.classes) | ||||||||
|
||||||||
Comment on lines
+916
to
921
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Multiple occurrences of The
Please ensure all instances of 🔗 Analysis chainReplace At line 921, Apply this diff to correct the variable: elif self.categories is None:
- labels_map_rev = _to_labels_map_rev(self.classes)
+ labels_map_rev = _to_labels_map_rev(self.categories) Run the following script to verify any remaining occurrences of 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find all occurrences of 'self.classes' in the codebase.
# Expected result: No occurrences of 'self.classes' should remain.
rg --type python -F 'self.classes'
Length of output: 64 Script: #!/bin/bash
# Description: Find all occurrences of 'self.classes' in Python files within the codebase.
rg --type py -F 'self.classes'
Length of output: 8709 |
||||||||
_info = self.info or {} | ||||||||
_date_created = datetime.now().replace(microsecond=0).isoformat() | ||||||||
|
@@ -933,10 +938,10 @@ def close(self, *args): | |||||||
categories = [ | ||||||||
{ | ||||||||
"id": i, | ||||||||
"name": l, | ||||||||
"name": c, | ||||||||
"supercategory": None, | ||||||||
} | ||||||||
for i, l in enumerate(classes) | ||||||||
for c, i in sorted(labels_map_rev.items(), key=lambda t: t[1]) | ||||||||
] | ||||||||
|
||||||||
labels = { | ||||||||
|
@@ -1681,7 +1686,7 @@ def download_coco_dataset_split( | |||||||
if classes is not None: | ||||||||
# Filter by specified classes | ||||||||
all_ids, any_ids = _get_images_with_classes( | ||||||||
image_ids, annotations, classes, all_classes | ||||||||
image_ids, annotations, classes, all_classes_map | ||||||||
) | ||||||||
else: | ||||||||
all_ids = image_ids | ||||||||
|
@@ -1846,7 +1851,7 @@ def _parse_include_license(include_license): | |||||||
|
||||||||
|
||||||||
def _get_matching_image_ids( | ||||||||
all_classes, | ||||||||
classes_map, | ||||||||
images, | ||||||||
annotations, | ||||||||
image_ids=None, | ||||||||
|
@@ -1862,7 +1867,7 @@ def _get_matching_image_ids( | |||||||
|
||||||||
if classes is not None: | ||||||||
all_ids, any_ids = _get_images_with_classes( | ||||||||
image_ids, annotations, classes, all_classes | ||||||||
image_ids, annotations, classes, classes_map | ||||||||
) | ||||||||
else: | ||||||||
all_ids = image_ids | ||||||||
Comment on lines
+1870
to
1873
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Rename parameter The parameter Apply this diff to rename the parameter: def _get_images_with_classes(
image_ids, annotations, target_classes, classes_map
- ):
+ ):
+ # Rename target_classes to target_categories
+ target_categories = target_classes And update the variable usage within the function accordingly.
|
||||||||
|
@@ -1930,7 +1935,7 @@ def _do_download(args): | |||||||
|
||||||||
|
||||||||
def _get_images_with_classes( | ||||||||
image_ids, annotations, target_classes, all_classes | ||||||||
image_ids, annotations, target_classes, classes_map | ||||||||
): | ||||||||
if annotations is None: | ||||||||
logger.warning("Dataset is unlabeled; ignoring classes requirement") | ||||||||
|
@@ -1939,11 +1944,12 @@ def _get_images_with_classes( | |||||||
if etau.is_str(target_classes): | ||||||||
target_classes = [target_classes] | ||||||||
|
||||||||
bad_classes = [c for c in target_classes if c not in all_classes] | ||||||||
labels_map_rev = {c: i for i, c in classes_map.items()} | ||||||||
|
||||||||
bad_classes = [c for c in target_classes if c not in labels_map_rev] | ||||||||
if bad_classes: | ||||||||
raise ValueError("Unsupported classes: %s" % bad_classes) | ||||||||
|
||||||||
labels_map_rev = _to_labels_map_rev(all_classes) | ||||||||
class_ids = {labels_map_rev[c] for c in target_classes} | ||||||||
|
||||||||
all_ids = [] | ||||||||
|
@@ -2029,7 +2035,7 @@ def _load_image_ids_json(json_path): | |||||||
|
||||||||
|
||||||||
def _to_labels_map_rev(classes): | ||||||||
return {c: i for i, c in enumerate(classes)} | ||||||||
return {c: i for i, c in enumerate(classes, 1)} | ||||||||
|
||||||||
|
||||||||
def _to_classes(classes_map): | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Rename
classes_map
tocategories_map
for consistencySince the parameter has been renamed from
classes
tocategories
, it's recommended to rename the variableclasses_map
tocategories_map
to maintain consistency and avoid confusion.Apply this diff to rename the variable:
Remember to update subsequent usages of
classes_map
tocategories_map
.📝 Committable suggestion