Skip to content

Commit

Permalink
Fix duplicated label import for Kaggle importer (#1244)
Browse files Browse the repository at this point in the history
<!-- Contributing guide:
https://github.com/openvinotoolkit/datumaro/blob/develop/CONTRIBUTING.md
-->

### Summary

<!--
Resolves #111 and #222.
Depends on #1000 (for series of dependent commits).

This PR introduces this capability to make the project better in this
and that.

- Added this feature
- Removed that feature
- Fixed the problem #1234
-->

### How to test
<!-- Describe the testing procedure for reviewers, if changes are
not fully covered by unit tests or manual testing can be complicated.
-->

### Checklist
<!-- Put an 'x' in all the boxes that apply -->
- [ ] I have added unit tests to cover my changes.​
- [ ] I have added integration tests to cover my changes.​
- [x] I have added the description of my changes into
[CHANGELOG](https://github.com/openvinotoolkit/datumaro/blob/develop/CHANGELOG.md).​
- [ ] I have updated the
[documentation](https://github.com/openvinotoolkit/datumaro/tree/develop/docs)
accordingly

### License

- [ ] I submit _my code changes_ under the same [MIT
License](https://github.com/openvinotoolkit/datumaro/blob/develop/LICENSE)
that covers the project.
  Feel free to contact the maintainers if that's a concern.
- [ ] I have updated the license header for each file (see an example
below).

```python
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
```
  • Loading branch information
wonjuleee authored Jan 17, 2024
1 parent 5f8ddef commit f0d7b13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/openvinotoolkit/datumaro/pull/1237>)
- Fix a bug in the previous behavior when importing nested datasets in the project
(<https://github.com/openvinotoolkit/datumaro/pull/1243>)
- Fix Kaggle importer when adding duplicated labels
(<https://github.com/openvinotoolkit/datumaro/pull/1244>)

## 16/11/2023 - Release 1.5.1
### Enhancements
Expand Down
20 changes: 13 additions & 7 deletions src/datumaro/plugins/data_formats/kaggle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ def __init__(
for img_filename in os.listdir(path):
if not img_filename.lower().endswith(tuple(IMAGE_EXTENSIONS)):
continue
item_id = os.path.splitext(img_filename)[0]
item_id = osp.splitext(img_filename)[0]

img_file = os.path.join(path, img_filename)
ann_file = os.path.join(ann_path, item_id + self.ann_extensions)
img_file = osp.join(path, img_filename)
ann_file = osp.join(ann_path, item_id + self.ann_extensions)

annotations = (
self._parse_annotations(img_file, ann_file) if os.path.isfile(ann_file) else []
self._parse_annotations(img_file, ann_file) if osp.isfile(ann_file) else []
)

media = Image.from_file(path=img_file, size=self._size)
Expand Down Expand Up @@ -351,8 +351,11 @@ def _parse_annotations(self, img_file: str, ann_file: str):
ymin = self._parse_field(bbox_elem, "ymin", float)
ymax = self._parse_field(bbox_elem, "ymax", float)

self._label_cat.add(label_name)
label_id, _ = self._label_cat.find(label_name)
label_id, cat = self._label_cat.find(label_name)
if not cat:
self._label_cat.add(label_name)
label_id, _ = self._label_cat.find(label_name)

annotations.append(
Bbox(id=obj_id, label=label_id, x=xmin, y=ymin, w=xmax - xmin, h=ymax - ymin)
)
Expand Down Expand Up @@ -419,7 +422,10 @@ def _parse_annotations(self, img_file: str, ann_file: str):
w *= image_width
h *= image_height

self._label_cat.add(label_name)
label_id, cat = self._label_cat.find(label_name)
if not cat:
self._label_cat.add(label_name)
label_id, _ = self._label_cat.find(label_name)
label_id, _ = self._label_cat.find(label_name)

annotations.append(Bbox(id=obj_id, label=label_id, x=x, y=y, w=w, h=h))
Expand Down

0 comments on commit f0d7b13

Please sign in to comment.