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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -39,13 +39,23 @@ def init_db():
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.")
 
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 the checkpoint
46
  state_dict = torch.load('densenet169_seed40_best.pt', map_location='cpu')
 
47
 
48
+ # 3️⃣ Rename keys
49
+ new_state_dict = {}
50
+ for k, v in state_dict.items():
51
+ if k.startswith('0.'):
52
+ new_key = k[2:] # Removes the leading '0.'
53
+ else:
54
+ new_key = k
55
+ new_state_dict[new_key] = v
56
+
57
+ # 4️⃣ Load
58
+ model.load_state_dict(new_state_dict)
59
  model.eval()
60
 
61
  print("✅ Model successfully loaded and ready for inference.")