codedad commited on
Commit
a7b6188
·
verified ·
1 Parent(s): 9fba7e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
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
- model = models.resnet18()
10
- model.fc = torch.nn.Linear(model.fc.in_features, 2)
 
 
 
 
 
 
 
 
 
 
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