Skip to content

Commit

Permalink
Get list of subsets and support only Image media in visualizer (#768)
Browse files Browse the repository at this point in the history
* get subset as list

* Support only Image media type for visualizer

* check media type is image or not

* Check subset len and ids len equal

* check subset is list or not

* Raise exception if subset is list and len is not equal to ids

* Update CHANGELOG

* Fix black
  • Loading branch information
sooahleex authored Nov 24, 2022
1 parent c5327b3 commit eabce02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/openvinotoolkit/datumaro/pull/758>)

### Changed
- N/A
- Get list of subsets and support only Image media type in visualizer
(<https://github.com/openvinotoolkit/datumaro/pull/768>)

### Deprecated
- N/A
Expand Down
18 changes: 15 additions & 3 deletions datumaro/components/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
from datumaro.components.dataset import IDataset
from datumaro.components.extractor import DatasetItem
from datumaro.components.media import Image

CAPTION_BBOX_PAD = 0.2
DEFAULT_COLOR_CYCLES: List[str] = [
Expand Down Expand Up @@ -192,14 +193,22 @@ def _sort_key(ann: Annotation):
def vis_gallery(
self,
ids: List[Union[str, DatasetItem]],
subset: Optional[str] = None,
subset: Optional[Union[str, List[str]]] = None,
grid_size: Tuple[Optional[int], Optional[int]] = (None, None),
) -> Figure:
nrows, ncols = _infer_grid_size(len(ids), grid_size)
fig, axs = plt.subplots(nrows, ncols, figsize=self.figsize)

for dataset_id, ax in zip(ids, axs.flatten()):
self.vis_one_sample(dataset_id, subset, ax)
if isinstance(subset, list):
assert len(ids) == len(
subset
), "If subset is a list, it should have the same length as ids."

for i, (dataset_id, ax) in enumerate(zip(ids, axs.flatten())):
if isinstance(subset, List):
self.vis_one_sample(dataset_id, subset[i], ax)
else:
self.vis_one_sample(dataset_id, subset, ax)

return fig

Expand All @@ -215,6 +224,9 @@ def vis_one_sample(

item: DatasetItem = self.dataset.get(id, subset)
assert item is not None, f"Cannot find id={id}, subset={subset}"
assert (
item is not Image
), f"Media type should be Image, Current media type={type(item.media)}"

img = item.media.data.astype(np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
Expand Down

0 comments on commit eabce02

Please sign in to comment.