mbar0075 commited on
Commit
ab7b7a8
·
verified ·
1 Parent(s): b629a46

Initial Commit

Browse files
.gitattributes CHANGED
@@ -1,35 +1,49 @@
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
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz 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
+ examples/9.jpeg filter=lfs diff=lfs merge=lfs -text
37
+ examples/16.jpg filter=lfs diff=lfs merge=lfs -text
38
+ examples/23.jpg filter=lfs diff=lfs merge=lfs -text
39
+ examples/1.jpg filter=lfs diff=lfs merge=lfs -text
40
+ examples/10.jpg filter=lfs diff=lfs merge=lfs -text
41
+ examples/11.jpg filter=lfs diff=lfs merge=lfs -text
42
+ examples/14.jpg filter=lfs diff=lfs merge=lfs -text
43
+ examples/15.jpg filter=lfs diff=lfs merge=lfs -text
44
+ examples/17.png filter=lfs diff=lfs merge=lfs -text
45
+ examples/21.jpg filter=lfs diff=lfs merge=lfs -text
46
+ examples/3.jpg filter=lfs diff=lfs merge=lfs -text
47
+ examples/5.jpg filter=lfs diff=lfs merge=lfs -text
48
+ examples/6.jpg filter=lfs diff=lfs merge=lfs -text
49
+ examples/7.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,14 @@
1
- ---
2
- title: YOLO Application Toolkit
3
- emoji: 🐢
4
- colorFrom: purple
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 5.25.2
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
+ ---
2
+ title: YOLO-Application Toolkit
3
+ emoji: 🌍
4
+ colorFrom: yellow
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 4.44.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ short_description: Inference for various YOLO11 trained models in contexts
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Tuple
2
+ import gradio as gr
3
+ import numpy as np
4
+ import supervision as sv
5
+ from ultralytics import YOLO
6
+ import os
7
+
8
+ MARKDOWN = """
9
+ <h1 style='text-align: left'>YOLO-Application Toolkit 🚀</h1>
10
+ <p>Welcome to the YOLO-Application Toolkit! This demo highlights the powerful detection capabilities of various YOLO models pre-trained on different datasets. 🎉
11
+
12
+ Easily detect different objects for various contexts in images on the go. Perfect for quick experimentation and practical use. 🎉🔍</p>
13
+
14
+
15
+ **YOLO11**
16
+ <div style="display: flex; align-items: center;">
17
+ <a href="https://docs.ultralytics.com/models/yolo11/" style="margin-right: 10px;">
18
+ <img src="https://badges.aleen42.com/src/github.svg">
19
+ </a>
20
+ <a href="https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolo11-object-detection-on-custom-dataset.ipynb?ref=blog.roboflow.com" style="margin-right: 10px;">
21
+ <img src="https://colab.research.google.com/assets/colab-badge.svg">
22
+ </a>
23
+ </div>
24
+
25
+ Powered by
26
+ [Ultralytics](https://github.com/ultralytics/ultralytics).🔥
27
+
28
+ """
29
+ # Roboflow [Inference](https://github.com/roboflow/inference), [Supervision](https://github.com/roboflow/supervision) and [Ultralytics](https://github.com/ultralytics/ultralytics).🔥
30
+
31
+ # Load models dynamically
32
+
33
+ MODELS = {
34
+ "YOLO11m (COCO128)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m.pt"),
35
+ "American Sign Language (ASL) (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_sign_language.pt"),
36
+ # "Microscopic Cell Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_microscope_cells.pt"),
37
+ "Website Screenshots (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_website_screenshots.pt"),
38
+ "Zoo Animals (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_zoo_animals.pt"),
39
+ "Pinned Circuit Boards (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_circuit_boards.pt"),
40
+ "Smoke Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_smoke_detection.pt"),
41
+ "Blood Cell Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_blood_cells.pt"),
42
+ "Coins Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_coins.pt"),
43
+ "Pizza Toppings Detection (YOLOv8s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolov8s_pizza.pt"),
44
+ "Aquarium Fish Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_aquarium_fish.pt"),
45
+ # "Pelvis X-ray Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_pelvis_xray.pt"),
46
+ "Road Signs Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_road_signs.pt"),
47
+ # "Pizza Toppings Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_pizza.pt"),
48
+ "Pelvis X-ray Segmentation (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_seg_pelvis_xray.pt"),
49
+ "Teeth X-ray Segmentation (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_seg_teeth_xray.pt"),
50
+ "Football Players Detection (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_football_players.pt"),
51
+ # "Litter Detection (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_litter_detection.pt"),
52
+ "Wheat Detection (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_wheat_detection.pt"),
53
+ "Signatures Detection (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_signatures_detection.pt"),
54
+ "Billiards Detection (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_billiards_detection.pt"),
55
+ "Car Parts Segmentation (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_seg_car_parts.pt"),
56
+ "YOLO11s-Pose (COCO128)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s-pose.pt"),
57
+ "Hand Keypoints Detection (YOLO11s)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11s_hand_keypoints.pt"),
58
+ "Garbage Detection (YOLO11m)": YOLO("https://huggingface.co/mbar0075/YOLO-Application-Toolkit/resolve/main/yolo11m_garbage_detection.pt"),
59
+ }
60
+
61
+
62
+ example_dir = "https://huggingface.co/spaces/mbar0075/YOLO-Application-Toolkit/resolve/main/examples/"
63
+ # Your existing example dictionary
64
+ EXAMPLE_DICT = {
65
+ "YOLO11m (COCO128)": example_dir + "1.jpg",
66
+ "American Sign Language (ASL) (YOLO11m)": example_dir + "2.jpg",
67
+ # "Microscopic Cell Detection (YOLO11m)": example_dir + "3.jpg",
68
+ "Website Screenshots (YOLO11m)": example_dir + "4.jpg",
69
+ "Zoo Animals (YOLO11m)": example_dir + "5.jpg",
70
+ "Pinned Circuit Boards (YOLO11m)": example_dir + "6.jpg",
71
+ "Smoke Detection (YOLO11m)": example_dir + "7.jpg",
72
+ "Blood Cell Detection (YOLO11m)": example_dir + "8.jpg",
73
+ "Coins Detection (YOLO11m)": example_dir + "9.jpg",
74
+ "Pizza Toppings Detection (YOLOv8s)": example_dir + "10.jpg",
75
+ "Aquarium Fish Detection (YOLO11m)": example_dir + "11.jpg",
76
+ # "Pelvis X-ray Detection (YOLO11m)": example_dir + "12.jpg",
77
+ "Road Signs Detection (YOLO11m)": example_dir + "13.jpg",
78
+ # "Pizza Toppings Detection (YOLO11m)": example_dir + "10.jpg",
79
+ "Pelvis X-ray Segmentation (YOLO11s)": example_dir + "12.jpg",
80
+ "Teeth X-ray Segmentation (YOLO11s)": example_dir + "14.jpg",
81
+ "Football Players Detection (YOLO11s)": example_dir + "15.jpg",
82
+ # "Litter Detection (YOLO11s)": example_dir + "16.jpg",
83
+ "Wheat Detection (YOLO11s)": example_dir + "17.png",
84
+ "Signatures Detection (YOLO11s)": example_dir + "18.jpg",
85
+ "Billiards Detection (YOLO11s)": example_dir + "19.jpg",
86
+ "Car Parts Segmentation (YOLO11s)": example_dir + "20.jpg",
87
+ "YOLO11s-Pose (COCO128)": example_dir + "21.jpg",
88
+ "Hand Keypoints Detection (YOLO11s)": example_dir + "22.jpg",
89
+ "Garbage Detection (YOLO11m)": example_dir + "23.jpg",
90
+ }
91
+
92
+ LABEL_ANNOTATORS = sv.LabelAnnotator()
93
+ BOUNDING_BOX_ANNOTATORS = sv.BoxAnnotator()
94
+
95
+ def detect_and_annotate(
96
+ model,
97
+ input_image: np.ndarray,
98
+ confidence_threshold: float,
99
+ iou_threshold: float,
100
+ class_id_mapping: dict = None
101
+ ) -> np.ndarray:
102
+ result = model(input_image, conf=confidence_threshold, iou=iou_threshold)[0]
103
+ # Extracting Annotated Image
104
+ return result.plot()
105
+
106
+ # For supervision annotations:
107
+ detections = sv.Detections.from_ultralytics(result)
108
+
109
+ if class_id_mapping:
110
+ detections.class_id = np.array([class_id_mapping[class_id] for class_id in detections.class_id])
111
+
112
+ labels = [f"{class_name} ({confidence:.2f})" for class_name, confidence in zip(detections['class_name'], detections.confidence)]
113
+
114
+ annotated_image = input_image.copy()
115
+ annotated_image = BOUNDING_BOX_ANNOTATORS.annotate(scene=annotated_image, detections=detections)
116
+ annotated_image = LABEL_ANNOTATORS.annotate(scene=annotated_image, detections=detections, labels=labels)
117
+ return annotated_image
118
+
119
+ def process_image(
120
+ input_image,
121
+ yolov11_confidence_threshold: float,
122
+ iou_threshold: float,
123
+ model_name: str
124
+ ) -> np.ndarray:
125
+ # Load the selected model from the preloaded models
126
+ model = MODELS[model_name]
127
+
128
+ # Process the image
129
+ return detect_and_annotate(model, np.array(input_image), yolov11_confidence_threshold, iou_threshold)
130
+
131
+ # Gradio UI components
132
+ yolo_11s_confidence_threshold_component = gr.Slider(
133
+ minimum=0,
134
+ maximum=1.0,
135
+ value=0.3,
136
+ step=0.01,
137
+ label="YOLO Confidence Threshold",
138
+ info=(
139
+ "The confidence threshold for the YOLO model. Lower the threshold to "
140
+ "reduce false negatives, enhancing the model's sensitivity to detect "
141
+ "sought-after objects. Conversely, increase the threshold to minimize false "
142
+ "positives, preventing the model from identifying objects it shouldn't."
143
+ )
144
+ )
145
+
146
+ iou_threshold_component = gr.Slider(
147
+ minimum=0,
148
+ maximum=1.0,
149
+ value=0.5,
150
+ step=0.01,
151
+ label="IoU Threshold",
152
+ info=(
153
+ "The Intersection over Union (IoU) threshold for non-maximum suppression. "
154
+ "Decrease the value to lessen the occurrence of overlapping bounding boxes, "
155
+ "making the detection process stricter. On the other hand, increase the value "
156
+ "to allow more overlapping bounding boxes, accommodating a broader range of "
157
+ "detections."
158
+ )
159
+ )
160
+
161
+ model_dropdown = gr.Dropdown(
162
+ choices=list(MODELS.keys()),
163
+ label="Select Model",
164
+ value="YOLO11m (COCO128)",
165
+ info=(
166
+ "Choose the YOLO model you want to use for object detection. Each model is "
167
+ "trained on a specific dataset, making them suitable for various detection tasks."
168
+ )
169
+ )
170
+
171
+ def update_example(model_name):
172
+ return EXAMPLE_DICT[model_name]
173
+
174
+ with gr.Blocks() as demo:
175
+ gr.Markdown(MARKDOWN)
176
+
177
+ with gr.Accordion("Configuration", open=False):
178
+ yolo_11s_confidence_threshold_component.render()
179
+ iou_threshold_component.render()
180
+
181
+ with gr.Row():
182
+ model_dropdown.render()
183
+
184
+ with gr.Row():
185
+ image_input_component = gr.Image(type='pil', label='Input Image')
186
+ yolo_11s_output_component = gr.Image(type='pil', label='YOLO Output')
187
+
188
+ submit_button = gr.Button(value='Submit', scale=1, variant='primary')
189
+
190
+ gr.Examples(
191
+ fn=process_image,
192
+ examples=[[EXAMPLE_DICT[i], 0.3, 0.5, i] for i in EXAMPLE_DICT.keys()],
193
+ inputs=[image_input_component, yolo_11s_confidence_threshold_component, iou_threshold_component, model_dropdown],
194
+ outputs=[yolo_11s_output_component]
195
+ )
196
+
197
+ model_dropdown.change(fn=update_example, inputs=model_dropdown, outputs=image_input_component)
198
+
199
+ submit_button.click(
200
+ fn=process_image,
201
+ inputs=[image_input_component, yolo_11s_confidence_threshold_component, iou_threshold_component, model_dropdown],
202
+ outputs=[yolo_11s_output_component]
203
+ )
204
+
205
+ demo.launch(debug=False, show_error=True, max_threads=1)
examples/1.jpg ADDED

