Kr1n3 commited on
Commit
90ca1cc
·
1 Parent(s): 8415643

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -1,32 +1,28 @@
1
- import torch as tf
2
-
3
  import gradio as gr
4
-
5
- inception_net = tf.keras.models.load_model('best.pt') # load the model
6
-
7
- labels = ['bom', 'ruim']
8
-
9
-
10
- title = "Fashion Items Classification"
11
- description = """
12
- """
13
-
14
- def classify_image(inp):
15
- inp = inp.reshape((-1, 640, 640, 3))
16
- inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
17
- prediction = inception_net.predict(inp).flatten()
18
- return (labels[1] if float(prediction) >= 0 else labels[0])
19
-
20
-
21
- image = gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Imagem", optional=False)
22
- label = gr.outputs.Textbox(type="auto", label="Classificação")
23
-
24
- gr.Interface(
25
- fn=classify_image,
26
- inputs=image,
27
- outputs=label,
28
- title=title,
29
- description=description,
30
- examples=[["https://github.com/Kr1n3/MPC_2022/blob/main/dataset/pants_30.jpeg?raw=true"], ["https://github.com/Kr1n3/MPC_2022/blob/main/dataset/bag_01.jpg?raw=true"],
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)