Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,20 @@ from PIL import Image
|
|
| 5 |
|
| 6 |
# 1. Load your model (Ensure this matches your training architecture)
|
| 7 |
# Change 'models.resnet18' if you used a different one
|
|
|
|
| 8 |
from torchvision import models
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
model.load_state_dict(torch.load("fine_tuned_model.pt", map_location="cpu"))
|
| 12 |
model.eval()
|
| 13 |
|
|
|
|
| 5 |
|
| 6 |
# 1. Load your model (Ensure this matches your training architecture)
|
| 7 |
# Change 'models.resnet18' if you used a different one
|
| 8 |
+
# --- UPDATED MODEL ARCHITECTURE ---
|
| 9 |
from torchvision import models
|
| 10 |
+
import torch.nn as nn
|
| 11 |
+
|
| 12 |
+
# 1. Use resnet50 instead of resnet18 to match your weights
|
| 13 |
+
model = models.resnet50()
|
| 14 |
+
|
| 15 |
+
# 2. Update the final layer to match your 2 classes (Defect, Normal)
|
| 16 |
+
# Note: ResNet50 uses 2048 features in the final layer
|
| 17 |
+
model.fc = nn.Linear(2048, 2)
|
| 18 |
+
|
| 19 |
+
# 3. Load the weights
|
| 20 |
+
model.load_state_dict(torch.load("fine_tuned_model.pt", map_location="cpu"))
|
| 21 |
+
model.eval()
|
| 22 |
model.load_state_dict(torch.load("fine_tuned_model.pt", map_location="cpu"))
|
| 23 |
model.eval()
|
| 24 |
|