|
|
@@ -66,13 +66,13 @@ class UniversalPaddleToPyTorchConverter:
|
|
|
onnx_path = self._convert_paddlex_to_onnx(model_name)
|
|
|
|
|
|
# ONNX → PyTorch
|
|
|
- pytorch_path = self._onnx_to_pytorch(onnx_path, model_name)
|
|
|
+ # pytorch_path = self._onnx_to_pytorch(onnx_path, model_name)
|
|
|
|
|
|
print(f"{'='*60}")
|
|
|
print(f"✅ 转换完成: {model_name}")
|
|
|
print(f"{'='*60}\n")
|
|
|
|
|
|
- return pytorch_path
|
|
|
+ return onnx_path
|
|
|
|
|
|
def _convert_legacy_to_onnx(self, model_name: str) -> Path:
|
|
|
"""传统格式 → ONNX"""
|
|
|
@@ -86,7 +86,7 @@ class UniversalPaddleToPyTorchConverter:
|
|
|
"--model_filename", "inference.pdmodel",
|
|
|
"--params_filename", "inference.pdiparams",
|
|
|
"--save_file", str(onnx_output_path),
|
|
|
- "--opset_version", "11",
|
|
|
+ # "--opset_version", "11", # 不用指定
|
|
|
"--enable_onnx_checker", "True"
|
|
|
]
|
|
|
|
|
|
@@ -100,35 +100,14 @@ class UniversalPaddleToPyTorchConverter:
|
|
|
|
|
|
def _convert_paddlex_to_onnx(self, model_name: str) -> Path:
|
|
|
"""PaddleX 3.0 格式 → ONNX"""
|
|
|
- print(f"\n📦 步骤1: PaddleX 3.0 → ONNX")
|
|
|
-
|
|
|
+ # 使用 PaddleX CLI
|
|
|
+ print(f" PaddleX CLI...")
|
|
|
onnx_output_path = self.output_dir / f"{model_name}.onnx"
|
|
|
-
|
|
|
- # 方法1: 尝试直接使用 paddle2onnx 处理 JSON
|
|
|
- print(f" 尝试方法1: paddle2onnx 直接转换 JSON...")
|
|
|
- cmd = [
|
|
|
- "paddle2onnx",
|
|
|
- "--model_dir", str(self.paddle_model_dir),
|
|
|
- "--model_filename", "inference.json",
|
|
|
- "--params_filename", "inference.pdiparams",
|
|
|
- "--save_file", str(onnx_output_path),
|
|
|
- "--opset_version", "11",
|
|
|
- ]
|
|
|
-
|
|
|
- result = subprocess.run(cmd, capture_output=True, text=True)
|
|
|
-
|
|
|
- if result.returncode == 0 and onnx_output_path.exists():
|
|
|
- print(f" ✅ 方法1成功!ONNX已保存: {onnx_output_path}")
|
|
|
- return onnx_output_path
|
|
|
-
|
|
|
- # 方法2: 使用 PaddleX CLI
|
|
|
- print(f" 方法1失败,尝试方法2: PaddleX CLI...")
|
|
|
cmd = [
|
|
|
"paddlex",
|
|
|
"--paddle2onnx",
|
|
|
"--paddle_model_dir", str(self.paddle_model_dir),
|
|
|
"--onnx_model_dir", str(self.output_dir),
|
|
|
- "--opset_version", "11"
|
|
|
]
|
|
|
|
|
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
|
@@ -136,8 +115,8 @@ class UniversalPaddleToPyTorchConverter:
|
|
|
if result.returncode != 0:
|
|
|
raise RuntimeError(
|
|
|
f"所有转换方法都失败了!\n"
|
|
|
- f"方法1输出: {result.stdout}\n"
|
|
|
- f"方法2输出: {result.stderr}\n"
|
|
|
+ f"输出: {result.stdout}\n"
|
|
|
+ f"输出: {result.stderr}\n"
|
|
|
f"建议:请手动使用 PaddleX 导出 ONNX 模型"
|
|
|
)
|
|
|
|
|
|
@@ -184,7 +163,7 @@ def batch_convert_all_models():
|
|
|
|
|
|
MODELS = [
|
|
|
# ("PicoDet_layout_1x", "Layout"),
|
|
|
- ("PP-DocLayoutV2", "Layout"),
|
|
|
+ ("PP-LCNet_x1_0_doc_ori", "Layout"),
|
|
|
("RT-DETR-H_layout_17cls", "Layout"),
|
|
|
]
|
|
|
|