otx.data.entity#

Module for OTX data entities.

Classes

OTXDataItem(image[, label, masks, bboxes, ...])

OTX data item implementation.

OTXDataBatch(batch_size, images[, labels, ...])

Torch data item batch implementation.

OTXPredBatch(batch_size, images[, labels, ...])

Torch prediction data item batch implementation.

OTXPredItem(image[, label, masks, bboxes, ...])

Torch prediction data item implementation.

TileDetDataEntity(num_tiles, entity_list, ...)

Data entity for detection tile task.

TileSegDataEntity(num_tiles, entity_list, ...)

Data entity for segmentation tile task.

TileBatchInstSegDataEntity(batch_size, ...)

Batch data entity for instance segmentation tile task.

TileBatchDetDataEntity(batch_size, ...)

Batch data entity for detection tile task.

TileBatchSegDataEntity(batch_size, ...)

Batch data entity for semantic segmentation tile task.

ImageType(value[, names, module, qualname, ...])

Enum to indicate the image type in ImageInfo class.

ImageInfo(img_idx, img_shape, ori_shape[, ...])

Meta info for image.

Points(data, *, canvas_size[, dtype, ...])

torch.Tensor subclass for points.

class otx.data.entity.ImageInfo(img_idx: int, img_shape: tuple[int, int], ori_shape: tuple[int, int], padding: tuple[int, int, int, int] = (0, 0, 0, 0), scale_factor: tuple[float, float] | None = (1.0, 1.0), normalized: bool = False, norm_mean: tuple[float, float, float] = (0.0, 0.0, 0.0), norm_std: tuple[float, float, float] = (1.0, 1.0, 1.0), image_color_channel: ImageColorChannel = ImageColorChannel.RGB, ignored_labels: list[int] | None = None)[source]#

Bases: TVTensor

Meta info for image.

img_id#

Image id

img_shape#

Image shape (heigth, width) after preprocessing

Type:

tuple[int, int]

ori_shape#

Image shape (heigth, width) right after loading it

Type:

tuple[int, int]

padding#

Number of pixels to pad all borders (left, top, right, bottom)

Type:

tuple[int, int, int, int]

scale_factor#

Scale factor (height, width) if the image is resized during preprocessing. Default value is (1.0, 1.0) when there is no resizing. However, if the image is cropped, it will lose the scaling information and be None.

Type:

tuple[float, float] | None

normalized#

If true, this image is normalized with norm_mean and norm_std

Type:

bool

norm_mean#

Mean vector used to normalize this image

Type:

tuple[float, float, float]

norm_std#

Standard deviation vector used to normalize this image

Type:

tuple[float, float, float]

image_color_channel#

Color channel type of this image, RGB or BGR.

Type:

otx.types.image.ImageColorChannel

ignored_labels#

Label that should be ignored in this image. Default to None.

Type:

list[int]

class otx.data.entity.ImageType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

Enum to indicate the image type in ImageInfo class.

classmethod get_image_type(image: ndarray | Image | list[ndarray] | list[Image]) ImageType[source]#

Infer the image type from the given image object.

class otx.data.entity.OTXDataBatch(batch_size: int, images: torch.Tensor | list[torch.Tensor], labels: list[torch.Tensor] | None = None, masks: list[Mask] | None = None, bboxes: list[BoundingBoxes] | None = None, keypoints: list[torch.Tensor] | None = None, polygons: list[list[Polygon]] | None = None, imgs_info: Sequence[ImageInfo | None] | None = None)[source]#

Bases: ValidateBatchMixin

Torch data item batch implementation.

pin_memory() OTXDataBatch[source]#

Pin memory for member tensor variables.

wrap(**kwargs) OTXDataBatch[source]#

Wrap this dataclass with the given keyword arguments.

Parameters:

**kwargs – Keyword arguments to be overwritten on top of this dataclass

Returns:

Updated dataclass

