Skip to content

Change RoIImage and MosaicImage to have np.uint8 dtype as default #1245

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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