File size: 2,295 Bytes
5613916
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f35443
5613916
 
 
 
6a0eb8e
5613916
15fd999
5613916
 
 
 
 
 
 
 
 
 
 
 
9fefd1d
5613916
 
 
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

import numpy as np
from keras_cv_attention_models.yolox import * # import all yolox model
from keras_cv_attention_models.coco import data
import matplotlib.pyplot as plt
import gradio as gr
 
# semua yolox model
choices = ["YOLOXNano", "YOLOXTiny", "YOLOXS", "YOLOXM", "YOLOXL", "YOLOXX"]

def main(input_img, models):
    
    #
    fig, ax = plt.subplots() # pakai ini,jika tidak akan muncul error

    # YOLOXNano models
    if models == "YOLOXNano": 
        model = YOLOXNano(pretrained="coco") 

    # YOLOXTiny models
    elif models == "YOLOXTiny": 
        model = YOLOXTiny(pretrained="coco") 

    # YOLOXS models   
    elif models == "YOLOXS":       
        model = YOLOXS(pretrained="coco") 

    # YOLOXM models    
    elif models == "YOLOXM": 
        model = YOLOXM(pretrained="coco") 

    # YOLOXL models    
    elif models == "YOLOXL":
        model = YOLOXL(pretrained="coco") 

    # YOLOXX models   
    elif models == "YOLOXX":      
        model = YOLOXX(pretrained="coco") 

    # pass    
    else:  
        pass

    # image pre processing yolox
    preds = model(model.preprocess_input(input_img))
    bboxs, lables, confidences = model.decode_predictions(preds)[0]
    data.show_image_with_bboxes(input_img, bboxs, lables, confidences, num_classes=100,label_font_size=17, ax=ax)

    return fig

# define params

input = [gr.inputs.Image(shape=(2000, 1500),label = "Input Image"),
         gr.inputs.Dropdown(choices= choices, type="value", default='YOLOXS', label="Model")]

output = gr.outputs.Image(type="plot", label="Output Image")

title = "YOLOX Demo"

example = [["images_1.jpeg ","YOLOXM"],["images_2.jpeg","YOLOXS"]]

description = "Demo for YOLOX(Object Detection). Models are YOLOXNano - YOLOXX"           

article = "<p style='text-align: center'>Untuk penjelasan lihat di <a href='https://github.com/sultanbst123/Text_summarization-id2id' target='_blank'><u>repo ku </u>😁</a></p>"

# deploy
iface = gr.Interface(main, 
                    inputs = input,
                    outputs = output, 
                    title = title,
                    article = article,
                    description = description, 
                    examples = example, 
                    theme = "dark") 
                    
iface.launch(debug = True)