Skip to content

Commit 74fda8b

Browse files
committed
fix inference KIE model using onnx model
1 parent d1bc416 commit 74fda8b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

ppstructure/kie/predict_kie_token_ser.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
class SerPredictor(object):
4242
def __init__(self, args):
43+
self.args = args
4344
self.ocr_engine = PaddleOCR(
4445
use_angle_cls=args.use_angle_cls,
4546
det_model_dir=args.det_model_dir,
@@ -113,15 +114,18 @@ def __call__(self, img):
113114
data[idx] = np.expand_dims(data[idx], axis=0)
114115
else:
115116
data[idx] = [data[idx]]
117+
if self.args.use_onnx:
118+
input_tensor = {name: data[idx] for idx, name in enumerate(self.input_tensor)}
119+
self.output_tensors = self.predictor.run(None, input_tensor)
120+
else:
121+
for idx in range(len(self.input_tensor)):
122+
self.input_tensor[idx].copy_from_cpu(data[idx])
116123

117-
for idx in range(len(self.input_tensor)):
118-
self.input_tensor[idx].copy_from_cpu(data[idx])
119-
120-
self.predictor.run()
124+
self.predictor.run()
121125

122126
outputs = []
123127
for output_tensor in self.output_tensors:
124-
output = output_tensor.copy_to_cpu()
128+
output = output_tensor if self.args.use_onnx else output_tensor.copy_to_cpu()
125129
outputs.append(output)
126130
preds = outputs[0]
127131

tools/infer/utility.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def create_predictor(args, mode, logger):
221221
providers=["CPUExecutionProvider"],
222222
sess_options=sess_options,
223223
)
224-
return sess, sess.get_inputs()[0], None, None
224+
return sess, [vo.name for vo in sess.get_inputs()], None, None
225225

226226
else:
227227
file_names = ["model", "inference"]

0 commit comments

Comments
 (0)