Existing tensor decoder has been bifurcated into two seperate gst element as: `yoloodv5tensordecoder`: decodes tensors output(masks) from detection-only models e.g yolov8s.onnx `yolsegv8tensordecoder`: decoder tensors output(masks and logits) from segementation models e.g FastSAM or yolov8s-seg
128 lines
4.0 KiB
C
128 lines
4.0 KiB
C
/*
|
|
* GStreamer gstreamer-yolotensordecoder
|
|
* Copyright (C) 2024 Collabora Ltd
|
|
* Authors: Daniel Morin <daniel.morin@collabora.com>
|
|
* Vineet Suryan <vineet.suryan@collabora.com>
|
|
* Santosh Mahto <santosh.mahto@collabora.com>
|
|
*
|
|
* gstyolotensordecoder.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_YOLO_TENSOR_DECODER_H__
|
|
#define __GST_YOLO_TENSOR_DECODER_H__
|
|
|
|
#include <gst/gst.h>
|
|
#include <gst/video/video.h>
|
|
#include <gst/base/base.h>
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
#define GST_TYPE_YOLO_OD_TENSOR_DECODER (gst_yolo_od_tensor_decoder_get_type ())
|
|
#define GST_YOLO_OD_TENSOR_DECODER(obj) \
|
|
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_YOLO_OD_TENSOR_DECODER, GstYoloOdTensorDecoder))
|
|
#define GST_YOLO_OD_TENSOR_DECODER_CLASS(klass) \
|
|
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_YOLO_OD_TENSOR_DECODER, GstYoloOdTensorDecoderClass))
|
|
#define GST_IS_YOLO_OD_TENSOR_DECODER(obj) \
|
|
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_YOLO_OD_TENSOR_DECODER))
|
|
#define GST_IS_YOLO_OD_TENSOR_DECODER_CLASS(klass) \
|
|
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_YOLO_OD_TENSOR_DECODER))
|
|
#define GST_YOLO_OD_TENSOR_DECODER_GET_CLASS(obj) \
|
|
(G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_YOLO_OD_TENSOR_DECODER, GstYoloOdTensorDecoderClass))
|
|
|
|
typedef struct _GstYoloOdTensorDecoder GstYoloOdTensorDecoder;
|
|
typedef struct _GstYoloOdTensorDecoderClass GstYoloOdTensorDecoderClass;
|
|
|
|
typedef struct _BBox
|
|
{
|
|
gint x;
|
|
gint y;
|
|
guint w;
|
|
guint h;
|
|
} BBox;
|
|
|
|
struct _GstYoloOdTensorDecoder
|
|
{
|
|
GstBaseTransform basetransform;
|
|
/* Box confidence threshold */
|
|
gfloat box_confi_thresh;
|
|
/* Class confidence threshold */
|
|
gfloat cls_confi_thresh;
|
|
/* Intersection-of-Union threshold */
|
|
gfloat iou_thresh;
|
|
/* Maximum detection/mask */
|
|
gsize max_detection;
|
|
/* Video Info */
|
|
/* Candidates with a class confidence level above threshold. */
|
|
GPtrArray *sel_candidates;
|
|
/* Final candidates selected that respect class confidence level,
|
|
* NMS and maximum detection. */
|
|
GPtrArray *selected;
|
|
/* Tensor-id identifying mask tensors out of yolo inference process. */
|
|
GQuark mask_tensor_id;
|
|
|
|
GstVideoInfo video_info;
|
|
/* Labels file */
|
|
gchar *label_file;
|
|
/* Labels */
|
|
GArray *labels;
|
|
/* GstAnalyticsODMtd data */
|
|
GArray *od_mtds;
|
|
/* Hash table to store the offset in the mask tensor buffer where
|
|
* OdMtd data are stored. key is OdMtd.id */
|
|
GHashTable *candidate_offsets;
|
|
};
|
|
|
|
struct _GstYoloOdTensorDecoderClass
|
|
{
|
|
GstBaseTransformClass parent_class;
|
|
};
|
|
|
|
GType gst_yolo_od_tensor_decoder_get_type (void);
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstYoloOdTensorDecoder, g_object_unref)
|
|
|
|
GST_ELEMENT_REGISTER_DECLARE (yolo_od_tensor_decoder)
|
|
|
|
/* Yolo segmentation tensor decoder */
|
|
|
|
#define GST_TYPE_YOLO_SEG_TENSOR_DECODER (gst_yolo_seg_tensor_decoder_get_type ())
|
|
G_DECLARE_FINAL_TYPE (GstYoloSegTensorDecoder, gst_yolo_seg_tensor_decoder,
|
|
GST, YOLO_SEG_TENSOR_DECODER, GstYoloOdTensorDecoder)
|
|
|
|
struct _GstYoloSegTensorDecoder
|
|
{
|
|
GstYoloOdTensorDecoder parent;
|
|
/* Mask width */
|
|
guint mask_w;
|
|
/* Mask height */
|
|
guint mask_h;
|
|
/* Mask length */
|
|
gsize mask_length;
|
|
GQuark logits_tensor_id;
|
|
gfloat bb2mask_gain;
|
|
/* BufferPool for mask */
|
|
BBox mask_roi;
|
|
/* BufferPool for mask */
|
|
GstBufferPool *mask_pool;
|
|
};
|
|
|
|
GST_ELEMENT_REGISTER_DECLARE (yolo_seg_tensor_decoder)
|
|
|
|
G_END_DECLS
|
|
#endif /* __GST_YOLO_TENSOR_DECODER_H__ */
|