34 from cnn_manager
import CNNManager
35 from metadata_service
import MetadataService
36 from tools
import str2bool
40 """Parse the arguments provided when the module was initialized""" 42 rospy.init_node(
'cnn_bridge', log_level=rospy.DEBUG)
48 if rospy.has_param(
'~source'):
49 if isinstance(rospy.get_param(
'~source'), str):
50 params[
'source'] = rospy.get_param(
'~source')
52 raise rospy.ROSInitException(
53 'The source display needs to be of type: String')
55 raise rospy.ROSInitException(
'Param source is required (String)')
58 if rospy.has_param(
'~logdir'):
59 if isinstance(rospy.get_param(
'~logdir'), str):
60 params[
'logdir'] = rospy.get_param(
'~logdir')
62 raise rospy.ROSInitException(
63 'The logdir display needs to be of type: String')
65 raise rospy.ROSInitException(
'Param logdir is required (String)')
68 if rospy.has_param(
'~metadata_source'):
69 if isinstance(rospy.get_param(
'~metadata_source'), str):
70 params[
'metadata_source'] = rospy.get_param(
'~metadata_source')
72 raise rospy.ROSInitException(
73 'The metadata source needs to be of type: String')
75 raise rospy.ROSInitException(
'Param source is required (String)')
78 if rospy.has_param(
'~input_tensor'):
79 if isinstance(rospy.get_param(
'~input_tensor'), str):
80 params[
'input_tensor'] = rospy.get_param(
'~input_tensor')
82 raise rospy.ROSInitException(
83 'The input_tensor needs to be of type: String')
85 raise rospy.ROSInitException(
'Param input_tensor is required (String)')
88 if rospy.has_param(
'~output_tensor'):
89 if isinstance(rospy.get_param(
'~output_tensor'), str):
90 params[
'output_tensor'] = rospy.get_param(
'~output_tensor')
92 raise rospy.ROSInitException(
93 'The output_tensor needs to be of type: String')
95 raise rospy.ROSInitException(
96 'Param output_tensor is required (String)')
99 if rospy.has_param(
'~display'):
100 if str2bool(rospy.get_param(
'~display'))
is not None:
101 params[
'display'] = rospy.get_param(
'~display')
103 raise rospy.ROSInitException(
104 'The param display needs to be of type: Boolean')
106 params[
'display'] =
True 111 if rospy.has_param(
'~video_save'):
112 params[
'video_save'] = rospy.get_param(
'~video_save')
114 params[
'video_save'] =
'' 117 if rospy.has_param(
'~cpu'):
118 if str2bool(rospy.get_param(
'~cpu'))
is not None:
119 params[
'cpu'] = rospy.get_param(
'~cpu')
121 raise rospy.ROSInitException(
122 'The param cpu needs to be of type: Boolean')
124 params[
'cpu'] =
False 127 if rospy.has_param(
'~mode'):
128 if isinstance(rospy.get_param(
'~metadata_source'), str):
129 if rospy.get_param(
'~mode') ==
'detection' or rospy.get_param(
'~mode') ==
'segmentation':
130 params[
'mode'] = rospy.get_param(
'~mode')
132 raise rospy.ROSInitException(
135 raise rospy.ROSInitException(
136 'The param mode needs to be of type: String')
138 raise rospy.ROSInitException(
'Param mode is required (String)')
141 if rospy.has_param(
'~gpu_percent'):
142 if isinstance(rospy.get_param(
'~gpu_percent'), float):
143 params[
'gpu_percent'] = rospy.get_param(
'~gpu_percent')
145 raise rospy.ROSInitException(
146 'The param gpu_percent needs to be of type: Float')
148 params[
'gpu_percent'] = 1
153 if __name__ ==
"__main__":
156 tensor_io[
'input_tensor'] = args[
'input_tensor']
157 tensor_io[
'output_tensor'] = args[
'output_tensor']
158 if args[
'mode'] ==
'segmentation':
159 tensor_io[
'output_tensor'] = args[
'output_tensor']
160 elif args[
'mode'] ==
'detection':
161 tensor_io[
'output_tensor'] = args[
'output_tensor'].split(
',')
163 manager =
CNNManager(args[
'source'], args[
'video_save'], args[
'logdir'], args[
'cpu'],
164 args[
'display'], tensor_io, args[
'mode'], gpu_percent=args[
'gpu_percent'])
166 manager.camera.original_image_size, args[
'metadata_source'], args[
'logdir'], args[
'mode'])