Skip to content

Commit

Permalink
Mergeback 1.9.0 to develop (#1604)
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.​
- [ ] 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) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
```

---------

Co-authored-by: Yunchu Lee <yunchu.lee@intel.com>
Co-authored-by: Wonju Lee <wonju.lee@intel.com>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent 7dd7ad2 commit 7b85e96
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 33 deletions.
17 changes: 17 additions & 0 deletions 3rd-party.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7518,5 +7518,22 @@ Apache-2.0
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------
portalocker

BSD-3-Clause

Copyright 2022 Rick van Hattem

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-------------------------------------------------------------

* Other names and brands may be claimed as the property of others.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## \[unreleased\]
## \[Q3 2024 Release 1.9.0\]
### New features
- Add a new CLI command: datum format
(<https://github.com/openvinotoolkit/datumaro/pull/1570>)
- Support language dataset for DmTorchDataset
(<https://github.com/openvinotoolkit/datumaro/pull/1592>)

### Enhancements
- Change _Shape to Shape and add comments for subclasses of Shape
(<https://github.com/openvinotoolkit/datumaro/pull/1568>)
- Fix `kitti_raw` importer and exporter for dimensions (height, width, length) in meters
(<https://github.com/openvinotoolkit/datumaro/pull/1596>)

### Bug fixes
- Fix KITTI-3D importer and exporter
(<https://github.com/openvinotoolkit/datumaro/pull/1596>)

## Q3 2024 Release 1.8.0
### New features
Expand Down
16 changes: 16 additions & 0 deletions docs/source/docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ Release Notes
.. toctree::
:maxdepth: 1

v1.9.0 (2024 Q3)
----------------

New features
^^^^^^^^^^^^
- Add a new CLI command: datum format
- Support language dataset for DmTorchDataset

Enhancements
^^^^^^^^^^^^
- Change _Shape to Shape and add comments for subclasses of Shape

Bug fixes
^^^^^^^^^
- Fix KITTI-3D importer and exporter

v1.8.0 (2024 Q3)
----------------

Expand Down
3 changes: 3 additions & 0 deletions requirements-core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ json-stream

# TabularValidator
nltk

# torch converter for language
portalocker
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def parse_requirements(filename=CORE_REQUIREMENTS_FILE):
extras_require={
"tf": ["tensorflow"],
"tfds": ["tensorflow-datasets<4.9.3"],
"torch": ["torch", "torchvision"],
"torch": ["torch", "torchvision", "torchtext==0.16.0"],
"default": DEFAULT_REQUIREMENTS,
},
ext_modules=ext_modules,
Expand Down
4 changes: 2 additions & 2 deletions src/datumaro/plugins/data_formats/kitti_raw/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021-2023 Intel Corporation
# Copyright (C) 2021-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -182,7 +182,7 @@ def _parse_attr(cls, value):
@classmethod
def _parse_track(cls, track_id, track, categories):
common_attrs = {k: cls._parse_attr(v) for k, v in track["attributes"].items()}
scale = [track["scale"][k] for k in ["w", "h", "l"]]
scale = [track["scale"][k] for k in ["h", "w", "l"]]
label = categories[AnnotationType.label].find(track["label"])[0]

kf_occluded = False
Expand Down
8 changes: 4 additions & 4 deletions src/datumaro/plugins/data_formats/kitti_raw/exporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021 Intel Corporation
# Copyright (C) 2021-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -339,16 +339,16 @@ def _create_tracklets(self, subset):
if not track:
track = {
"objectType": label,
"h": ann.scale[1],
"w": ann.scale[0],
"h": ann.scale[0],
"w": ann.scale[1],
"l": ann.scale[2],
"first_frame": frame_id,
"poses": [],
"finished": 1, # keep last
}
tracks[track_id] = track
else:
if [track["w"], track["h"], track["l"]] != ann.scale:
if [track["h"], track["w"], track["l"]] != ann.scale:
# Tracks have fixed scale in the format
raise DatasetExportError(
"Item %s: mismatching track shapes, "
Expand Down
51 changes: 49 additions & 2 deletions src/datumaro/plugins/framework_converter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2023 Intel Corporation
# Copyright (C) 2023-2024 Intel Corporation
#
# SPDX-License-Identifier: MIT

Expand All @@ -17,6 +17,7 @@
"detection": AnnotationType.bbox,
"instance_segmentation": AnnotationType.polygon,
"semantic_segmentation": AnnotationType.mask,
"tabular": [AnnotationType.label, AnnotationType.caption],
}


Expand Down Expand Up @@ -88,7 +89,10 @@ def _gen_item(self, idx: int):
if ann.type == TASK_ANN_TYPE[self.task]
]
label = mask_tools.merge_masks((mask, label_id) for mask, label_id in masks)

elif self.task == "tabular":
label = [
ann.as_dict() for ann in item.annotations if ann.type in TASK_ANN_TYPE[self.task]
]
return image, label


Expand All @@ -103,15 +107,58 @@ def __init__(
task: str,
transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None,
target: Optional[str] = None,
tokenizer: Optional[tuple[Callable, Callable]] = None,
vocab: Optional[tuple[Callable, Callable]] = None,
):
super().__init__(dataset=dataset, subset=subset, task=task)

self.transform = transform
self.target_transform = target_transform

if self.task == "tabular":
if not isinstance(target, dict):
raise ValueError(
"Target should be a dictionary with 'input' and 'output' keys."
)
self.input_target = target.get("input")
self.output_target = target.get("output")
if not self.input_target:
raise ValueError(
"Please provide target column for tabular task which is used for input"
)

if not (tokenizer and vocab):
raise ValueError("Both tokenizer and vocab must be provided for tabular task")
self.tokenizer = tokenizer
self.vocab = vocab

def __getitem__(self, idx):
image, label = self._gen_item(idx)

if self.task == "tabular":
text = image()[self.input_target]

if self.output_target:
src_tokenizer, tgt_tokenizer = self.tokenizer
src_vocab, tgt_vocab = self.vocab
src_tokens = src_tokenizer(text)
src_token_ids = src_vocab(src_tokens)

label_text = label[0]["caption"].split(f"{self.output_target}:")[-1]
tgt_tokens = tgt_tokenizer(label_text)
tgt_token_ids = tgt_vocab(tgt_tokens)

return torch.tensor(src_token_ids, dtype=torch.long), torch.tensor(
tgt_token_ids, dtype=torch.long
)
else:
tokens = self.tokenizer(text)
token_ids = self.vocab(tokens)
return torch.tensor(token_ids, dtype=torch.long), torch.tensor(
label[0]["label"], dtype=torch.long
)

if len(image.shape) == 2:
image = np.expand_dims(image, axis=-1)

Expand Down
2 changes: 1 addition & 1 deletion src/datumaro/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.9.0rc0"
__version__ = "1.9.0"
8 changes: 4 additions & 4 deletions tests/integration/cli/test_kitti_raw_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def test_can_convert_to_kitti_raw(self):
annotations=[
Cuboid3d(
position=[1, 2, 3],
scale=[7.95, -3.62, -1.03],
scale=[-3.62, 7.95, -1.03],
label=1,
attributes={"occluded": False, "track_id": 1},
),
Cuboid3d(
position=[1, 1, 0],
scale=[8.34, 23.01, -0.76],
scale=[23.01, 8.34, -0.76],
label=0,
attributes={"occluded": False, "track_id": 2},
),
Expand All @@ -65,7 +65,7 @@ def test_can_convert_to_kitti_raw(self):
annotations=[
Cuboid3d(
position=[0, 1, 0],
scale=[8.34, 23.01, -0.76],
scale=[23.01, 8.34, -0.76],
rotation=[1, 1, 3],
label=0,
attributes={"occluded": True, "track_id": 2},
Expand All @@ -92,7 +92,7 @@ def test_can_convert_to_kitti_raw(self):
annotations=[
Cuboid3d(
position=[1, 2, 3],
scale=[-9.41, 13.54, 0.24],
scale=[13.54, -9.41, 0.24],
label=1,
attributes={"occluded": False, "track_id": 3},
)
Expand Down
Loading

0 comments on commit 7b85e96

Please sign in to comment.