Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,28 @@
|
|
1 |
-
import torch as tf
|
2 |
-
|
3 |
import gradio as gr
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
["https://github.com/Kr1n3/MPC_2022/blob/main/dataset/bag_14.JPG?raw=true"], ["https://github.com/Kr1n3/MPC_2022/blob/main/dataset/dress_45.JPG?raw=true"]],
|
32 |
-
).launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
import torchvision
|
6 |
+
from torchvision import transforms
|
7 |
+
|
8 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', 'runs/train-cls/exp/weights/best.pt')
|
9 |
+
data_transform1=transforms.Compose([
|
10 |
+
transforms.Resize((224,224)),
|
11 |
+
transforms.ToTensor(),
|
12 |
+
transforms.Normalize((0.485,0.456,0.406),(0.229,0.224,0.225))
|
13 |
+
])
|
14 |
+
|
15 |
+
title = " Fashion Items Classification"
|
16 |
+
|
17 |
+
examples=[['https://github.com/Kr1n3/MPC_2022/blob/main/dataset/bag_14.JPG?raw=true'],['https://github.com/Kr1n3/MPC_2022/blob/main/dataset/dress_45.JPG?raw=true'],['https://github.com/Kr1n3/MPC_2022/blob/main/dataset/pants_30.jpeg?raw=true']]
|
18 |
+
|
19 |
+
classes=['Bag','Dress','Pants','Shoes','Skirt']
|
20 |
+
def predict(img):
|
21 |
+
imag=data_transform1(img)
|
22 |
+
inp =imag.unsqueeze(0)
|
23 |
+
outputs=model(inp)
|
24 |
+
pred=F.softmax(outputs[0], dim=0).cpu().data.numpy()
|
25 |
+
confidences = {classes[i]:(float(pred[i])) for i in range(5)}
|
26 |
+
return confidences
|
27 |
+
|
28 |
+
gr.Interface(predict,gr.inputs.Image(type='pil'),title=title,examples=examples,outputs='label').launch(debug=True)
|
|
|
|