Git LFS Details

  • SHA256: 355c42da8cadc9f6b03839159e9f2ed7aca73844002d88012bae4b180025f05e
  • Pointer size: 131 Bytes
  • Size of remote file: 237 kB
examples/10.jpg ADDED

Git LFS Details

  • SHA256: 0b3319270a95ac00db8de728b00b400652a60ad7fa0a37e195d554df2322a083
  • Pointer size: 131 Bytes
  • Size of remote file: 219 kB
examples/11.jpg ADDED

Git LFS Details

  • SHA256: eb801d4a071517ca71d13a16a84881f109d239840d9d765c0b244d493d9227e2
  • Pointer size: 131 Bytes
  • Size of remote file: 266 kB
examples/12.jpg ADDED
examples/13.jpg ADDED
examples/14.jpg ADDED

Git LFS Details

  • SHA256: e53e4552e189c6c613b56e17b0aee82090e3f474b3ad475e25f934c86b320d29
  • Pointer size: 131 Bytes
  • Size of remote file: 255 kB
examples/15.jpg ADDED

Git LFS Details

  • SHA256: 17fc74cd5d413db785ee8c24d5b5f92310568d9579fa30bf117f8fa65b330875
  • Pointer size: 131 Bytes
  • Size of remote file: 161 kB
