ethix commited on
Commit
7ec67b8
·
1 Parent(s): 4d30312

fix: resolve old checkpoint path relative to repo root

Browse files

Previously used a relative path that would fail depending on CWD.
Now resolved via __file__ to always point to the correct pretrained_weights/ directory.

Files changed (1) hide show
  1. test_app/app.py +6 -1
test_app/app.py CHANGED
@@ -57,8 +57,13 @@ def _load_old_model():
57
  device = old_cfg["device"]
58
  if not torch.cuda.is_available():
59
  device = "cpu"
 
 
 
 
 
60
  model = OldViTClassifier(old_cfg, device=device)
61
- ckpt = torch.load(old_cfg["checkpoint_path"], map_location=device, weights_only=False)
62
  model.load_state_dict(ckpt["model"])
63
  return model.to(device).eval()
64
 
 
57
  device = old_cfg["device"]
58
  if not torch.cuda.is_available():
59
  device = "cpu"
60
+ # Resolve checkpoint path relative to repo root (one level up from test_app/)
61
+ ckpt_rel = old_cfg["checkpoint_path"]
62
+ ckpt_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ckpt_rel)
63
+ if not os.path.exists(ckpt_path):
64
+ raise FileNotFoundError(f"Checkpoint not found: {ckpt_path}")
65
  model = OldViTClassifier(old_cfg, device=device)
66
+ ckpt = torch.load(ckpt_path, map_location=device, weights_only=False)
67
  model.load_state_dict(ckpt["model"])
68
  return model.to(device).eval()
69