Yolo#
- class model_api.models.yolo.DetectionBox(x, y, w, h)#
Bases:
tuple
Create new instance of DetectionBox(x, y, w, h)
- h#
Alias for field number 3
- w#
Alias for field number 2
- x#
Alias for field number 0
- y#
Alias for field number 1
- class model_api.models.yolo.YOLO(inference_adapter, configuration, preload=False)#
Bases:
DetectionModel
Detection Model constructor
It extends the ImageModel construtor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the model has more than 1 image inputs
- class Params(param, sides)#
Bases:
object
- classmethod parameters()#
Defines the description and type of configurable data parameters for the wrapper.
See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.
- The example of possible data parameter:
- ‘confidence_threshold’: NumericalValue(
default_value=0.5, description=”Threshold value for detection box confidence”
)
The method must be implemented in each specific inherited wrapper.
- Returns:
the dictionary with defined wrapper data parameters
- postprocess(outputs, meta)#
Interface for postprocess method.
- Parameters:
outputs (dict) –
model raw output in the following format: {
’output_layer_name_1’: raw_result_1, ‘output_layer_name_2’: raw_result_2, …
}
meta (dict) – the input metadata obtained from preprocess method
- Returns:
postprocessed data in the format defined by wrapper
- class model_api.models.yolo.YOLOF(inference_adapter, configuration={}, preload=False)#
Bases:
YOLO
Detection Model constructor
It extends the ImageModel construtor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the model has more than 1 image inputs
- class Params(classes, num, sides, anchors)#
Bases:
object
- classmethod parameters()#
Defines the description and type of configurable data parameters for the wrapper.
See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.
- The example of possible data parameter:
- ‘confidence_threshold’: NumericalValue(
default_value=0.5, description=”Threshold value for detection box confidence”
)
The method must be implemented in each specific inherited wrapper.
- Returns:
the dictionary with defined wrapper data parameters
- class model_api.models.yolo.YOLOX(inference_adapter, configuration={}, preload=False)#
Bases:
DetectionModel
Detection Model constructor
It extends the ImageModel construtor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the model has more than 1 image inputs
- classmethod parameters()#
Defines the description and type of configurable data parameters for the wrapper.
See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.
- The example of possible data parameter:
- ‘confidence_threshold’: NumericalValue(
default_value=0.5, description=”Threshold value for detection box confidence”
)
The method must be implemented in each specific inherited wrapper.
- Returns:
the dictionary with defined wrapper data parameters
- postprocess(outputs, meta)#
Interface for postprocess method.
- Parameters:
outputs (dict) –
model raw output in the following format: {
’output_layer_name_1’: raw_result_1, ‘output_layer_name_2’: raw_result_2, …
}
meta (dict) – the input metadata obtained from preprocess method
- Returns:
postprocessed data in the format defined by wrapper
- preprocess(inputs)#
Data preprocess method
- It performs basic preprocessing of a single image:
Resizes the image to fit the model input size via the defined resize type
Normalizes the image: subtracts means, divides by scales, switch channels BGR-RGB
Changes the image layout according to the model input layout
Also, it keeps the size of original image and resized one as original_shape and resized_shape in the metadata dictionary.
Note
It supports only models with single image input. If the model has more image inputs or has additional supported inputs, the preprocess should be overloaded in a specific wrapper.
- Parameters:
inputs (ndarray) – a single image as 3D array in HWC layout
- Returns:
- {
‘input_layer_name’: preprocessed_image
}
the input metadata, which might be used in postprocess method
- Return type:
the preprocessed image in the following format
- set_strides_grids()#
- class model_api.models.yolo.YOLOv5(inference_adapter, configuration, preload=False)#
Bases:
DetectionModel
Reimplementation of ultralytics.YOLO
Detection Model constructor
It extends the ImageModel construtor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the model has more than 1 image inputs
- classmethod parameters()#
Defines the description and type of configurable data parameters for the wrapper.
See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.
- The example of possible data parameter:
- ‘confidence_threshold’: NumericalValue(
default_value=0.5, description=”Threshold value for detection box confidence”
)
The method must be implemented in each specific inherited wrapper.
- Returns:
the dictionary with defined wrapper data parameters
- postprocess(outputs, meta)#
Interface for postprocess method.
- Parameters:
outputs (dict) –
model raw output in the following format: {
’output_layer_name_1’: raw_result_1, ‘output_layer_name_2’: raw_result_2, …
}
meta (dict) – the input metadata obtained from preprocess method
- Returns:
postprocessed data in the format defined by wrapper
- class model_api.models.yolo.YOLOv8(inference_adapter, configuration, preload=False)#
Bases:
YOLOv5
YOLOv5 and YOLOv8 are identical in terms of inference
Detection Model constructor
It extends the ImageModel construtor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the model has more than 1 image inputs
- class model_api.models.yolo.YoloV3ONNX(inference_adapter, configuration={}, preload=False)#
Bases:
DetectionModel
Detection Model constructor
It extends the ImageModel construtor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the model has more than 1 image inputs
- classmethod parameters()#
Defines the description and type of configurable data parameters for the wrapper.
See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.
- The example of possible data parameter:
- ‘confidence_threshold’: NumericalValue(
default_value=0.5, description=”Threshold value for detection box confidence”
)
The method must be implemented in each specific inherited wrapper.
- Returns:
the dictionary with defined wrapper data parameters
- postprocess(outputs, meta)#
Interface for postprocess method.
- Parameters:
outputs (dict) –
model raw output in the following format: {
’output_layer_name_1’: raw_result_1, ‘output_layer_name_2’: raw_result_2, …
}
meta (dict) – the input metadata obtained from preprocess method
- Returns:
postprocessed data in the format defined by wrapper
- preprocess(inputs)#
Data preprocess method
- It performs basic preprocessing of a single image:
Resizes the image to fit the model input size via the defined resize type
Normalizes the image: subtracts means, divides by scales, switch channels BGR-RGB
Changes the image layout according to the model input layout
Also, it keeps the size of original image and resized one as original_shape and resized_shape in the metadata dictionary.
Note
It supports only models with single image input. If the model has more image inputs or has additional supported inputs, the preprocess should be overloaded in a specific wrapper.
- Parameters:
inputs (ndarray) – a single image as 3D array in HWC layout
- Returns:
- {
‘input_layer_name’: preprocessed_image
}
the input metadata, which might be used in postprocess method
- Return type:
the preprocessed image in the following format
- class model_api.models.yolo.YoloV4(inference_adapter, configuration={}, preload=False)#
Bases:
YOLO
Detection Model constructor
It extends the ImageModel construtor.
- Parameters:
inference_adapter (InferenceAdapter) – allows working with the specified executor
configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes
preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference
- Raises:
WrapperError – if the model has more than 1 image inputs
- class Params(classes, num, sides, anchors, mask, layout)#
Bases:
object
- classmethod parameters()#
Defines the description and type of configurable data parameters for the wrapper.
See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.
- The example of possible data parameter:
- ‘confidence_threshold’: NumericalValue(
default_value=0.5, description=”Threshold value for detection box confidence”
)
The method must be implemented in each specific inherited wrapper.
- Returns:
the dictionary with defined wrapper data parameters
- model_api.models.yolo.permute_to_N_HWA_K(tensor, K, output_layout)#
Transpose/reshape a tensor from (N, (A x K), H, W) to (N, (HxWxA), K)
- model_api.models.yolo.sigmoid(x)#
- model_api.models.yolo.xywh2xyxy(xywh)#