priyansh-nagar commited on
Commit
02717b0
·
verified ·
1 Parent(s): 98ab802

Update model/predict.py

Browse files
Files changed (1) hide show
  1. model/predict.py +9 -4
model/predict.py CHANGED
@@ -1,12 +1,16 @@
1
  import torch
2
- from torchvision import transforms
3
  from PIL import Image
4
 
5
- MODEL_PATH = "models/deeptrust.pt"
6
  device = "cuda" if torch.cuda.is_available() else "cpu"
7
 
8
- # Load the local model
9
- model = torch.load(MODEL_PATH, map_location=device)
 
 
 
 
10
  model.eval()
11
 
12
  # Transform for input images
@@ -40,3 +44,4 @@ def predict(image: Image.Image):
40
  trust_score = int(conf.item()*100 if pred.item() == 0 else (1 - conf.item())*100)
41
 
42
  return pred.item(), conf.item(), trust_score, tensor, model
 
 
1
  import torch
2
+ from torchvision import models, transforms
3
  from PIL import Image
4
 
5
+ MODEL_PATH = "models/deeptrust_weights.pt"
6
  device = "cuda" if torch.cuda.is_available() else "cpu"
7
 
8
+ # Recreate the same model architecture
9
+ model = models.efficientnet_b0(pretrained=False)
10
+ model.classifier[1] = torch.nn.Linear(model.classifier[1].in_features, 2)
11
+
12
+ # Load the weights only (state_dict)
13
+ model.load_state_dict(torch.load(MODEL_PATH, map_location=device))
14
  model.eval()
15
 
16
  # Transform for input images
 
44
  trust_score = int(conf.item()*100 if pred.item() == 0 else (1 - conf.item())*100)
45
 
46
  return pred.item(), conf.item(), trust_score, tensor, model
47
+