Skip to content

Commit 64e3160

Browse files
committed
Expand supported model list
1 parent 28097ba commit 64e3160

File tree

3 files changed

+84
-89
lines changed

3 files changed

+84
-89
lines changed

demos/python_demos/common/models/ssd.py

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -21,85 +21,6 @@
2121

2222

2323
class SSD(Model):
24-
class SingleOutputParser:
25-
def __init__(self, all_outputs):
26-
if len(all_outputs) != 1:
27-
raise ValueError('Network must have only one output.')
28-
self.output_name, output_data = next(iter(all_outputs.items()))
29-
last_dim = np.shape(output_data)[-1]
30-
if last_dim != 7:
31-
raise ValueError('The last dimension of the output blob must be equal to 7, '
32-
'got {} instead.'.format(last_dim))
33-
34-
def __call__(self, outputs):
35-
return [Detection(xmin, ymin, xmax, ymax, score, label)
36-
for _, label, score, xmin, ymin, xmax, ymax in outputs[self.output_name][0][0]]
37-
38-
class MultipleOutputParser:
39-
def __init__(self, layers, bboxes_layer='bboxes', scores_layer='scores', labels_layer='labels'):
40-
def find_layer_by_name(name, layers):
41-
suitable_layers = [layer_name for layer_name in layers if name in layer_name]
42-
if not suitable_layers:
43-
raise ValueError('Suitable layer for "{}" output is not found'.format(name))
44-
45-
if len(suitable_layers) > 1:
46-
raise ValueError('More than 1 layer matched to "{}" output'.format(name))
47-
48-
return suitable_layers[0]
49-
self.labels_layer = find_layer_by_name(labels_layer, layers)
50-
self.scores_layer = find_layer_by_name(scores_layer, layers)
51-
self.bboxes_layer = find_layer_by_name(bboxes_layer, layers)
52-
53-
def __call__(self, outputs):
54-
bboxes = outputs[self.bboxes_layer][0]
55-
scores = outputs[self.scores_layer][0]
56-
labels = outputs[self.labels_layer][0]
57-
return [Detection(*bbox, score, label) for label, score, bbox in zip(labels, scores, bboxes)]
58-
59-
class BoxesLabelsParser:
60-
def __init__(self, input_size, all_outputs, labels_layer='labels', default_label=1):
61-
try:
62-
self.labels_layer = find_layer_by_name(labels_layer, all_outputs) # ?
63-
self.logger.info('Use output "{}" as the one containing labels of detected objects.'
64-
.format(self.labels_layer))
65-
except ValueError:
66-
self.logger.warning('Suitable layer for "{}" output is not found. '
67-
'Treating detector as class agnostic with output label {}'
68-
.format(labels_layer, default_label))
69-
self.labels_layer = None
70-
self.default_label = default_label
71-
72-
self.input_size = input_size
73-
self.bboxes_layer = self.find_layer_bboxes_output(all_outputs)
74-
self.logger.info('Use auto-detected output "{}" as the one containing detected bounding boxes.'
75-
.format(self.bboxes_layer))
76-
77-
@staticmethod
78-
def find_layer_bboxes_output(all_outputs):
79-
filter_outputs = [
80-
output_name for output_name, out_data in all_outputs.items()
81-
if len(np.shape(out_data)) == 2 and np.shape(out_data)[-1] == 5
82-
]
83-
if not filter_outputs:
84-
raise ValueError('Suitable output with bounding boxes is not found')
85-
if len(filter_outputs) > 1:
86-
raise ValueError('More than 1 candidate for output with bounding boxes.')
87-
return filter_outputs[0]
88-
89-
def __call__(self, outputs):
90-
bboxes = outputs[self.bboxes_layer]
91-
scores = bboxes[:, 4]
92-
bboxes = bboxes[:, :4]
93-
bboxes[:, 0::2] /= self.input_size[0]
94-
bboxes[:, 1::2] /= self.input_size[1]
95-
if self.labels_layer:
96-
labels = outputs[self.labels_layer] + 1
97-
else:
98-
labels = np.full(len(bboxes), self.default_label, dtype=bboxes.dtype)
99-
100-
detections = [Detection(*bbox, score, label) for label, score, bbox in zip(labels, scores, bboxes)]
101-
return detections
102-
10324
def __init__(self, ie, model_path, labels=None, keep_aspect_ratio_resize=False):
10425
super().__init__(ie, model_path)
10526

@@ -131,22 +52,21 @@ def _get_inputs(self):
13152

13253
def _get_output_parser(self, net, image_blob_name, bboxes='bboxes', labels='labels', scores='scores'):
13354
try:
134-
parser = self.SingleOutputParser(net.outputs)
55+
parser = SingleOutputParser(net.outputs)
13556
self.logger.info('Use SingleOutputParser')
13657
return parser
13758
except ValueError:
13859
pass
13960

14061
try:
141-
parser = self.MultipleOutputParser(net.outputs, bboxes, scores, labels)
62+
parser = MultipleOutputParser(net.outputs, bboxes, scores, labels)
14263
self.logger.info('Use MultipleOutputParser')
14364
return parser
14465
except ValueError:
14566
pass
14667

