From 7f6fa22b4ee85476687d30f4ed6b0e348d4891e2 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Mon, 13 Feb 2023 23:03:51 -0600 Subject: [PATCH] fix(api): skip model download if final converted version already exists (fixes #139) --- api/onnx_web/convert/__main__.py | 7 +++++++ api/onnx_web/convert/utils.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/onnx_web/convert/__main__.py b/api/onnx_web/convert/__main__.py index 46967563..bf900d01 100644 --- a/api/onnx_web/convert/__main__.py +++ b/api/onnx_web/convert/__main__.py @@ -136,6 +136,13 @@ def fetch_model( ctx: ConversionContext, name: str, source: str, model_format: Optional[str] = None ) -> str: cache_name = path.join(ctx.cache_path, name) + model_path = path.join(ctx.model_path, name) + model_onnx = model_path + ".onnx" + + for p in [model_path, model_onnx]: + if path.exists(p): + logger.debug("Model already exists, skipping fetch.") + return p # add an extension if possible, some of the conversion code checks for it if model_format is None: diff --git a/api/onnx_web/convert/utils.py b/api/onnx_web/convert/utils.py index 689af692..22186ad5 100644 --- a/api/onnx_web/convert/utils.py +++ b/api/onnx_web/convert/utils.py @@ -49,7 +49,7 @@ def download_progress(urls: List[Tuple[str, str]]): dest_path.parent.mkdir(parents=True, exist_ok=True) if dest_path.exists(): - logger.info("Destination already exists: %s", dest_path) + logger.debug("Destination already exists: %s", dest_path) return str(dest_path.absolute()) req = requests.get(