atalaydenknalbant commited on
Commit
cc582e0
·
verified ·
1 Parent(s): 6f6b144

Upload 10 files

Browse files
Files changed (11) hide show
  1. .gitattributes +7 -0
  2. README.md +18 -13
  3. San Diego Airport.jpg +3 -0
  4. Theodore_Roosevelt.png +3 -0
  5. Tricycle.jpg +3 -0
  6. app.py +194 -0
  7. bus.jpg +3 -0
  8. requirements.txt +3 -0
  9. tcganadolu.jpg +3 -0
  10. yolo_vision.jpg +3 -0
  11. zidane.jpg +3 -0
.gitattributes CHANGED
@@ -33,3 +33,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ bus.jpg filter=lfs diff=lfs merge=lfs -text
37
+ San[[:space:]]Diego[[:space:]]Airport.jpg filter=lfs diff=lfs merge=lfs -text
38
+ tcganadolu.jpg filter=lfs diff=lfs merge=lfs -text
39
+ Theodore_Roosevelt.png filter=lfs diff=lfs merge=lfs -text
40
+ Tricycle.jpg filter=lfs diff=lfs merge=lfs -text
41
+ yolo_vision.jpg filter=lfs diff=lfs merge=lfs -text
42
+ zidane.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,18 @@
1
- ---
2
- title: Yolo13
3
- emoji: 🔥
4
- colorFrom: green
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 5.37.0
8
- app_file: app.py
9
- pinned: false
10
- short_description: Detect objects in images and videos
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
1
+ ---
2
+ title: Yolo13
3
+ emoji: 👁
4
+ colorFrom: pink
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 5.29.1
8
+ app_file: app.py
9
+ pinned: false
10
+ tags:
11
+ - Object Detection
12
+ - Instance Segmentation
13
+ - Pose/Keypoints
14
+ - Oriented Detection
15
+ - Image Classification
16
+ ---
17
+
18
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
San Diego Airport.jpg ADDED

Git LFS Details

  • SHA256: 55b7890afdb58a1fd78912b980bf63ed9040915734aa3ae1e7d7785d540813d8
  • Pointer size: 131 Bytes
  • Size of remote file: 335 kB
Theodore_Roosevelt.png ADDED

Git LFS Details

  • SHA256: 2f26f6876212efaf4c2e5551cc618cc70210b31c98d28fb2c72387b609b2887c
  • Pointer size: 132 Bytes
  • Size of remote file: 1.79 MB
Tricycle.jpg ADDED

Git LFS Details

  • SHA256: dee0d670a1753d635550fc8b58b010063799fd005c0d5591e9207d9f9372a582
  • Pointer size: 131 Bytes
  • Size of remote file: 763 kB
