# text embedding
toks = self.tokenizer([text])
if self.debug:
print('toks', toks)
text_embed = self.text_model_session.run(output_names=['output'], input_feed=toks)
Traceback (most recent call last):
File "/xx/workspace/model/test_onnx.py", line 90, in
res = inferencer.inference(text, img_path)
File "/xx/workspace/model/test_onnx.py", line 58, in inference
text_embed = self.text_model_session.run(output_names=['output'], input_feed=toks)
File "/xx/miniconda3/envs/py39/lib/python3.9/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 220, in run
return self._sess.run(output_names, input_feed, run_options)
TypeError: run(): incompatible function arguments. The following argument types are supported:
1. (self: onnxruntime.capi.onnxruntime_pybind11_state.InferenceSession, arg0: List[str], arg1: Dict[str, object], arg2: onnxruntime.capi.onnxruntime_pybind11_state.RunOptions) -> List[object]
Invoked with: , ['output'], {'input_ids': array([[ 101, 3899, 102]]), 'token_type_ids': array([[0, 0, 0]]), 'attention_mask': array([[1, 1, 1]])}, None
TypeError: run(): incompatible function arguments. The following argument types are supported:
1. (self: onnxruntime.capi.onnxruntime_pybind11_state.InferenceSession, arg0: List[str], arg1: Dict[str, object], arg2: onnxruntime.capi.onnxruntime_pybind11_state.RunOptions) -> List[object]
arg0: List[str]
arg1: Dict[str, object]
对应的参数
output_names=['output'], input_feed=toks
arg0=[‘output’] 参数类型正确
arg1=toks 表面看参数也正常,打印看看toks的每个值的类型
type(toks[‘input_ids’]) 输出为
# text embedding
toks = self.tokenizer([text])
if self.debug:
print('toks', toks)
text_input = {}
text_input['input_ids'] = toks['input_ids'].numpy()
text_input['token_type_ids'] = toks['token_type_ids'].numpy()
text_input['attention_mask'] = toks['attention_mask'].numpy()
text_embed = self.text_model_session.run(output_names=['output'], input_feed=text_input)
再次执行代码,正常运行,无报错!!