examples/16.jpg ADDED

Git LFS Details

  • SHA256: c2c1152b2284734b3fefe03cee7116542190de088b318c3c890e85f79fae4fc0
  • Pointer size: 132 Bytes
  • Size of remote file: 3.73 MB
examples/17.png ADDED

Git LFS Details

  • SHA256: 3ed9fcf9ac93e485361a5f6a8ee457a317e1aa9e14189a1af3a697e8326b0f06
  • Pointer size: 131 Bytes
  • Size of remote file: 756 kB
examples/18.jpg ADDED
examples/19.jpg ADDED
examples/2.jpg ADDED
examples/20.jpg ADDED
examples/21.jpg ADDED

Git LFS Details

  • SHA256: c02019c4979c191eb739ddd944445ef408dad5679acab6fd520ef9d434bfbc63
  • Pointer size: 131 Bytes
  • Size of remote file: 137 kB
examples/22.jpg ADDED
examples/23.jpg ADDED

Git LFS Details

  • SHA256: ff92f205d761a9cb05f0df9e0017a683eb3f78c0ba40941ae013de98aece8dec
  • Pointer size: 132 Bytes
  • Size of remote file: 2.53 MB
examples/3.jpg ADDED

Git LFS Details

  • SHA256: 22f0b5608bceeceb086fb3756d760af34a3db33908b484b94d855e504e35c5bf
  • Pointer size: 131 Bytes
  • Size of remote file: 149 kB
