otx.api.utils.dataset_utils#

Dataset utils.

Functions

add_saliency_maps_to_dataset_item(...[, ...])

Add saliency maps (2D array for class-agnostic saliency map, 3D array or list or 2D arrays for class-wise saliency maps) to a single dataset item.

contains_anomalous_images(dataset)

Check if a dataset contains any items with the anomalous label.

get_fully_annotated_idx(dataset)

Find the indices of the fully annotated items in a dataset.

get_global_subset(dataset)

Extract a subset that contains only the global annotations.

get_local_subset(dataset[, ...])

Extract a subset that contains only those dataset items that have local annotations.

non_linear_normalization(saliency_map)

Use non-linear normalization y=x**1.5 for 2D saliency maps.

split_local_global_dataset(dataset)

Split a dataset into the globally and locally annotated subsets.

split_local_global_resultset(resultset)

Split a resultset into the globally and locally annotated resultsets.

otx.api.utils.dataset_utils.add_saliency_maps_to_dataset_item(dataset_item: DatasetItemEntity, saliency_map: List[ndarray | None] | ndarray, model: ModelEntity | None, labels: List[LabelEntity], predicted_scored_labels: List[ScoredLabel] | None = None, explain_predicted_classes: bool = True, process_saliency_maps: bool = False)[source]#

Add saliency maps (2D array for class-agnostic saliency map, 3D array or list or 2D arrays for class-wise saliency maps) to a single dataset item.

otx.api.utils.dataset_utils.contains_anomalous_images(dataset: DatasetEntity) bool[source]#

Check if a dataset contains any items with the anomalous label.

Parameters:

dataset (DatasetEntity) – Dataset to check for anomalous items.

Returns:

True if the dataset contains anomalous items, False otherwise.

Return type:

bool

otx.api.utils.dataset_utils.get_fully_annotated_idx(dataset: DatasetEntity) List[int][source]#

Find the indices of the fully annotated items in a dataset.

A dataset item is fully annotated if local annotations are available, or if the item has the normal label.

Parameters:

dataset (DatasetEntity) – Dataset that may contain both partially and fully annotated items.

Returns:

List of indices of the fully annotated dataset items.

Return type:

List[int]

otx.api.utils.dataset_utils.get_global_subset(dataset: DatasetEntity) DatasetEntity[source]#

Extract a subset that contains only the global annotations.

Parameters:

dataset (DatasetEntity) – Dataset from which we want to extract the globally annotated subset.

Returns:

Output dataset with only global annotations

Return type:

DatasetEntity

otx.api.utils.dataset_utils.get_local_subset(dataset: DatasetEntity, fully_annotated_idx: List[int] | None = None, include_normal: bool = True) DatasetEntity[source]#

Extract a subset that contains only those dataset items that have local annotations.

Parameters:
  • dataset (DatasetEntity) – Dataset from which we want to extract the locally annotated subset.

  • fully_annotated_idx (Optional[List[int]]) – The indices of the fully annotated dataset items. If not provided, the function will compute the indices before creating the subset.

  • include_normal (bool) – When true, global normal annotations will be included in the local dataset.

Returns:

Output dataset with only local annotations

Return type:

DatasetEntity

otx.api.utils.dataset_utils.non_linear_normalization(saliency_map: ndarray) ndarray[source]#

Use non-linear normalization y=x**1.5 for 2D saliency maps.

otx.api.utils.dataset_utils.split_local_global_dataset(dataset: DatasetEntity) Tuple[DatasetEntity, DatasetEntity][source]#

Split a dataset into the globally and locally annotated subsets.

Parameters:

dataset (DatasetEntity) – Input dataset

Returns:

Tuple of the globally and locally annotated subsets.

Return type:

Tuple[DatasetEntity, DatasetEntity]

otx.api.utils.dataset_utils.split_local_global_resultset(resultset: ResultSetEntity) Tuple[ResultSetEntity, ResultSetEntity][source]#

Split a resultset into the globally and locally annotated resultsets.

Parameters:

resultset (ResultSetEntity) – Input resultset

Returns:

Tuple of the globally and locally annotated resultsets.

Return type:

Tuple[ResultSetEntity, ResultSetEntity]