@@ -78,6 +78,7 @@ class BackEnd(IntEnum):
7878 CAFFE = 1
7979 SNPE = 2
8080 TRT = 3
81+ NNIE = 4
8182
8283
8384def isconst (x ):
@@ -118,7 +119,10 @@ def _gen_layer(opr, etype, context, single_input=True, **kwargs):
118119 if single_input
119120 else list (map (context .get_blob_name , opr .inp_tensors ))
120121 )
121- top = [context .set_blob_name (opr .out_tensors [0 ], opr .out_tensors [0 ].name )]
122+ if etype == "ReLU" and context .convert_backend == BackEnd .NNIE :
123+ top = [context .set_blob_name (opr .out_tensors [0 ], opr .inp_tensors [0 ].name )]
124+ else :
125+ top = [context .set_blob_name (opr .out_tensors [0 ], opr .out_tensors [0 ].name )]
122126 return cp .LayerParameter (
123127 bottom = bottom , top = top , name = opr .out_tensors [0 ].name , type = etype , ** kwargs
124128 )
@@ -949,11 +953,8 @@ def _reshape(opr, context):
949953 tmp_shape = out_shape + (1 ,) * d
950954 bottom = [context .get_blob_name (opr .inp_tensors [0 ])]
951955 top = [context .set_blob_name (opr .out_tensors [0 ], opr .out_tensors [0 ].name )]
952- if context .convert_backend == BackEnd .CAFFE :
956+ if context .convert_backend == BackEnd .NNIE :
953957 if inp_shape != tmp_shape :
954- logger .warning (
955- "trt don't support flatten after reshape, but caffe support! please use BackEnd.TRT in tracedmodule_to_caffe by pass convert_backend:BackEnd=BackEnd.TRT"
956- )
957958 param = cp .ReshapeParameter (shape = cp .BlobShape (dim = tmp_shape ))
958959 tmp = [bottom [0 ] + "tmp" ]
959960 context .add_layer (
@@ -976,18 +977,17 @@ def _reshape(opr, context):
976977 flatten_param = param ,
977978 )
978979 )
979- elif context .convert_backend == BackEnd .TRT :
980- if inp_shape != tmp_shape :
981- param = cp .ReshapeParameter (shape = cp .BlobShape (dim = tmp_shape ))
982- context .add_layer (
983- cp .LayerParameter (
984- bottom = bottom ,
985- top = top ,
986- name = opr .out_tensors [0 ].name ,
987- type = "Reshape" ,
988- reshape_param = param ,
989- )
980+ else :
981+ param = cp .ReshapeParameter (shape = cp .BlobShape (dim = out_shape ))
982+ context .add_layer (
983+ cp .LayerParameter (
984+ bottom = bottom ,
985+ top = top ,
986+ name = opr .out_tensors [0 ].name ,
987+ type = "Reshape" ,
988+ reshape_param = param ,
990989 )
990+ )
991991 else :
992992 logger .warning (
993993 "NNIE doesn't support this reshape Opr %s, inp_shape %s, out_shape %s, NNIE reshape only support C/H/W, not N!" ,
0 commit comments