examples/4.jpg ADDED
examples/5.jpg ADDED

Git LFS Details

  • SHA256: c415a360de634db4c1e6740af95df1da081f5fa542ad29c11f120f2439acd9b3
  • Pointer size: 131 Bytes
  • Size of remote file: 106 kB
examples/6.jpg ADDED

Git LFS Details

  • SHA256: e9f6ca48c272a2d4b949cd2a2131321a9d2cac288d282902950404a715a49e66
  • Pointer size: 131 Bytes
  • Size of remote file: 104 kB
examples/7.jpg ADDED

Git LFS Details

  • SHA256: c5ce812067cd0514a71ffaaffe392dfb65c83ff290d034571c91abf2b144e9fb
  • Pointer size: 131 Bytes
  • Size of remote file: 229 kB
examples/8.jpg ADDED
examples/9.jpeg ADDED

Git LFS Details

  • SHA256: 4f32cf8b160266f71617e09b733d95058c5b47094f74570235e98e7a9cecfbf3
  • Pointer size: 132 Bytes
  • Size of remote file: 1.49 MB
examples/9.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ setuptools<70.0.0
2
+ awscli==1.29.54
3
+ gradio
4
+ pydantic==2.10.6
5
+ inference
6
+ supervision
7
+ ultralytics
8
+ dill
9
+ timm
train_YOLOv11.ipynb ADDED
@@ -0,0 +1,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "<center><h1>YOLO11 Training</h1>\n",
8
+ "<h2>Matthias Bartolo</h2>\n",
9
+ "\n",
10
+ "</center>"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "metadata": {},
16
+ "source": [
17
+ "<h3>Package Imports</h3>"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "execution_count": 1,
23
+ "metadata": {
24
+ "colab": {
25
+ "base_uri": "https://localhost:8080/",
26
+ "height": 1000
27
+ },
28
+ "id": "aFbKjvakDnZE",
29
+ "outputId": "dbe28130-1112-4141-e265-65d3f6b06acc"
30
+ },
31
+ "outputs": [],
32
+ "source": [
33
+ "# !pip install --upgrade roboflow ultralytics"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "markdown",
38
+ "metadata": {
39
+ "id": "dWZ2DvvEDnZF"
40
+ },
41
+ "source": [
42
+ "**<h3>Required libraries.</h3>**"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 2,
48
+ "metadata": {
49
+ "id": "9Zbf3zFkDnZG"
50
+ },
51
+ "outputs": [],
52
+ "source": [
53
+ "import torch\n",
54
+ "import os\n",
55
+ "import ultralytics\n",
56
+ "import locale\n",
57
+ "import glob\n",
58
+ "import pandas as pd\n",
59
+ "import matplotlib.pyplot as plt\n",
60
+ "\n",
61
+ "from IPython import display\n",
62
+ "from ultralytics import YOLO\n",
63
+ "from IPython.display import display, Image\n",
64
+ "from roboflow import Roboflow\n",
65
+ "\n",
66
+ "%matplotlib inline"
67
+ ]
68
+ },
69
+ {
70
+ "cell_type": "markdown",
71
+ "metadata": {
72
+ "id": "FyRdDYkqAKN4"
73
+ },
74
+ "source": [
75
+ "**<h3>Using GPU if one is available.</h3>**"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": null,
81
+ "metadata": {},
82
+ "outputs": [],
83
+ "source": [
84
+ "!nvidia-smi"
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": null,
90
+ "metadata": {
91
+ "colab": {
92
+ "base_uri": "https://localhost:8080/"
93
+ },
94
+ "id": "dgNdkO48DnZG",
95
+ "outputId": "11ca77d8-7b09-4d02-a899-0dfdc5aaac2d"
96
+ },
97
+ "outputs": [],
98
+ "source": [
99
+ "device = 'cuda' if torch.cuda.is_available() else 'cpu'\n",
100
+ "print(device)"
101
+ ]
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "execution_count": null,
106
+ "metadata": {
107
+ "colab": {
108
+ "base_uri": "https://localhost:8080/"
109
+ },
110
+ "id": "CjpPg4mGKc1v",
111
+ "outputId": "7035eeee-b2d1-438c-bb57-188bd34ea8eb"
112
+ },
113
+ "outputs": [],
114
+ "source": [
115
+ "# Retrieving the current working directory\n",
116
+ "HOME = os.getcwd()\n",
117
+ "print(HOME)"
118
+ ]
119
+ },
120
+ {
121
+ "cell_type": "markdown",
122
+ "metadata": {
123
+ "id": "3C3EO_2zNChu"
124
+ },
125
+ "source": [
126
+ "**<h3>Downloading the Roboflow dataset.</h3>**"
127
+ ]
128
+ },
129
+ {
130
+ "cell_type": "code",
131
+ "execution_count": null,
132
+ "metadata": {
133
+ "colab": {
134
+ "base_uri": "https://localhost:8080/"
135
+ },
136
+ "id": "BSd93ZJzZZKt",
137
+ "outputId": "cd51037c-4df9-415e-ecd8-540168fb544a"
138
+ },
139
+ "outputs": [],
140
+ "source": [
141
+ "if not os.path.isdir(os.path.join(HOME, 'datasets')):\n",
142
+ " os.mkdir(os.path.join(HOME, 'datasets'))\n",
143
+ "os.chdir(os.path.join(HOME, 'datasets'))\n",
144
+ "\n",
145
+ "\n",
146
+ "rf = Roboflow(api_key=\"<ROBOFLOW API KEY>\")\n",
147
+ "project = rf.workspace(\"<WORKSPACE>\").project(\"<PROJECT>\")\n",
148
+ "version = project.version(2)\n",
149
+ "dataset = version.download(\"yolov11\")"
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "markdown",
154
+ "metadata": {},
155
+ "source": [
156
+ "**<h3>Training the YOLO11 model.</h3>**"
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": null,
162
+ "metadata": {
163
+ "colab": {
164
+ "base_uri": "https://localhost:8080/"
165
+ },
166
+ "id": "_WRhnBXjDnZH",
167
+ "outputId": "09bcb11a-5656-4c53-8564-51b29cc08d6c"
168
+ },
169
+ "outputs": [],
170
+ "source": [
171
+ "# Specifying the paths\n",
172
+ "model_path = 'yolo11m.pt'\n",
173
+ "\n",
174
+ "yaml_path = dataset.location+\"/data.yaml\"\n",
175
+ "\n",
176
+ "# Creating YOLO object\n",
177
+ "model = YOLO(model_path)\n",
178
+ "\n",
179
+ "# Specifying training parameters\n",
180
+ "num_epochs = 100 # Number of epochs\n",
181
+ "batch_size = 16 #8 # Adjust based on GPU memory\n",
182
+ "image_size = 640 # Decrease for faster training\n",
183
+ "\n",
184
+ "# Training configuration\n",
185
+ "train_config = {\n",
186
+ " 'data': yaml_path,\n",
187
+ " 'imgsz': image_size,\n",
188
+ " 'batch': batch_size,\n",
189
+ " 'epochs': num_epochs,\n",
190
+ " 'device': 0, # Use GPU 0\n",
191
+ " # 'workers': 1, # Number of data loading workers\n",
192
+ " 'optimizer': 'Adam', # Use Adam optimizer\n",
193
+ " 'cache': True,#'disk', # Cache images for faster training\n",
194
+ " 'patience': 10, # epochs to wait before decreasing LR\n",
195
+ " 'val': True, # Run validation during training\n",
196
+ " 'plots': True, # Run plots during training\n",
197
+ "}\n",
198
+ "\n",
199
+ "# Train the model\n",
200
+ "model.train(**train_config)\n"
201
+ ]
202
+ },
203
+ {
204
+ "cell_type": "markdown",
205
+ "metadata": {
206
+ "id": "6ODk1VTlevxn"
207
+ },
208
+ "source": [
209
+ "**<h3>Validating the YOLO11 model on the Validation subset.</h3>**"
210
+ ]
211
+ },
212
+ {
213
+ "cell_type": "code",
214
+ "execution_count": 8,
215
+ "metadata": {
216
+ "colab": {
217
+ "base_uri": "https://localhost:8080/"
218
+ },
219
+ "id": "IkrxsRHoV67H",
220
+ "outputId": "ecb3eac0-3a4f-4df6-fdb0-9db829ad7a76"
221
+ },
222
+ "outputs": [],
223
+ "source": [
224
+ "locale.getpreferredencoding = lambda: \"UTF-8\"\n",
225
+ "# !pip install aspose-words"
226
+ ]
227
+ },
228
+ {
229
+ "cell_type": "code",
230
+ "execution_count": null,
231
+ "metadata": {
232
+ "colab": {
233
+ "base_uri": "https://localhost:8080/"
234
+ },
235
+ "id": "YpyuwrNlXc1P",
236
+ "outputId": "f4718557-cd29-4208-d5fa-ad0776a893b7"
237
+ },
238
+ "outputs": [],
239
+ "source": [
240
+ "model.val() #This will output a train file however it will be on the validation data"
241
+ ]
242
+ },
243
+ {
244
+ "cell_type": "markdown",
245
+ "metadata": {},
246
+ "source": [
247
+ "**<h3>Validating the YOLO11 model on the Testing subset.</h3>**"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "code",
252
+ "execution_count": null,
253
+ "metadata": {},
254
+ "outputs": [],
255
+ "source": [
256
+ "model.val(split='test') #This will output a train file however it will be on the test data"
257
+ ]
258
+ },
259
+ {
260
+ "cell_type": "markdown",
261
+ "metadata": {
262
+ "id": "i4eASbcWkQBq"
263
+ },
264
+ "source": [
265
+ "**<h3>Testing the YOLO11 model on the Testing subset.</h3>**"
266
+ ]
267
+ },
268
+ {
269
+ "cell_type": "code",
270
+ "execution_count": null,
271
+ "metadata": {
272
+ "colab": {
273
+ "base_uri": "https://localhost:8080/"
274
+ },
275
+ "id": "Wjc1ctZykYuf",
276
+ "outputId": "38b730a6-7d15-4f9f-b812-e814fc861557"
277
+ },
278
+ "outputs": [],
279
+ "source": [
280
+ "!yolo task=detect \\\n",
281
+ "mode=predict \\\n",
282
+ "model={HOME}/datasets/runs/detect/train1/weights/best.pt \\\n",
283
+ "source={dataset.location}/test/images \\\n",
284
+ "save=True"
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "markdown",
289
+ "metadata": {
290
+ "id": "uBkrV5y5X9CH"
291
+ },
292
+ "source": [
293
+ "**<h3>Training Results.</h3>**"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "execution_count": null,
299
+ "metadata": {
300
+ "colab": {
301
+ "base_uri": "https://localhost:8080/",
302
+ "height": 447
303
+ },
304
+ "id": "mWCxLBpMbKoQ",
305
+ "outputId": "722f7b87-4d71-4e44-85aa-0c6a33f08362"
306
+ },
307
+ "outputs": [],
308
+ "source": [
309
+ "from IPython.display import Image as IPyImage\n",
310
+ "\n",
311
+ "IPyImage(filename=f'{HOME}/datasets/runs/detect/train/results.png', width=600)"
312
+ ]
313
+ },
314
+ {
315
+ "cell_type": "markdown",
316
+ "metadata": {
317
+ "id": "t6EZwLBNfjKP"
318
+ },
319
+ "source": [
320
+ "**<h3>Testing Resultant Images.</h3>**"
321
+ ]
322
+ },
323
+ {
324
+ "cell_type": "code",
325
+ "execution_count": null,
326
+ "metadata": {
327
+ "colab": {
328
+ "background_save": true
329
+ },
330
+ "id": "mzkcnDekgUWf"
331
+ },
332
+ "outputs": [],
333
+ "source": [
334
+ "counter =0\n",
335
+ "limit = 10\n",
336
+ "for image_path in glob.glob(f'{HOME}/datasets/runs/detect/predict/*.jpg'):\n",
337
+ " display(Image(filename=image_path))\n",
338
+ " print(\"\\n\")\n",
339
+ " counter += 1\n",
340
+ " if counter == limit:\n",
341
+ " break"
342
+ ]
343
+ }
344
+ ],
345
+ "metadata": {
346
+ "accelerator": "GPU",
347
+ "colab": {
348
+ "provenance": []
349
+ },
350
+ "kernelspec": {
351
+ "display_name": "Python 3",
352
+ "name": "python3"
353
+ },
354
+ "language_info": {
355
+ "codemirror_mode": {
356
+ "name": "ipython",
357
+ "version": 3
358
+ },
359
+ "file_extension": ".py",
360
+ "mimetype": "text/x-python",
361
+ "name": "python",
362
+ "nbconvert_exporter": "python",
363
+ "pygments_lexer": "ipython3",
364
+ "version": "3.9.19"
365
+ }
366
+ },
367
+ "nbformat": 4,
368
+ "nbformat_minor": 0
369
+ }