Spaces:
Runtime error
Runtime error
add sample images
Browse files- .DS_Store +0 -0
- app.py +11 -11
- sample/n_0000000130.jpg +0 -0
- sample/n_0000000148.jpg +0 -0
- sample/t_0000000112.jpg +0 -0
- sample/t_0000000121.jpg +0 -0
- sample/t_0000000231.jpg +0 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
app.py
CHANGED
@@ -1,20 +1,13 @@
|
|
1 |
-
|
2 |
-
import
|
|
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
import torch.nn as nn
|
6 |
import torchvision.models as models
|
7 |
import torchvision.transforms as transforms
|
8 |
-
import os
|
9 |
-
import gradio as gr
|
10 |
-
import albumentations as A
|
11 |
-
from albumentations.pytorch import ToTensorV2
|
12 |
import urllib.request
|
13 |
|
14 |
-
MODEL_URL = "https://huggingface.co/caisarl76/HI_motorcycle_trunk_cls_model/resolve/main/best_model.pth"
|
15 |
-
MODEL_PATH = "/tmp/best_model.pth"
|
16 |
-
urllib.request.urlretrieve(MODEL_URL, MODEL_PATH)
|
17 |
-
|
18 |
test_transforms = A.Compose(
|
19 |
[
|
20 |
A.SmallestMaxSize(max_size=350),
|
@@ -24,6 +17,12 @@ test_transforms = A.Compose(
|
|
24 |
]
|
25 |
)
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def predict(img):
|
28 |
img = Image.fromarray(img.astype('uint8'), 'RGB')
|
29 |
img = transforms.ToTensor()(img).unsqueeze(0)
|
@@ -57,7 +56,8 @@ inputs = gr.inputs.Image()
|
|
57 |
outputs = gr.outputs.Label(num_top_classes=1)
|
58 |
gr.Interface(fn=predict,
|
59 |
inputs=inputs,
|
60 |
-
outputs=outputs
|
|
|
61 |
|
62 |
|
63 |
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import albumentations as A
|
3 |
+
from albumentations.pytorch import ToTensorV2
|
4 |
from PIL import Image
|
5 |
import torch
|
6 |
import torch.nn as nn
|
7 |
import torchvision.models as models
|
8 |
import torchvision.transforms as transforms
|
|
|
|
|
|
|
|
|
9 |
import urllib.request
|
10 |
|
|
|
|
|
|
|
|
|
11 |
test_transforms = A.Compose(
|
12 |
[
|
13 |
A.SmallestMaxSize(max_size=350),
|
|
|
17 |
]
|
18 |
)
|
19 |
|
20 |
+
img_samples = os.listdir('./sample/')
|
21 |
+
MODEL_URL = "https://huggingface.co/caisarl76/HI_motorcycle_trunk_cls_model/resolve/main/best_model.pth"
|
22 |
+
MODEL_PATH = "/tmp/best_model.pth"
|
23 |
+
urllib.request.urlretrieve(MODEL_URL, MODEL_PATH)
|
24 |
+
|
25 |
+
|
26 |
def predict(img):
|
27 |
img = Image.fromarray(img.astype('uint8'), 'RGB')
|
28 |
img = transforms.ToTensor()(img).unsqueeze(0)
|
|
|
56 |
outputs = gr.outputs.Label(num_top_classes=1)
|
57 |
gr.Interface(fn=predict,
|
58 |
inputs=inputs,
|
59 |
+
outputs=outputs,
|
60 |
+
examples=img_samples).launch()
|
61 |
|
62 |
|
63 |
|
sample/n_0000000130.jpg
ADDED
![]() |
sample/n_0000000148.jpg
ADDED
![]() |
sample/t_0000000112.jpg
ADDED
![]() |
sample/t_0000000121.jpg
ADDED
![]() |
sample/t_0000000231.jpg
ADDED
![]() |