Skip to content

Commit d4e9250

Browse files
committed
add matmul to proto
1 parent ac7d815 commit d4e9250

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

convert_script.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ sor4onnx \
6363
--output_onnx_file_path nms_yolact_edge.onnx \
6464
--mode inputs
6565

66+
sor4onnx \
67+
--input_onnx_file_path nms_yolact_edge.onnx \
68+
--old_new "input_5" "nms_proto" \
69+
--output_onnx_file_path nms_yolact_edge.onnx \
70+
--mode inputs
71+
72+
73+
74+
sor4onnx \
75+
--input_onnx_file_path nms_yolact_edge.onnx \
76+
--old_new "Identity_1" "proto_out" \
77+
--output_onnx_file_path nms_yolact_edge.onnx \
78+
--mode outputs
79+
6680
sor4onnx \
6781
--input_onnx_file_path nms_yolact_edge.onnx \
6882
--old_new "Identity" "x1y1x2y2_scores_classes_masks_4x1x1x32" \
@@ -73,7 +87,7 @@ sor4onnx \
7387
snc4onnx \
7488
--input_onnx_file_paths yolact_edge_mobilenetv2_54_800000.onnx nms_yolact_edge.onnx \
7589
--op_prefixes_after_merging main post \
76-
--srcop_destop boxes nms_boxes scores nms_scores classes nms_classes masks nms_masks \
90+
--srcop_destop boxes nms_boxes scores nms_scores classes nms_classes masks nms_masks proto nms_proto \
7791
--output_onnx_file_path yolact_edge_mobilenetv2_550x550.onnx
7892

7993

@@ -92,10 +106,13 @@ sor4onnx \
92106

93107
sor4onnx \
94108
--input_onnx_file_path yolact_edge_mobilenetv2_550x550.onnx \
95-
--old_new "main_proto" "proto" \
109+
--old_new "post_proto_out" "proto_out" \
96110
--output_onnx_file_path yolact_edge_mobilenetv2_550x550.onnx \
97111
--mode outputs
98112

113+
onnxsim yolact_edge_mobilenetv2_550x550.onnx yolact_edge_mobilenetv2_550x550.onnx
114+
onnxsim yolact_edge_mobilenetv2_550x550.onnx yolact_edge_mobilenetv2_550x550.onnx
115+
99116

100117

101118
$INTEL_OPENVINO_DIR/deployment_tools/model_optimizer/mo.py \

nms_yolact_edge.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343
dtype=tf.float32,
4444
)
4545

46+
protos = tf.keras.layers.Input(
47+
shape=[
48+
138,
49+
138,
50+
BOXES,
51+
],
52+
batch_size=1,
53+
dtype=tf.float32,
54+
)
4655

4756
boxes_non_batch = tf.squeeze(boxes)
4857
x1 = boxes_non_batch[:,0][:,np.newaxis]
@@ -85,10 +94,17 @@
8594
selected_indices
8695
)
8796

97+
selected_protos = tf.gather(
98+
protos[0],
99+
selected_indices,
100+
axis=2,
101+
)
102+
selected_protos_trans = tf.transpose(selected_protos, perm=[2,0,1])
103+
88104

89105
outputs = tf.concat([selected_boxes, selected_scores, selected_classes, selected_masks], axis=1)
90106

91-
model = tf.keras.models.Model(inputs=[boxes,scores,classes,masks], outputs=[outputs])
107+
model = tf.keras.models.Model(inputs=[boxes,scores,classes,masks,protos], outputs=[outputs, selected_protos_trans])
92108
model.summary()
93109
output_path = 'saved_model_postprocess'
94110
tf.saved_model.save(model, output_path)

yolact_edge/yolact.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,11 @@ def forward(self, x, extras=None):
958958
priors = torch.cat(priors, 0)
959959
boxes, scores, classes, masks = self.detect(loc, conf, mask, priors)
960960

961+
proto_out = proto_out[0] @ masks[0].t()
962+
proto_out = torch.sigmoid(proto_out)
963+
# masks = crop(masks, boxes)
964+
proto_out = proto_out.permute(2, 0, 1).contiguous()[np.newaxis, ...]
965+
961966
return boxes, scores, classes, masks, proto_out
962967

963968

0 commit comments

Comments
 (0)