Spaces:
Runtime error
Runtime error
Commit
·
1caaa13
1
Parent(s):
5611621
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = "YoLoX Demo"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
description = "Demo for YOLOX(Object Detection). Models are YOLOXNano - YOLOXX"
|
| 62 |
+
|
| 63 |
+
# deploy
|
| 64 |
+
iface = gr.Interface(main,
|
| 65 |
+
inputs = input,
|
| 66 |
+
outputs = output,
|
| 67 |
+
title = title,
|
| 68 |
+
article = article,
|
| 69 |
+
description = description,
|
| 70 |
+
theme = "dark")
|
| 71 |
+
|
| 72 |
+
iface.launch(debug = True)
|