Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
@@ -8,6 +9,9 @@ torch.hub.download_url_to_file("https://github.com/pytorch/hub/raw/master/images
|
|
8 |
model = torch.hub.load('pytorch/vision:v0.9.0', 'alexnet', pretrained=True)
|
9 |
model.eval()
|
10 |
|
|
|
|
|
|
|
11 |
def inference(input_image):
|
12 |
|
13 |
preprocess = transforms.Compose([
|
@@ -28,8 +32,6 @@ 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 |
-
# Download ImageNet labels
|
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()]
|
|
|
1 |
+
import os
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
from PIL import Image
|
|
|
9 |
model = torch.hub.load('pytorch/vision:v0.9.0', 'alexnet', pretrained=True)
|
10 |
model.eval()
|
11 |
|
12 |
+
# Download ImageNet labels
|
13 |
+
os.system("wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt")
|
14 |
+
|
15 |
def inference(input_image):
|
16 |
|
17 |
preprocess = transforms.Compose([
|
|
|
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 |
# Read the categories
|
36 |
with open("imagenet_classes.txt", "r") as f:
|
37 |
categories = [s.strip() for s in f.readlines()]
|