You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use 'generate_artifacts' to convert the'. h5 'file to onnx for training
But the training effect in Qt is completely inferior to using Python's'. h5 '
I suspect it's a code conversion issue with 'onnxrruntime. training. artifacts' that caused the fusion of operators in training_madel.onnx, which can only predict but cannot be trained
import os
import onnx
import tf2onnx
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model, save_model
from tensorflow.keras.layers import Activation
from tensorflow.keras.models import clone_model
from tensorflow.keras.activations import relu
import onnxruntime.training.artifacts as artifacts
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Use 'generate_artifacts' to convert the'. h5 'file to onnx for training
But the training effect in Qt is completely inferior to using Python's'. h5 '
I suspect it's a code conversion issue with 'onnxrruntime. training. artifacts' that caused the fusion of operators in training_madel.onnx, which can only predict but cannot be trained
import os
import onnx
import tf2onnx
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model, save_model
from tensorflow.keras.layers import Activation
from tensorflow.keras.models import clone_model
from tensorflow.keras.activations import relu
import onnxruntime.training.artifacts as artifacts
def export_initial_models(keras_model_path, output_dir):
"""
Args:
keras_model_path: Keras模型文件路径 (.h5)
output_dir: 输出目录
"""
# 创建输出目录
baseline_dir = os.path.join(output_dir, 'baseline')
current_dir = os.path.join(output_dir, 'current')
os.makedirs(baseline_dir, exist_ok=True)
os.makedirs(current_dir, exist_ok=True)
# 加载Keras模型
print("Loading Keras model...")
keras_model = load_model(keras_model_path)
# ==========================================================
# 导出 ONNX + ORT Training Artifacts
# ==========================================================
try:
print("开始导出 ONNX...")
# ONNX输出路径
onnx_path = os.path.join(baseline_dir, 'inference_model.onnx')
spec = (
tf.TensorSpec(
(1, 1, 5, 1000),
tf.float32,
name="input"
),
)
model_proto, _ = tf2onnx.convert.from_keras(
keras_model,
input_signature=spec,
opset=17
)
with open(onnx_path, "wb") as f:
f.write(model_proto.SerializeToString())
print("✓ inference_model.onnx 导出成功")
# ======================================================
# 生成 ORT Training Artifacts
# ======================================================
print("开始生成 ORT Training Artifacts...")
onnx_model = onnx.load(onnx_path)
if name == "main":
keras_model_path = "./Model/CrossSubject/Net.h5"
export_initial_models(keras_model_path, "./models")
All reactions