Skip to content

Commit 4a11323

Browse files
committed
Merge branch 'dev-0.6'
2 parents aca30ba + b22ac76 commit 4a11323

31 files changed

+5077
-887
lines changed

COPYING

+479
Large diffs are not rendered by default.

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dnl please read gstreamer/docs/random/autotools before changing this file
55
dnl initialize autoconf
66
dnl releases only do -Wall, git and prerelease does -Werror too
77
dnl use a three digit version number for releases, and four for git/pre
8-
AC_INIT([GStreamer Inference],[0.5.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
8+
AC_INIT([GStreamer Inference],[0.6.0.1],[https://github.com/RidgeRun/gst-inference/issues],[gst-inference])
99

1010
AG_GST_INIT
1111

ext/r2inference/Makefile.am

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
plugin_LTLIBRARIES = libgstinference.la
22

33
libgstinference_la_SOURCES = \
4+
gstinceptionv1.c \
45
gstinceptionv2.c \
6+
gstinceptionv3.c \
57
gstinceptionv4.c \
68
gstinference.c \
79
gsttinyyolov2.c \
810
gsttinyyolov3.c \
911
gstfacenetv1.c \
10-
gstresnet50v1.c
12+
gstresnet50v1.c \
13+
gstmobilenetv2.c
1114

1215
libgstinference_la_CFLAGS = \
1316
$(GST_CFLAGS) \
@@ -37,9 +40,12 @@ libgstinference_la_LIBTOOLFLAGS = \
3740
$(GST_PLUGIN_LIBTOOLFLAGS)
3841

3942
noinst_HEADERS = \
43+
gstinceptionv1.h \
4044
gstinceptionv2.h \
45+
gstinceptionv3.h \
4146
gstinceptionv4.h \
4247
gsttinyyolov2.h \
4348
gsttinyyolov3.h \
4449
gstfacenetv1.h \
45-
gstresnet50v1.h
50+
gstresnet50v1.h \
51+
gstmobilenetv2.h

ext/r2inference/gstfacenetv1.c

+10-75
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@
4242
#include "gst/r2inference/gstinferencemeta.h"
4343
#include <string.h>
4444
#include <math.h>
45+
#include "gst/r2inference/gstinferencepreprocess.h"
46+
#include "gst/r2inference/gstinferencepostprocess.h"
47+
#include "gst/r2inference/gstinferencedebug.h"
4548

4649
GST_DEBUG_CATEGORY_STATIC (gst_facenetv1_debug_category);
4750
#define GST_CAT_DEFAULT gst_facenetv1_debug_category
4851

52+
#define MODEL_CHANNELS 3
53+
4954
/* prototypes */
5055
static void gst_facenetv1_set_property (GObject * object,
5156
guint property_id, const GValue * value, GParamSpec * pspec);
@@ -195,66 +200,8 @@ static gboolean
195200
gst_facenetv1_preprocess (GstVideoInference * vi,
196201
GstVideoFrame * inframe, GstVideoFrame * outframe)
197202
{
198-
gint i, j, pixel_stride, width, height, channels;
199-
gfloat mean, std, variance, sum, normalized, R, G, B;
200-
201203
GST_LOG_OBJECT (vi, "Preprocess");
202-
channels = GST_VIDEO_FRAME_N_COMPONENTS (inframe);
203-
pixel_stride = GST_VIDEO_FRAME_COMP_STRIDE (inframe, 0) / channels;
204-
width = GST_VIDEO_FRAME_WIDTH (inframe);
205-
height = GST_VIDEO_FRAME_HEIGHT (inframe);
206-
207-
sum = 0;
208-
normalized = 0;
209-
210-
for (i = 0; i < height; ++i) {
211-
for (j = 0; j < width; ++j) {
212-
sum =
213-
sum + (((guchar *) inframe->data[0])[(i * pixel_stride +
214-
j) * channels + 0]);
215-
sum =
216-
sum + (((guchar *) inframe->data[0])[(i * pixel_stride +
217-
j) * channels + 1]);
218-
sum =
219-
sum + (((guchar *) inframe->data[0])[(i * pixel_stride +
220-
j) * channels + 2]);
221-
}
222-
}
223-
224-
mean = sum / (float) (width * height * channels);
225-
226-
for (i = 0; i < height; ++i) {
227-
for (j = 0; j < width; ++j) {
228-
R = (gfloat) ((((guchar *) inframe->data[0])[(i * pixel_stride +
229-
j) * channels + 0])) - mean;
230-
G = (gfloat) ((((guchar *) inframe->data[0])[(i * pixel_stride +
231-
j) * channels + 1])) - mean;
232-
B = (gfloat) ((((guchar *) inframe->data[0])[(i * pixel_stride +
233-
j) * channels + 2])) - mean;
234-
normalized = normalized + pow (R, 2);
235-
normalized = normalized + pow (G, 2);
236-
normalized = normalized + pow (B, 2);
237-
}
238-
}
239-
240-
variance = normalized / (float) (width * height * channels);
241-
std = sqrt (variance);
242-
243-
for (i = 0; i < height; ++i) {
244-
for (j = 0; j < width; ++j) {
245-
((gfloat *) outframe->data[0])[(i * width + j) * channels + 0] =
246-
(((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels +
247-
0] - mean) / std;
248-
((gfloat *) outframe->data[0])[(i * width + j) * channels + 1] =
249-
(((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels +
250-
1] - mean) / std;
251-
((gfloat *) outframe->data[0])[(i * width + j) * channels + 2] =
252-
(((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels +
253-
2] - mean) / std;
254-
}
255-
}
256-
257-
return TRUE;
204+
return gst_normalize_face (inframe, outframe, MODEL_CHANNELS);
258205
}
259206

260207
static gboolean
@@ -263,25 +210,13 @@ gst_facenetv1_postprocess (GstVideoInference * vi, const gpointer prediction,
263210
gboolean * valid_prediction)
264211
{
265212
GstClassificationMeta *class_meta = (GstClassificationMeta *) meta_model;
266-
GstDebugLevel level;
213+
GstDebugLevel gst_debug_level = GST_LEVEL_LOG;
267214
GST_LOG_OBJECT (vi, "Postprocess");
268215

269-
class_meta->num_labels = predsize / sizeof (gfloat);
270-
class_meta->label_probs =
271-
g_malloc (class_meta->num_labels * sizeof (gdouble));
272-
for (gint i = 0; i < class_meta->num_labels; ++i) {
273-
class_meta->label_probs[i] = (gdouble) ((gfloat *) prediction)[i];
274-
}
275-
276-
/* Only display vector if debug level >= 6 */
277-
level = gst_debug_category_get_threshold (gst_facenetv1_debug_category);
278-
if (level >= GST_LEVEL_LOG) {
279-
for (gint i = 0; i < class_meta->num_labels; ++i) {
280-
gfloat current = ((gfloat *) prediction)[i];
281-
GST_LOG_OBJECT (vi, "Output vector element %i : (%f)", i, current);
282-
}
283-
}
216+
gst_fill_classification_meta (class_meta, prediction, predsize);
284217

218+
gst_inference_print_embedding (vi, gst_facenetv1_debug_category, class_meta,
219+
prediction, gst_debug_level);
285220
*valid_prediction = TRUE;
286221
return TRUE;
287222
}

ext/r2inference/gstinceptionv1.c

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* GStreamer
3+
* Copyright (C) 2019 RidgeRun
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Library General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Library General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Library General Public
16+
* License along with this library; if not, write to the
17+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18+
* Boston, MA 02111-1307, USA.
19+
*
20+
*/
21+
22+
/**
23+
* SECTION:element-gstinceptionv1
24+
*
25+
* The inceptionv1 element allows the user to infer/execute a pretrained model
26+
* based on the GoogLeNet (Inception v1 or Inception v2) architectures on
27+
* incoming image frames.
28+
*
29+
* <refsect2>
30+
* <title>Example launch line</title>
31+
* |[
32+
* gst-launch-1.0 -v videotestsrc ! inceptionv1 ! xvimagesink
33+
* ]|
34+
* Process video frames from the camera using a GoogLeNet (Inception v1 or
35+
* Inception v2) model.
36+
* </refsect2>
37+
*/
38+
39+
#ifdef HAVE_CONFIG_H
40+
#include "config.h"
41+
#endif
42+
43+
#include "gstinceptionv1.h"
44+
#include "gst/r2inference/gstinferencemeta.h"
45+
#include <string.h>
46+
#include "gst/r2inference/gstinferencepreprocess.h"
47+
#include "gst/r2inference/gstinferencepostprocess.h"
48+
#include "gst/r2inference/gstinferencedebug.h"
49+
50+
GST_DEBUG_CATEGORY_STATIC (gst_inceptionv1_debug_category);
51+
#define GST_CAT_DEFAULT gst_inceptionv1_debug_category
52+
53+
#define MEAN 128.0
54+
#define STD 1/128.0
55+
#define MODEL_CHANNELS 3
56+
57+
static gboolean gst_inceptionv1_preprocess (GstVideoInference * vi,
58+
GstVideoFrame * inframe, GstVideoFrame * outframe);
59+
static gboolean gst_inceptionv1_postprocess (GstVideoInference * vi,
60+
const gpointer prediction, gsize predsize, GstMeta * meta_model,
61+
GstVideoInfo * info_model, gboolean * valid_prediction);
62+
static gboolean gst_inceptionv1_start (GstVideoInference * vi);
63+
static gboolean gst_inceptionv1_stop (GstVideoInference * vi);
64+
65+
enum
66+
{
67+
PROP_0
68+
};
69+
70+
/* pad templates */
71+
#define CAPS \
72+
"video/x-raw, " \
73+
"width=224, " \
74+
"height=224, " \
75+
"format={RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, ARGB, xBGR, ABGR}"
76+
77+
static GstStaticPadTemplate sink_model_factory =
78+
GST_STATIC_PAD_TEMPLATE ("sink_model",
79+
GST_PAD_SINK,
80+
GST_PAD_REQUEST,
81+
GST_STATIC_CAPS (CAPS)
82+
);
83+
84+
static GstStaticPadTemplate src_model_factory =
85+
GST_STATIC_PAD_TEMPLATE ("src_model",
86+
GST_PAD_SRC,
87+
GST_PAD_REQUEST,
88+
GST_STATIC_CAPS (CAPS)
89+
);
90+
91+
struct _GstInceptionv1
92+
{
93+
GstVideoInference parent;
94+
};
95+
96+
struct _GstInceptionv1Class
97+
{
98+
GstVideoInferenceClass parent;
99+
};
100+
101+
/* class initialization */
102+
103+
G_DEFINE_TYPE_WITH_CODE (GstInceptionv1, gst_inceptionv1,
104+
GST_TYPE_VIDEO_INFERENCE,
105+
GST_DEBUG_CATEGORY_INIT (gst_inceptionv1_debug_category, "inceptionv1", 0,
106+
"debug category for inceptionv1 element"));
107+
108+
static void
109+
gst_inceptionv1_class_init (GstInceptionv1Class * klass)
110+
{
111+
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
112+
GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
113+
114+
gst_element_class_add_static_pad_template (element_class,
115+
&sink_model_factory);
116+
gst_element_class_add_static_pad_template (element_class, &src_model_factory);
117+
118+
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
119+
"inceptionv1", "Filter",
120+
"Infers incoming image frames using a pretrained GoogLeNet (Inception v1 or Inception v2) model",
121+
"Carlos Rodriguez <[email protected]> \n\t\t\t"
122+
" Jose Jimenez <[email protected]> \n\t\t\t"
123+
" Michael Gruner <[email protected]> \n\t\t\t"
124+
" Mauricio Montero <[email protected]>");
125+
126+
vi_class->start = GST_DEBUG_FUNCPTR (gst_inceptionv1_start);
127+
vi_class->stop = GST_DEBUG_FUNCPTR (gst_inceptionv1_stop);
128+
vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_inceptionv1_preprocess);
129+
vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_inceptionv1_postprocess);
130+
vi_class->inference_meta_info = gst_classification_meta_get_info ();
131+
}
132+
133+
static void
134+
gst_inceptionv1_init (GstInceptionv1 * inceptionv1)
135+
{
136+
}
137+
138+
static gboolean
139+
gst_inceptionv1_preprocess (GstVideoInference * vi,
140+
GstVideoFrame * inframe, GstVideoFrame * outframe)
141+
{
142+
GST_LOG_OBJECT (vi, "Preprocess");
143+
return gst_normalize (inframe, outframe, MEAN, STD, MODEL_CHANNELS);
144+
}
145+
146+
static gboolean
147+
gst_inceptionv1_postprocess (GstVideoInference * vi, const gpointer prediction,
148+
gsize predsize, GstMeta * meta_model, GstVideoInfo * info_model,
149+
gboolean * valid_prediction)
150+
{
151+
GstClassificationMeta *class_meta = (GstClassificationMeta *) meta_model;
152+
GstDebugLevel gst_debug_level = GST_LEVEL_LOG;
153+
GST_LOG_OBJECT (vi, "Postprocess");
154+
155+
gst_fill_classification_meta (class_meta, prediction, predsize);
156+
157+
gst_inference_print_highest_probability (vi, gst_inceptionv1_debug_category,
158+
class_meta, prediction, gst_debug_level);
159+
160+
*valid_prediction = TRUE;
161+
return TRUE;
162+
}
163+
164+
static gboolean
165+
gst_inceptionv1_start (GstVideoInference * vi)
166+
{
167+
GST_INFO_OBJECT (vi, "Starting Inception v1");
168+
169+
return TRUE;
170+
}
171+
172+
static gboolean
173+
gst_inceptionv1_stop (GstVideoInference * vi)
174+
{
175+
GST_INFO_OBJECT (vi, "Stopping Inception v1");
176+
177+
return TRUE;
178+
}

ext/r2inference/gstinceptionv1.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* GStreamer
3+
* Copyright (C) 2018 RidgeRun
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Library General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Library General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Library General Public
16+
* License along with this library; if not, write to the
17+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18+
* Boston, MA 02111-1307, USA.
19+
*
20+
*/
21+
22+
#ifndef _GST_INCEPTIONV1_H_
23+
#define _GST_INCEPTIONV1_H_
24+
25+
#include <gst/r2inference/gstvideoinference.h>
26+
27+
G_BEGIN_DECLS
28+
29+
#define GST_TYPE_INCEPTIONV1 gst_inceptionv1_get_type ()
30+
G_DECLARE_FINAL_TYPE (GstInceptionv1, gst_inceptionv1, GST, INCEPTIONV1, GstVideoInference)
31+
32+
G_END_DECLS
33+
34+
#endif

0 commit comments

Comments
 (0)