gstreamer_analytics/auto/model_info.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{TensorDimOrder, ffi};
7use glib::translate::*;
8
9glib::wrapper! {
10 /// The [`ModelInfo`][crate::ModelInfo] is an object storing artifical neural network
11 /// model metadata describing the input and output tensors. These information's
12 /// are required by inference elements.
13 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14 pub struct ModelInfo(Boxed<ffi::GstAnalyticsModelInfo>);
15
16 match fn {
17 copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::gst_analytics_modelinfo_get_type(), ptr as *mut _) as *mut ffi::GstAnalyticsModelInfo,
18 free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::gst_analytics_modelinfo_get_type(), ptr as *mut _),
19 type_ => || ffi::gst_analytics_modelinfo_get_type(),
20 }
21}
22
23impl ModelInfo {
24 /// Retrieve the dimension ordering for a given tensor.
25 ///
26 /// The dimension ordering specifies how multi-dimensional tensor data is
27 /// laid out in memory:
28 /// - Row-major (C/NumPy style): Last dimension changes fastest in memory
29 /// - Column-major (Fortran style): First dimension changes fastest in memory
30 ///
31 /// If not specified in the modelinfo, defaults to row-major.
32 /// ## `tensor_name`
33 /// The name of the tensor
34 ///
35 /// # Returns
36 ///
37 /// The dimension order as [`TensorDimOrder`][crate::TensorDimOrder]
38 #[doc(alias = "gst_analytics_modelinfo_get_dims_order")]
39 #[doc(alias = "get_dims_order")]
40 pub fn dims_order(&self, tensor_name: &str) -> TensorDimOrder {
41 unsafe {
42 from_glib(ffi::gst_analytics_modelinfo_get_dims_order(
43 mut_override(self.to_glib_none().0),
44 tensor_name.to_glib_none().0,
45 ))
46 }
47 }
48
49 /// Get the group ID that groups related tensors together (e.g., all outputs
50 /// from the same model).
51 ///
52 /// The group ID is stored in the modelinfo section and is global for all
53 /// tensors in the model.
54 ///
55 /// # Returns
56 ///
57 /// The group ID string, or [`None`] if not found.
58 /// The caller must free this with `g_free()` when done.
59 #[doc(alias = "gst_analytics_modelinfo_get_group_id")]
60 #[doc(alias = "get_group_id")]
61 pub fn group_id(&self) -> Option<glib::GString> {
62 unsafe {
63 from_glib_full(ffi::gst_analytics_modelinfo_get_group_id(mut_override(
64 self.to_glib_none().0,
65 )))
66 }
67 }
68
69 /// Get the tensor ID from the modelinfo for the specified tensor name.
70 ///
71 /// The tensor ID is ideally registered in the [Tensor ID Registry](https://github.com/collabora/tensor-id-registry/blob/main/tensor-id-register.md).
72 /// ## `tensor_name`
73 /// The name of the tensor
74 ///
75 /// # Returns
76 ///
77 /// The tensor ID string, or [`None`] if not found.
78 /// The caller must free this with `g_free()` when done.
79 #[doc(alias = "gst_analytics_modelinfo_get_id")]
80 #[doc(alias = "get_id")]
81 pub fn id(&self, tensor_name: &str) -> Option<glib::GString> {
82 unsafe {
83 from_glib_full(ffi::gst_analytics_modelinfo_get_id(
84 mut_override(self.to_glib_none().0),
85 tensor_name.to_glib_none().0,
86 ))
87 }
88 }
89
90 /// Get the group ID as a GQuark for efficient string comparison and storage.
91 ///
92 /// Using GQuark is more efficient than string comparison when you need to
93 /// compare multiple group IDs.
94 ///
95 /// # Returns
96 ///
97 /// The GQuark of the group ID, or 0 if not found
98 #[doc(alias = "gst_analytics_modelinfo_get_quark_group_id")]
99 #[doc(alias = "get_quark_group_id")]
100 pub fn quark_group_id(&self) -> glib::Quark {
101 unsafe {
102 from_glib(ffi::gst_analytics_modelinfo_get_quark_group_id(
103 mut_override(self.to_glib_none().0),
104 ))
105 }
106 }
107
108 /// Get the tensor ID as a GQuark for efficient string comparison and storage.
109 ///
110 /// Using GQuark is more efficient than string comparison when you need to
111 /// compare multiple IDs.
112 /// ## `tensor_name`
113 /// The name of the tensor
114 ///
115 /// # Returns
116 ///
117 /// The GQuark of the tensor ID, or 0 if not found
118 #[doc(alias = "gst_analytics_modelinfo_get_quark_id")]
119 #[doc(alias = "get_quark_id")]
120 pub fn quark_id(&self, tensor_name: &str) -> glib::Quark {
121 unsafe {
122 from_glib(ffi::gst_analytics_modelinfo_get_quark_id(
123 mut_override(self.to_glib_none().0),
124 tensor_name.to_glib_none().0,
125 ))
126 }
127 }
128
129 /// Retrieve the version string of the modelinfo file format.
130 ///
131 /// The version is in the format "Major.Minor" and is stored in the
132 /// [modelinfo] section of the modelinfo file.
133 ///
134 /// # Returns
135 ///
136 /// The version string (e.g., "1.0").
137 /// The caller must free this with `g_free()` when done.
138 /// Defaults to "1.0" if not specified.
139 #[doc(alias = "gst_analytics_modelinfo_get_version")]
140 #[doc(alias = "get_version")]
141 pub fn version(&self) -> glib::GString {
142 unsafe {
143 from_glib_full(ffi::gst_analytics_modelinfo_get_version(mut_override(
144 self.to_glib_none().0,
145 )))
146 }
147 }
148
149 /// Load a modelinfo file associated with the given model file.
150 ///
151 /// This function attempts to load a `.modelinfo` file in the following order:
152 /// 1. `{model_filename}.modelinfo`
153 /// 2. `{model_filename_without_extension}.modelinfo`
154 ///
155 /// The modelinfo file contains metadata for the model's input and output tensors,
156 /// including normalization ranges, dimension ordering, tensor IDs, etc.
157 ///
158 /// The loaded modelinfo must be freed with `gst_analytics_modelinfo_free()`
159 /// when no longer needed.
160 /// ## `model_filename`
161 /// Path to the model file (e.g., "model.onnx", "model.tflite")
162 ///
163 /// # Returns
164 ///
165 /// A new [`ModelInfo`][crate::ModelInfo] instance,
166 /// or [`None`] if the modelinfo file could not be found or loaded.
167 #[doc(alias = "gst_analytics_modelinfo_load")]
168 pub fn load(model_filename: impl AsRef<std::path::Path>) -> Option<ModelInfo> {
169 assert_initialized_main_thread!();
170 unsafe {
171 from_glib_full(ffi::gst_analytics_modelinfo_load(
172 model_filename.as_ref().to_glib_none().0,
173 ))
174 }
175 }
176}
177
178unsafe impl Send for ModelInfo {}
179unsafe impl Sync for ModelInfo {}