Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,13 @@ import torch
|
|
2 |
from PIL import Image
|
3 |
from torchvision import transforms
|
4 |
import gradio as gr
|
|
|
|
|
5 |
model = torch.hub.load('XingangPan/IBN-Net', 'resnet50_ibn_a', pretrained=True)
|
6 |
model.eval()
|
7 |
|
|
|
|
|
8 |
# Download an example image from the pytorch website
|
9 |
torch.hub.download_url_to_file("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
|
10 |
|
@@ -28,8 +32,7 @@ def inference(input_image):
|
|
28 |
output = model(input_batch)
|
29 |
# The output has unnormalized scores. To get probabilities, you can run a softmax on it.
|
30 |
probabilities = torch.nn.functional.softmax(output[0], dim=0)
|
31 |
-
|
32 |
-
!wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt
|
33 |
# Read the categories
|
34 |
with open("imagenet_classes.txt", "r") as f:
|
35 |
categories = [s.strip() for s in f.readlines()]
|
|
|
2 |
from PIL import Image
|
3 |
from torchvision import transforms
|
4 |
import gradio as gr
|
5 |
+
import os
|
6 |
+
|
7 |
model = torch.hub.load('XingangPan/IBN-Net', 'resnet50_ibn_a', pretrained=True)
|
8 |
model.eval()
|
9 |
|
10 |
+
# Download ImageNet labels
|
11 |
+
os.system("wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt")
|
12 |
# Download an example image from the pytorch website
|
13 |
torch.hub.download_url_to_file("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
|
14 |
|
|
|
32 |
output = model(input_batch)
|
33 |
# The output has unnormalized scores. To get probabilities, you can run a softmax on it.
|
34 |
probabilities = torch.nn.functional.softmax(output[0], dim=0)
|
35 |
+
|
|
|
36 |
# Read the categories
|
37 |
with open("imagenet_classes.txt", "r") as f:
|
38 |
categories = [s.strip() for s in f.readlines()]
|