Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,14 +25,21 @@ class MMIM(nn.Module):
|
|
| 25 |
# ✅ Load model
|
| 26 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 27 |
model = MMIM(num_classes=9)
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
model.to(device)
|
| 30 |
model.eval()
|
| 31 |
|
| 32 |
# ✅ Updated class names (match folder structure)
|
| 33 |
class_names = [
|
| 34 |
"Chinee apple", "Lantana", "Negative", "Parkinsonia", "Parthenium",
|
| 35 |
-
"Prickly acacia", "Rubber vine", "Siam weed", "Snake weed"
|
| 36 |
]
|
| 37 |
|
| 38 |
# 🔁 Image transform
|
|
|
|
| 25 |
# ✅ Load model
|
| 26 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 27 |
model = MMIM(num_classes=9)
|
| 28 |
+
|
| 29 |
+
# 🧠 Load pretrained weights except mismatched classifier
|
| 30 |
+
checkpoint = torch.load("MMIM_best.pth", map_location=device)
|
| 31 |
+
filtered_checkpoint = {
|
| 32 |
+
k: v for k, v in checkpoint.items() if k in model.state_dict() and model.state_dict()[k].shape == v.shape
|
| 33 |
+
}
|
| 34 |
+
model.load_state_dict(filtered_checkpoint, strict=False)
|
| 35 |
+
|
| 36 |
model.to(device)
|
| 37 |
model.eval()
|
| 38 |
|
| 39 |
# ✅ Updated class names (match folder structure)
|
| 40 |
class_names = [
|
| 41 |
"Chinee apple", "Lantana", "Negative", "Parkinsonia", "Parthenium",
|
| 42 |
+
"Prickly acacia", "Rubber vine", "Siam weed", "Snake weed",
|
| 43 |
]
|
| 44 |
|
| 45 |
# 🔁 Image transform
|