app.py ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ from PIL import Image, ImageDraw, ImageFont
4
+ from ultralytics import YOLO
5
+ from huggingface_hub import hf_hub_download
6
+ import cv2
7
+ import tempfile
8
+
9
+ def download_model(model_filename):
10
+ return hf_hub_download(repo_id="atalaydenknalbant/Yolov13", filename=model_filename)
11
+
12
+ @spaces.GPU
13
+ def yolo_inference(input_type, image, video, model_id, conf_threshold, iou_threshold, max_detection):
14
+ model_path = download_model(model_id)
15
+
16
+ if input_type == "Image":
17
+ if image is None:
18
+ width, height = 640, 480
19
+ blank_image = Image.new("RGB", (width, height), color="white")
20
+ draw = ImageDraw.Draw(blank_image)
21
+ message = "No image provided"
22
+ font = ImageFont.load_default(size=40)
23
+ bbox = draw.textbbox((0, 0), message, font=font)
24
+ text_width = bbox[2] - bbox[0]
25
+ text_height = bbox[3] - bbox[1]
26
+ text_x = (width - text_width) / 2
27
+ text_y = (height - text_height) / 2
28
+ draw.text((text_x, text_y), message, fill="black", font=font)
29
+ return blank_image, None
30
+
31
+ model = YOLO(model_path)
32
+ results = model.predict(
33
+ source=image,
34
+ conf=conf_threshold,
35
+ iou=iou_threshold,
36
+ imgsz=640,
37
+ max_det=max_detection,
38
+ show_labels=True,
39
+ show_conf=True,
40
+ )
41
+ for r in results:
42
+ image_array = r.plot()
43
+ annotated_image = Image.fromarray(image_array[..., ::-1])
44
+ return annotated_image, None
45
+
46
+ elif input_type == "Video":
47
+ if video is None:
48
+ width, height = 640, 480
49
+ blank_image = Image.new("RGB", (width, height), color="white")
50
+ draw = ImageDraw.Draw(blank_image)
51
+ message = "No video provided"
52
+ font = ImageFont.load_default(size=40)
53
+ bbox = draw.textbbox((0, 0), message, font=font)
54
+ text_width = bbox[2] - bbox[0]
55
+ text_height = bbox[3] - bbox[1]
56
+ text_x = (width - text_width) / 2
57
+ text_y = (height - text_height) / 2
58
+ draw.text((text_x, text_y), message, fill="black", font=font)
59
+ temp_video_file = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
60
+ fourcc = cv2.VideoWriter_fourcc(*"mp4v")
61
+ out = cv2.VideoWriter(temp_video_file, fourcc, 1, (width, height))
62
+ frame = cv2.cvtColor(np.array(blank_image), cv2.COLOR_RGB2BGR)
63
+ out.write(frame)
64
+ out.release()
65
+ return None, temp_video_file
66
+
67
+ model = YOLO(model_path)
68
+ cap = cv2.VideoCapture(video)
69
+ fps = cap.get(cv2.CAP_PROP_FPS) if cap.get(cv2.CAP_PROP_FPS) > 0 else 25
70
+ frames = []
71
+ while True:
72
+ ret, frame = cap.read()
73
+ if not ret:
74
+ break
75
+ pil_frame = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
76
+ results = model.predict(
77
+ source=pil_frame,
78
+ conf=conf_threshold,
79
+ iou=iou_threshold,
80
+ imgsz=640,
81
+ max_det=max_detection,
82
+ show_labels=True,
83
+ show_conf=True,
84
+ )
85
+ for r in results:
86
+ annotated_frame_array = r.plot()
87
+ annotated_frame = cv2.cvtColor(annotated_frame_array, cv2.COLOR_BGR2RGB)
88
+ frames.append(annotated_frame)
89
+ cap.release()
90
+ if not frames:
91
+ return None, None
92
+
93
+ height_out, width_out, _ = frames[0].shape
94
+ temp_video_file = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
95
+ fourcc = cv2.VideoWriter_fourcc(*"mp4v")
96
+ out = cv2.VideoWriter(temp_video_file, fourcc, fps, (width_out, height_out))
97
+ for f in frames:
98
+ f_bgr = cv2.cvtColor(f, cv2.COLOR_RGB2BGR)
99
+ out.write(f_bgr)
100
+ out.release()
101
+ return None, temp_video_file
102
+
103
+ return None, None
104
+
105
+ def update_visibility(input_type):
106
+ if input_type == "Image":
107
+ return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
108
+ else:
109
+ return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=true)
110
+
111
+ def yolo_inference_for_examples(image, model_id, conf_threshold, iou_threshold, max_detection):
112
+ annotated_image, _ = yolo_inference(
113
+ input_type="Image",
114
+ image=image,
115
+ video=None,
116
+ model_id=model_id,
117
+ conf_threshold=conf_threshold,
118
+ iou_threshold=iou_threshold,
119
+ max_detection=max_detection
120
+ )
121
+ return gr.update(value="Image"), annotated_image
122
+
123
+ with gr.Blocks() as app:
124
+ gr.Markdown("# Yolo13: Object Detection")
125
+ gr.Markdown("Upload an image or video for inference using the latest YOLOv13 models.")
126
+ with gr.Accordion("Paper and Citation", open=False):
127
+ gr.Markdown("""
128
+ This application is based on the research from the paper: **YOLOv13: Real-Time Object Detection with Hypergraph-Enhanced Adaptive Visual Perception**.
129
+
130
+ - **Authors:** Mengqi Lei, Siqi Li, Yihong Wu, et al.
131
+ - **Preprint Link:** [https://arxiv.org/abs/2506.17733](https://arxiv.org/abs/2506.17733)
132
+
133
+ **BibTeX:**
134
+ ```
135
+ @article{yolov13,
136
+ title={YOLOv13: Real-Time Object Detection with Hypergraph-Enhanced Adaptive Visual Perception},
137
+ author={Lei, Mengqi and Li, Siqi and Wu, Yihong and et al.},
138
+ journal={arXiv preprint arXiv:2506.17733},
139
+ year={2025}
140
+ }
141
+ ```
142
+ """)
143
+
144
+ with gr.Row():
145
+ with gr.Column():
146
+ image = gr.Image(type="pil", label="Image", visible=True)
147
+ video = gr.Video(label="Video", visible=False)
148
+ input_type = gr.Radio(
149
+ choices=["Image", "Video"],
150
+ value="Image",
151
+ label="Input Type",
152
+ )
153
+ model_id = gr.Dropdown(
154
+ label="Model Name",
155
+ choices=[
156
+ 'yolov13n.pt', 'yolov13s.pt', 'yolov13l.pt', 'yolov13x.pt',
157
+ ],
158
+ value="yolov13n.pt",
159
+ )
160
+ conf_threshold = gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence Threshold")
161
+ iou_threshold = gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU Threshold")
162
+ max_detection = gr.Slider(minimum=1, maximum=300, step=1, value=300, label="Max Detection")
163
+ infer_button = gr.Button("Detect Objects")
164
+ with gr.Column():
165
+ output_image = gr.Image(type="pil", label="Annotated Image", visible=True)
166
+ output_video = gr.Video(label="Annotated Video", visible=False)
167
+ gr.DeepLinkButton()
168
+
169
+ input_type.change(
170
+ fn=update_visibility,
171
+ inputs=input_type,
172
+ outputs=[image, video, output_image, output_video],
173
+ )
174
+
175
+ infer_button.click(
176
+ fn=yolo_inference,
177
+ inputs=[input_type, image, video, model_id, conf_threshold, iou_threshold, max_detection],
178
+ outputs=[output_image, output_video],
179
+ )
180
+
181
+ gr.Examples(
182
+ examples=[
183
+ ["zidane.jpg", "yolov13s.pt", 0.25, 0.45, 300],
184
+ ["bus.jpg", "yolov13l.pt", 0.25, 0.45, 300],
185
+ ["yolo_vision.jpg", "yolov13x.pt", 0.25, 0.45, 300],
186
+ ],
187
+ fn=yolo_inference_for_examples,
188
+ inputs=[image, model_id, conf_threshold, iou_threshold, max_detection],
189
+ outputs=[input_type, output_image],
190
+ label="Examples (Images)",
191
+ )
192
+
193
+ if __name__ == '__main__':
194
+ app.launch()
bus.jpg ADDED

Git LFS Details

  • SHA256: c02019c4979c191eb739ddd944445ef408dad5679acab6fd520ef9d434bfbc63
  • Pointer size: 131 Bytes
  • Size of remote file: 137 kB
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ spaces
2
+ git+https://github.com/iMoonLab/yolov13
3
+ Pillow
tcganadolu.jpg ADDED

Git LFS Details

  • SHA256: 73d87d4a1b11899bf662519c517ea4e078c998f2d44662dd43d7ec6495c64012
  • Pointer size: 131 Bytes
  • Size of remote file: 143 kB
yolo_vision.jpg ADDED

Git LFS Details

  • SHA256: d03501c0ba152a185a5dc2ed2e93211557c4670adba67e4497b8df80435d7090
  • Pointer size: 131 Bytes
  • Size of remote file: 205 kB
zidane.jpg ADDED

Git LFS Details

  • SHA256: 356dad2107bb0254e4e4a81bc1d9c7140043e88569d546e5b404b19bffa77d0a
  • Pointer size: 131 Bytes
  • Size of remote file: 169 kB