aibc commited on
Commit
6cd3f8f
β€’
1 Parent(s): 9fd1e55

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from keras_cv_attention_models.yolox import * # import all yolox model
3
+ from keras_cv_attention_models.coco import data
4
+ import matplotlib.pyplot as plt
5
+ import gradio as gr
6
+
7
+ # semua yolox model
8
+ choices = ["YOLOXNano", "YOLOXTiny", "YOLOXS", "YOLOXM", "YOLOXL", "YOLOXX"]
9
+
10
+ def main(input_img, models):
11
+
12
+ #
13
+ fig, ax = plt.subplots() # pakai ini,jika tidak akan muncul error
14
+
15
+ # YOLOXNano models
16
+ if models == "YOLOXNano":
17
+ model = YOLOXNano(pretrained="coco")
18
+
19
+ # YOLOXTiny models
20
+ elif models == "YOLOXTiny":
21
+ model = YOLOXTiny(pretrained="coco")
22
+
23
+ # YOLOXS models
24
+ elif models == "YOLOXS":
25
+ model = YOLOXS(pretrained="coco")
26
+
27
+ # YOLOXM models
28
+ elif models == "YOLOXM":
29
+ model = YOLOXM(pretrained="coco")
30
+
31
+ # YOLOXL models
32
+ elif models == "YOLOXL":
33
+ model = YOLOXL(pretrained="coco")
34
+
35
+ # YOLOXX models
36
+ elif models == "YOLOXX":
37
+ model = YOLOXX(pretrained="coco")
38
+
39
+ # pass
40
+ else:
41
+ pass
42
+
43
+ # image pre processing yolox
44
+ preds = model(model.preprocess_input(input_img))
45
+ bboxs, lables, confidences = model.decode_predictions(preds)[0]
46
+ data.show_image_with_bboxes(input_img, bboxs, lables, confidences, num_classes=100,label_font_size=17, ax=ax)
47
+
48
+ return fig
49
+
50
+ # define params
51
+
52
+ input = [gr.inputs.Image(shape=(2000, 1500),label = "Input Image"),
53
+ gr.inputs.Dropdown(choices= choices, type="value", default='YOLOXS', label="Model")]
54
+
55
+ output = gr.outputs.Image(type="plot", label="Output Image")
56
+
57
+ title = "aibc YOLOX Demo"
58
+
59
+ example = [["images_1.jpeg ","YOLOXM"],["images_2.jpeg","YOLOXS"],["images.jpeg","YOLOXL"]]
60
+
61
+ description = "Demo for YOLOX(Object Detection). Models are YOLOXNano - YOLOXX"
62
+
63
+ article = "<a href='https://github.com/Megvii-BaseDetection/YOLOX' target='_blank'><u>YOLOX </u></a>is an anchor-free version of YOLO, with a simpler design but better performance!<br><br><p style='text-align: center'>Untuk penjelasan lihat di <a href='https://github.com/sultanbst123/YOLOX-Demo' target='_blank'><u>repo ku </u>😁</a></p>"
64
+
65
+ # deploy
66
+ iface = gr.Interface(main,
67
+ inputs = input,
68
+ outputs = output,
69
+ title = title,
70
+ article = article,
71
+ description = description,
72
+ examples = example,
73
+ theme = "dark")
74
+
75
+ iface.launch(debug = True)