dhruv2842 commited on
Commit
29a6cea
·
verified ·
1 Parent(s): 1b4fc02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -39,22 +39,13 @@ def init_db():
39
 
40
  init_db()
41
 
42
- model = models.densenet169(pretrained=False)
43
- model.classifier = nn.Linear(model.classifier.in_features, 3)
44
 
45
- # 2️⃣ Load your checkpoint
46
  state_dict = torch.load('densenet169_seed40_best.pt', map_location='cpu')
 
47
 
48
- # 3️⃣ Strip the "features.0." prefix
49
- new_state_dict = {}
50
- for k, v in state_dict.items():
51
- new_key = k.replace("features.0.", "")
52
- new_state_dict[new_key] = v
53
-
54
- # 4️⃣ Load the stripped state dict
55
- model.load_state_dict(new_state_dict)
56
-
57
- # 5️⃣ Set eval mode
58
  model.eval()
59
 
60
  print("✅ Model successfully loaded and ready for inference.")
 
39
 
40
  init_db()
41
 
42
+ densenet_model = models.densenet169(pretrained=False)
43
+ densenet_model.classifier = nn.Linear(densenet_model.classifier.in_features, 3)
44
 
45
+ model = torch.nn.Sequential(densenet_model) # IMPORTANT
46
  state_dict = torch.load('densenet169_seed40_best.pt', map_location='cpu')
47
+ model.load_state_dict(state_dict)
48
 
 
 
 
 
 
 
 
 
 
 
49
  model.eval()
50
 
51
  print("✅ Model successfully loaded and ready for inference.")