Update inference.py
Browse files- inference.py +3 -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)
|
|
@@ -19,13 +19,13 @@ def load_models():
|
|
| 19 |
# Load ResNet18 model
|
| 20 |
resnet18 = models.resnet18(pretrained=False)
|
| 21 |
resnet18.fc = nn.Linear(resnet18.fc.in_features, 11) # Modify output layer for 11 classes
|
| 22 |
-
resnet18.load_state_dict(torch.load('models/resnet18_fish_classification_model.pth'))
|
| 23 |
resnet18.to(device)
|
| 24 |
|
| 25 |
# Load MobileNetV2 model
|
| 26 |
mobilenet_v2 = models.mobilenet_v2(pretrained=False)
|
| 27 |
mobilenet_v2.classifier[1] = nn.Linear(1280, 11) # Modify output layer for 11 classes
|
| 28 |
-
mobilenet_v2.load_state_dict(torch.load('models/mobilenetv2_fish_classification_model.pth'))
|
| 29 |
mobilenet_v2.to(device)
|
| 30 |
|
| 31 |
models_dict = {
|
|
|
|
| 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)
|
|
|
|
| 19 |
# Load ResNet18 model
|
| 20 |
resnet18 = models.resnet18(pretrained=False)
|
| 21 |
resnet18.fc = nn.Linear(resnet18.fc.in_features, 11) # Modify output layer for 11 classes
|
| 22 |
+
resnet18.load_state_dict(torch.load('models/resnet18_fish_classification_model.pth', map_location=device))
|
| 23 |
resnet18.to(device)
|
| 24 |
|
| 25 |
# Load MobileNetV2 model
|
| 26 |
mobilenet_v2 = models.mobilenet_v2(pretrained=False)
|
| 27 |
mobilenet_v2.classifier[1] = nn.Linear(1280, 11) # Modify output layer for 11 classes
|
| 28 |
+
mobilenet_v2.load_state_dict(torch.load('models/mobilenetv2_fish_classification_model.pth', map_location=device))
|
| 29 |
mobilenet_v2.to(device)
|
| 30 |
|
| 31 |
models_dict = {
|