Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,13 +39,23 @@ def init_db():
|
|
39 |
|
40 |
init_db()
|
41 |
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
|
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.")
|