Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import torchvision
|
|
3 |
import torch.nn as nn
|
4 |
import torchvision.transforms as transforms
|
5 |
|
6 |
-
model = torchvision.models.resnet50(pretrained=
|
7 |
model.fc = nn.Linear(model.fc.in_features, 2)
|
8 |
model.load_state_dict(torch.load("model.pth", map_location=torch.device('cpu')))
|
9 |
model.eval()
|
@@ -15,6 +15,8 @@ transform = transforms.Compose([
|
|
15 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
16 |
])
|
17 |
|
|
|
|
|
18 |
import gradio as gr
|
19 |
from PIL import Image
|
20 |
|
@@ -25,7 +27,7 @@ def predict(image):
|
|
25 |
with torch.no_grad():
|
26 |
output = model(image)
|
27 |
_, predicted = torch.max(output.data, 1)
|
28 |
-
return
|
29 |
|
30 |
# Define the input and output components
|
31 |
image_input = gr.inputs.Image(type="pil", label="Upload Image")
|
|
|
3 |
import torch.nn as nn
|
4 |
import torchvision.transforms as transforms
|
5 |
|
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", map_location=torch.device('cpu')))
|
9 |
model.eval()
|
|
|
15 |
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
16 |
])
|
17 |
|
18 |
+
classes = ['Fruta pr贸pria para o consumo', 'Fruta impr贸pria para o consumo']
|
19 |
+
|
20 |
import gradio as gr
|
21 |
from PIL import Image
|
22 |
|
|
|
27 |
with torch.no_grad():
|
28 |
output = model(image)
|
29 |
_, predicted = torch.max(output.data, 1)
|
30 |
+
return classes[predicted.item()]
|
31 |
|
32 |
# Define the input and output components
|
33 |
image_input = gr.inputs.Image(type="pil", label="Upload Image")
|