Skip to content

fix: let MegaDetector load explicit weights via get_checkpoint_path#31

Open
JasonWildMe wants to merge 1 commit into
mainfrom
fix/megadetector-explicit-checkpoint
Open

fix: let MegaDetector load explicit weights via get_checkpoint_path#31
JasonWildMe wants to merge 1 commit into
mainfrom
fix/megadetector-explicit-checkpoint

Conversation

@JasonWildMe

Copy link
Copy Markdown

What

MegaDetector was the only model type that couldn't take an explicit weight file: it always let PytorchWildlife fetch its hardcoded zenodo URL at load time — a hidden internet download on every cold start that deployment config could neither pin nor serve locally.

An optional checkpoint_path config key now resolves through the shared get_checkpoint_path resolver (local path or URL) and is passed to MegaDetectorV6 as weights=. Verified against the installed PytorchWildlife source: the base loader prioritizes a truthy weights before its version URL, and weights=None follows the existing auto-download branch — so absent checkpoint_path, behavior is byte-for-byte unchanged. A configured-but-missing local weight fails fast instead of silently downloading something else.

app/model_config.json is deliberately untouched (prod bind-mounts it; flipping the megadetector entry to checkpoint_path requires the weight present in MODELS_DIR first). This PR adds the capability; #26 can flip the config when the weights are staged.

Why

Closes the gap #26's review found in its MODEL_BASE story: 'every model loader resolves through get_checkpoint_path' was untrue for MegaDetector, which added an unpinnable third-party download to every serverless cold start.

Testing

TDD: tests/test_megadetector_checkpoint.py (PytorchWildlife stubbed — it isn't importable without GPU extras). Two failing tests drove the change (explicit path reaches the constructor; missing local path fails before construction), one pins the auto-download default. Full suite: 45 passed.

Provenance

Carved out of #26. Reviewed by Codex 5.6 (gpt-5.6-terra): converged on round 1, no findings — it independently verified the weights= semantics in the installed package source and the kwargs flow from config to constructor.

🤖 Generated with Claude Code

MegaDetector was the only model type that could not take an explicit
weight file: it always let PytorchWildlife fetch its hardcoded zenodo
URL at load time — a hidden internet download on every cold start that
deployment config could neither pin nor serve locally.

An optional checkpoint_path config key now resolves through the shared
get_checkpoint_path resolver (local path or URL) and is passed to
MegaDetectorV6 as weights. Absent, behavior is unchanged (auto-download).
A configured-but-missing local weight fails fast instead of silently
downloading something else.

Written test-first: tests/test_megadetector_checkpoint.py (stubbed
PytorchWildlife; 2 failing tests drove the change, 1 pins the
auto-download default).

Carved out of #26 (its review found this gap in the MODEL_BASE story).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant