Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,18 +42,22 @@ init_db()
|
|
42 |
model = models.densenet169(pretrained=False)
|
43 |
model.classifier = nn.Linear(model.classifier.in_features, 3)
|
44 |
|
45 |
-
# 2️⃣ Load checkpoint
|
46 |
-
|
47 |
|
48 |
-
#
|
49 |
-
|
|
|
|
|
|
|
50 |
|
51 |
-
#
|
52 |
-
|
53 |
-
model.load_state_dict(checkpoint['model_state_dict'])
|
54 |
-
else:
|
55 |
-
model.load_state_dict(checkpoint)
|
56 |
|
|
|
|
|
|
|
|
|
57 |
# ✅ Preprocess Image
|
58 |
transform = transforms.Compose([
|
59 |
transforms.Resize((224, 224)), # Adjust if needed
|
|
|
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.")
|
61 |
# ✅ Preprocess Image
|
62 |
transform = transforms.Compose([
|
63 |
transforms.Resize((224, 224)), # Adjust if needed
|