Atualli commited on
Commit
dc4b4f2
0 Parent(s):

Duplicate from Atualli/yolox1

Browse files
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: YOLOX is a high-performance anchor-free YOLO.
3
+ emoji: 🌖
4
+ colorFrom: red
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.15.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ duplicated_from: Atualli/yolox1
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ #os.system("pip -qq install yoloxdetect==0.0.7")
4
+ os.system("pip -qq install yoloxdetect")
5
+ import torch
6
+ import json
7
+
8
+ from yoloxdetect import YoloxDetector
9
+
10
+ # Images
11
+ torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
12
+ torch.hub.download_url_to_file('https://raw.githubusercontent.com/obss/sahi/main/tests/data/small-vehicles1.jpeg', 'small-vehicles1.jpeg')
13
+ torch.hub.download_url_to_file('https://raw.githubusercontent.com/Megvii-BaseDetection/YOLOX/main/assets/dog.jpg', 'dog.jpg')
14
+
15
+ def yolox_inference(
16
+ image_path: gr.inputs.Image = None,
17
+ model_path: gr.inputs.Dropdown = 'kadirnar/yolox_s-v0.1.1',
18
+ config_path: gr.inputs.Textbox = 'configs.yolox_s',
19
+ image_size: gr.inputs.Slider = 640
20
+ ):
21
+ """
22
+ YOLOX inference function
23
+ Args:
24
+ image: Input image
25
+ model_path: Path to the model
26
+ config_path: Path to the config file
27
+ image_size: Image size
28
+ Returns:
29
+ Rendered image
30
+ """
31
+
32
+ model = YoloxDetector(model_path, config_path=config_path, device="cpu", hf_model=True)
33
+ #pred = model.predict(image_path=image_path, image_size=image_size)
34
+ model.torchyolo = True
35
+ pred2 = model.predict(image_path=image_path, image_size=image_size)
36
+ #text = "Ola"
37
+ #print (vars(model))
38
+ #print (pred2[0])
39
+ #print (pred2[1])
40
+ #print (pred2[2])
41
+
42
+
43
+ tensor = {
44
+ "tensorflow": [
45
+ ]
46
+ }
47
+
48
+ #print (pred2[3])
49
+ for i, element in enumerate(pred2[0]):
50
+ object = {}
51
+ itemclass = round(pred2[2][i].item())
52
+ object["classe"] = itemclass
53
+ object["nome"] = pred2[3][itemclass]
54
+ object["score"] = pred2[1][i].item()
55
+ object["x"] = element[0].item()
56
+ object["y"] = element[1].item()
57
+ object["w"] = element[2].item()
58
+ object["h"] = element[3].item()
59
+ tensor["tensorflow"].append(object)
60
+
61
+ #print(tensor)
62
+
63
+ text = json.dumps(tensor)
64
+ return text
65
+
66
+
67
+ inputs = [
68
+ gr.inputs.Image(type="filepath", label="Input Image"),
69
+ gr.inputs.Textbox(lines=1, label="Model Path", default="kadirnar/yolox_s-v0.1.1"),
70
+ gr.inputs.Textbox(lines=1, label="Config Path", default="configs.yolox_s"),
71
+ gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
72
+ ]
73
+
74
+ outputs = gr.outputs.Image(type="filepath", label="Output Image")
75
+ title = "SIMULADOR PARA RECONHECIMENTO DE IMAGEM"
76
+
77
+ examples = [
78
+ ["small-vehicles1.jpeg", "kadirnar/yolox_m-v0.1.1", "configs.yolox_m", 640],
79
+ ["zidane.jpg", "kadirnar/yolox_s-v0.1.1", "configs.yolox_s", 640],
80
+ ["dog.jpg", "kadirnar/yolox_tiny-v0.1.1", "configs.yolox_tiny", 640],
81
+ ]
82
+
83
+ demo_app = gr.Interface(
84
+ fn=yolox_inference,
85
+ inputs=inputs,
86
+ outputs=["text"],
87
+ title=title,
88
+ examples=examples,
89
+ cache_examples=True,
90
+ live=True,
91
+ theme='huggingface',
92
+ )
93
+ demo_app.launch(debug=True, enable_queue=True)
configs/__init__.py ADDED
File without changes
configs/yolov3.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) Megvii, Inc. and its affiliates.
4
+
5
+ import os
6
+
7
+ import torch.nn as nn
8
+
9
+ from yolox.exp import Exp as MyExp
10
+
11
+
12
+ class Exp(MyExp):
13
+ def __init__(self):
14
+ super(Exp, self).__init__()
15
+ self.depth = 1.0
16
+ self.width = 1.0
17
+ self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
18
+
19
+ def get_model(self, sublinear=False):
20
+ def init_yolo(M):
21
+ for m in M.modules():
22
+ if isinstance(m, nn.BatchNorm2d):
23
+ m.eps = 1e-3
24
+ m.momentum = 0.03
25
+ if "model" not in self.__dict__:
26
+ from yolox.models import YOLOX, YOLOFPN, YOLOXHead
27
+ backbone = YOLOFPN()
28
+ head = YOLOXHead(self.num_classes, self.width, in_channels=[128, 256, 512], act="lrelu")
29
+ self.model = YOLOX(backbone, head)
30
+ self.model.apply(init_yolo)
31
+ self.model.head.initialize_biases(1e-2)
32
+
33
+ return self.model
configs/yolox_l.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) Megvii, Inc. and its affiliates.
4
+
5
+ import os
6
+
7
+ from yolox.exp import Exp as MyExp
8
+
9
+
10
+ class Exp(MyExp):
11
+ def __init__(self):
12
+ super(Exp, self).__init__()
13
+ self.depth = 1.0
14
+ self.width = 1.0
15
+ self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
configs/yolox_m.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) Megvii, Inc. and its affiliates.
4
+
5
+ import os
6
+
7
+ from yolox.exp import Exp as MyExp
8
+
9
+
10
+ class Exp(MyExp):
11
+ def __init__(self):
12
+ super(Exp, self).__init__()
13
+ self.depth = 0.67
14
+ self.width = 0.75
15
+ self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
configs/yolox_nano.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) Megvii, Inc. and its affiliates.
4
+
5
+ import os
6
+
7
+ import torch.nn as nn
8
+
9
+ from yolox.exp import Exp as MyExp
10
+
11
+
12
+ class Exp(MyExp):
13
+ def __init__(self):
14
+ super(Exp, self).__init__()
15
+ self.depth = 0.33
16
+ self.width = 0.25
17
+ self.input_size = (416, 416)
18
+ self.random_size = (10, 20)
19
+ self.mosaic_scale = (0.5, 1.5)
20
+ self.test_size = (416, 416)
21
+ self.mosaic_prob = 0.5
22
+ self.enable_mixup = False
23
+ self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
24
+
25
+ def get_model(self, sublinear=False):
26
+
27
+ def init_yolo(M):
28
+ for m in M.modules():
29
+ if isinstance(m, nn.BatchNorm2d):
30
+ m.eps = 1e-3
31
+ m.momentum = 0.03
32
+ if "model" not in self.__dict__:
33
+ from yolox.models import YOLOX, YOLOPAFPN, YOLOXHead
34
+ in_channels = [256, 512, 1024]
35
+ # NANO model use depthwise = True, which is main difference.
36
+ backbone = YOLOPAFPN(
37
+ self.depth, self.width, in_channels=in_channels,
38
+ act=self.act, depthwise=True,
39
+ )
40
+ head = YOLOXHead(
41
+ self.num_classes, self.width, in_channels=in_channels,
42
+ act=self.act, depthwise=True
43
+ )
44
+ self.model = YOLOX(backbone, head)
45
+
46
+ self.model.apply(init_yolo)
47
+ self.model.head.initialize_biases(1e-2)
48
+ return self.model
configs/yolox_s.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) Megvii, Inc. and its affiliates.
4
+
5
+ import os
6
+
7
+ from yolox.exp import Exp as MyExp
8
+
9
+
10
+ class Exp(MyExp):
11
+ def __init__(self):
12
+ super(Exp, self).__init__()
13
+ self.depth = 0.33
14
+ self.width = 0.50
15
+ self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
configs/yolox_tiny.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) Megvii, Inc. and its affiliates.
4
+
5
+ import os
6
+
7
+ from yolox.exp import Exp as MyExp
8
+
9
+
10
+ class Exp(MyExp):
11
+ def __init__(self):
12
+ super(Exp, self).__init__()
13
+ self.depth = 0.33
14
+ self.width = 0.375
15
+ self.input_size = (416, 416)
16
+ self.mosaic_scale = (0.5, 1.5)
17
+ self.random_size = (10, 20)
18
+ self.test_size = (416, 416)
19
+ self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
20
+ self.enable_mixup = False
configs/yolox_x.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) Megvii, Inc. and its affiliates.
4
+
5
+ import os
6
+
7
+ from yolox.exp import Exp as MyExp
8
+
9
+
10
+ class Exp(MyExp):
11
+ def __init__(self):
12
+ super(Exp, self).__init__()
13
+ self.depth = 1.33
14
+ self.width = 1.25
15
+ self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0]
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ torch