-
Notifications
You must be signed in to change notification settings - Fork 66
/
make_trafficcamnet_engine_files.py
150 lines (122 loc) · 5.92 KB
/
make_trafficcamnet_engine_files.py
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
################################################################################
# The MIT License
#
# Copyright (c) 2022, Prominence AI, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
################################################################################
#!/usr/bin/env python
import sys
import time
from dsl import *
################################################################################
# This script can be used to generate the tensorflow Resnet caffemodel engine
# files using the config files under the installed NVIDIA Samples folder.
#
# Default is set to nano - Swap/update the primary config pathspec for other platforms.
# Test URI used for all sources
uri = '/opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h265.mp4'
# Config file for the Primary GIE
inferConfigFile = \
'/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_primary.txt'
tracker_config_file = \
'/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_tracker_IOU.yml'
# Config files for the Secondary GIEs
sgie1_config_file = \
'/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_secondary_vehiclemake.txt'
sgie2_config_file = \
'/opt/nvidia/deepstream/deepstream/samples/configs/deepstream-app/config_infer_secondary_vehicletypes.txt'
TILER_WIDTH = DSL_1K_HD_WIDTH
TILER_HEIGHT = DSL_1K_HD_HEIGHT
##
# Function to be called on End-of-Stream (EOS) event
##
def eos_event_listener(client_data):
print('Pipeline EOS event')
dsl_main_loop_quit()
def main(args):
# Since we're not using args, we can Let DSL initialize GST on first call
while True:
#
# Create the Pipeline components
# ... starting with eight URI File Sources
retval = dsl_source_uri_new('Camera 1', uri, False, False, 0)
if retval != DSL_RETURN_SUCCESS:
break
dsl_source_uri_new('Camera 2', uri, False, False, 0)
dsl_source_uri_new('Camera 3', uri, False, False, 0)
dsl_source_uri_new('Camera 4', uri, False, False, 0)
dsl_source_uri_new('Camera 5', uri, False, False, 0)
dsl_source_uri_new('Camera 6', uri, False, False, 0)
dsl_source_uri_new('Camera 7', uri, False, False, 0)
dsl_source_uri_new('Camera 8', uri, False, False, 0)
# New Primary GIE using the filespecs above, with interval and Id. Setting the
# model_engine_files parameter to None allows for model generation if not found.
retval = dsl_infer_gie_primary_new('primary-gie',
inferConfigFile, None, interval=10)
if retval != DSL_RETURN_SUCCESS:
break
# New Secondary GIEs using the filespecs above with interval = 0
retval = dsl_infer_gie_secondary_new('vehiclemake-sgie',
sgie1_config_file, None, 'primary-gie', 10)
if retval != DSL_RETURN_SUCCESS:
break
retval = dsl_infer_gie_secondary_new('vehicletype-sgie',
sgie2_config_file, None, 'primary-gie', 10)
if retval != DSL_RETURN_SUCCESS:
break
# New IOU Tracker, setting max width and height of input frame
retval = dsl_tracker_new('tracker', tracker_config_file, 480, 288)
if retval != DSL_RETURN_SUCCESS:
break
# New Tiler, setting width and height, use default cols/rows set by source count
retval = dsl_tiler_new('tiler', TILER_WIDTH, TILER_HEIGHT)
if retval != DSL_RETURN_SUCCESS:
break
# New Fake Sink to terminate the stream.
retval = dsl_sink_fake_new('fake-sink')
if retval != DSL_RETURN_SUCCESS:
break
#----------------------------------------------------------------------------------------------------
# Pipeline assembly
#
# New Pipeline (trunk) with our Sources, Tracker, and Pre-Tiler as last component
# Note: *** change 'iou-tracker' to 'ktl-tracker' to try both. KTL => higher CPU load
retval = dsl_pipeline_new_component_add_many('pipeline',
['Camera 1', 'Camera 2', 'Camera 3', 'Camera 4', 'Camera 5', 'Camera 6',
'Camera 7', 'Camera 8', 'primary-gie', 'tracker', 'vehiclemake-sgie',
'vehicletype-sgie', 'tiler', 'fake-sink', None])
if retval != DSL_RETURN_SUCCESS:
break
retval = dsl_pipeline_eos_listener_add('pipeline', eos_event_listener, None)
if retval != DSL_RETURN_SUCCESS:
break
# Play the pipeline
retval = dsl_pipeline_play('pipeline')
if retval != DSL_RETURN_SUCCESS:
break
# Once the pipeline is playing, the model engine files will have been saved.
# Safe to stop the pipline and quit now.
retval = dsl_pipeline_stop('pipeline')
break
# Print out the final result
print(dsl_return_value_to_string(retval))
dsl_delete_all()
if __name__ == '__main__':
sys.exit(main(sys.argv))