|
6 | 6 | from __future__ import annotations
|
7 | 7 |
|
8 | 8 | from functools import partial
|
9 |
| -from typing import Callable |
| 9 | +from typing import TYPE_CHECKING, Callable |
10 | 10 |
|
11 | 11 | import torch
|
12 | 12 | from datumaro import Label
|
13 | 13 |
|
14 | 14 | from otx.core.data.dataset.base import OTXDataset
|
15 | 15 | from otx.core.data.entity.action_classification import ActionClsBatchDataEntity, ActionClsDataEntity
|
16 | 16 | from otx.core.data.entity.base import ImageInfo
|
| 17 | +from otx.core.data.mem_cache import NULL_MEM_CACHE_HANDLER |
| 18 | +from otx.core.types.image import ImageColorChannel |
| 19 | + |
| 20 | +if TYPE_CHECKING: |
| 21 | + from datumaro import DatasetSubset |
| 22 | + |
| 23 | + from otx.core.data.dataset.base import Transforms |
| 24 | + from otx.core.data.mem_cache import MemCacheHandlerBase |
17 | 25 |
|
18 | 26 |
|
19 | 27 | class OTXActionClsDataset(OTXDataset[ActionClsDataEntity]):
|
20 | 28 | """OTXDataset class for action classification task."""
|
21 | 29 |
|
| 30 | + def __init__( |
| 31 | + self, |
| 32 | + dm_subset: DatasetSubset, |
| 33 | + transforms: Transforms, |
| 34 | + mem_cache_handler: MemCacheHandlerBase = NULL_MEM_CACHE_HANDLER, |
| 35 | + mem_cache_img_max_size: tuple[int, int] | None = None, |
| 36 | + max_refetch: int = 1000, |
| 37 | + image_color_channel: ImageColorChannel = ImageColorChannel.BGR, |
| 38 | + stack_images: bool = True, |
| 39 | + to_tv_image: bool = True, |
| 40 | + ) -> None: |
| 41 | + super().__init__( |
| 42 | + dm_subset, |
| 43 | + transforms, |
| 44 | + mem_cache_handler, |
| 45 | + mem_cache_img_max_size, |
| 46 | + max_refetch, |
| 47 | + image_color_channel, |
| 48 | + stack_images, |
| 49 | + to_tv_image, |
| 50 | + ) |
| 51 | + # TODO(Someone): ImageColorChannel is not used in action classification task |
| 52 | + # This task only supports BGR color format. |
| 53 | + # There should be implementation that links between ImageColorChannel and action classification task. |
| 54 | + if self.image_color_channel != ImageColorChannel.BGR: |
| 55 | + msg = "Action classification task only supports BGR color format." |
| 56 | + raise ValueError(msg) |
| 57 | + |
22 | 58 | def _get_item_impl(self, idx: int) -> ActionClsDataEntity | None:
|
23 | 59 | item = self.dm_subset[idx]
|
24 | 60 |
|
|
0 commit comments