Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ import torchvision.transforms as transforms
|
|
6 |
model = torchvision.models.resnet50(pretrained=True)
|
7 |
model.fc = nn.Linear(model.fc.in_features, 2)
|
8 |
model.load_state_dict(torch.load("model.pth"))
|
|
|
|
|
9 |
model.eval()
|
10 |
|
11 |
transform = transforms.Compose([
|
@@ -30,10 +32,7 @@ def inference(input_image):
|
|
30 |
input_tensor = preprocess(input_image)
|
31 |
input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model
|
32 |
|
33 |
-
|
34 |
-
if torch.cuda.is_available():
|
35 |
-
input_batch = input_batch.to('cuda')
|
36 |
-
model.to('cuda')
|
37 |
|
38 |
with torch.no_grad():
|
39 |
output = model(input_batch)
|
|
|
6 |
model = torchvision.models.resnet50(pretrained=True)
|
7 |
model.fc = nn.Linear(model.fc.in_features, 2)
|
8 |
model.load_state_dict(torch.load("model.pth"))
|
9 |
+
input_batch = input_batch.to('cpu')
|
10 |
+
model.to('cpu')
|
11 |
model.eval()
|
12 |
|
13 |
transform = transforms.Compose([
|
|
|
32 |
input_tensor = preprocess(input_image)
|
33 |
input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model
|
34 |
|
35 |
+
|
|
|
|
|
|
|
36 |
|
37 |
with torch.no_grad():
|
38 |
output = model(input_batch)
|