otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset#

Visual Prompting Dataset & DataModule.

Functions

convert_polygon_to_mask(shape, width, height)

Convert polygon to mask.

generate_bbox(x1, y1, x2, y2, width, height)

Generate bounding box.

generate_bbox_from_mask(gt_mask, width, height)

Generate bounding box from given mask.

get_transform([image_size, mean, std])

Get transform pipeline.

Classes

OTXVisualPromptingDataModule(config, dataset)

Visual Prompting DataModule.

OTXVisualPromptingDataset(mode, dataset, ...)

Visual Prompting Dataset Adaptor.

OTXZeroShotVisualPromptingDataset(mode, ...)

Visual Prompting for Zero-shot learning Dataset Adaptor.

class otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset.OTXVisualPromptingDataModule(config: DictConfig | ListConfig, dataset: DatasetEntity, train_type: TrainType = TrainType.Incremental)[source]#

Bases: LightningDataModule

Visual Prompting DataModule.

Parameters:
  • config (Union[DictConfig, ListConfig]) – Configuration.

  • dataset (DatasetEntity) – Dataset entity.

prepare_data_per_node#

If True, each LOCAL_RANK=0 will call prepare data. Otherwise only NODE_RANK=0, LOCAL_RANK=0 will prepare data.

allow_zero_length_dataloader_with_multiple_devices#

If True, dataloader with zero length within local rank is allowed. Default value is False.

predict_dataloader() DataLoader[source]#

Predict Dataloader.

Returns:

Predict Dataloader.

Return type:

DataLoader

setup(stage: str | None = None) None[source]#

Setup Visual Prompting Data Module.

Parameters:

stage (Optional[str], optional) – train/val/test stages, defaults to None.

summary()[source]#

Print size of the dataset, number of images.

test_dataloader() DataLoader[source]#

Test Dataloader.

Returns:

Test Dataloader.

Return type:

DataLoader

train_dataloader() DataLoader[source]#

Train Dataloader.

Returns:

Train dataloader.

Return type:

DataLoader

val_dataloader() DataLoader[source]#

Validation Dataloader.

Returns:

Validation Dataloader.

Return type:

DataLoader

class otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset.OTXVisualPromptingDataset(mode: Subset, dataset: DatasetEntity, image_size: int, mean: List[float], std: List[float], offset_bbox: int = 0, use_point: bool = False, use_bbox: bool = False)[source]#

Bases: Dataset

Visual Prompting Dataset Adaptor.

Parameters:
  • dataset (DatasetEntity) – Dataset entity.

  • image_size (int) – Target size to resize image.

  • mean (List[float]) – Mean for normalization.

  • std (List[float]) – Standard deviation for normalization.

  • offset_bbox (int) – Offset to apply to the bounding box, defaults to 0.

static get_prompts(dataset_item: DatasetItemEntity, dataset_labels: List[LabelEntity], prob: float = 1.0, mode: Subset = Subset.TESTING) Dict[str, Any][source]#

Get propmts from dataset_item.

Parameters:
  • dataset_item (DatasetItemEntity) – Dataset item entity.

  • dataset_labels (List[LabelEntity]) – Label information.

  • prob (float) – Probability of which prompts will be generated.

  • mode (Subset) – To check which mode is used between training, validation, and testing.

Returns:

Processed prompts with ground truths.

Return type:

Dict[str, Any]

class otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset.OTXZeroShotVisualPromptingDataset(mode: Subset, dataset: DatasetEntity, image_size: int, mean: List[float], std: List[float], offset_bbox: int = 0, use_point: bool = False, use_bbox: bool = False)[source]#

Bases: OTXVisualPromptingDataset

Visual Prompting for Zero-shot learning Dataset Adaptor.

otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset.convert_polygon_to_mask(shape: Polygon, width: int, height: int) ndarray[source]#

Convert polygon to mask.

Parameters:
  • shape (Polygon) – Polygon to convert.

  • width (int) – Width of image.

  • height (int) – Height of image.

Returns:

Generated mask from given polygon.

Return type:

np.ndarray

otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset.generate_bbox(x1: int, y1: int, x2: int, y2: int, width: int, height: int, offset_bbox: int = 0) List[int][source]#

Generate bounding box.

Parameters:
  • x1 (int) – Bounding box coordinates. # type: ignore

  • y1 (int) – Bounding box coordinates. # type: ignore

  • x2 (int) – Bounding box coordinates. # type: ignore

  • y2 (int) – Bounding box coordinates. # type: ignore

  • width (int) – Width of image.

  • height (int) – Height of image.

  • offset_bbox (int) – Offset to apply to the bounding box, defaults to 0.

Returns:

Generated bounding box.

Return type:

List[int]

otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset.generate_bbox_from_mask(gt_mask: ndarray, width: int, height: int) List[int][source]#

Generate bounding box from given mask.

Parameters:
  • gt_mask (np.ndarry) – Mask to generate bounding box.

  • width (int) – Width of image.

  • height (int) – Height of image.

Returns:

Generated bounding box from given mask.

Return type:

List[int]

otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset.get_transform(image_size: int = 1024, mean: List[float] = [123.675, 116.28, 103.53], std: List[float] = [58.395, 57.12, 57.375]) MultipleInputsCompose[source]#

Get transform pipeline.

Parameters:
  • image_size (int) – Size of image. Defaults to 1024.

  • mean (List[float]) – Mean for normalization. Defaults to [123.675, 116.28, 103.53].

  • std (List[float]) – Standard deviation for normalization. Defaults to [58.395, 57.12, 57.375].

Returns:

Transform pipeline.

Return type:

MultipleInputsCompose