Skip to content

Commit ce7e2b7

Browse files
committed
fix(inference): fall back to demo weights when ONNX file is unreadable
An LFS pointer file (or any corrupt .onnx) crashed InferenceSession with InvalidProtobuf — failing CI and any prod flood prediction after a checkout without LFS objects. Treat unloadable ONNX like a missing model and fall back to untrained/demo weights, matching existing behavior.
1 parent b43a712 commit ce7e2b7

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/climatevision/inference/pipeline.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,20 @@ def _try_load_onnx(
198198
providers = ["CPUExecutionProvider"]
199199
if "CUDAExecutionProvider" in ort.get_available_providers():
200200
providers = ["CUDAExecutionProvider", "CPUExecutionProvider"]
201-
session = ort.InferenceSession(str(onnx_path), providers=providers)
201+
try:
202+
session = ort.InferenceSession(str(onnx_path), providers=providers)
203+
except Exception:
204+
# The file exists but is not a loadable model. Most commonly this is a
205+
# Git LFS pointer file left behind by a checkout without LFS objects
206+
# (a few hundred bytes of text instead of the real weights). Treat it
207+
# the same as a missing model so callers fall back to demo weights.
208+
logger.warning(
209+
"ONNX model at %s could not be loaded (possibly a Git LFS pointer "
210+
"file). Falling back to untrained/demo weights.",
211+
onnx_path,
212+
exc_info=True,
213+
)
214+
return None
202215
input_name = session.get_inputs()[0].name
203216
return _ONNXSegmenter(session, n_channels, n_classes, input_name)
204217

0 commit comments

Comments
 (0)