From 6c5a56ade38a542687a234ab19bbace6f407124f Mon Sep 17 00:00:00 2001 From: Asep Haryana Saputra <90584806+MythEclipse@users.noreply.github.com> Date: Sat, 23 May 2026 10:28:34 +0000 Subject: [PATCH] fix: capture ONNX conversion errors --- Machine_Learning/convert_onnx.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Machine_Learning/convert_onnx.py b/Machine_Learning/convert_onnx.py index 0ebf7eb..9d6d267 100644 --- a/Machine_Learning/convert_onnx.py +++ b/Machine_Learning/convert_onnx.py @@ -7,11 +7,11 @@ import subprocess import sys from pathlib import Path -logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s") - def main(): """Convert a TensorFlow SavedModel to ONNX format using tf2onnx.""" + logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s") + parser = argparse.ArgumentParser( description="Convert TensorFlow SavedModel to ONNX format" ) @@ -37,7 +37,9 @@ def main(): args = parser.parse_args() if not args.saved_model.exists(): - raise FileNotFoundError(f"SavedModel not found at {args.saved_model}") + msg = f"SavedModel not found at {args.saved_model}" + logging.error(msg) + raise FileNotFoundError(msg) args.output.parent.mkdir(parents=True, exist_ok=True) @@ -54,9 +56,11 @@ def main(): ] try: - subprocess.run(cmd, check=True) + subprocess.run(cmd, check=True, capture_output=True, text=True) except subprocess.CalledProcessError as e: logging.error(f"tf2onnx conversion failed with exit code {e.returncode}") + if e.stderr: + logging.error(f"stderr: {e.stderr}") raise logging.info(f"ONNX model saved to {args.output}")