otx.algorithms.common.utils#
Collection of utils to run common OTX algorithms.
Functions
|
Embeds serialized data to IR xml file. |
|
Function for getting image indices per class. |
|
Function for getting old & new indices of dataset. |
|
Loading model template function. |
|
Return Task classes. |
|
Get argument spec of function. |
|
Load an image and cache it if it's a training video frame. |
|
Set random seed. |
|
Append distributed training rank suffix to the file name. |
|
Reads py config to a dict. |
Returns a default number of infer request for OV models. |
|
Checks if XPU device is available. |
|
Check if HPU device is available. |
|
|
Cast bf16 tensor to fp32 before processed by numpy. |
|
Find a config file according to device. |
Classes
TrainingProgressCallback class for time monitoring. |
|
|
InferenceProgressCallback class for time monitoring. |
|
Progress callback used for optimization using NNCF. |
Defauldict type object to avoid deepcopy. |
|
|
DataLoader implementation for ClassificationOpenVINOTask. |
- class otx.algorithms.common.utils.InferenceProgressCallback(num_test_steps, update_progress_callback, **kwargs)[source]#
Bases:
TimeMonitorCallback
InferenceProgressCallback class for time monitoring.
- class otx.algorithms.common.utils.OTXOpenVinoDataLoader(dataset: DatasetEntity, inferencer: Any, shuffle: bool = True)[source]#
Bases:
object
DataLoader implementation for ClassificationOpenVINOTask.
- class otx.algorithms.common.utils.OptimizationProgressCallback(update_progress_callback, loading_stage_progress_percentage: int = 5, initialization_stage_progress_percentage: int = 5, **kwargs)[source]#
Bases:
TrainingProgressCallback
Progress callback used for optimization using NNCF.
- There are three stages to the progress bar:
5 % model is loaded
10 % compressed model is initialized
10-100 % compressed model is being fine-tuned
- class otx.algorithms.common.utils.TrainingProgressCallback(update_progress_callback, **kwargs)[source]#
Bases:
TimeMonitorCallback
TrainingProgressCallback class for time monitoring.
- class otx.algorithms.common.utils.UncopiableDefaultDict[source]#
Bases:
defaultdict
Defauldict type object to avoid deepcopy.
- otx.algorithms.common.utils.append_dist_rank_suffix(file_name: str | Path) str [source]#
Append distributed training rank suffix to the file name.
- otx.algorithms.common.utils.cast_bf16_to_fp32(tensor: Tensor) Tensor [source]#
Cast bf16 tensor to fp32 before processed by numpy.
numpy doesn’t support bfloat16, it is required to convert bfloat16 tensor to float32.
- otx.algorithms.common.utils.embed_ir_model_data(xml_file: str, data_items: Dict[Tuple[str, str], Any]) None [source]#
Embeds serialized data to IR xml file.
- Parameters:
xml_file – a path to IR xml file.
data_items – a dict with tuple-keyworded serialized objects.
- otx.algorithms.common.utils.get_arg_spec(fn: Callable, depth: int | None = None) Tuple[str, ...] [source]#
Get argument spec of function.
- otx.algorithms.common.utils.get_cfg_based_on_device(cfg_file_path: str | Path) str [source]#
Find a config file according to device.
- otx.algorithms.common.utils.get_cls_img_indices(labels, dataset)[source]#
Function for getting image indices per class.
- Parameters:
labels (List[LabelEntity]) – List of labels
dataset (DatasetEntity) – dataset entity
- otx.algorithms.common.utils.get_default_async_reqs_num() int [source]#
Returns a default number of infer request for OV models.
- otx.algorithms.common.utils.get_image(results: Dict[str, Any], cache_dir: str, to_float32=False) ndarray [source]#
Load an image and cache it if it’s a training video frame.
- Parameters:
- Returns:
The loaded image.
- Return type:
np.ndarray
- otx.algorithms.common.utils.get_old_new_img_indices(labels, new_classes, dataset)[source]#
Function for getting old & new indices of dataset.
- Parameters:
labels (List[LabelEntity]) – List of labels
new_classes (List[str]) – List of new classes
dataset (DatasetEntity) – dataset entity
- otx.algorithms.common.utils.set_random_seed(seed, logger=None, deterministic=False)[source]#
Set random seed.
- Parameters:
seed (int) – Seed to be used.
logger (logging.Logger) – logger for logging seed info
deterministic (bool) – Whether to set the deterministic option for CUDNN backend, i.e., set torch.backends.cudnn.deterministic to True and torch.backends.cudnn.benchmark to False. Default: False.