class otx.data.entity.OTXDataItem(image: torch.Tensor | np.ndarray, label: torch.Tensor | None = None, masks: Mask | None = None, bboxes: BoundingBoxes | None = None, keypoints: torch.Tensor | None = None, polygons: list[Polygon] | None = None, img_info: ImageInfo | None = None)[source]#

Bases: ValidateItemMixin, Mapping

OTX data item implementation.

image#

The image tensor

Type:

torch.Tensor | np.ndarray

label#

The label tensor, optional.

Type:

torch.Tensor | None

masks#

The masks, optional.

Type:

Mask | None

bboxes#

The bounding boxes, optional.

Type:

BoundingBoxes | None

keypoints#

The keypoints, optional.

Type:

torch.Tensor | None

polygons#

The polygons, optional.

Type:

list[Polygon] | None

img_info#

Additional image information, optional.

Type:

ImageInfo | None

static collate_fn(items: list[OTXDataItem]) OTXDataBatch[source]#

Collate TorchDataItems into a batch.

Parameters:

items – List of TorchDataItems to batch

Returns:

Batched TorchDataItems with stacked tensors

to_tv_image() OTXDataItem[source]#

Return a new instance with the image attribute converted to a TorchVision Image if it is a NumPy array.

Returns:

A new instance with the image attribute converted to a TorchVision Image, if applicable. Otherwise, return this instance as is.

wrap(**kwargs) OTXDataItem[source]#

Wrap this dataclass with the given keyword arguments.

Parameters:

**kwargs – Keyword arguments to be overwritten on top of this dataclass

Returns:

Updated dataclass

class otx.data.entity.OTXPredBatch(batch_size: int, images: torch.Tensor | list[torch.Tensor], labels: list[torch.Tensor] | None = None, masks: list[Mask] | None = None, bboxes: list[BoundingBoxes] | None = None, keypoints: list[torch.Tensor] | None = None, polygons: list[list[Polygon]] | None = None, imgs_info: Sequence[ImageInfo | None] | None = None, scores: list[torch.Tensor] | None = None, feature_vector: list[torch.Tensor] | None = None, saliency_map: list[torch.Tensor] | None = None)[source]#

Bases: OTXDataBatch

Torch prediction data item batch implementation.

property has_xai_outputs: bool#

Check if the batch has XAI outputs.

Necessary for compatibility with tests.

class otx.data.entity.OTXPredItem(image: torch.Tensor | np.ndarray, label: torch.Tensor | None = None, masks: Mask | None = None, bboxes: BoundingBoxes | None = None, keypoints: torch.Tensor | None = None, polygons: list[Polygon] | None = None, img_info: ImageInfo | None = None, scores: torch.Tensor | None = None, feature_vector: torch.Tensor | None = None, saliency_map: torch.Tensor | None = None)[source]#

Bases: OTXDataItem

Torch prediction data item implementation.

class otx.data.entity.Points(data: Any, *, canvas_size: tuple[int, int], dtype: dtype | None = None, device: device | str | int | None = None, requires_grad: bool | None = None)[source]#

Bases: TVTensor

torch.Tensor subclass for points.

data#

Any data that can be turned into a tensor with torch.as_tensor.

canvas_size#

Height and width of the corresponding image or video.

Type:

two-tuple of ints

dtype#

Desired data type of the point. If omitted, will be inferred from data.

Type:

torch.dtype, optional

device#

Desired device of the point. If omitted and data is a torch.Tensor, the device is taken from it. Otherwise, the point is constructed on the CPU.

Type:

torch.device, optional

requires_grad#

Whether autograd should record operations on the point. If omitted and data is a torch.Tensor, the value is taken from it. Otherwise, defaults to False.

Type:

bool, optional

