Update app.py
Browse files
app.py
CHANGED
|
@@ -4,14 +4,15 @@ import gradio as gr
|
|
| 4 |
from PIL import Image
|
| 5 |
from torchvision import transforms
|
| 6 |
|
| 7 |
-
model = torch.hub.load('pytorch/vision:v0.
|
| 8 |
response = requests.get("https://git.io/JJkYN")
|
| 9 |
labels = response.text.split("\n")
|
| 10 |
|
| 11 |
def get_predictions(inp):
|
| 12 |
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
return conf
|
| 16 |
|
| 17 |
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from torchvision import transforms
|
| 6 |
|
| 7 |
+
model = torch.hub.load('pytorch/vision:v0.6.0', 'resnet18', pretrained = True).eval()
|
| 8 |
response = requests.get("https://git.io/JJkYN")
|
| 9 |
labels = response.text.split("\n")
|
| 10 |
|
| 11 |
def get_predictions(inp):
|
| 12 |
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
predictions = torch.nn.functional.softmax(model(inp)[0], dim = 0)
|
| 15 |
+
conf = {labels[i]: float(predictions[i]) for i in range(len(labels))}
|
| 16 |
return conf
|
| 17 |
|
| 18 |
|