Update inference.py
Browse files- 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
|
| 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(
|
|
|
|
| 40 |
models_dict = load_models()
|
| 41 |
-
|
|
|
|
| 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 = {}
|