Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,10 @@ import torch
|
|
2 |
from PIL import Image
|
3 |
from torchvision import transforms
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
5 |
|
6 |
model = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet68', pretrained=True)
|
7 |
# or any of these variants
|
@@ -11,6 +15,8 @@ model = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet68', pretrained=True)
|
|
11 |
model.eval()
|
12 |
torch.hub.download_url_to_file("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
|
13 |
|
|
|
|
|
14 |
# sample execution (requires torchvision)
|
15 |
def inference(input_image):
|
16 |
preprocess = transforms.Compose([
|
@@ -31,8 +37,7 @@ def inference(input_image):
|
|
31 |
output = model(input_batch)
|
32 |
# The output has unnormalized scores. To get probabilities, you can run a softmax on it.
|
33 |
probabilities = torch.nn.functional.softmax(output[0], dim=0)
|
34 |
-
|
35 |
-
!wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt
|
36 |
# Read the categories
|
37 |
with open("imagenet_classes.txt", "r") as f:
|
38 |
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 |
+
# Download ImageNet labels
|
8 |
+
os.system("wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt")
|
9 |
|
10 |
model = torch.hub.load('PingoLH/Pytorch-HarDNet', 'hardnet68', pretrained=True)
|
11 |
# or any of these variants
|
|
|
15 |
model.eval()
|
16 |
torch.hub.download_url_to_file("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
|
17 |
|
18 |
+
|
19 |
+
|
20 |
# sample execution (requires torchvision)
|
21 |
def inference(input_image):
|
22 |
preprocess = transforms.Compose([
|
|
|
37 |
output = model(input_batch)
|
38 |
# The output has unnormalized scores. To get probabilities, you can run a softmax on it.
|
39 |
probabilities = torch.nn.functional.softmax(output[0], dim=0)
|
40 |
+
|
|
|
41 |
# Read the categories
|
42 |
with open("imagenet_classes.txt", "r") as f:
|
43 |
categories = [s.strip() for s in f.readlines()]
|