Skip to content

Commit

Permalink
Change RoIImage and MosaicImage to have np.uint8 dtype as default (#1245
Browse files Browse the repository at this point in the history
)

### Summary

- This is something missed in
#1175

### How to test
I believe the existing tests (`tests/unit/test_images.py`) can cover it.

### 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) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
```

---------

Signed-off-by: Kim, Vinnam <[email protected]>
  • Loading branch information
vinnamkim authored Jan 23, 2024
1 parent f0d7b13 commit a905a0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/openvinotoolkit/datumaro/pull/1228>)
- Enhance Datumaro data format detect() to be memory-bounded and performant
(<https://github.com/openvinotoolkit/datumaro/pull/1229>)
- Change RoIImage and MosaicImage to have np.uint8 dtype as default
(<https://github.com/openvinotoolkit/datumaro/pull/1245>)

### Bug fixes
- Fix wrong example of Datumaro dataset creation in document
Expand Down
10 changes: 4 additions & 6 deletions src/datumaro/components/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,6 @@ def roi(self) -> BboxIntCoords:

def _get_roi_data(self, data: np.ndarray) -> np.ndarray:
x, y, w, h = self._roi
if isinstance(data, np.ndarray):
data = data.astype(np.float32)
return data[y : y + h, x : x + w]

def save(
Expand Down Expand Up @@ -1007,7 +1005,7 @@ def __init__(

@property
def data(self) -> Optional[np.ndarray]:
"""Image data in BGRA HWC [0; 255] (float) format"""
"""Image data in BGRA HWC [0; 255] (uint8) format"""
if not self.has_data:
return None
data = self.__data()
Expand All @@ -1030,7 +1028,7 @@ def __init__(

@property
def data(self) -> Optional[np.ndarray]:
"""Image data in BGRA HWC [0; 255] (float) format"""
"""Image data in BGRA HWC [0; 255] (uint8) format"""
data = super().data
if data is None:
return None
Expand All @@ -1051,7 +1049,7 @@ def __init__(

@property
def data(self) -> Optional[np.ndarray]:
"""Image data in BGRA HWC [0; 255] (float) format"""
"""Image data in BGRA HWC [0; 255] (uint8) format"""
data = super().data
if data is None:
return None
Expand Down Expand Up @@ -1116,7 +1114,7 @@ class MosaicImageFromImageRoIPairs(MosaicImageFromData):
def __init__(self, data: List[ImageWithRoI], size: Tuple[int, int]) -> None:
def _get_mosaic_img() -> np.ndarray:
h, w = self.size
mosaic_img = np.zeros(shape=(h, w, 3), dtype=np.float32)
mosaic_img = np.zeros(shape=(h, w, 3), dtype=np.uint8)
for img, roi in data:
assert isinstance(img, Image), "MosaicImage can only take a list of Images."
x, y, w, h = roi
Expand Down

0 comments on commit a905a0c

Please sign in to comment.