analytics: change tensor-id and use new API

- tensor-id changed to match tensor-id-registry at https://github.com/collabora/tensor-id-registry
- Use new GstTensorMeta API to get tensor.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8548>
This commit is contained in:
Daniel Morin 2025-05-05 17:38:08 -04:00 committed by GStreamer Marge Bot
parent ec60daa66d
commit 57e8dbfeb4

View File

@ -52,11 +52,12 @@
* *
* ## Example launch command: * ## Example launch command:
* |[ * |[
* gst-launch-1.0 multifilesrc location=/onnx-models/images/bus.jpg \ * gst-launch-1.0 filesrc location=/onnx-models/images/bus.jpg \
* ! decodebin ! videoconvert ! onnxinference execution-provider=cpu \ * ! jpegdec \
* model-file=/onnx-models/models/mobilenet_v1.onnx \ * ! videoconvertscale add-borders=1 \
* ! onnxinference execution-provider=cpu \
* model-file=/onnx-models/models/mobilenet_v1.onnx \
* ! classifiertensordecoder labels-file=labels.txt ! fakesink \ * ! classifiertensordecoder labels-file=labels.txt ! fakesink \
)
* ]| This pipeline create an tensor-decoder for classification model * ]| This pipeline create an tensor-decoder for classification model
* *
*/ */
@ -70,7 +71,7 @@
#include <math.h> #include <math.h>
#include <gst/analytics/analytics.h> #include <gst/analytics/analytics.h>
const gchar GST_MODEL_STD_IMAGE_CLASSIFICATION[] = "Gst.Model.Classifier.Std"; const gchar GST_MODEL_STD_IMAGE_CLASSIFICATION[] = "classification-generic-out";
GST_DEBUG_CATEGORY_STATIC (classifier_tensor_decoder_debug); GST_DEBUG_CATEGORY_STATIC (classifier_tensor_decoder_debug);
#define GST_CAT_DEFAULT classifier_tensor_decoder_debug #define GST_CAT_DEFAULT classifier_tensor_decoder_debug
@ -391,15 +392,12 @@ gst_classifier_tensor_decoder_decode (GstClassifierTensorDecoder * self,
gsize len; gsize len;
GQuark q, qmax; GQuark q, qmax;
gint max_idx = -1; gint max_idx = -1;
gsize index; const GstTensor *tensor;
GstTensor *tensor;
GstAnalyticsClsMtd cls_mtd; GstAnalyticsClsMtd cls_mtd;
index = gst_tensor_meta_get_index_from_id (tmeta, tensor = gst_tensor_meta_get_by_id (tmeta,
g_quark_from_static_string (GST_MODEL_STD_IMAGE_CLASSIFICATION)); g_quark_from_static_string (GST_MODEL_STD_IMAGE_CLASSIFICATION));
tensor = tmeta->tensors[index];
if (tensor->dims_order != GST_TENSOR_DIM_ORDER_ROW_MAJOR) { if (tensor->dims_order != GST_TENSOR_DIM_ORDER_ROW_MAJOR) {
GST_ELEMENT_ERROR (GST_BASE_TRANSFORM (self), STREAM, NOT_IMPLEMENTED, GST_ELEMENT_ERROR (GST_BASE_TRANSFORM (self), STREAM, NOT_IMPLEMENTED,
("Only row-major tensor are supported"), ("Only row-major tensor are supported"),