GstInference with GstClassificationMeta metadata

From RidgeRun Developer Connection
Jump to: navigation, search



Previous: Metadatas Index Next: Metadatas/GstEmbeddingMeta





This metadata consists of a probability for each of the model's trained classes.

GstClassificationMeta example

Fields

All classification elements on GstInference use the same metadata standard. GstClassificationMeta consist on the following fields:

field type description
num_labels gint The number of labels outputted by the model. This can vary from model to model.
label_probs gdouble * The probability for each label.

Access metadata

If you want to access this metadata from your custom Gstreamer element instead the process is fairly easy:

  1. Add a GstInference classification element such as InceptionV4 to your pipeline
  2. Include GstInference metadata header: #include "gst/r2inference/gstinferencemeta.h"
  3. Get a GstClassificationMeta object from the buffer: class_meta = (GstClassificationMeta *) gst_buffer_get_meta (frame->buffer, GST_CLASSIFICATION_META_API_TYPE);

All GstInference classification elements also raise a signal containing GstClassificationMeta, for details on how to use this signal please check the example applications section.

In the following section of code, we add the include like in point 2 and safe the GstClassificationMeta in the class_meta variable like in point 3.

 1 #include "gst/r2inference/gstinferencemeta.h"
 2 static void 
 3 get_buffer(GstPadProbeInfo * info)
 4 {
 5   GstBuffer *buffer;
 6   GstDetectionMeta *meta;
 7   buffer = gst_pad_probe_info_get_buffer (info);
 8   class_meta = (GstClassificationMeta *) gst_buffer_get_meta (buffer,
 9                   GST_DETECTION_META_API_TYPE);
10 
11   g_print ("Class: 0 has probability %f\n", class_meta->label_probs[0]);
12 }
Previous: Metadatas Index Next: Metadatas/GstEmbeddingMeta