MoinulwithAI commited on
Commit
ac55edc
·
verified ·
1 Parent(s): 81c4aa2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -3,7 +3,6 @@ import torch
3
  import torch.nn as nn
4
  from torchvision import models, transforms
5
  from PIL import Image
6
- import os
7
 
8
  # Define the same custom residual block and EfficientNetWithNovelty model
9
  class ResidualBlock(nn.Module):
@@ -53,11 +52,11 @@ class EfficientNetWithNovelty(nn.Module):
53
 
54
  return x
55
 
56
- # Load the model checkpoint
57
- device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
58
  num_classes = 10 # Number of classes as per your dataset
59
  model = EfficientNetWithNovelty(num_classes)
60
- checkpoint = torch.load('best_model2.pth')
61
  model.load_state_dict(checkpoint['model_state_dict'])
62
  model.to(device)
63
  model.eval()
 
3
  import torch.nn as nn
4
  from torchvision import models, transforms
5
  from PIL import Image
 
6
 
7
  # Define the same custom residual block and EfficientNetWithNovelty model
8
  class ResidualBlock(nn.Module):
 
52
 
53
  return x
54
 
55
+ # Load the model checkpoint on CPU
56
+ device = torch.device('cpu') # Ensure it's using CPU
57
  num_classes = 10 # Number of classes as per your dataset
58
  model = EfficientNetWithNovelty(num_classes)
59
+ checkpoint = torch.load('best_model2.pth', map_location=torch.device('cpu'))
60
  model.load_state_dict(checkpoint['model_state_dict'])
61
  model.to(device)
62
  model.eval()