Utils#

class model_api.adapters.utils.InputTransform(reverse_input_channels=False, mean_values=None, scale_values=None, intensity_fn=None)#

Bases: object

__call__(inputs)#

Call self as a function.

class model_api.adapters.utils.Layout(layout='')#

Bases: object

static from_openvino(input)#

Create Layout from openvino input

static from_shape(shape)#

Create Layout from given shape

Return type:

str

static from_user_layouts(input_names, user_layouts)#

Create Layout for input based on user info

static parse_layouts(layout_string)#

Parse layout parameter in format “input0:NCHW,input1:NC” or “NCHW” (applied to all inputs)

Return type:

dict | None

model_api.adapters.utils.change_layout(image, layout)#

Changes the input image layout to fit the layout of the model input layer.

Parameters:
  • image (ndarray) – a single image as 3D array in HWC layout

  • layout (str) – target layout

Returns:

the image with layout aligned with the model layout

Return type:

ndarray

model_api.adapters.utils.create_intensity_fn(mode, *, max_value=None, window_center=None, window_width=None, percentile_low=1.0, percentile_high=99.0, scale_factor=1.0, min_value=0.0)#

Create a Python-side intensity transform callable for the given mode.

Returns None for ‘none’ mode (no transformation).

Return type:

Callable | None

model_api.adapters.utils.crop_resize(size, interpolation, pad_value, input_dtype='u8')#
Return type:

Callable

model_api.adapters.utils.crop_resize_graph(input, size, input_dtype='u8')#
Return type:

Node

model_api.adapters.utils.crop_resize_ocv(image, size)#
Return type:

ndarray

model_api.adapters.utils.get_rt_info_from_dict(rt_info_dict, path)#
Return type:

OVAny

model_api.adapters.utils.load_parameters_from_onnx(onnx_model)#
Return type:

dict[str, Any]

model_api.adapters.utils.range_scale_preprocess(scale_factor, min_value, max_value)#

Return an OV custom preprocess function for range_scale intensity scaling.

Return type:

Callable

model_api.adapters.utils.range_scale_preprocess_graph(output, *, scale_factor, min_value, max_value)#

OV graph: range_scale intensity scaling.

Multiplies by scale_factor, clamps to [min_value, max_value], then normalises to [0, 1] via (clamped - min) / (max - min).

Return type:

Node

model_api.adapters.utils.repeat_channels_preprocess()#

Return an OV custom preprocess function that repeats 1 channel to 3.

Return type:

Callable

model_api.adapters.utils.repeat_channels_preprocess_graph(output)#

OV graph: tile a single-channel tensor to 3 channels along the last axis.

Return type:

Node

model_api.adapters.utils.resize_image(size, interpolation, pad_value, input_dtype='u8')#
Return type:

Callable

model_api.adapters.utils.resize_image_graph(input, size, keep_aspect_ratio, interpolation, pad_value, input_dtype='u8')#
Return type:

Node

model_api.adapters.utils.resize_image_letterbox(size, interpolation, pad_value, input_dtype='u8')#
Return type:

Callable

model_api.adapters.utils.resize_image_letterbox_graph(input, size, interpolation, pad_value, input_dtype='u8')#
Return type:

Node

model_api.adapters.utils.resize_image_letterbox_ocv(image, size, interpolation=1, pad_value=0)#
Return type:

ndarray

model_api.adapters.utils.resize_image_ocv(image, size, keep_aspect_ratio=False, is_pad=False, pad_value=0, interpolation=1)#
Return type:

ndarray

model_api.adapters.utils.resize_image_with_aspect(size, interpolation, pad_value, input_dtype='u8')#
Return type:

Callable

model_api.adapters.utils.resize_image_with_aspect_ocv(image, size, interpolation=1)#
Return type:

ndarray

model_api.adapters.utils.setup_python_preprocessing_pipeline(layout, resize_mode, interpolation_mode, target_shape, pad_value, dtype=<class 'int'>, brg2rgb=False, mean=None, scale=None, input_idx=0, intensity_mode='none', intensity_max_value=None, intensity_window_center=None, intensity_window_width=None, intensity_percentile_low=1.0, intensity_percentile_high=99.0, intensity_scale_factor=1.0, intensity_min_value=0.0, intensity_repeat_channels=False)#

Sets up a Python preprocessing pipeline for model adapters.

Parameters:
  • layout (str) – Target layout for the input (e.g., “NCHW”, “NHWC”)

  • resize_mode (str) – Type of resizing (“crop”, “standard”, “fit_to_window”, “fit_to_window_letterbox”)

  • interpolation_mode (str) – Interpolation method (“LINEAR”, “CUBIC”, “NEAREST”)

  • target_shape (tuple[int, ...]) – Target shape for resizing

  • pad_value (int) – Padding value for letterbox resizing

  • dtype (type) – Data type for preprocessing

  • brg2rgb (bool) – Whether to convert BGR to RGB

  • mean (list[Any] | None) – Mean values for normalization

  • scale (list[Any] | None) – Scale values for normalization

  • input_idx (int) – Input index (unused but kept for compatibility)

  • intensity_mode (str) – Intensity scaling mode applied before normalization

  • intensity_max_value (float | None) – Maximum input value for scale_to_unit or range_scale

  • intensity_window_center (float | None) – Window center for window intensity mode

  • intensity_window_width (float | None) – Window width for window intensity mode

  • intensity_percentile_low (float) – Lower percentile for percentile intensity mode

  • intensity_percentile_high (float) – Upper percentile for percentile intensity mode

  • intensity_scale_factor (float) – Scale factor for range_scale intensity mode

  • intensity_min_value (float) – Minimum output value for range_scale intensity mode

  • intensity_repeat_channels (bool) – Whether to repeat single-channel input to 3 channels

Returns:

A preprocessing function that can be applied to input data

Return type:

Callable

model_api.adapters.utils.window_preprocess(window_center, window_width)#

Return an OV custom preprocess function for window intensity scaling.

Return type:

Callable

model_api.adapters.utils.window_preprocess_graph(output, *, window_center, window_width)#

OV graph: window intensity scaling [center-width/2, center+width/2] to [0, 1].

Return type:

Node