14768
try:
148-
h, w = net.input_info[image_blob_name].input_data.shape[2:]
149-
parser = self.BoxesLabelsParser([w, h], net.outputs)
69+
parser = BoxesLabelsParser(net.outputs, net.input_info[image_blob_name].input_data.shape[2:])
15070
self.logger.info('Use BoxesLabelsParser')
15171
return parser
15272
except ValueError:
@@ -184,3 +104,77 @@ def postprocess(self, outputs, meta):
184104
detection.ymin *= scale_y
185105
detection.ymax *= scale_y
186106
return detections
107+
108+
109+
def find_layer_by_name(name, layers):
110+
suitable_layers = [layer_name for layer_name in layers if name in layer_name]
111+
if not suitable_layers:
112+
raise ValueError('Suitable layer for "{}" output is not found'.format(name))
113+
114+
if len(suitable_layers) > 1:
115+
raise ValueError('More than 1 layer matched to "{}" output'.format(name))
116+
117+
return suitable_layers[0]
118+
119+
120+
class SingleOutputParser:
121+
def __init__(self, all_outputs):
122+
if len(all_outputs) != 1:
123+
raise ValueError('Network must have only one output.')
124+
self.output_name, output_data = next(iter(all_outputs.items()))
125+
last_dim = np.shape(output_data)[-1]
126+
if last_dim != 7:
127+
raise ValueError('The last dimension of the output blob must be equal to 7, '
128+
'got {} instead.'.format(last_dim))
129+
130+
def __call__(self, outputs):
131+
return [Detection(xmin, ymin, xmax, ymax, score, label)
132+
for _, label, score, xmin, ymin, xmax, ymax in outputs[self.output_name][0][0]]
133+
134+
135+
class MultipleOutputParser:
136+
def __init__(self, layers, bboxes_layer='bboxes', scores_layer='scores', labels_layer='labels'):
137+
self.labels_layer = find_layer_by_name(labels_layer, layers)
138+
self.scores_layer = find_layer_by_name(scores_layer, layers)
139+
self.bboxes_layer = find_layer_by_name(bboxes_layer, layers)
140+
141+
def __call__(self, outputs):
142+
bboxes = outputs[self.bboxes_layer][0]
143+
scores = outputs[self.scores_layer][0]
144+
labels = outputs[self.labels_layer][0]
145+
return [Detection(*bbox, score, label) for label, score, bbox in zip(labels, scores, bboxes)]
146+
147+
148+
class BoxesLabelsParser:
149+
def __init__(self, layers, input_size, labels_layer='labels', default_label=0):
150+
try:
151+
self.labels_layer = find_layer_by_name(labels_layer, layers)
152+
except ValueError:
153+
self.labels_layer = None
154+
self.default_label = default_label
155+
156+
self.bboxes_layer = self.find_layer_bboxes_output(layers)
157+
self.input_size = input_size
158+
159+
@staticmethod
160+
def find_layer_bboxes_output(layers):
161+
filter_outputs = [name for name, data in layers.items() if len(np.shape(data)) == 2 and np.shape(data)[-1] == 5]
162+
if not filter_outputs:
163+
raise ValueError('Suitable output with bounding boxes is not found')
164+
if len(filter_outputs) > 1:
165+
raise ValueError('More than 1 candidate for output with bounding boxes.')
166+
return filter_outputs[0]
167+
168+
def __call__(self, outputs):
169+
bboxes = outputs[self.bboxes_layer]
170+
scores = bboxes[:, 4]
171+
bboxes = bboxes[:, :4]
172+
bboxes[:, 0::2] /= self.input_size[0]
173+
bboxes[:, 1::2] /= self.input_size[1]
174+
if self.labels_layer:
175+
labels = outputs[self.labels_layer]
176+
else:
177+
labels = np.full(len(bboxes), self.default_label, dtype=bboxes.dtype)
178+
179+
detections = [Detection(*bbox, score, label) for label, score, bbox in zip(labels, scores, bboxes)]
180+
return detections

demos/python_demos/object_detection_demo/models.lst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# This file can be used with the --list option of the model downloader.
22
# For --architecture_type=ssd
3-
face-detection-0200
4-
face-detection-0202
5-
face-detection-0204
3+
face-detection-????
64
face-detection-adas-????
75
face-detection-retail-????
86
pedestrian-and-vehicle-detector-adas-????
97
pedestrian-detection-adas-????
108
pelee-coco
11-
person-detection-0200
12-
person-detection-0201
13-
person-detection-0202
9+
person-detection-????
1410
person-detection-retail-0013
11+
product-detection-0001
1512
retinanet-tf
1613
ssd-resnet34-1200-onnx
1714
vehicle-detection-adas-????

demos/tests/cases.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,21 @@ def single_option_cases(key, *args):
499499
ModelArg('face-detection-0200'),
500500
ModelArg('face-detection-0202'),
501501
ModelArg('face-detection-0204'),
502+
ModelArg('face-detection-0205'),
503+
ModelArg('face-detection-0206'),
502504
ModelArg('face-detection-adas-0001'),
503505
ModelArg('face-detection-retail-0004'),
504506
ModelArg('face-detection-retail-0005'),
505507
ModelArg('face-detection-retail-0044'),
506508
ModelArg('pedestrian-and-vehicle-detector-adas-0001'),
507509
ModelArg('pedestrian-detection-adas-0002'),
510+
ModelArg('person-detection-0106'),
508511
ModelArg('person-detection-0200'),
509512
ModelArg('person-detection-0201'),
510513
ModelArg('person-detection-0202'),
511514
ModelArg('person-detection-retail-0013'),
512515
ModelArg('pelee-coco'),
516+
ModelArg('product-detection-0001'),
513517
ModelArg('retinanet-tf'),
514518
ModelArg('ssd-resnet34-1200-onnx'),
515519
ModelArg('vehicle-detection-adas-0002'),

0 commit comments

Comments
 (0)