PavanKumarD commited on
Commit
e789a74
·
verified ·
1 Parent(s): 90ac071

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +5 -3
inference.py CHANGED
@@ -4,7 +4,7 @@ import torchvision.models as models
4
  from PIL import Image
5
  from torchvision import transforms
6
 
7
- # Device setup (CPU only)
8
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
 
10
  # Image transformations (same as the one used during training)
@@ -36,9 +36,11 @@ def load_models():
36
  return models_dict
37
 
38
  # Image prediction function
39
- def predict_image(image_path):
 
40
  models_dict = load_models()
41
- image = Image.open(image_path).convert('RGB')
 
42
  image = transform(image).unsqueeze(0).to(device) # Add batch dimension and move to device
43
 
44
  predictions = {}
 
4
  from PIL import Image
5
  from torchvision import transforms
6
 
7
+ # Device setup
8
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
 
10
  # Image transformations (same as the one used during training)
 
36
  return models_dict
37
 
38
  # Image prediction function
39
+ def predict_image(image):
40
+ # image is already a PIL object, no need to open it again
41
  models_dict = load_models()
42
+
43
+ # Apply transformations (resize and normalization)
44
  image = transform(image).unsqueeze(0).to(device) # Add batch dimension and move to device
45
 
46
  predictions = {}