Skip to main content

ModelInfo

Struct ModelInfo 

Source
pub struct ModelInfo { /* private fields */ }
Expand description

The ModelInfo is an object storing artifical neural network model metadata describing the input and output tensors. These information’s are required by inference elements.

GLib type: Boxed type with copy-on-clone semantics.

Implementations§

Source§

impl ModelInfo

Source

pub fn as_ptr(&self) -> *mut GstAnalyticsModelInfo

Return the inner pointer to the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GstAnalyticsModelInfo) -> &Self

Borrows the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow_mut( ptr: &mut *mut GstAnalyticsModelInfo, ) -> &mut Self

Borrows the underlying C value mutably.

Source§

impl ModelInfo

Source

pub fn dims_order(&self, tensor_name: &str) -> TensorDimOrder

Retrieve the dimension ordering for a given tensor.

The dimension ordering specifies how multi-dimensional tensor data is laid out in memory:

  • Row-major (C/NumPy style): Last dimension changes fastest in memory
  • Column-major (Fortran style): First dimension changes fastest in memory

If not specified in the modelinfo, defaults to row-major.

§tensor_name

The name of the tensor

§Returns

The dimension order as TensorDimOrder

Source

pub fn group_id(&self) -> Option<GString>

Get the group ID that groups related tensors together (e.g., all outputs from the same model).

The group ID is stored in the modelinfo section and is global for all tensors in the model.

§Returns

The group ID string, or None if not found. The caller must free this with g_free() when done.

Source

pub fn id(&self, tensor_name: &str) -> Option<GString>

Get the tensor ID from the modelinfo for the specified tensor name.

The tensor ID is ideally registered in the Tensor ID Registry.

§tensor_name

The name of the tensor

§Returns

The tensor ID string, or None if not found. The caller must free this with g_free() when done.

Source

pub fn quark_group_id(&self) -> Quark

Get the group ID as a GQuark for efficient string comparison and storage.

Using GQuark is more efficient than string comparison when you need to compare multiple group IDs.

§Returns

The GQuark of the group ID, or 0 if not found

Source

pub fn quark_id(&self, tensor_name: &str) -> Quark

Get the tensor ID as a GQuark for efficient string comparison and storage.

Using GQuark is more efficient than string comparison when you need to compare multiple IDs.

§tensor_name

The name of the tensor

§Returns

The GQuark of the tensor ID, or 0 if not found

Source

pub fn version(&self) -> GString

Retrieve the version string of the modelinfo file format.

The version is in the format “Major.Minor” and is stored in the [modelinfo] section of the modelinfo file.

§Returns

The version string (e.g., “1.0”). The caller must free this with g_free() when done. Defaults to “1.0” if not specified.

Source

pub fn load(model_filename: impl AsRef<Path>) -> Option<ModelInfo>

Load a modelinfo file associated with the given model file.

This function attempts to load a .modelinfo file in the following order:

  1. {model_filename}.modelinfo
  2. {model_filename_without_extension}.modelinfo

The modelinfo file contains metadata for the model’s input and output tensors, including normalization ranges, dimension ordering, tensor IDs, etc.

The loaded modelinfo must be freed with gst_analytics_modelinfo_free() when no longer needed.

§model_filename

Path to the model file (e.g., “model.onnx”, “model.tflite”)

§Returns

A new ModelInfo instance, or None if the modelinfo file could not be found or loaded.

Source§

impl ModelInfo

Source

pub fn find_tensor_name( &self, dir: ModelInfoTensorDirection, index: usize, in_tensor_name: Option<&str>, data_type: TensorDataType, dims: &[usize], ) -> Option<GString>

Find the name of a tensor in the modelinfo that matches the given criteria.

The function performs the following checks in order:

  1. If in_tensor_name is provided and exists in modelinfo, validate it matches
  2. Search by index for the specified direction and validate
  3. Search by dimensions and data type
§dir

The tensor direction (input or output)

§index

The tensor index within the specified direction

§in_tensor_name

An optional tensor name hint to check first

§data_type

The tensor data type to match

§dims

The dimension sizes. Use -1 for dynamic dimensions.

§Returns

The tensor name if found, or None otherwise. The caller must free this with g_free() when done.

Source

pub fn input_scales_offsets( &self, tensor_name: &str, input_mins: &[f64], input_maxs: &[f64], ) -> Option<(Slice<f64>, Slice<f64>)>

Calculate normalization scales and offsets to transform input data to the target range.

This function calculates transformation parameters to convert from the actual input data range [input_min, input_max] to the target range expected by the model [target_min, target_max]: normalized_value[i] = input[i] * output_scale[i] + output_offset[i]

The target ranges are read from the modelinfo ranges field: Semicolon-separated list of comma-separated pairs (min,max) for per-channel target ranges (e.g., “0.0,255.0;-1.0,1.0;0.0,1.0” for RGB channels with different target ranges).

Common input ranges:

  • [0.0, 255.0]: 8-bit unsigned (uint8)
  • [-128.0, 127.0]: 8-bit signed (int8)
  • [0.0, 65535.0]: 16-bit unsigned (uint16)
  • [-32768.0, 32767.0]: 16-bit signed (int16)
  • [0.0, 1.0]: Normalized float
  • [-1.0, 1.0]: Normalized signed float

The number of input ranges (num_input_ranges) must equal the number of target ranges in the modelinfo. The function will return FALSE if they don’t match.

The caller must free output_scales and output_offsets with g_free() when done.

§tensor_name

The name of the tensor

§input_mins

The minimum values of the actual input data for each channel

§input_maxs

The maximum values of the actual input data for each channel

§Returns

true on success, false on error, if ranges field is not found, or if num_input_ranges doesn’t match the number of target ranges in the modelinfo

§output_scales

The scale values for normalization

§output_offsets

The offset values for normalization

Source

pub fn target_ranges( &self, tensor_name: &str, ) -> Option<(Slice<f64>, Slice<f64>)>

Retrieve all target ranges (min/max pairs) expected by the model for a given tensor.

This function retrieves all target ranges from the ranges field in the modelinfo. Each range represents the expected input range for a channel or dimension that the model requires.

The function reads from the ranges field: Semicolon-separated list of comma-separated pairs (min,max) for per-channel target ranges (e.g., “0.0,1.0;-1.0,1.0;0.0,1.0” for RGB channels with different normalization targets).

The caller must free mins and maxs with g_free() when done.

§tensor_name

The name of the tensor

§Returns

true if range information was found and valid, false otherwise

§mins

The minimum values for each target range

§maxs

The maximum values for each target range

Trait Implementations§

Source§

impl Clone for ModelInfo

Source§

fn clone(&self) -> Self

Copies the boxed type with the type-specific copy function.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ModelInfo> for Value

Source§

fn from(o: ModelInfo) -> Self

Converts to this type from the input type.
Source§

impl HasParamSpec for ModelInfo

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = ModelInfo

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<'_, ModelInfo>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for ModelInfo

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for ModelInfo

Source§

fn cmp(&self, other: &ModelInfo) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ModelInfo

Source§

fn eq(&self, other: &ModelInfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ModelInfo

Source§

fn partial_cmp(&self, other: &ModelInfo) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for ModelInfo

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl Eq for ModelInfo

Source§

impl Send for ModelInfo

Source§

impl StructuralPartialEq for ModelInfo

Source§

impl Sync for ModelInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GPtrArray, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSendValue for T
where T: Send + ToValue + ?Sized,

Source§

fn to_send_value(&self) -> SendValue

Returns a SendValue clone of self.
Source§

impl<T> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,