class otx.data.entity.TileBatchDetDataEntity(batch_size: int, batch_tiles: list[list[tv_tensors.Image]], batch_tile_img_infos: list[list[ImageInfo]], batch_tile_attr_list: list[TileAttrDictList], imgs_info: list[ImageInfo], bboxes: list[tv_tensors.BoundingBoxes], labels: list[LongTensor])[source]#

Bases: OTXTileBatchDataEntity

Batch data entity for detection tile task.

bboxes#

The bounding boxes of the original image.

Type:

list[tv_tensors.BoundingBoxes]

labels#

The labels of the original image.

Type:

list[LongTensor]

classmethod collate_fn(batch_entities: list[TileDetDataEntity]) TileBatchDetDataEntity[source]#

Collate function to collect TileDetDataEntity into TileBatchDetDataEntity in data loader.

unbind() list[tuple[list[dict[str, int | str]], OTXDataBatch]][source]#

Unbind batch data entity for detection task.

class otx.data.entity.TileBatchInstSegDataEntity(batch_size: int, batch_tiles: list[list[tv_tensors.Image]], batch_tile_img_infos: list[list[ImageInfo]], batch_tile_attr_list: list[TileAttrDictList], imgs_info: list[ImageInfo], bboxes: list[tv_tensors.BoundingBoxes], labels: list[LongTensor], masks: list[tv_tensors.Mask], polygons: list[list[Polygon]])[source]#

Bases: OTXTileBatchDataEntity

Batch data entity for instance segmentation tile task.

bboxes#

The bounding boxes of the original image.

Type:

list[tv_tensors.BoundingBoxes]

labels#

The labels of the original image.

Type:

list[LongTensor]

masks#

The masks of the original image.

Type:

list[tv_tensors.Mask]

polygons#

The polygons of the original image.

Type:

list[list[Polygon]]

classmethod collate_fn(batch_entities: list[TileInstSegDataEntity]) TileBatchInstSegDataEntity[source]#

Collate function to collect TileInstSegDataEntity into TileBatchInstSegDataEntity in data loader.

unbind() list[tuple[list[dict[str, int | str]], OTXDataBatch]][source]#

Unbind batch data entity for instance segmentation task.

class otx.data.entity.TileBatchSegDataEntity(batch_size: int, batch_tiles: list[list[Image]], batch_tile_img_infos: list[list[ImageInfo]], batch_tile_attr_list: list[list[dict[str, int | str]]], imgs_info: list[ImageInfo], masks: list[Mask])[source]#

Bases: OTXTileBatchDataEntity

Batch data entity for semantic segmentation tile task.

masks#

The masks of the original image.

Type:

list[tv_tensors.Mask]

classmethod collate_fn(batch_entities: list[TileSegDataEntity]) TileBatchSegDataEntity[source]#

Collate function to collect TileSegDataEntity into TileBatchSegDataEntity in data loader.

unbind() list[tuple[list[dict[str, int | str]], OTXDataBatch]][source]#

Unbind batch data entity for semantic segmentation task.

class otx.data.entity.TileDetDataEntity(num_tiles: int, entity_list: Sequence[OTXDataItem], tile_attr_list: list[dict[str, int | str]], ori_img_info: ImageInfo, ori_bboxes: tv_tensors.BoundingBoxes, ori_labels: LongTensor)[source]#

Bases: TileDataEntity

Data entity for detection tile task.

ori_bboxes#

The bounding boxes of the original image.

Type:

tv_tensors.BoundingBoxes

ori_labels#

The labels of the original image.

Type:

LongTensor

property task: OTXTaskType#

OTX Task type definition.

class otx.data.entity.TileSegDataEntity(num_tiles: int, entity_list: Sequence[OTXDataItem], tile_attr_list: list[dict[str, int | str]], ori_img_info: ImageInfo, ori_masks: Mask)[source]#

Bases: TileDataEntity

Data entity for segmentation tile task.

ori_masks#

The masks of the original image.

Type:

tv_tensors.Mask

property task: OTXTaskType#

OTX Task type definition.