forked from zhouyuchong/gst-nvinfer-custom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gstnvinfer_property_parser.cpp
1361 lines (1277 loc) · 53.1 KB
/
gstnvinfer_property_parser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA Corporation is strictly prohibited.
*
*/
#include <gst/gst.h>
#include <string.h>
#include <assert.h>
#include "gstnvinfer_property_parser.h"
#include "gstnvinfer.h"
#define CHECK_ERROR(error) \
if (error) { \
g_printerr ("Error while parsing config file: %s\n", error->message); \
goto done; \
}
extern const int DEFAULT_REINFER_INTERVAL;
/* Get the absolute path of a file mentioned in the config given a
* file path absolute/relative to the config file. */
static gboolean
get_absolute_file_path (
const gchar * cfg_file_path, const gchar * file_path,
char *abs_path_str)
{
gchar abs_cfg_path[PATH_MAX + 1];
gchar abs_real_file_path[PATH_MAX + 1];
gchar *abs_file_path;
gchar *delim;
/* Absolute path. No need to resolve further. */
if (file_path[0] == '/') {
/* Check if the file exists, return error if not. */
if (!realpath (file_path, abs_real_file_path)) {
/* Ignore error if file does not exist and use the unresolved path. */
if (errno != ENOENT)
return FALSE;
}
g_strlcpy (abs_path_str, abs_real_file_path, _PATH_MAX);
return TRUE;
}
/* Get the absolute path of the config file. */
if (!realpath (cfg_file_path, abs_cfg_path)) {
return FALSE;
}
/* Remove the file name from the absolute path to get the directory of the
* config file. */
delim = g_strrstr (abs_cfg_path, "/");
*(delim + 1) = '\0';
/* Get the absolute file path from the config file's directory path and
* relative file path. */
abs_file_path = g_strconcat (abs_cfg_path, file_path, nullptr);
/* Resolve the path.*/
if (realpath (abs_file_path, abs_real_file_path) == nullptr) {
/* Ignore error if file does not exist and use the unresolved path. */
if (errno == ENOENT)
g_strlcpy (abs_real_file_path, abs_file_path, _PATH_MAX);
else
return FALSE;
}
g_free (abs_file_path);
g_strlcpy (abs_path_str, abs_real_file_path, _PATH_MAX);
return TRUE;
}
/* Parse per-class detection parameters. Returns FALSE in case of an error. */
static gboolean
gst_nvinfer_parse_class_attrs (GKeyFile * key_file, gchar * group,
NvDsInferDetectionParams & detection_params,
GstNvInferDetectionFilterParams & detection_filter_params,
GstNvInferColorParams & color_params)
{
gboolean ret = FALSE;
gchar **keys = nullptr;
gchar **key = nullptr;
GError *error = nullptr;
keys = g_key_file_get_keys (key_file, group, nullptr, &error);
CHECK_ERROR (error);
for (key = keys; *key; key++) {
if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_THRESHOLD)) {
g_printerr("Warn: 'threshold' parameter has been deprecated."
" Use 'pre-cluster-threshold' instead.\n");
detection_params.preClusterThreshold =
g_key_file_get_double (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_THRESHOLD, &error);
CHECK_ERROR (error);
if (detection_params.preClusterThreshold < 0) {
g_printerr ("Error: Negative threshold (%.5f) specified for group %s\n",
detection_params.preClusterThreshold, group);
goto done;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_PRE_CLUSTER_THRESHOLD)) {
detection_params.preClusterThreshold =
g_key_file_get_double (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_PRE_CLUSTER_THRESHOLD, &error);
CHECK_ERROR (error);
if (detection_params.preClusterThreshold < 0) {
g_printerr ("Error: Negative pre cluster threshold (%.5f) specified for group %s\n",
detection_params.preClusterThreshold, group);
goto done;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_POST_CLUSTER_THRESHOLD)) {
detection_params.postClusterThreshold =
g_key_file_get_double (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_POST_CLUSTER_THRESHOLD, &error);
CHECK_ERROR (error);
if (detection_params.postClusterThreshold < 0) {
g_printerr ("Error: Negative post cluster threshold (%.5f) specified for group %s\n",
detection_params.postClusterThreshold, group);
goto done;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_EPS)) {
detection_params.eps =
g_key_file_get_double (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_EPS, &error);
CHECK_ERROR (error);
if (detection_params.eps < 0) {
g_printerr ("Error: Negative eps (%.5f) specified for group %s\n",
detection_params.eps, group);
goto done;
}
} else if (!g_strcmp0 (*key,
CONFIG_GROUP_INFER_CLASS_ATTRS_GROUP_THRESHOLD)) {
detection_params.groupThreshold =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_GROUP_THRESHOLD, &error);
CHECK_ERROR (error);
if (detection_params.groupThreshold < 0) {
g_printerr
("Error: Negative group-threshold (%d) specified for group %s\n",
detection_params.groupThreshold, group);
goto done;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_MIN_BOXES)) {
detection_params.minBoxes =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_MIN_BOXES, &error);
CHECK_ERROR (error);
if (detection_params.minBoxes < 0) {
g_printerr
("Error: Negative minBoxes (%d) specified for group %s\n",
detection_params.minBoxes, group);
goto done;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_DBSCAN_MIN_SCORE)) {
detection_params.minScore =
g_key_file_get_double (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_DBSCAN_MIN_SCORE, &error);
CHECK_ERROR (error);
if (detection_params.minScore < 0) {
g_printerr
("Error: Negative minScore (%f) specified for group %s\n",
detection_params.minScore, group);
goto done;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_ROI_TOP_OFFSET)) {
detection_filter_params.roiTopOffset =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_ROI_TOP_OFFSET, &error);
CHECK_ERROR (error);
if ((gint) detection_filter_params.roiTopOffset < 0) {
g_printerr
("Error: Negative roiTopOffset (%d) specified for group %s\n",
detection_filter_params.roiTopOffset, group);
goto done;
}
} else if (!g_strcmp0 (*key,
CONFIG_GROUP_INFER_CLASS_ATTRS_ROI_BOTTOM_OFFSET)) {
detection_filter_params.roiBottomOffset =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_ROI_BOTTOM_OFFSET, &error);
CHECK_ERROR (error);
if ((gint) detection_filter_params.roiBottomOffset < 0) {
g_printerr
("Error: Negative roiBottomOffset (%d) specified for group %s\n",
detection_filter_params.roiBottomOffset, group);
goto done;
}
} else if (!g_strcmp0 (*key,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MIN_WIDTH)) {
detection_filter_params.detectionMinWidth =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MIN_WIDTH, &error);
CHECK_ERROR (error);
if ((gint) detection_filter_params.detectionMinWidth < 0) {
g_printerr
("Error: Negative detectionMinWidth (%d) specified for group %s\n",
detection_filter_params.detectionMinWidth, group);
goto done;
}
} else if (!g_strcmp0 (*key,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MIN_HEIGHT)) {
detection_filter_params.detectionMinHeight =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MIN_HEIGHT, &error);
CHECK_ERROR (error);
if ((gint) detection_filter_params.detectionMinHeight < 0) {
g_printerr
("Error: Negative detectionMinHeight (%d) specified for group %s\n",
detection_filter_params.detectionMinHeight, group);
goto done;
}
} else if (!g_strcmp0 (*key,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MAX_WIDTH)) {
detection_filter_params.detectionMaxWidth =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MAX_WIDTH, &error);
CHECK_ERROR (error);
if ((gint) detection_filter_params.detectionMaxWidth < 0) {
g_printerr
("Error: Negative detectionMaxWidth (%d) specified for group %s\n",
detection_filter_params.detectionMaxWidth, group);
goto done;
}
} else if (!g_strcmp0 (*key,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MAX_HEIGHT)) {
detection_filter_params.detectionMaxHeight =
g_key_file_get_integer (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_DETECTED_MAX_HEIGHT, &error);
if ((gint) detection_filter_params.detectionMaxHeight < 0) {
g_printerr
("Error: Negative detectionMaxHeight (%d) specified for group %s\n",
detection_filter_params.detectionMaxHeight, group);
goto done;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_BORDER_COLOR)) {
gsize length;
gdouble *list = g_key_file_get_double_list (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_BORDER_COLOR, &length, &error);
CHECK_ERROR (error);
if (length != 4) {
g_printerr
("Error: Group %s, Number of Color params should be exactly 4 "
"floats {r, g, b, a} between 0 and 1", group);
goto done;
}
color_params.border_color.red = list[0];
color_params.border_color.green = list[1];
color_params.border_color.blue = list[2];
color_params.border_color.alpha = list[3];
g_free (list);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CLASS_ATTRS_BG_COLOR)) {
gsize length;
gdouble *list = g_key_file_get_double_list (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_BG_COLOR, &length, &error);
CHECK_ERROR (error);
if (length != 4) {
g_printerr
("Error: Group %s, Number of Color params should be exactly 4 "
"floats {r, g, b, a} between 0 and 1", group);
goto done;
}
color_params.bg_color.red = list[0];
color_params.bg_color.green = list[1];
color_params.bg_color.blue = list[2];
color_params.bg_color.alpha = list[3];
color_params.have_bg_color = TRUE;
g_free (list);
} else if (!g_strcmp0(*key, CONFIG_GROUP_INFER_CLASS_ATTRS_NMS_IOU_THRESHOLD)) {
detection_params.nmsIOUThreshold = g_key_file_get_double (key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_NMS_IOU_THRESHOLD, &error);
CHECK_ERROR (error);
if (detection_params.nmsIOUThreshold < 0 || detection_params.nmsIOUThreshold > 1) {
g_printerr ("Error: Invalid nms iou threshold (%.2f) specified for group %s."
"Enter a value between 0 & 1. \n",
detection_params.nmsIOUThreshold, group);
goto done;
}
} else if (!g_strcmp0(*key, CONFIG_GROUP_INFER_CLASS_ATTRS_TOP_K)) {
detection_params.topK = g_key_file_get_integer(key_file, group,
CONFIG_GROUP_INFER_CLASS_ATTRS_TOP_K, &error);
CHECK_ERROR(error);
if(detection_params.topK < 0) {
g_printerr("Error: Invalid topk value %d specified for group %s."
" topk should be greater than of equal to '0'\n", detection_params.topK, group);
goto done;
}
} else {
g_printerr ("Unknown key '%s' for group [%s]\n", *key,
CONFIG_GROUP_PROPERTY);
}
}
ret = TRUE;
done:
if (error) {
g_error_free (error);
}
if (keys) {
g_strfreev (keys);
}
return ret;
}
static gboolean
gst_nvinfer_parse_other_attribute (GstNvInfer * nvinfer,
GKeyFile * key_file, const gchar * group_name, const gchar * key,
const gchar * cfg_file_path)
{
GError *error = nullptr;
gboolean ret = FALSE;
assert (nvinfer);
if (!g_strcmp0 (key, CONFIG_GROUP_INFER_PROCESS_MODE)) {
if ((*nvinfer->is_prop_set)[PROP_PROCESS_MODE])
return TRUE;
guint val = g_key_file_get_integer (key_file, group_name,
CONFIG_GROUP_INFER_PROCESS_MODE, &error);
CHECK_ERROR (error);
switch (val) {
case 1:
nvinfer->process_full_frame = TRUE;
break;
case 2:
nvinfer->process_full_frame = FALSE;
break;
default:
g_printerr ("Error: Invalid value for %s (%d)\n",
CONFIG_GROUP_INFER_PROCESS_MODE, val);
goto done;
}
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_CLASSIFIER_ASYNC_MODE)) {
if (g_key_file_get_boolean (key_file, group_name,
CONFIG_GROUP_INFER_CLASSIFIER_ASYNC_MODE, &error))
nvinfer->classifier_async_mode = TRUE;
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_CLASSIFIER_TYPE)) {
nvinfer->classifier_type = g_key_file_get_string (key_file,
group_name, CONFIG_GROUP_INFER_CLASSIFIER_TYPE, &error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_INTERVAL)) {
if ((*nvinfer->is_prop_set)[PROP_INTERVAL])
return TRUE;
nvinfer->interval =
g_key_file_get_integer (key_file, group_name,
CONFIG_GROUP_INFER_INTERVAL, &error);
CHECK_ERROR (error);
if ((gint) nvinfer->interval < 0) {
g_printerr ("Error: Negative value (%d) specified for interval\n",
nvinfer->interval);
goto done;
}
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_OUTPUT_TENSOR_META)) {
if (g_key_file_get_boolean (key_file, group_name,
CONFIG_GROUP_INFER_OUTPUT_TENSOR_META, &error))
nvinfer->output_tensor_meta = TRUE;
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_OUTPUT_INSTANCE_MASK)) {
if (g_key_file_get_boolean (key_file, group_name,
CONFIG_GROUP_INFER_OUTPUT_INSTANCE_MASK, &error))
nvinfer->output_instance_mask = TRUE;
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_SECONDARY_REINFER_INTERVAL)) {
nvinfer->secondary_reinfer_interval =
g_key_file_get_integer (key_file, group_name,
CONFIG_GROUP_INFER_SECONDARY_REINFER_INTERVAL, &error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_MAINTAIN_ASPECT_RATIO)) {
if (g_key_file_get_boolean (key_file, group_name,
CONFIG_GROUP_INFER_MAINTAIN_ASPECT_RATIO, &error))
nvinfer->maintain_aspect_ratio = TRUE;
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_SYMMETRIC_PADDING)) {
if (g_key_file_get_boolean (key_file, group_name,
CONFIG_GROUP_INFER_SYMMETRIC_PADDING, &error))
nvinfer->symmetric_padding = TRUE;
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_INPUT_OBJECT_MIN_WIDTH)) {
nvinfer->min_input_object_width = g_key_file_get_integer (key_file,
group_name, CONFIG_GROUP_INFER_INPUT_OBJECT_MIN_WIDTH,
&error);
CHECK_ERROR (error);
if ((gint) nvinfer->min_input_object_width < 0) {
g_printerr ("Error: Negative value specified for %s(%d)\n",
CONFIG_GROUP_INFER_INPUT_OBJECT_MIN_WIDTH,
nvinfer->min_input_object_width);
goto done;
}
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_INPUT_OBJECT_MIN_HEIGHT)) {
nvinfer->min_input_object_height = g_key_file_get_integer (key_file,
group_name, CONFIG_GROUP_INFER_INPUT_OBJECT_MIN_HEIGHT,
&error);
CHECK_ERROR (error);
if ((gint) nvinfer->min_input_object_height < 0) {
g_printerr ("Error: Negative value specified for %s(%d)\n",
CONFIG_GROUP_INFER_INPUT_OBJECT_MIN_HEIGHT,
nvinfer->min_input_object_height);
goto done;
}
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_INPUT_OBJECT_MAX_WIDTH)) {
nvinfer->max_input_object_width = g_key_file_get_integer (key_file,
group_name, CONFIG_GROUP_INFER_INPUT_OBJECT_MAX_WIDTH,
&error);
CHECK_ERROR (error);
if ((gint) nvinfer->max_input_object_width < 0) {
g_printerr ("Error: Negative value specified for %s(%d)\n",
CONFIG_GROUP_INFER_INPUT_OBJECT_MAX_WIDTH,
nvinfer->max_input_object_width);
goto done;
}
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_INPUT_OBJECT_MAX_HEIGHT)) {
nvinfer->max_input_object_height = g_key_file_get_integer (key_file,
group_name, CONFIG_GROUP_INFER_INPUT_OBJECT_MAX_HEIGHT,
&error);
CHECK_ERROR (error);
if ((gint) nvinfer->max_input_object_height < 0) {
g_printerr ("Error: Negative value specified for %s(%d)\n",
CONFIG_GROUP_INFER_INPUT_OBJECT_MAX_HEIGHT,
nvinfer->max_input_object_height);
goto done;
}
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_INPUT_OBJECT_ALIGNMENT)) {
if ((*nvinfer->is_prop_set)[PROP_OPERATE_ON_GIE_ID] ||
(*nvinfer->is_prop_set)[PROP_OPERATE_ON_CLASS_IDS])
return TRUE;
nvinfer->alignment = g_key_file_get_integer (key_file,
group_name, CONFIG_GROUP_INFER_INPUT_OBJECT_ALIGNMENT,
&error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_INPUT_OBJECT_USER_META)) {
nvinfer->user_meta = g_key_file_get_integer (key_file,
group_name, CONFIG_GROUP_INFER_INPUT_OBJECT_USER_META,
&error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_GIE_ID_FOR_OPERATION)) {
if ((*nvinfer->is_prop_set)[PROP_OPERATE_ON_GIE_ID] ||
(*nvinfer->is_prop_set)[PROP_OPERATE_ON_CLASS_IDS])
return TRUE;
nvinfer->operate_on_gie_id = g_key_file_get_integer (key_file,
group_name, CONFIG_GROUP_INFER_GIE_ID_FOR_OPERATION,
&error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_CLASS_IDS_FOR_OPERATION)) {
if ((*nvinfer->is_prop_set)[PROP_OPERATE_ON_GIE_ID] ||
(*nvinfer->is_prop_set)[PROP_OPERATE_ON_CLASS_IDS])
return TRUE;
gsize length, i;
gint max_class_id = -1;
gint *int_list =
g_key_file_get_integer_list (key_file, group_name,
CONFIG_GROUP_INFER_CLASS_IDS_FOR_OPERATION, &length, &error);
CHECK_ERROR(error);
for (i = 0; i < length; i++) {
if (int_list[i] > max_class_id)
max_class_id = int_list[i];
}
nvinfer->operate_on_class_ids->assign (max_class_id + 1, FALSE);
for (i = 0; i < length; i++) {
nvinfer->operate_on_class_ids->at (int_list[i]) = TRUE;
}
g_free (int_list);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_CLASS_IDS_FOR_FILTERING)) {
gsize length;
gint *int_list = g_key_file_get_integer_list(key_file, group_name,
CONFIG_GROUP_INFER_CLASS_IDS_FOR_FILTERING, &length, &error);
CHECK_ERROR (error);
for (guint i = 0; i < length; i++) {
nvinfer->filter_out_class_ids->insert(int_list[i]);
}
g_free(int_list);
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_SCALING_COMPUTE_HW)) {
int val = g_key_file_get_integer (key_file, group_name,
CONFIG_GROUP_INFER_SCALING_COMPUTE_HW, &error);
CHECK_ERROR (error);
switch (val) {
case NvBufSurfTransformCompute_Default:
case NvBufSurfTransformCompute_GPU:
#ifdef __aarch64__
case NvBufSurfTransformCompute_VIC:
#endif
break;
default:
g_printerr ("Error. Invalid value for '%s':'%d'\n",
CONFIG_GROUP_INFER_SCALING_COMPUTE_HW, val);
goto done;
}
nvinfer->transform_config_params.compute_mode = (NvBufSurfTransform_Compute) val;
} else if (!g_strcmp0 (key, CONFIG_GROUP_INFER_SCALING_FILTER)) {
int val = g_key_file_get_integer (key_file, group_name,
CONFIG_GROUP_INFER_SCALING_FILTER, &error);
CHECK_ERROR (error);
switch (val) {
case NvBufSurfTransformInter_Nearest:
case NvBufSurfTransformInter_Bilinear:
case NvBufSurfTransformInter_Algo1:
case NvBufSurfTransformInter_Algo2:
case NvBufSurfTransformInter_Algo3:
case NvBufSurfTransformInter_Algo4:
case NvBufSurfTransformInter_Default:
break;
default:
g_printerr ("Error. Invalid value for '%s':'%d'\n",
CONFIG_GROUP_INFER_SCALING_FILTER, val);
goto done;
}
nvinfer->transform_params.transform_filter = (NvBufSurfTransform_Inter) val;
} else {
g_printerr ("Unknown or legacy key specified '%s' for group [%s]\n", key,
CONFIG_GROUP_PROPERTY);
}
ret = TRUE;
done:
if (error) {
g_error_free (error);
}
return ret;
}
/* Parse 'property' group. Returns FALSE in case of an error. If any of the
* properties are set through the GObject set method this function does not
* parse those properties i.e. values set through g_object_set override the
* corresponding properties in the config file. */
static gboolean
gst_nvinfer_parse_props (GstNvInfer * nvinfer,
NvDsInferContextInitParams * init_params,
GKeyFile * key_file, const gchar * cfg_file_path)
{
gboolean ret = FALSE;
gchar **keys = nullptr;
gchar **key = nullptr;
GError *error = nullptr;
assert (init_params != nullptr);
/* Handle legacy key names. */
if (g_key_file_has_key (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_IS_CLASSIFIER_LEGACY, nullptr)
&& !g_key_file_has_key (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_NETWORK_TYPE, nullptr)) {
/* Do not parse here, set the key-value pair with the new key. */
gboolean value = g_key_file_get_boolean (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_IS_CLASSIFIER_LEGACY, &error);
CHECK_ERROR (error);
guint new_value = (value) ? NvDsInferNetworkType_Classifier : NvDsInferNetworkType_Detector;
g_key_file_set_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_NETWORK_TYPE, new_value);
g_key_file_remove_key (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_IS_CLASSIFIER_LEGACY, nullptr);
}
keys = g_key_file_get_keys (key_file, CONFIG_GROUP_PROPERTY, nullptr, &error);
CHECK_ERROR (error);
if (nvinfer)
nvinfer->secondary_reinfer_interval = DEFAULT_REINFER_INTERVAL;
init_params->networkInputFormat = NvDsInferFormat_RGB;
for (key = keys; *key; key++) {
if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_UNIQUE_ID)) {
if (nvinfer && (*nvinfer->is_prop_set)[PROP_UNIQUE_ID])
continue;
init_params->uniqueID =
g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_UNIQUE_ID, &error);
CHECK_ERROR (error);
if (init_params->uniqueID <= 0) {
g_printerr ("Error: %s (%d) should be > 0\n",
CONFIG_GROUP_INFER_UNIQUE_ID, nvinfer->unique_id);
goto done;
}
if (nvinfer)
nvinfer->unique_id = init_params->uniqueID;
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_LABEL)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_LABEL, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->labelsFilePath)) {
g_printerr ("Error: Could not parse labels file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_GPU_ID)) {
if (nvinfer && (*nvinfer->is_prop_set)[PROP_GPU_DEVICE_ID])
continue;
gint devices;
init_params->gpuID =
g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_GPU_ID, &error);
CHECK_ERROR (error);
if (cudaGetDeviceCount (&devices) != cudaSuccess) {
g_printerr ("Error: Could not get cuda device count (%s)\n",
cudaGetErrorName (cudaGetLastError ()));
goto done;
}
if (init_params->gpuID >= (guint) devices && 0) {
g_printerr
("Error: Invalid gpu device ID (%d). CUDA device count (%d)\n",
init_params->gpuID, devices);
goto done;
}
if (nvinfer)
nvinfer->gpu_id = init_params->gpuID;
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_ENABLE_DLA)) {
if (g_key_file_get_boolean (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_ENABLE_DLA, &error))
init_params->useDLA = TRUE;
CHECK_ERROR (error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_USE_DLA_CORE)) {
init_params->dlaCore =
g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_USE_DLA_CORE, &error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_TENSOR_META_POOL_SIZE)) {
init_params->outputBufferPoolSize =
g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_TENSOR_META_POOL_SIZE, &error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_BATCH_SIZE)) {
if (nvinfer && (*nvinfer->is_prop_set)[PROP_BATCH_SIZE])
continue;
init_params->maxBatchSize =
g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_BATCH_SIZE, &error);
CHECK_ERROR (error);
if (init_params->maxBatchSize <= 0
|| init_params->maxBatchSize > NVDSINFER_MAX_BATCH_SIZE) {
g_printerr ("Error: %s(%d) should be in the range [%d,%d]\n",
CONFIG_GROUP_INFER_BATCH_SIZE, nvinfer->max_batch_size, 1,
NVDSINFER_MAX_BATCH_SIZE);
goto done;
}
if (nvinfer)
nvinfer->max_batch_size = init_params->maxBatchSize;
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_FORCE_IMPLICIT_BATCH_DIM)) {
if (g_key_file_get_boolean (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_FORCE_IMPLICIT_BATCH_DIM, &error))
init_params->forceImplicitBatchDimension = TRUE;
CHECK_ERROR (error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_WORKSPACE_SIZE)) {
init_params->workspaceSize =
g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_WORKSPACE_SIZE, &error);
CHECK_ERROR (error);
if (init_params->workspaceSize <= 0) {
g_print ("Info: workspace-size is 0, will use default size");
init_params->workspaceSize = 0;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_INFER_DIMENSIONS)) {
gsize length;
gint *int_list = g_key_file_get_integer_list (key_file,
CONFIG_GROUP_PROPERTY, CONFIG_GROUP_INFER_INFER_DIMENSIONS,
&length, &error);
CHECK_ERROR (error);
if (length != 3) {
g_printerr ("Error. '%s' array length is %lu. Should be 3 as [c;h;w] order.\n",
CONFIG_GROUP_INFER_INFER_DIMENSIONS, length);
goto done;
}
init_params->inferInputDims = NvDsInferDimsCHW {
(unsigned int) int_list[0],
(unsigned int) int_list[1], (unsigned int) int_list[2]};
g_free (int_list);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_NETWORK_MODE)) {
guint val = g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_NETWORK_MODE, &error);
CHECK_ERROR (error);
switch (val) {
case NvDsInferNetworkMode_FP32:
case NvDsInferNetworkMode_FP16:
case NvDsInferNetworkMode_INT8:
break;
default:
g_printerr ("Error. Invalid value for '%s':'%d'\n",
CONFIG_GROUP_INFER_NETWORK_MODE, val);
goto done;
break;
}
init_params->networkMode = (NvDsInferNetworkMode) val;
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_MODEL_ENGINE)) {
if (nvinfer && (*nvinfer->is_prop_set)[PROP_MODEL_ENGINEFILE])
continue;
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_MODEL_ENGINE, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->modelEngineFilePath)) {
g_printerr ("Error: Could not parse model engine file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_INT8_CALIBRATION_FILE)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_INT8_CALIBRATION_FILE, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->int8CalibrationFilePath)) {
g_printerr ("Error: Could not parse INT8 calibration file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_OUTPUT_BLOB_NAMES)) {
gsize length;
init_params->outputLayerNames =
g_key_file_get_string_list (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_OUTPUT_BLOB_NAMES, &length, &error);
init_params->numOutputLayers = length;
CHECK_ERROR (error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_OUTPUT_IO_FORMATS)) {
gsize length;
init_params->outputIOFormats = g_key_file_get_string_list(key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_OUTPUT_IO_FORMATS, &length, &error);
init_params->numOutputIOFormats = length;
CHECK_ERROR(error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_LAYER_DEVICE_PRECISION)) {
gsize length;
init_params->layerDevicePrecisions = g_key_file_get_string_list(key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_LAYER_DEVICE_PRECISION, &length, &error);
init_params->numLayerDevicePrecisions = length;
CHECK_ERROR(error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_NETWORK_TYPE)) {
guint val = g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_NETWORK_TYPE, &error);
CHECK_ERROR (error);
switch ((NvDsInferNetworkType) val) {
case NvDsInferNetworkType_Detector:
case NvDsInferNetworkType_Classifier:
case NvDsInferNetworkType_Segmentation:
case NvDsInferNetworkType_InstanceSegmentation:
case NvDsInferNetworkType_Other:
init_params->networkType = (NvDsInferNetworkType) val;
break;
default:
g_printerr ("Error. Invalid value for '%s':'%d'\n",
CONFIG_GROUP_INFER_NETWORK_TYPE, val);
goto done;
break;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_MODEL_COLOR_FORMAT)) {
guint val = g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_MODEL_COLOR_FORMAT, &error);
CHECK_ERROR (error);
switch (val) {
case 0:
init_params->networkInputFormat = NvDsInferFormat_RGB;
break;
case 1:
init_params->networkInputFormat = NvDsInferFormat_BGR;
break;
case 2:
init_params->networkInputFormat = NvDsInferFormat_GRAY;
break;
default:
g_printerr ("Error. Invalid value for '%s':'%d'\n",
CONFIG_GROUP_INFER_MODEL_COLOR_FORMAT, val);
goto done;
break;
}
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_SCALE_FACTOR)) {
init_params->networkScaleFactor =
g_key_file_get_double (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_SCALE_FACTOR, &error);
CHECK_ERROR (error);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_OFFSETS)) {
gsize length, i;
gdouble *dbl_list =
g_key_file_get_double_list (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_OFFSETS, &length, &error);
CHECK_ERROR (error);
if (length > _MAX_CHANNELS) {
g_printerr ("Error. Maximum length of %d is allowed for '%s'\n",
_MAX_CHANNELS, CONFIG_GROUP_INFER_OFFSETS);
g_free (dbl_list);
goto done;
}
for (i = 0; i < length; i++)
init_params->offsets[i] = dbl_list[i];
init_params->numOffsets = length;
g_free (dbl_list);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_MEANFILE)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_MEANFILE, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->meanImageFilePath)) {
g_printerr ("Error: Could not parse mean image file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CUSTOM_LIB_PATH)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_CUSTOM_LIB_PATH, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->customLibPath)) {
g_printerr ("Error: Could not parse custom library path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CUSTOM_PARSE_BBOX_FUNC)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_CUSTOM_PARSE_BBOX_FUNC, &error);
CHECK_ERROR (error);
g_strlcpy (init_params->customBBoxParseFuncName, str,
_MAX_STR_LENGTH);
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CUSTOM_PARSE_BBOX_IM_FUNC)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_CUSTOM_PARSE_BBOX_IM_FUNC, &error);
CHECK_ERROR (error);
g_strlcpy (init_params->customBBoxInstanceMaskParseFuncName, str,
_MAX_STR_LENGTH);
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CUSTOM_ENGINE_CREATE_FUNC)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_CUSTOM_ENGINE_CREATE_FUNC, &error);
CHECK_ERROR (error);
g_strlcpy (init_params->customEngineCreateFuncName, str,
_MAX_STR_LENGTH);
g_free (str);
} else if (!g_strcmp0 (*key,
CONFIG_GROUP_INFER_CUSTOM_PARSE_CLASSIFIER_FUNC)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_CUSTOM_PARSE_CLASSIFIER_FUNC, &error);
CHECK_ERROR (error);
g_strlcpy (init_params->customClassifierParseFuncName, str,
_MAX_STR_LENGTH);
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_CUSTOM_NETWORK_CONFIG)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_CUSTOM_NETWORK_CONFIG, &error);
CHECK_ERROR (error);
g_strlcpy (init_params->customNetworkConfigFilePath, str,
_MAX_STR_LENGTH);
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_MODEL)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_MODEL, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->modelFilePath)) {
g_printerr ("Error: Could not parse model file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_PROTO)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_PROTO, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->protoFilePath)) {
g_printerr ("Error: Could not parse prototxt file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_UFF)) {
gchar *str = g_key_file_get_string (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_UFF, &error);
CHECK_ERROR (error);
if (!get_absolute_file_path (cfg_file_path, str,
init_params->uffFilePath)) {
g_printerr ("Error: Could not parse UFF file path\n");
g_free (str);
goto done;
}
g_free (str);
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY)) {
/* Parse here if infer-dims has not been set, else ignore input-dims / uff-input-dims */
if(!g_key_file_has_key(key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_INFER_DIMENSIONS, nullptr)) {
g_printerr("Warning: 'input-dims' parameter has been deprecated. Use 'infer-dims' instead.\n");
gsize length;
gint *int_list = g_key_file_get_integer_list (key_file,
CONFIG_GROUP_PROPERTY, CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY,
&length, &error);
CHECK_ERROR (error);
if (length != 4) {
g_printerr ("Error. '%s' array length is %lu. Should be 4[a;b;c;ORDER].\n",
CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY, length);
goto done;
}
switch (int_list[3]) {
case 0:
init_params->uffInputOrder = NvDsInferTensorOrder_kNCHW;
break;
case 1:
init_params->uffInputOrder = NvDsInferTensorOrder_kNHWC;
break;
case 2:
init_params->uffInputOrder = NvDsInferTensorOrder_kNC;
break;
default:
g_printerr ("Error. Invalid value for '%s', UFF input order :'%d'\n",
CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY, int_list[3]);
goto done;
break;
}
init_params->inferInputDims = NvDsInferDimsCHW {(unsigned int) int_list[0],
(unsigned int) int_list[1], (unsigned int) int_list[2]};
g_free (int_list);
}
else
g_printerr("Warning: Ignoring 'input-dims' parameter since 'infer-dims' has been set.\n");
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY_V2)) {
/* Parse here if infer-dims has not been set, else ignore input-dims / uff-input-dims */
if(!g_key_file_has_key(key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_INFER_DIMENSIONS, nullptr)) {
g_printerr("Warning: 'input-dims' parameter has been deprecated. Use 'infer-dims' instead.\n");
gsize length;
gint *int_list = g_key_file_get_integer_list (key_file,
CONFIG_GROUP_PROPERTY, CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY_V2,
&length, &error);
CHECK_ERROR (error);
if (length != 4) {
g_printerr ("Error. '%s' array length is %lu. Should be 4[a;b;c;ORDER].\n",
CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY_V2, length);
goto done;
}
switch (int_list[3]) {
case 0:
init_params->uffInputOrder = NvDsInferTensorOrder_kNCHW;
break;
case 1:
init_params->uffInputOrder = NvDsInferTensorOrder_kNHWC;
break;
case 2:
init_params->uffInputOrder = NvDsInferTensorOrder_kNC;
break;
default:
g_printerr ("Error. Invalid value for '%s', UFF input order :'%d'\n",
CONFIG_GROUP_INFER_UFF_INPUT_DIMENSIONS_LEGACY_V2, int_list[3]);
goto done;
break;
}
init_params->inferInputDims = NvDsInferDimsCHW {(unsigned int) int_list[0],
(unsigned int) int_list[1], (unsigned int) int_list[2]};
g_free (int_list);
}
else
g_printerr("Warning: Ignoring 'uff-input-dims' parameter since 'infer-dims' has been set.\n");
} else if (!g_strcmp0 (*key, CONFIG_GROUP_INFER_NET_INPUT_ORDER)){
gint val = g_key_file_get_integer (key_file, CONFIG_GROUP_PROPERTY,
CONFIG_GROUP_INFER_NET_INPUT_ORDER, &error);
CHECK_ERROR (error);
switch (val) {
case 0:
init_params->netInputOrder = NvDsInferTensorOrder_kNCHW;
break;
case 1:
init_params->netInputOrder = NvDsInferTensorOrder_kNHWC;
break;
default:
g_printerr ("Error. Invalid value for '%s', network input order :'%d'\n",
CONFIG_GROUP_INFER_NET_INPUT_ORDER, val);
goto done;