Error-onnxruntime.capi.onnxruntime_pybind11_state.Fail:

转换之后运行onnx文件就报错:

复制代码
onnxruntime.capi.onnxruntime_pybind11_state.Fail:

解决:

最好把h5模型重新加载一下,保存save_model文件:

复制代码
model, _ = build_model(image_height=height, image_width=width, channels=1, num_classes=args.num_classes)
# model = tf.keras.models.load_model(model_path)
model.load_weights(model_path, skip_mismatch=False, by_name=False)
model.summary()  
saved_model_dir=os.path.join(outpath,'save_model')
tf.saved_model.save(model, saved_model_dir)

转pb:

复制代码
full_model = tf.function(lambda Input: model(Input))
full_model = full_model.get_concrete_function(
        tf.TensorSpec([1,  height, width, 1], model.inputs[0].dtype))  
    
# Get frozen ConcreteFunction
frozen_func = convert_variables_to_constants_v2(full_model)
frozen_func.graph.as_graph_def()
    
    
# Save frozen graph from frozen ConcreteFunction to hard drive
tf.io.write_graph(graph_or_graph_def=frozen_func.graph,
                      logdir="./",
                      name=outpath,
                      as_text=False)

转onnx的时候使用的是save_model格式:

复制代码
os.system(
            'python -m tf2onnx.convert --saved-model "{}" --output "{}" --opset 10'.format(
                saved_model_dir,
                outpath.replace('.pb', '.onnx')))
相关推荐
SelectDB7 小时前
Apache Doris Python UDF:让 SQL 直接调用 Python 生态,支撑 Agent 时代复杂业务逻辑
大数据·数据库·python
荣码14 小时前
GraphRAG:普通RAG只能回答"点"的问题,我踩了4个坑才搞懂
java·python
金銀銅鐵1 天前
[Python] 基于欧几里得算法,实现分数约分计算器
python·数学
Lyn_Li1 天前
Kaggle Top 5 | 198只股票、200条数据的金融预测——BattleFin高分方案从零复现
python·kaggle·比赛复盘·金融预测
Lihua奏1 天前
从单核到多核:CPU为什么不能再只靠提频变快
深度学习
拾年2751 天前
大模型的"聪明"从哪来?聊聊 AI 数据集的那些事儿
人工智能·深度学习·机器学习
小九九的爸爸1 天前
前端想要入门Agent开发,要具备哪些Python基础?
python·agent·ai编程
阿耶同学1 天前
手把手教你用 LangGraph 搭建三层嵌套 Agent 架构
python·程序员
花酒锄作田2 天前
Pydantic校验配置文件
python
hboot2 天前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络