mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 02:01:12 +00:00
onnx: Remove unnecessary tensorid class
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4916>
This commit is contained in:
parent
62f292ac73
commit
a225755489
6 changed files with 10 additions and 130 deletions
|
@ -23,7 +23,6 @@
|
||||||
#include "gstobjectdetectorutils.h"
|
#include "gstobjectdetectorutils.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "tensor/gsttensorid.h"
|
|
||||||
|
|
||||||
GstMlBoundingBox::GstMlBoundingBox (std::string lbl, float score, float _x0,
|
GstMlBoundingBox::GstMlBoundingBox (std::string lbl, float score, float _x0,
|
||||||
float _y0, float _width, float _height):
|
float _y0, float _width, float _height):
|
||||||
|
@ -66,7 +65,7 @@ namespace GstObjectDetectorUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
auto classIndex = gst_tensor_meta_get_index_from_id (tmeta,
|
auto classIndex = gst_tensor_meta_get_index_from_id (tmeta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_CLASSES));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_CLASSES));
|
||||||
if (classIndex == GST_TENSOR_MISSING_ID) {
|
if (classIndex == GST_TENSOR_MISSING_ID) {
|
||||||
GST_ERROR ("Missing class tensor id");
|
GST_ERROR ("Missing class tensor id");
|
||||||
return std::vector < GstMlBoundingBox > ();
|
return std::vector < GstMlBoundingBox > ();
|
||||||
|
@ -91,7 +90,7 @@ namespace GstObjectDetectorUtils
|
||||||
|
|
||||||
// number of detections
|
// number of detections
|
||||||
index = gst_tensor_meta_get_index_from_id (tmeta,
|
index = gst_tensor_meta_get_index_from_id (tmeta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS));
|
||||||
if (index == GST_TENSOR_MISSING_ID) {
|
if (index == GST_TENSOR_MISSING_ID) {
|
||||||
GST_WARNING ("Missing tensor data for tensor index %d", index);
|
GST_WARNING ("Missing tensor data for tensor index %d", index);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -110,7 +109,7 @@ namespace GstObjectDetectorUtils
|
||||||
// bounding boxes
|
// bounding boxes
|
||||||
index =
|
index =
|
||||||
gst_tensor_meta_get_index_from_id (tmeta,
|
gst_tensor_meta_get_index_from_id (tmeta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_BOXES));
|
g_quark_from_static_string(GST_MODEL_OBJECT_DETECTOR_BOXES));
|
||||||
if (index == GST_TENSOR_MISSING_ID) {
|
if (index == GST_TENSOR_MISSING_ID) {
|
||||||
GST_WARNING ("Missing tensor data for tensor index %d", index);
|
GST_WARNING ("Missing tensor data for tensor index %d", index);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -129,7 +128,7 @@ namespace GstObjectDetectorUtils
|
||||||
// scores
|
// scores
|
||||||
index =
|
index =
|
||||||
gst_tensor_meta_get_index_from_id (tmeta,
|
gst_tensor_meta_get_index_from_id (tmeta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_SCORES));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_SCORES));
|
||||||
if (index == GST_TENSOR_MISSING_ID) {
|
if (index == GST_TENSOR_MISSING_ID) {
|
||||||
GST_ERROR ("Missing scores tensor id");
|
GST_ERROR ("Missing scores tensor id");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -149,7 +148,7 @@ namespace GstObjectDetectorUtils
|
||||||
labelIndex = nullptr;
|
labelIndex = nullptr;
|
||||||
index =
|
index =
|
||||||
gst_tensor_meta_get_index_from_id (tmeta,
|
gst_tensor_meta_get_index_from_id (tmeta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_CLASSES));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_CLASSES));
|
||||||
if (index != GST_TENSOR_MISSING_ID) {
|
if (index != GST_TENSOR_MISSING_ID) {
|
||||||
memory[index] = gst_buffer_peek_memory (tmeta->tensor[index].data, 0);
|
memory[index] = gst_buffer_peek_memory (tmeta->tensor[index].data, 0);
|
||||||
if (!memory[index]) {
|
if (!memory[index]) {
|
||||||
|
|
|
@ -56,7 +56,6 @@
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
#include <gst/video/gstvideometa.h>
|
#include <gst/video/gstvideometa.h>
|
||||||
#include "tensor/gsttensormeta.h"
|
#include "tensor/gsttensormeta.h"
|
||||||
#include "tensor/gsttensorid.h"
|
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (ssd_object_detector_debug);
|
GST_DEBUG_CATEGORY_STATIC (ssd_object_detector_debug);
|
||||||
#define GST_CAT_DEFAULT ssd_object_detector_debug
|
#define GST_CAT_DEFAULT ssd_object_detector_debug
|
||||||
|
@ -248,13 +247,13 @@ gst_ssd_object_detector_get_tensor_meta (GstSsdObjectDetector * object_detector,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
gint boxesIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
gint boxesIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_BOXES));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_BOXES));
|
||||||
gint scoresIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
gint scoresIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_SCORES));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_SCORES));
|
||||||
gint numDetectionsIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
gint numDetectionsIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS));
|
||||||
gint clasesIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
gint clasesIndex = gst_tensor_meta_get_index_from_id (tensor_meta,
|
||||||
gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_CLASSES));
|
g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_CLASSES));
|
||||||
|
|
||||||
if (boxesIndex == GST_TENSOR_MISSING_ID || scoresIndex == GST_TENSOR_MISSING_ID
|
if (boxesIndex == GST_TENSOR_MISSING_ID || scoresIndex == GST_TENSOR_MISSING_ID
|
||||||
|| numDetectionsIndex == GST_TENSOR_MISSING_ID)
|
|| numDetectionsIndex == GST_TENSOR_MISSING_ID)
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gstonnxclient.h"
|
#include "gstonnxclient.h"
|
||||||
#include <tensor/gsttensorid.h>
|
|
||||||
#include <cpu_provider_factory.h>
|
#include <cpu_provider_factory.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@ -207,7 +206,7 @@ GstOnnxClient::GstOnnxClient ():session (nullptr),
|
||||||
Ort::AllocatedStringPtr res =
|
Ort::AllocatedStringPtr res =
|
||||||
metaData.LookupCustomMetadataMapAllocated (name, ortAllocator);
|
metaData.LookupCustomMetadataMapAllocated (name, ortAllocator);
|
||||||
if (res) {
|
if (res) {
|
||||||
GQuark quark = gst_tensorid_get_quark (res.get ());
|
GQuark quark = g_quark_from_static_string (res.get ());
|
||||||
outputIds.push_back (quark);
|
outputIds.push_back (quark);
|
||||||
} else {
|
} else {
|
||||||
GST_ERROR ("Failed to look up id for key %s", name);
|
GST_ERROR ("Failed to look up id for key %s", name);
|
||||||
|
|
|
@ -19,7 +19,6 @@ if onnxrt_dep.found()
|
||||||
'decoders/gstssdobjectdetector.cpp',
|
'decoders/gstssdobjectdetector.cpp',
|
||||||
'gstonnxinference.cpp',
|
'gstonnxinference.cpp',
|
||||||
'gstonnxclient.cpp',
|
'gstonnxclient.cpp',
|
||||||
'tensor/gsttensorid.cpp',
|
|
||||||
'tensor/gsttensormeta.c',
|
'tensor/gsttensormeta.c',
|
||||||
c_args : gst_plugins_bad_args + extra_args,
|
c_args : gst_plugins_bad_args + extra_args,
|
||||||
cpp_args : gst_plugins_bad_args + extra_args,
|
cpp_args : gst_plugins_bad_args + extra_args,
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* GStreamer gstreamer-tensorid
|
|
||||||
* Copyright (C) 2023 Collabora Ltd
|
|
||||||
*
|
|
||||||
* gsttensorid.c
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <gst/gst.h>
|
|
||||||
#include "gsttensorid.h"
|
|
||||||
|
|
||||||
/* Structure to encapsulate a string and its associated GQuark */
|
|
||||||
struct TensorQuark
|
|
||||||
{
|
|
||||||
const char *string;
|
|
||||||
GQuark quark_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TensorId
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TensorId (void):tensor_quarks_array (g_array_new (FALSE, FALSE,
|
|
||||||
sizeof (TensorQuark)))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
~TensorId (void)
|
|
||||||
{
|
|
||||||
if (tensor_quarks_array) {
|
|
||||||
for (guint i = 0; i < tensor_quarks_array->len; i++) {
|
|
||||||
TensorQuark *quark =
|
|
||||||
&g_array_index (tensor_quarks_array, TensorQuark, i);
|
|
||||||
g_free ((gpointer) quark->string); // free the duplicated string
|
|
||||||
}
|
|
||||||
g_array_free (tensor_quarks_array, TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GQuark get_quark (const char *str)
|
|
||||||
{
|
|
||||||
for (guint i = 0; i < tensor_quarks_array->len; i++) {
|
|
||||||
TensorQuark *quark = &g_array_index (tensor_quarks_array, TensorQuark, i);
|
|
||||||
if (g_strcmp0 (quark->string, str) == 0) {
|
|
||||||
return quark->quark_id; // already registered
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register the new quark and append to the GArray
|
|
||||||
TensorQuark new_quark;
|
|
||||||
new_quark.string = g_strdup (str); // create a copy of the string
|
|
||||||
new_quark.quark_id = g_quark_from_string (new_quark.string);
|
|
||||||
g_array_append_val (tensor_quarks_array, new_quark);
|
|
||||||
|
|
||||||
return new_quark.quark_id;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
GArray * tensor_quarks_array;
|
|
||||||
};
|
|
||||||
|
|
||||||
static TensorId tensorId;
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
GQuark
|
|
||||||
gst_tensorid_get_quark (const char *tensor_id)
|
|
||||||
{
|
|
||||||
return tensorId.get_quark (tensor_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* GStreamer gstreamer-tensorid
|
|
||||||
* Copyright (C) 2023 Collabora Ltd
|
|
||||||
*
|
|
||||||
* gsttensorid.h
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
#ifndef __GST_TENSOR_ID_H__
|
|
||||||
#define __GST_TENSOR_ID_H__
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
/**
|
|
||||||
* gst_tensorid_get_quark get tensor id
|
|
||||||
*
|
|
||||||
* @param tensor_id unique string id for tensor node
|
|
||||||
*/
|
|
||||||
GQuark gst_tensorid_get_quark (const char *tensor_id);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
#endif
|
|
Loading…
Reference in a new issue