|
@@ -38,11 +38,6 @@ class Predictor:
|
|
|
self.model_name = self.info['Model']
|
|
self.model_name = self.info['Model']
|
|
|
self.num_classes = self.info['_Attributes']['num_classes']
|
|
self.num_classes = self.info['_Attributes']['num_classes']
|
|
|
self.labels = self.info['_Attributes']['labels']
|
|
self.labels = self.info['_Attributes']['labels']
|
|
|
- if self.info['Model'] == 'MaskRCNN':
|
|
|
|
|
- if self.info['_init_params']['with_fpn']:
|
|
|
|
|
- self.mask_head_resolution = 28
|
|
|
|
|
- else:
|
|
|
|
|
- self.mask_head_resolution = 14
|
|
|
|
|
transforms_mode = self.info.get('TransformsMode', 'RGB')
|
|
transforms_mode = self.info.get('TransformsMode', 'RGB')
|
|
|
if transforms_mode == 'RGB':
|
|
if transforms_mode == 'RGB':
|
|
|
to_rgb = True
|
|
to_rgb = True
|
|
@@ -137,7 +132,7 @@ class Predictor:
|
|
|
def preprocess(self, image):
|
|
def preprocess(self, image):
|
|
|
res = dict()
|
|
res = dict()
|
|
|
if self.model_type == "classifier":
|
|
if self.model_type == "classifier":
|
|
|
- im, = self.transforms(image)
|
|
|
|
|
|
|
+ im = self.transforms(image)
|
|
|
im = np.expand_dims(im, axis=0).copy()
|
|
im = np.expand_dims(im, axis=0).copy()
|
|
|
res['image'] = im
|
|
res['image'] = im
|
|
|
elif self.model_type == "detector":
|
|
elif self.model_type == "detector":
|
|
@@ -147,14 +142,6 @@ class Predictor:
|
|
|
im_shape = np.expand_dims(im_shape, axis=0).copy()
|
|
im_shape = np.expand_dims(im_shape, axis=0).copy()
|
|
|
res['image'] = im
|
|
res['image'] = im
|
|
|
res['im_size'] = im_shape
|
|
res['im_size'] = im_shape
|
|
|
- if self.model_name.count('RCNN') > 0:
|
|
|
|
|
- im, im_resize_info, im_shape = self.transforms(image)
|
|
|
|
|
- im = np.expand_dims(im, axis=0).copy()
|
|
|
|
|
- im_resize_info = np.expand_dims(im_resize_info, axis=0).copy()
|
|
|
|
|
- im_shape = np.expand_dims(im_shape, axis=0).copy()
|
|
|
|
|
- res['image'] = im
|
|
|
|
|
- res['im_info'] = im_resize_info
|
|
|
|
|
- res['im_shape'] = im_shape
|
|
|
|
|
elif self.model_type == "segmenter":
|
|
elif self.model_type == "segmenter":
|
|
|
im, im_info = self.transforms(image)
|
|
im, im_info = self.transforms(image)
|
|
|
im = np.expand_dims(im, axis=0).copy()
|
|
im = np.expand_dims(im, axis=0).copy()
|
|
@@ -173,6 +160,7 @@ class Predictor:
|
|
|
'category': self.labels[l],
|
|
'category': self.labels[l],
|
|
|
'score': preds[output_name][0][l],
|
|
'score': preds[output_name][0][l],
|
|
|
} for l in pred_label]
|
|
} for l in pred_label]
|
|
|
|
|
+ print(result)
|
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
def segmenter_postprocess(self, preds, preprocessed_inputs):
|
|
def segmenter_postprocess(self, preds, preprocessed_inputs):
|
|
@@ -185,8 +173,10 @@ class Predictor:
|
|
|
score_name = next(it)
|
|
score_name = next(it)
|
|
|
score_map = np.squeeze(preds[score_name])
|
|
score_map = np.squeeze(preds[score_name])
|
|
|
score_map = np.transpose(score_map, (1, 2, 0))
|
|
score_map = np.transpose(score_map, (1, 2, 0))
|
|
|
|
|
+
|
|
|
im_info = preprocessed_inputs['im_info']
|
|
im_info = preprocessed_inputs['im_info']
|
|
|
- for info in im_info[::-1]:
|
|
|
|
|
|
|
+
|
|
|
|
|
+ for info in im_info[0][::-1]:
|
|
|
if info[0] == 'resize':
|
|
if info[0] == 'resize':
|
|
|
w, h = info[1][1], info[1][0]
|
|
w, h = info[1][1], info[1][0]
|
|
|
label_map = cv2.resize(label_map, (w, h), cv2.INTER_NEAREST)
|
|
label_map = cv2.resize(label_map, (w, h), cv2.INTER_NEAREST)
|
|
@@ -195,21 +185,18 @@ class Predictor:
|
|
|
w, h = info[1][1], info[1][0]
|
|
w, h = info[1][1], info[1][0]
|
|
|
label_map = label_map[0:h, 0:w]
|
|
label_map = label_map[0:h, 0:w]
|
|
|
score_map = score_map[0:h, 0:w, :]
|
|
score_map = score_map[0:h, 0:w, :]
|
|
|
- else:
|
|
|
|
|
- raise Exception("Unexpected info '{}' in im_info".format(info[
|
|
|
|
|
- 0]))
|
|
|
|
|
return {'label_map': label_map, 'score_map': score_map}
|
|
return {'label_map': label_map, 'score_map': score_map}
|
|
|
|
|
|
|
|
def detector_postprocess(self, preds, preprocessed_inputs):
|
|
def detector_postprocess(self, preds, preprocessed_inputs):
|
|
|
"""对图像检测结果做后处理
|
|
"""对图像检测结果做后处理
|
|
|
"""
|
|
"""
|
|
|
outputs = self.net.outputs
|
|
outputs = self.net.outputs
|
|
|
- for name in outpus:
|
|
|
|
|
- if (len(outputs[name].shape == 3)):
|
|
|
|
|
|
|
+ for name in outputs:
|
|
|
|
|
+ if (len(outputs[name].shape) == 3):
|
|
|
output = preds[name][0]
|
|
output = preds[name][0]
|
|
|
result = []
|
|
result = []
|
|
|
for out in output:
|
|
for out in output:
|
|
|
- if (out[0] > 0):
|
|
|
|
|
|
|
+ if (out[0] >= 0):
|
|
|
result.append(out.tolist())
|
|
result.append(out.tolist())
|
|
|
else:
|
|
else:
|
|
|
pass
|
|
pass
|