├── README.md
├── main.py
├── object_models
├── __pycache__
│ ├── object_detection_capture.cpython-310.pyc
│ ├── object_detection_live.cpython-310.pyc
│ └── object_detection_upload.cpython-310.pyc
├── data
│ └── coco.names
├── object_detection_capture.py
├── object_detection_live.py
└── object_detection_upload.py
├── project synopsis report - saachi shinde.pdf
├── requirements.txt
├── static
├── css
│ └── cover.css
├── eyes.png
├── eyeslogo.png
├── image.png
├── lady.png
├── logo.png
├── object.png
├── script1.js
├── sound.png
├── synopsis.pdf
├── text.png
└── volume.png
├── templates
├── about.html
├── contact.html
├── home-page.html
├── object-detection-capture.html
├── object-detection-live.html
├── object-detection-upload.html
├── object-detection.html
├── text-recognition-capture.html
├── text-recognition-live.html
├── text-recognition-upload.html
└── text-recognition.html
├── text_models
├── __pycache__
│ ├── kraken.cpython-310.pyc
│ ├── t_upload.cpython-310.pyc
│ ├── text_recognition_capture.cpython-310.pyc
│ ├── text_recognition_live.cpython-310.pyc
│ ├── text_recognition_upload.cpython-310.pyc
│ └── text_upload.cpython-310.pyc
├── text_recognition_capture.py
├── text_recognition_live.py
└── text_recognition_upload.py
└── yolov5
├── CITATION.cff
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── README.zh-CN.md
├── __pycache__
└── export.cpython-310.pyc
├── benchmarks.py
├── classify
├── predict.py
├── train.py
├── tutorial.ipynb
└── val.py
├── data
├── Argoverse.yaml
├── GlobalWheat2020.yaml
├── ImageNet.yaml
├── ImageNet10.yaml
├── ImageNet100.yaml
├── ImageNet1000.yaml
├── Objects365.yaml
├── SKU-110K.yaml
├── VOC.yaml
├── VisDrone.yaml
├── coco.yaml
├── coco128-seg.yaml
├── coco128.yaml
├── hyps
│ ├── hyp.Objects365.yaml
│ ├── hyp.VOC.yaml
│ ├── hyp.no-augmentation.yaml
│ ├── hyp.scratch-high.yaml
│ ├── hyp.scratch-low.yaml
│ └── hyp.scratch-med.yaml
├── images
│ ├── bus.jpg
│ └── zidane.jpg
├── scripts
│ ├── download_weights.sh
│ ├── get_coco.sh
│ ├── get_coco128.sh
│ ├── get_imagenet.sh
│ ├── get_imagenet10.sh
│ ├── get_imagenet100.sh
│ └── get_imagenet1000.sh
└── xView.yaml
├── detect.py
├── export.py
├── hubconf.py
├── models
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-310.pyc
│ ├── common.cpython-310.pyc
│ ├── experimental.cpython-310.pyc
│ └── yolo.cpython-310.pyc
├── common.py
├── experimental.py
├── hub
│ ├── anchors.yaml
│ ├── yolov3-spp.yaml
│ ├── yolov3-tiny.yaml
│ ├── yolov3.yaml
│ ├── yolov5-bifpn.yaml
│ ├── yolov5-fpn.yaml
│ ├── yolov5-p2.yaml
│ ├── yolov5-p34.yaml
│ ├── yolov5-p6.yaml
│ ├── yolov5-p7.yaml
│ ├── yolov5-panet.yaml
│ ├── yolov5l6.yaml
│ ├── yolov5m6.yaml
│ ├── yolov5n6.yaml
│ ├── yolov5s-LeakyReLU.yaml
│ ├── yolov5s-ghost.yaml
│ ├── yolov5s-transformer.yaml
│ ├── yolov5s6.yaml
│ └── yolov5x6.yaml
├── segment
│ ├── yolov5l-seg.yaml
│ ├── yolov5m-seg.yaml
│ ├── yolov5n-seg.yaml
│ ├── yolov5s-seg.yaml
│ └── yolov5x-seg.yaml
├── tf.py
├── yolo.py
├── yolov5l.yaml
├── yolov5m.yaml
├── yolov5n.yaml
├── yolov5s.yaml
└── yolov5x.yaml
├── pyproject.toml
├── requirements.txt
├── runs
└── detect
│ └── exp
│ └── images.jpg
├── segment
├── predict.py
├── train.py
├── tutorial.ipynb
└── val.py
├── train.py
├── tutorial.ipynb
├── utils
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-310.pyc
│ ├── augmentations.cpython-310.pyc
│ ├── autoanchor.cpython-310.pyc
│ ├── dataloaders.cpython-310.pyc
│ ├── downloads.cpython-310.pyc
│ ├── general.cpython-310.pyc
│ ├── metrics.cpython-310.pyc
│ ├── plots.cpython-310.pyc
│ └── torch_utils.cpython-310.pyc
├── activations.py
├── augmentations.py
├── autoanchor.py
├── autobatch.py
├── aws
│ ├── __init__.py
│ ├── mime.sh
│ ├── resume.py
│ └── userdata.sh
├── callbacks.py
├── dataloaders.py
├── docker
│ ├── Dockerfile
│ ├── Dockerfile-arm64
│ └── Dockerfile-cpu
├── downloads.py
├── flask_rest_api
│ ├── README.md
│ ├── example_request.py
│ └── restapi.py
├── general.py
├── google_app_engine
│ ├── Dockerfile
│ ├── additional_requirements.txt
│ └── app.yaml
├── loggers
│ ├── __init__.py
│ ├── clearml
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── clearml_utils.py
│ │ └── hpo.py
│ ├── comet
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── comet_utils.py
│ │ ├── hpo.py
│ │ └── optimizer_config.json
│ └── wandb
│ │ ├── __init__.py
│ │ └── wandb_utils.py
├── loss.py
├── metrics.py
├── plots.py
├── segment
│ ├── __init__.py
│ ├── augmentations.py
│ ├── dataloaders.py
│ ├── general.py
│ ├── loss.py
│ ├── metrics.py
│ └── plots.py
├── torch_utils.py
└── triton.py
├── val.py
└── yolov5s.pt
/README.md:
--------------------------------------------------------------------------------
1 | **‘WeSee - A Helper for the Visually Impaired’**
2 |
3 | Simply, a web application for individuals with low vision capabilities to excel in daily tasks.
4 |
5 | Video of complete execeution of project: https://drive.google.com/file/d/1porrbt0-UMHPqTRN3VeefBLsWTg0TSJW/view?usp=sharing
6 |
7 | The project, ‘WeSee’ is aimed to address the challenges faced by visually impaired individuals by leveraging cutting-edge technologies, primarily based in Computer Vision and Digital Image Processing, specifically built upon the foundations of Deep Learning.
8 | It is an innovative assistive tool that empowers visually impaired users to access written and digital content seamlessly, by leveraging a device's camera to provide real-time information about the user's surroundings.
9 |
10 | Key structures of ‘WeSee’ include real-time text recognition, real-time object detection and audio output capabilities, enabling users to effortlessly comprehend and interact with their surroundings. Moreover, the system is designed to adapt to various environmental conditions, providing a robust solution for users in different settings.
11 |
12 | In conclusion, this project contributes to the inclusive integration of individuals with visual disability into our society by fostering independent access to information and promoting equal opportunities.
13 |
14 | Through the integration of state-of-the-art technologies in Artificial Intelligence and Machine Learning, this project aligns with the overarching goal of creating a more accessible and inclusive world for all individuals.
15 |
--------------------------------------------------------------------------------
/object_models/__pycache__/object_detection_capture.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/object_models/__pycache__/object_detection_capture.cpython-310.pyc
--------------------------------------------------------------------------------
/object_models/__pycache__/object_detection_live.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/object_models/__pycache__/object_detection_live.cpython-310.pyc
--------------------------------------------------------------------------------
/object_models/__pycache__/object_detection_upload.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/object_models/__pycache__/object_detection_upload.cpython-310.pyc
--------------------------------------------------------------------------------
/object_models/data/coco.names:
--------------------------------------------------------------------------------
1 | person
2 | bicycle
3 | car
4 | motorbike
5 | aeroplane
6 | bus
7 | train
8 | truck
9 | boat
10 | traffic light
11 | fire hydrant
12 | stop sign
13 | parking meter
14 | bench
15 | bird
16 | cat
17 | dog
18 | horse
19 | sheep
20 | cow
21 | elephant
22 | bear
23 | zebra
24 | giraffe
25 | backpack
26 | umbrella
27 | handbag
28 | tie
29 | suitcase
30 | frisbee
31 | skis
32 | snowboard
33 | sports ball
34 | kite
35 | baseball bat
36 | baseball glove
37 | skateboard
38 | surfboard
39 | tennis racket
40 | bottle
41 | wine glass
42 | cup
43 | fork
44 | knife
45 | spoon
46 | bowl
47 | banana
48 | apple
49 | sandwich
50 | orange
51 | broccoli
52 | carrot
53 | hot dog
54 | pizza
55 | donut
56 | cake
57 | chair
58 | sofa
59 | pottedplant
60 | bed
61 | diningtable
62 | toilet
63 | tvmonitor
64 | laptop
65 | mouse
66 | remote
67 | keyboard
68 | cell phone
69 | microwave
70 | oven
71 | toaster
72 | sink
73 | refrigerator
74 | book
75 | clock
76 | vase
77 | scissors
78 | teddy bear
79 | hair drier
80 | toothbrush
81 |
--------------------------------------------------------------------------------
/object_models/object_detection_capture.py:
--------------------------------------------------------------------------------
1 |
2 | from flask import Flask
3 | import cv2
4 | import torch
5 | from gtts import gTTS
6 | import os
7 | from datetime import datetime
8 | from PIL import Image
9 | import numpy as np
10 |
11 | app = Flask(__name__, static_folder='static')
12 |
13 |
14 | app.config['AUDIO_FOLDER'] = 'static/audio'
15 |
16 |
17 |
18 | def adjust_brightness_contrast(img, alpha=1.0, beta=0):
19 |
20 | # Apply brightness and contrast adjustment
21 | adjusted_img = cv2.convertScaleAbs(img, alpha=alpha, beta=beta)
22 |
23 | return adjusted_img
24 |
25 |
26 | def perform_object_detection():
27 | cap = cv2.VideoCapture(0)
28 |
29 | # Load a pre-trained model. Here, we're assuming YOLOv5; adjust as needed.
30 | model = torch.hub.load('ultralytics/yolov5', 'yolov5l', pretrained=True)
31 |
32 | while True:
33 | ret, frame = cap.read()
34 | cv2.imshow('Press "c" to Capture', frame)
35 |
36 | key = cv2.waitKey(1) & 0xFF
37 | if key == ord('c'):
38 | img_path = 'static/captured/captured_image.jpg'
39 | cv2.imwrite(img_path, frame)
40 | print("Image captured and saved.")
41 |
42 | adjusted_frame = adjust_brightness_contrast(frame, alpha=1.5, beta=20)
43 |
44 | adjusted_img_path = 'static/captured/adjusted_captured_image.jpg'
45 |
46 | cv2.imwrite(adjusted_img_path, adjusted_frame)
47 | print("Adjusted Image captured and saved.")
48 |
49 | # Perform detection
50 | results = model(adjusted_frame)
51 |
52 |
53 | # Get detected objects and generate description
54 | detected_objects = results.pandas().xyxy[0]['name'].unique()
55 | if detected_objects.size > 0:
56 | objects_list = ", ".join(detected_objects)
57 | description_text = f"The objects detected in the image are: {objects_list}."
58 | else:
59 | description_text = "No objects detected."
60 | # Print the description
61 |
62 | # Generate audio from the description text
63 | timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
64 | audio_path = os.path.join('static/audio', f'description_{timestamp}.mp3')
65 | tts = gTTS(description_text, lang='en')
66 | tts.save(audio_path)
67 | print(f"Audio description saved at: {audio_path}")
68 |
69 | img_filename = os.path.basename(adjusted_img_path)
70 | audio_filename = os.path.basename(audio_path)
71 |
72 | cap.release()
73 | cv2.destroyAllWindows()
74 | break
75 |
76 | elif key == 27: # Press 'Esc' to exit
77 | cap.release()
78 | cv2.destroyAllWindows()
79 | break
80 |
81 | return description_text, img_filename, audio_filename
82 |
83 |
84 |
--------------------------------------------------------------------------------
/object_models/object_detection_live.py:
--------------------------------------------------------------------------------
1 |
2 | import cv2
3 | import torch
4 | import pyttsx3
5 | from transformers import pipeline
6 | import time
7 |
8 |
9 |
10 |
11 | def object_detection():
12 | # Initialize the components
13 | model = torch.hub.load('ultralytics/yolov5', 'yolov5l', pretrained=True)
14 | text_generator = pipeline('text-generation', model='gpt2')
15 | tts_engine = pyttsx3.init()
16 |
17 | def generate_scene_description(objects):
18 | description = ' and '.join(objects) + ' are visible in the scene.'
19 | return description
20 |
21 | cap = cv2.VideoCapture(0)
22 | last_speech_time = time.time() - 6
23 |
24 | while True:
25 | ret, frame = cap.read()
26 | if not ret:
27 | break
28 |
29 | results = model(frame)
30 | detected_objects = [model.names[int(x)] for x in results.xyxy[0][:, -1]]
31 |
32 | if detected_objects and (time.time() - last_speech_time) >= 6:
33 | last_speech_time = time.time()
34 | scene_description = generate_scene_description(detected_objects)
35 | print(scene_description)
36 | tts_engine.say(scene_description)
37 | tts_engine.runAndWait()
38 |
39 | cv2.imshow('press c to stop detection.', results.render()[0])
40 |
41 | if cv2.waitKey(1) & 0xFF == ord('c'):
42 | break
43 |
44 | cap.release()
45 | cv2.destroyAllWindows()
46 |
47 | return detected_objects
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/object_models/object_detection_upload.py:
--------------------------------------------------------------------------------
1 |
2 |
3 | from gtts import gTTS
4 | import torch
5 | from PIL import Image
6 | import os
7 | from datetime import datetime
8 |
9 | from flask import Flask
10 |
11 | app = Flask(__name__)
12 |
13 | app.config['AUDIO_FOLDER'] = 'static/audio'
14 |
15 |
16 | def detect_objects(image_path):
17 | # Load the YOLOv5 model
18 | model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
19 |
20 | # Load an image
21 | img = Image.open(image_path)
22 |
23 | # Inference
24 | results = model(img)
25 |
26 | # Get detected objects
27 | detected_objects = results.pandas().xyxy[0]['name'].unique() # Get unique detected object names
28 |
29 | if detected_objects.size > 0:
30 | objects_list = ", ".join(detected_objects)
31 | description_text = f"The objects detected in the image are: {objects_list}."
32 | else:
33 | description_text = "No objects detected."
34 |
35 |
36 | # Generate audio from text
37 |
38 | timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
39 |
40 | tts = gTTS(description_text, lang='en')
41 |
42 | audio_path = os.path.join(app.config['AUDIO_FOLDER'] , f'desciption_{timestamp}.mp3' )
43 |
44 | tts.save(audio_path)
45 |
46 | return description_text, audio_path, timestamp
47 |
--------------------------------------------------------------------------------
/project synopsis report - saachi shinde.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/project synopsis report - saachi shinde.pdf
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==2.0.2
2 | pytesseract==0.3.8
3 | torch==1.10.0
4 | opencv-python==4.5.4.60
5 | numpy==1.21.4
6 | Pillow==8.4.0
7 | matplotlib==3.5.0
8 | scipy==1.7.3
9 | scikit-learn==1.0.1
10 | imutils==0.5.4
11 | pyttsx3==2.90
12 |
--------------------------------------------------------------------------------
/static/css/cover.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Globals
3 | */
4 |
5 |
6 | /* Custom default button */
7 | .btn-secondary,
8 | .btn-secondary:hover,
9 | .btn-secondary:focus {
10 | color: #096e6c;
11 | text-shadow: none; /* Prevent inheritance from `body` */
12 | }
13 |
14 |
15 | /*
16 | * Base structure
17 | */
18 |
19 | body {
20 | text-shadow: 0 .05rem .1rem rgba(0, 0, 0, .5);
21 | box-shadow: inset 0 0 5rem rgba(0, 0, 0, .5);
22 | }
23 |
24 | .cover-container {
25 | max-width: 42em;
26 | }
27 |
28 |
29 | /*
30 | * Header
31 | */
32 |
33 | .nav-masthead .nav-link {
34 | padding: .25rem 0;
35 | font-weight: 700;
36 | color: rgba(255, 255, 255, .5);
37 | background-color: transparent;
38 | border-bottom: .25rem solid transparent;
39 | }
40 |
41 | .nav-masthead .nav-link:hover,
42 | .nav-masthead .nav-link:focus {
43 | border-bottom-color: rgba(255, 255, 255, .25);
44 | }
45 |
46 | .nav-masthead .nav-link + .nav-link {
47 | margin-left: 1rem;
48 | }
49 |
50 | .nav-masthead .active {
51 | color: #fff;
52 | border-bottom-color: #fff;
53 | }
54 |
--------------------------------------------------------------------------------
/static/eyes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/eyes.png
--------------------------------------------------------------------------------
/static/eyeslogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/eyeslogo.png
--------------------------------------------------------------------------------
/static/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/image.png
--------------------------------------------------------------------------------
/static/lady.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/lady.png
--------------------------------------------------------------------------------
/static/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/logo.png
--------------------------------------------------------------------------------
/static/object.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/object.png
--------------------------------------------------------------------------------
/static/script1.js:
--------------------------------------------------------------------------------
1 |
2 | // audio_player.js
3 |
4 | document.addEventListener('DOMContentLoaded', function () {
5 | var audio = document.getElementById('audioElement');
6 | var playButton = document.getElementById('playButton');
7 | var pauseButton = document.getElementById('pauseButton');
8 |
9 | playButton.addEventListener('click', function () {
10 | audio.play();
11 | });
12 |
13 | pauseButton.addEventListener('click', function () {
14 | audio.pause();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/static/sound.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/sound.png
--------------------------------------------------------------------------------
/static/synopsis.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/synopsis.pdf
--------------------------------------------------------------------------------
/static/text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/text.png
--------------------------------------------------------------------------------
/static/volume.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/static/volume.png
--------------------------------------------------------------------------------
/templates/contact.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | WeSee - a helper!
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
WeSee.
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | Home
64 |
65 |
66 |
67 | About
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
More About Me.
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | Hello! My name is Saachi G. Shinde, and I am a final year student pursuing Bachelor of Science in Computer Science, specializing in
112 | Artificial Intelligence and Machine Learning.
113 |
114 |
115 |
As an aspiring technology enthusiast, I have always been passionate about Artifical Intelligence. Throughout my academic journey, I have delved into various subjects, honing my skills in various domains of AI and Machine Learning.
116 |
117 |
118 | One of the highlights of my academic career is my final year project, where I worked to develop an innovative solution for the extensive community of people with blindess. This project not only challenges me to apply my knowledge and creativity but also allows me to contribute meaningfully to creating a more accessible and inclusive world for all individuals. I am excited about the possibilities this project brings and look forward to sharing our progress and outcomes with you.
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
My Contact Details:
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/templates/text-recognition-live.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
WeSee - a helper!
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
WeSee.
63 |
64 |
65 |
66 |
67 |
68 |
69 |
73 |
74 |
78 |
79 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
real time detection of text:
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
197 |
198 |
199 |
200 |
201 |
--------------------------------------------------------------------------------
/text_models/__pycache__/kraken.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/text_models/__pycache__/kraken.cpython-310.pyc
--------------------------------------------------------------------------------
/text_models/__pycache__/t_upload.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/text_models/__pycache__/t_upload.cpython-310.pyc
--------------------------------------------------------------------------------
/text_models/__pycache__/text_recognition_capture.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/text_models/__pycache__/text_recognition_capture.cpython-310.pyc
--------------------------------------------------------------------------------
/text_models/__pycache__/text_recognition_live.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/text_models/__pycache__/text_recognition_live.cpython-310.pyc
--------------------------------------------------------------------------------
/text_models/__pycache__/text_recognition_upload.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/text_models/__pycache__/text_recognition_upload.cpython-310.pyc
--------------------------------------------------------------------------------
/text_models/__pycache__/text_upload.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/text_models/__pycache__/text_upload.cpython-310.pyc
--------------------------------------------------------------------------------
/text_models/text_recognition_capture.py:
--------------------------------------------------------------------------------
1 |
2 | import cv2
3 | import pytesseract
4 | from gtts import gTTS
5 | import os
6 | from datetime import datetime
7 |
8 | pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
9 |
10 |
11 | def adjust_brightness_contrast(img, alpha=1.0, beta=0):
12 | # Apply brightness and contrast adjustment
13 | adjusted_img = cv2.convertScaleAbs(img, alpha=alpha, beta=beta)
14 | return adjusted_img
15 |
16 | def perform_text_capture():
17 | cap = cv2.VideoCapture(0)
18 |
19 |
20 | while True:
21 | ret, frame = cap.read()
22 | cv2.imshow('Press "c" to Capture', frame)
23 |
24 | key = cv2.waitKey(1) & 0xFF
25 | if key == ord('c'):
26 | # Save the original image
27 | cv2.imwrite('static/captured/original_image.jpg', frame)
28 |
29 | # Adjust brightness and contrast
30 | adjusted_frame = adjust_brightness_contrast(frame, alpha=1.5, beta=20)
31 | cv2.imwrite('static/captured/adjusted_image.jpg', adjusted_frame)
32 |
33 | cap.release()
34 | cv2.destroyAllWindows()
35 | print("Images captured and saved")
36 |
37 | break
38 |
39 | elif key == 27: # Press 'Esc' to exit
40 | break
41 |
42 | img_path = 'static/captured/adjusted_image.jpg'
43 | if os.path.exists(img_path):
44 | img = cv2.imread(img_path)
45 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
46 |
47 | text_output = pytesseract.image_to_string(img)
48 | print("Recognized text:")
49 | print(text_output)
50 |
51 | if text_output.strip(): # Check if the recognized text is not empty
52 |
53 | timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
54 |
55 | # Convert recognized text to speech using gTTS
56 | tts = gTTS(text=text_output, lang='en')
57 | audio_path = f"static/audio/output_audio_{timestamp}.mp3"
58 | tts.save(audio_path)
59 |
60 | return text_output, img_path, audio_path, timestamp
61 | else:
62 | return "Error: No text detected in the captured image", "", ""
63 | else:
64 | return "Error: Adjusted image not found", "", ""
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/text_models/text_recognition_live.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import pytesseract
3 | import numpy as np
4 | import pyttsx3
5 | import time
6 |
7 |
8 | # Point pytesseract to where the tesseract executable is located
9 | pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
10 |
11 |
12 |
13 | def perform_live_text():
14 |
15 | engine = pyttsx3.init()
16 |
17 | def detect_text(frame):
18 | # Convert the frame to grayscale
19 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
20 |
21 | # Use OpenCV's thresholding to preprocess the image
22 | _, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
23 |
24 | # Use Tesseract to perform OCR on the preprocessed image
25 | text = pytesseract.image_to_string(thresh)
26 |
27 | return text
28 |
29 | # Open the camera
30 | cap = cv2.VideoCapture(0)
31 |
32 | # Variable to track the time of the last speech output
33 | last_speech_time = 0
34 | # Minimum gap between speeches in seconds
35 | speech_gap = 2
36 |
37 | while cap.isOpened():
38 | ret, frame = cap.read()
39 |
40 | if not ret:
41 | break
42 |
43 | # Detect text in the frame
44 | detected_text = detect_text(frame)
45 |
46 |
47 | # Draw bounding boxes around the detected text
48 | h, w, _ = frame.shape
49 | cv2.rectangle(frame, (0, 0), (w, 30), (0, 0, 0), -1)
50 | cv2.putText(frame, detected_text, (10, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2)
51 |
52 | # Get the current time
53 | current_time = time.time()
54 |
55 | # Check if 4 seconds have passed since the last speech output
56 | if detected_text and (current_time - last_speech_time) > speech_gap:
57 | # Speak the detected text
58 | engine.say(detected_text)
59 | engine.runAndWait()
60 |
61 | # Update the last speech time
62 | last_speech_time = current_time
63 |
64 | # Display the frame
65 | cv2.imshow('press c to stop detection.', frame)
66 |
67 |
68 | # Press 'q' to exit
69 | if cv2.waitKey(1) & 0xFF == ord('c'):
70 | break
71 |
72 | # Release the camera and close all windows
73 | cap.release()
74 | cv2.destroyAllWindows()
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/text_models/text_recognition_upload.py:
--------------------------------------------------------------------------------
1 |
2 |
3 | import cv2
4 | import pytesseract
5 | from gtts import gTTS
6 | import os
7 | from datetime import datetime
8 |
9 | from flask import Flask, render_template, request, Response
10 |
11 |
12 |
13 | app = Flask(__name__)
14 |
15 | app.config['UPLOAD_FOLDER'] = 'static/captured'
16 | app.config['AUDIO_FOLDER'] = 'static/audio'
17 |
18 | pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
19 |
20 | def perform_ocr_and_audio(image_path):
21 | # Load the image
22 | img = cv2.imread(image_path)
23 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
24 |
25 | def adjust_brightness_contrast(image, alpha=1.0, beta=0):
26 | adjusted = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)
27 | return adjusted
28 |
29 | # Increase brightness and contrast of the image
30 | img_adjusted = adjust_brightness_contrast(img, alpha=1.5, beta=20)
31 |
32 | # Save the adjusted image
33 | timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
34 |
35 | adjusted_image_path = os.path.join(app.config['UPLOAD_FOLDER'], f'adjusted_image_{timestamp}.jpg')
36 |
37 | cv2.imwrite(adjusted_image_path, cv2.cvtColor(img_adjusted, cv2.COLOR_RGB2BGR))
38 |
39 | # Use pytesseract to extract text from the image
40 | text = pytesseract.image_to_string(img_adjusted)
41 |
42 | # Print the extracted text
43 | print(text)
44 |
45 | # Convert the extracted text to speech
46 | tts = gTTS(text=text, lang='en')
47 |
48 |
49 | # Save the audio file
50 |
51 | audio_file = os.path.join(app.config['AUDIO_FOLDER'], f'output_{timestamp}.mp3')
52 |
53 | tts.save(audio_file)
54 |
55 |
56 | return text, audio_file, adjusted_image_path, timestamp
57 |
58 |
59 |
--------------------------------------------------------------------------------
/yolov5/CITATION.cff:
--------------------------------------------------------------------------------
1 | cff-version: 1.2.0
2 | preferred-citation:
3 | type: software
4 | message: If you use YOLOv5, please cite it as below.
5 | authors:
6 | - family-names: Jocher
7 | given-names: Glenn
8 | orcid: "https://orcid.org/0000-0001-5950-6979"
9 | title: "YOLOv5 by Ultralytics"
10 | version: 7.0
11 | doi: 10.5281/zenodo.3908559
12 | date-released: 2020-5-29
13 | license: AGPL-3.0
14 | url: "https://github.com/ultralytics/yolov5"
15 |
--------------------------------------------------------------------------------
/yolov5/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing to YOLOv5 🚀
2 |
3 | We love your input! We want to make contributing to YOLOv5 as easy and transparent as possible, whether it's:
4 |
5 | - Reporting a bug
6 | - Discussing the current state of the code
7 | - Submitting a fix
8 | - Proposing a new feature
9 | - Becoming a maintainer
10 |
11 | YOLOv5 works so well due to our combined community effort, and for every small improvement you contribute you will be helping push the frontiers of what's possible in AI 😃!
12 |
13 | ## Submitting a Pull Request (PR) 🛠️
14 |
15 | Submitting a PR is easy! This example shows how to submit a PR for updating `requirements.txt` in 4 steps:
16 |
17 | ### 1. Select File to Update
18 |
19 | Select `requirements.txt` to update by clicking on it in GitHub.
20 |
21 |
22 |
23 | ### 2. Click 'Edit this file'
24 |
25 | The button is in the top-right corner.
26 |
27 |
28 |
29 | ### 3. Make Changes
30 |
31 | Change the `matplotlib` version from `3.2.2` to `3.3`.
32 |
33 |
34 |
35 | ### 4. Preview Changes and Submit PR
36 |
37 | Click on the **Preview changes** tab to verify your updates. At the bottom of the screen select 'Create a **new branch** for this commit', assign your branch a descriptive name such as `fix/matplotlib_version` and click the green **Propose changes** button. All done, your PR is now submitted to YOLOv5 for review and approval 😃!
38 |
39 |
40 |
41 | ### PR recommendations
42 |
43 | To allow your work to be integrated as seamlessly as possible, we advise you to:
44 |
45 | - ✅ Verify your PR is **up-to-date** with `ultralytics/yolov5` `master` branch. If your PR is behind you can update your code by clicking the 'Update branch' button or by running `git pull` and `git merge master` locally.
46 |
47 |
48 |
49 | - ✅ Verify all YOLOv5 Continuous Integration (CI) **checks are passing**.
50 |
51 |
52 |
53 | - ✅ Reduce changes to the absolute **minimum** required for your bug fix or feature addition. _"It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is."_ — Bruce Lee
54 |
55 | ## Submitting a Bug Report 🐛
56 |
57 | If you spot a problem with YOLOv5 please submit a Bug Report!
58 |
59 | For us to start investigating a possible problem we need to be able to reproduce it ourselves first. We've created a few short guidelines below to help users provide what we need to get started.
60 |
61 | When asking a question, people will be better able to provide help if you provide **code** that they can easily understand and use to **reproduce** the problem. This is referred to by community members as creating a [minimum reproducible example](https://docs.ultralytics.com/help/minimum_reproducible_example/). Your code that reproduces the problem should be:
62 |
63 | - ✅ **Minimal** – Use as little code as possible that still produces the same problem
64 | - ✅ **Complete** – Provide **all** parts someone else needs to reproduce your problem in the question itself
65 | - ✅ **Reproducible** – Test the code you're about to provide to make sure it reproduces the problem
66 |
67 | In addition to the above requirements, for [Ultralytics](https://ultralytics.com/) to provide assistance your code should be:
68 |
69 | - ✅ **Current** – Verify that your code is up-to-date with the current GitHub [master](https://github.com/ultralytics/yolov5/tree/master), and if necessary `git pull` or `git clone` a new copy to ensure your problem has not already been resolved by previous commits.
70 | - ✅ **Unmodified** – Your problem must be reproducible without any modifications to the codebase in this repository. [Ultralytics](https://ultralytics.com/) does not provide support for custom code ⚠️.
71 |
72 | If you believe your problem meets all of the above criteria, please close this issue and raise a new one using the 🐛 **Bug Report** [template](https://github.com/ultralytics/yolov5/issues/new/choose) and provide a [minimum reproducible example](https://docs.ultralytics.com/help/minimum_reproducible_example/) to help us better understand and diagnose your problem.
73 |
74 | ## License
75 |
76 | By contributing, you agree that your contributions will be licensed under the [AGPL-3.0 license](https://choosealicense.com/licenses/agpl-3.0/)
77 |
--------------------------------------------------------------------------------
/yolov5/__pycache__/export.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/__pycache__/export.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/data/Argoverse.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/ by Argo AI
3 | # Example usage: python train.py --data Argoverse.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── Argoverse ← downloads here (31.3 GB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/Argoverse # dataset root dir
11 | train: Argoverse-1.1/images/train/ # train images (relative to 'path') 39384 images
12 | val: Argoverse-1.1/images/val/ # val images (relative to 'path') 15062 images
13 | test: Argoverse-1.1/images/test/ # test images (optional) https://eval.ai/web/challenges/challenge-page/800/overview
14 |
15 | # Classes
16 | names:
17 | 0: person
18 | 1: bicycle
19 | 2: car
20 | 3: motorcycle
21 | 4: bus
22 | 5: truck
23 | 6: traffic_light
24 | 7: stop_sign
25 |
26 | # Download script/URL (optional) ---------------------------------------------------------------------------------------
27 | download: |
28 | import json
29 |
30 | from tqdm import tqdm
31 | from utils.general import download, Path
32 |
33 |
34 | def argoverse2yolo(set):
35 | labels = {}
36 | a = json.load(open(set, "rb"))
37 | for annot in tqdm(a['annotations'], desc=f"Converting {set} to YOLOv5 format..."):
38 | img_id = annot['image_id']
39 | img_name = a['images'][img_id]['name']
40 | img_label_name = f'{img_name[:-3]}txt'
41 |
42 | cls = annot['category_id'] # instance class id
43 | x_center, y_center, width, height = annot['bbox']
44 | x_center = (x_center + width / 2) / 1920.0 # offset and scale
45 | y_center = (y_center + height / 2) / 1200.0 # offset and scale
46 | width /= 1920.0 # scale
47 | height /= 1200.0 # scale
48 |
49 | img_dir = set.parents[2] / 'Argoverse-1.1' / 'labels' / a['seq_dirs'][a['images'][annot['image_id']]['sid']]
50 | if not img_dir.exists():
51 | img_dir.mkdir(parents=True, exist_ok=True)
52 |
53 | k = str(img_dir / img_label_name)
54 | if k not in labels:
55 | labels[k] = []
56 | labels[k].append(f"{cls} {x_center} {y_center} {width} {height}\n")
57 |
58 | for k in labels:
59 | with open(k, "w") as f:
60 | f.writelines(labels[k])
61 |
62 |
63 | # Download
64 | dir = Path(yaml['path']) # dataset root dir
65 | urls = ['https://argoverse-hd.s3.us-east-2.amazonaws.com/Argoverse-HD-Full.zip']
66 | download(urls, dir=dir, delete=False)
67 |
68 | # Convert
69 | annotations_dir = 'Argoverse-HD/annotations/'
70 | (dir / 'Argoverse-1.1' / 'tracking').rename(dir / 'Argoverse-1.1' / 'images') # rename 'tracking' to 'images'
71 | for d in "train.json", "val.json":
72 | argoverse2yolo(dir / annotations_dir / d) # convert VisDrone annotations to YOLO labels
73 |
--------------------------------------------------------------------------------
/yolov5/data/GlobalWheat2020.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Global Wheat 2020 dataset http://www.global-wheat.com/ by University of Saskatchewan
3 | # Example usage: python train.py --data GlobalWheat2020.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── GlobalWheat2020 ← downloads here (7.0 GB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/GlobalWheat2020 # dataset root dir
11 | train: # train images (relative to 'path') 3422 images
12 | - images/arvalis_1
13 | - images/arvalis_2
14 | - images/arvalis_3
15 | - images/ethz_1
16 | - images/rres_1
17 | - images/inrae_1
18 | - images/usask_1
19 | val: # val images (relative to 'path') 748 images (WARNING: train set contains ethz_1)
20 | - images/ethz_1
21 | test: # test images (optional) 1276 images
22 | - images/utokyo_1
23 | - images/utokyo_2
24 | - images/nau_1
25 | - images/uq_1
26 |
27 | # Classes
28 | names:
29 | 0: wheat_head
30 |
31 | # Download script/URL (optional) ---------------------------------------------------------------------------------------
32 | download: |
33 | from utils.general import download, Path
34 |
35 |
36 | # Download
37 | dir = Path(yaml['path']) # dataset root dir
38 | urls = ['https://zenodo.org/record/4298502/files/global-wheat-codalab-official.zip',
39 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/GlobalWheat2020_labels.zip']
40 | download(urls, dir=dir)
41 |
42 | # Make Directories
43 | for p in 'annotations', 'images', 'labels':
44 | (dir / p).mkdir(parents=True, exist_ok=True)
45 |
46 | # Move
47 | for p in 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'rres_1', 'inrae_1', 'usask_1', \
48 | 'utokyo_1', 'utokyo_2', 'nau_1', 'uq_1':
49 | (dir / p).rename(dir / 'images' / p) # move to /images
50 | f = (dir / p).with_suffix('.json') # json file
51 | if f.exists():
52 | f.rename((dir / 'annotations' / p).with_suffix('.json')) # move to /annotations
53 |
--------------------------------------------------------------------------------
/yolov5/data/ImageNet10.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # ImageNet-1k dataset https://www.image-net.org/index.php by Stanford University
3 | # Simplified class names from https://github.com/anishathalye/imagenet-simple-labels
4 | # Example usage: python classify/train.py --data imagenet
5 | # parent
6 | # ├── yolov5
7 | # └── datasets
8 | # └── imagenet10 ← downloads here
9 |
10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
11 | path: ../datasets/imagenet10 # dataset root dir
12 | train: train # train images (relative to 'path') 1281167 images
13 | val: val # val images (relative to 'path') 50000 images
14 | test: # test images (optional)
15 |
16 | # Classes
17 | names:
18 | 0: tench
19 | 1: goldfish
20 | 2: great white shark
21 | 3: tiger shark
22 | 4: hammerhead shark
23 | 5: electric ray
24 | 6: stingray
25 | 7: cock
26 | 8: hen
27 | 9: ostrich
28 |
29 | # Download script/URL (optional)
30 | download: data/scripts/get_imagenet10.sh
31 |
--------------------------------------------------------------------------------
/yolov5/data/ImageNet100.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # ImageNet-1k dataset https://www.image-net.org/index.php by Stanford University
3 | # Simplified class names from https://github.com/anishathalye/imagenet-simple-labels
4 | # Example usage: python classify/train.py --data imagenet
5 | # parent
6 | # ├── yolov5
7 | # └── datasets
8 | # └── imagenet100 ← downloads here
9 |
10 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
11 | path: ../datasets/imagenet100 # dataset root dir
12 | train: train # train images (relative to 'path') 1281167 images
13 | val: val # val images (relative to 'path') 50000 images
14 | test: # test images (optional)
15 |
16 | # Classes
17 | names:
18 | 0: tench
19 | 1: goldfish
20 | 2: great white shark
21 | 3: tiger shark
22 | 4: hammerhead shark
23 | 5: electric ray
24 | 6: stingray
25 | 7: cock
26 | 8: hen
27 | 9: ostrich
28 | 10: brambling
29 | 11: goldfinch
30 | 12: house finch
31 | 13: junco
32 | 14: indigo bunting
33 | 15: American robin
34 | 16: bulbul
35 | 17: jay
36 | 18: magpie
37 | 19: chickadee
38 | 20: American dipper
39 | 21: kite
40 | 22: bald eagle
41 | 23: vulture
42 | 24: great grey owl
43 | 25: fire salamander
44 | 26: smooth newt
45 | 27: newt
46 | 28: spotted salamander
47 | 29: axolotl
48 | 30: American bullfrog
49 | 31: tree frog
50 | 32: tailed frog
51 | 33: loggerhead sea turtle
52 | 34: leatherback sea turtle
53 | 35: mud turtle
54 | 36: terrapin
55 | 37: box turtle
56 | 38: banded gecko
57 | 39: green iguana
58 | 40: Carolina anole
59 | 41: desert grassland whiptail lizard
60 | 42: agama
61 | 43: frilled-necked lizard
62 | 44: alligator lizard
63 | 45: Gila monster
64 | 46: European green lizard
65 | 47: chameleon
66 | 48: Komodo dragon
67 | 49: Nile crocodile
68 | 50: American alligator
69 | 51: triceratops
70 | 52: worm snake
71 | 53: ring-necked snake
72 | 54: eastern hog-nosed snake
73 | 55: smooth green snake
74 | 56: kingsnake
75 | 57: garter snake
76 | 58: water snake
77 | 59: vine snake
78 | 60: night snake
79 | 61: boa constrictor
80 | 62: African rock python
81 | 63: Indian cobra
82 | 64: green mamba
83 | 65: sea snake
84 | 66: Saharan horned viper
85 | 67: eastern diamondback rattlesnake
86 | 68: sidewinder
87 | 69: trilobite
88 | 70: harvestman
89 | 71: scorpion
90 | 72: yellow garden spider
91 | 73: barn spider
92 | 74: European garden spider
93 | 75: southern black widow
94 | 76: tarantula
95 | 77: wolf spider
96 | 78: tick
97 | 79: centipede
98 | 80: black grouse
99 | 81: ptarmigan
100 | 82: ruffed grouse
101 | 83: prairie grouse
102 | 84: peacock
103 | 85: quail
104 | 86: partridge
105 | 87: grey parrot
106 | 88: macaw
107 | 89: sulphur-crested cockatoo
108 | 90: lorikeet
109 | 91: coucal
110 | 92: bee eater
111 | 93: hornbill
112 | 94: hummingbird
113 | 95: jacamar
114 | 96: toucan
115 | 97: duck
116 | 98: red-breasted merganser
117 | 99: goose
118 | # Download script/URL (optional)
119 | download: data/scripts/get_imagenet100.sh
120 |
--------------------------------------------------------------------------------
/yolov5/data/SKU-110K.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # SKU-110K retail items dataset https://github.com/eg4000/SKU110K_CVPR19 by Trax Retail
3 | # Example usage: python train.py --data SKU-110K.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── SKU-110K ← downloads here (13.6 GB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/SKU-110K # dataset root dir
11 | train: train.txt # train images (relative to 'path') 8219 images
12 | val: val.txt # val images (relative to 'path') 588 images
13 | test: test.txt # test images (optional) 2936 images
14 |
15 | # Classes
16 | names:
17 | 0: object
18 |
19 | # Download script/URL (optional) ---------------------------------------------------------------------------------------
20 | download: |
21 | import shutil
22 | from tqdm import tqdm
23 | from utils.general import np, pd, Path, download, xyxy2xywh
24 |
25 |
26 | # Download
27 | dir = Path(yaml['path']) # dataset root dir
28 | parent = Path(dir.parent) # download dir
29 | urls = ['http://trax-geometry.s3.amazonaws.com/cvpr_challenge/SKU110K_fixed.tar.gz']
30 | download(urls, dir=parent, delete=False)
31 |
32 | # Rename directories
33 | if dir.exists():
34 | shutil.rmtree(dir)
35 | (parent / 'SKU110K_fixed').rename(dir) # rename dir
36 | (dir / 'labels').mkdir(parents=True, exist_ok=True) # create labels dir
37 |
38 | # Convert labels
39 | names = 'image', 'x1', 'y1', 'x2', 'y2', 'class', 'image_width', 'image_height' # column names
40 | for d in 'annotations_train.csv', 'annotations_val.csv', 'annotations_test.csv':
41 | x = pd.read_csv(dir / 'annotations' / d, names=names).values # annotations
42 | images, unique_images = x[:, 0], np.unique(x[:, 0])
43 | with open((dir / d).with_suffix('.txt').__str__().replace('annotations_', ''), 'w') as f:
44 | f.writelines(f'./images/{s}\n' for s in unique_images)
45 | for im in tqdm(unique_images, desc=f'Converting {dir / d}'):
46 | cls = 0 # single-class dataset
47 | with open((dir / 'labels' / im).with_suffix('.txt'), 'a') as f:
48 | for r in x[images == im]:
49 | w, h = r[6], r[7] # image width, height
50 | xywh = xyxy2xywh(np.array([[r[1] / w, r[2] / h, r[3] / w, r[4] / h]]))[0] # instance
51 | f.write(f"{cls} {xywh[0]:.5f} {xywh[1]:.5f} {xywh[2]:.5f} {xywh[3]:.5f}\n") # write label
52 |
--------------------------------------------------------------------------------
/yolov5/data/VOC.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford
3 | # Example usage: python train.py --data VOC.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── VOC ← downloads here (2.8 GB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/VOC
11 | train: # train images (relative to 'path') 16551 images
12 | - images/train2012
13 | - images/train2007
14 | - images/val2012
15 | - images/val2007
16 | val: # val images (relative to 'path') 4952 images
17 | - images/test2007
18 | test: # test images (optional)
19 | - images/test2007
20 |
21 | # Classes
22 | names:
23 | 0: aeroplane
24 | 1: bicycle
25 | 2: bird
26 | 3: boat
27 | 4: bottle
28 | 5: bus
29 | 6: car
30 | 7: cat
31 | 8: chair
32 | 9: cow
33 | 10: diningtable
34 | 11: dog
35 | 12: horse
36 | 13: motorbike
37 | 14: person
38 | 15: pottedplant
39 | 16: sheep
40 | 17: sofa
41 | 18: train
42 | 19: tvmonitor
43 |
44 | # Download script/URL (optional) ---------------------------------------------------------------------------------------
45 | download: |
46 | import xml.etree.ElementTree as ET
47 |
48 | from tqdm import tqdm
49 | from utils.general import download, Path
50 |
51 |
52 | def convert_label(path, lb_path, year, image_id):
53 | def convert_box(size, box):
54 | dw, dh = 1. / size[0], 1. / size[1]
55 | x, y, w, h = (box[0] + box[1]) / 2.0 - 1, (box[2] + box[3]) / 2.0 - 1, box[1] - box[0], box[3] - box[2]
56 | return x * dw, y * dh, w * dw, h * dh
57 |
58 | in_file = open(path / f'VOC{year}/Annotations/{image_id}.xml')
59 | out_file = open(lb_path, 'w')
60 | tree = ET.parse(in_file)
61 | root = tree.getroot()
62 | size = root.find('size')
63 | w = int(size.find('width').text)
64 | h = int(size.find('height').text)
65 |
66 | names = list(yaml['names'].values()) # names list
67 | for obj in root.iter('object'):
68 | cls = obj.find('name').text
69 | if cls in names and int(obj.find('difficult').text) != 1:
70 | xmlbox = obj.find('bndbox')
71 | bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')])
72 | cls_id = names.index(cls) # class id
73 | out_file.write(" ".join([str(a) for a in (cls_id, *bb)]) + '\n')
74 |
75 |
76 | # Download
77 | dir = Path(yaml['path']) # dataset root dir
78 | url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/'
79 | urls = [f'{url}VOCtrainval_06-Nov-2007.zip', # 446MB, 5012 images
80 | f'{url}VOCtest_06-Nov-2007.zip', # 438MB, 4953 images
81 | f'{url}VOCtrainval_11-May-2012.zip'] # 1.95GB, 17126 images
82 | download(urls, dir=dir / 'images', delete=False, curl=True, threads=3)
83 |
84 | # Convert
85 | path = dir / 'images/VOCdevkit'
86 | for year, image_set in ('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test'):
87 | imgs_path = dir / 'images' / f'{image_set}{year}'
88 | lbs_path = dir / 'labels' / f'{image_set}{year}'
89 | imgs_path.mkdir(exist_ok=True, parents=True)
90 | lbs_path.mkdir(exist_ok=True, parents=True)
91 |
92 | with open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt') as f:
93 | image_ids = f.read().strip().split()
94 | for id in tqdm(image_ids, desc=f'{image_set}{year}'):
95 | f = path / f'VOC{year}/JPEGImages/{id}.jpg' # old img path
96 | lb_path = (lbs_path / f.name).with_suffix('.txt') # new label path
97 | f.rename(imgs_path / f.name) # move image
98 | convert_label(path, lb_path, year, id) # convert labels to YOLO format
99 |
--------------------------------------------------------------------------------
/yolov5/data/VisDrone.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # VisDrone2019-DET dataset https://github.com/VisDrone/VisDrone-Dataset by Tianjin University
3 | # Example usage: python train.py --data VisDrone.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── VisDrone ← downloads here (2.3 GB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/VisDrone # dataset root dir
11 | train: VisDrone2019-DET-train/images # train images (relative to 'path') 6471 images
12 | val: VisDrone2019-DET-val/images # val images (relative to 'path') 548 images
13 | test: VisDrone2019-DET-test-dev/images # test images (optional) 1610 images
14 |
15 | # Classes
16 | names:
17 | 0: pedestrian
18 | 1: people
19 | 2: bicycle
20 | 3: car
21 | 4: van
22 | 5: truck
23 | 6: tricycle
24 | 7: awning-tricycle
25 | 8: bus
26 | 9: motor
27 |
28 | # Download script/URL (optional) ---------------------------------------------------------------------------------------
29 | download: |
30 | from utils.general import download, os, Path
31 |
32 | def visdrone2yolo(dir):
33 | from PIL import Image
34 | from tqdm import tqdm
35 |
36 | def convert_box(size, box):
37 | # Convert VisDrone box to YOLO xywh box
38 | dw = 1. / size[0]
39 | dh = 1. / size[1]
40 | return (box[0] + box[2] / 2) * dw, (box[1] + box[3] / 2) * dh, box[2] * dw, box[3] * dh
41 |
42 | (dir / 'labels').mkdir(parents=True, exist_ok=True) # make labels directory
43 | pbar = tqdm((dir / 'annotations').glob('*.txt'), desc=f'Converting {dir}')
44 | for f in pbar:
45 | img_size = Image.open((dir / 'images' / f.name).with_suffix('.jpg')).size
46 | lines = []
47 | with open(f, 'r') as file: # read annotation.txt
48 | for row in [x.split(',') for x in file.read().strip().splitlines()]:
49 | if row[4] == '0': # VisDrone 'ignored regions' class 0
50 | continue
51 | cls = int(row[5]) - 1
52 | box = convert_box(img_size, tuple(map(int, row[:4])))
53 | lines.append(f"{cls} {' '.join(f'{x:.6f}' for x in box)}\n")
54 | with open(str(f).replace(os.sep + 'annotations' + os.sep, os.sep + 'labels' + os.sep), 'w') as fl:
55 | fl.writelines(lines) # write label.txt
56 |
57 |
58 | # Download
59 | dir = Path(yaml['path']) # dataset root dir
60 | urls = ['https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-train.zip',
61 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-val.zip',
62 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-dev.zip',
63 | 'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-challenge.zip']
64 | download(urls, dir=dir, curl=True, threads=4)
65 |
66 | # Convert
67 | for d in 'VisDrone2019-DET-train', 'VisDrone2019-DET-val', 'VisDrone2019-DET-test-dev':
68 | visdrone2yolo(dir / d) # convert VisDrone annotations to YOLO labels
69 |
--------------------------------------------------------------------------------
/yolov5/data/coco.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # COCO 2017 dataset http://cocodataset.org by Microsoft
3 | # Example usage: python train.py --data coco.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── coco ← downloads here (20.1 GB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/coco # dataset root dir
11 | train: train2017.txt # train images (relative to 'path') 118287 images
12 | val: val2017.txt # val images (relative to 'path') 5000 images
13 | test: test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794
14 |
15 | # Classes
16 | names:
17 | 0: person
18 | 1: bicycle
19 | 2: car
20 | 3: motorcycle
21 | 4: airplane
22 | 5: bus
23 | 6: train
24 | 7: truck
25 | 8: boat
26 | 9: traffic light
27 | 10: fire hydrant
28 | 11: stop sign
29 | 12: parking meter
30 | 13: bench
31 | 14: bird
32 | 15: cat
33 | 16: dog
34 | 17: horse
35 | 18: sheep
36 | 19: cow
37 | 20: elephant
38 | 21: bear
39 | 22: zebra
40 | 23: giraffe
41 | 24: backpack
42 | 25: umbrella
43 | 26: handbag
44 | 27: tie
45 | 28: suitcase
46 | 29: frisbee
47 | 30: skis
48 | 31: snowboard
49 | 32: sports ball
50 | 33: kite
51 | 34: baseball bat
52 | 35: baseball glove
53 | 36: skateboard
54 | 37: surfboard
55 | 38: tennis racket
56 | 39: bottle
57 | 40: wine glass
58 | 41: cup
59 | 42: fork
60 | 43: knife
61 | 44: spoon
62 | 45: bowl
63 | 46: banana
64 | 47: apple
65 | 48: sandwich
66 | 49: orange
67 | 50: broccoli
68 | 51: carrot
69 | 52: hot dog
70 | 53: pizza
71 | 54: donut
72 | 55: cake
73 | 56: chair
74 | 57: couch
75 | 58: potted plant
76 | 59: bed
77 | 60: dining table
78 | 61: toilet
79 | 62: tv
80 | 63: laptop
81 | 64: mouse
82 | 65: remote
83 | 66: keyboard
84 | 67: cell phone
85 | 68: microwave
86 | 69: oven
87 | 70: toaster
88 | 71: sink
89 | 72: refrigerator
90 | 73: book
91 | 74: clock
92 | 75: vase
93 | 76: scissors
94 | 77: teddy bear
95 | 78: hair drier
96 | 79: toothbrush
97 |
98 | # Download script/URL (optional)
99 | download: |
100 | from utils.general import download, Path
101 |
102 |
103 | # Download labels
104 | segments = False # segment or box labels
105 | dir = Path(yaml['path']) # dataset root dir
106 | url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/'
107 | urls = [url + ('coco2017labels-segments.zip' if segments else 'coco2017labels.zip')] # labels
108 | download(urls, dir=dir.parent)
109 |
110 | # Download data
111 | urls = ['http://images.cocodataset.org/zips/train2017.zip', # 19G, 118k images
112 | 'http://images.cocodataset.org/zips/val2017.zip', # 1G, 5k images
113 | 'http://images.cocodataset.org/zips/test2017.zip'] # 7G, 41k images (optional)
114 | download(urls, dir=dir / 'images', threads=3)
115 |
--------------------------------------------------------------------------------
/yolov5/data/coco128-seg.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # COCO128-seg dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
3 | # Example usage: python train.py --data coco128.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── coco128-seg ← downloads here (7 MB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/coco128-seg # dataset root dir
11 | train: images/train2017 # train images (relative to 'path') 128 images
12 | val: images/train2017 # val images (relative to 'path') 128 images
13 | test: # test images (optional)
14 |
15 | # Classes
16 | names:
17 | 0: person
18 | 1: bicycle
19 | 2: car
20 | 3: motorcycle
21 | 4: airplane
22 | 5: bus
23 | 6: train
24 | 7: truck
25 | 8: boat
26 | 9: traffic light
27 | 10: fire hydrant
28 | 11: stop sign
29 | 12: parking meter
30 | 13: bench
31 | 14: bird
32 | 15: cat
33 | 16: dog
34 | 17: horse
35 | 18: sheep
36 | 19: cow
37 | 20: elephant
38 | 21: bear
39 | 22: zebra
40 | 23: giraffe
41 | 24: backpack
42 | 25: umbrella
43 | 26: handbag
44 | 27: tie
45 | 28: suitcase
46 | 29: frisbee
47 | 30: skis
48 | 31: snowboard
49 | 32: sports ball
50 | 33: kite
51 | 34: baseball bat
52 | 35: baseball glove
53 | 36: skateboard
54 | 37: surfboard
55 | 38: tennis racket
56 | 39: bottle
57 | 40: wine glass
58 | 41: cup
59 | 42: fork
60 | 43: knife
61 | 44: spoon
62 | 45: bowl
63 | 46: banana
64 | 47: apple
65 | 48: sandwich
66 | 49: orange
67 | 50: broccoli
68 | 51: carrot
69 | 52: hot dog
70 | 53: pizza
71 | 54: donut
72 | 55: cake
73 | 56: chair
74 | 57: couch
75 | 58: potted plant
76 | 59: bed
77 | 60: dining table
78 | 61: toilet
79 | 62: tv
80 | 63: laptop
81 | 64: mouse
82 | 65: remote
83 | 66: keyboard
84 | 67: cell phone
85 | 68: microwave
86 | 69: oven
87 | 70: toaster
88 | 71: sink
89 | 72: refrigerator
90 | 73: book
91 | 74: clock
92 | 75: vase
93 | 76: scissors
94 | 77: teddy bear
95 | 78: hair drier
96 | 79: toothbrush
97 |
98 | # Download script/URL (optional)
99 | download: https://ultralytics.com/assets/coco128-seg.zip
100 |
--------------------------------------------------------------------------------
/yolov5/data/coco128.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
3 | # Example usage: python train.py --data coco128.yaml
4 | # parent
5 | # ├── yolov5
6 | # └── datasets
7 | # └── coco128 ← downloads here (7 MB)
8 |
9 | # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
10 | path: ../datasets/coco128 # dataset root dir
11 | train: images/train2017 # train images (relative to 'path') 128 images
12 | val: images/train2017 # val images (relative to 'path') 128 images
13 | test: # test images (optional)
14 |
15 | # Classes
16 | names:
17 | 0: person
18 | 1: bicycle
19 | 2: car
20 | 3: motorcycle
21 | 4: airplane
22 | 5: bus
23 | 6: train
24 | 7: truck
25 | 8: boat
26 | 9: traffic light
27 | 10: fire hydrant
28 | 11: stop sign
29 | 12: parking meter
30 | 13: bench
31 | 14: bird
32 | 15: cat
33 | 16: dog
34 | 17: horse
35 | 18: sheep
36 | 19: cow
37 | 20: elephant
38 | 21: bear
39 | 22: zebra
40 | 23: giraffe
41 | 24: backpack
42 | 25: umbrella
43 | 26: handbag
44 | 27: tie
45 | 28: suitcase
46 | 29: frisbee
47 | 30: skis
48 | 31: snowboard
49 | 32: sports ball
50 | 33: kite
51 | 34: baseball bat
52 | 35: baseball glove
53 | 36: skateboard
54 | 37: surfboard
55 | 38: tennis racket
56 | 39: bottle
57 | 40: wine glass
58 | 41: cup
59 | 42: fork
60 | 43: knife
61 | 44: spoon
62 | 45: bowl
63 | 46: banana
64 | 47: apple
65 | 48: sandwich
66 | 49: orange
67 | 50: broccoli
68 | 51: carrot
69 | 52: hot dog
70 | 53: pizza
71 | 54: donut
72 | 55: cake
73 | 56: chair
74 | 57: couch
75 | 58: potted plant
76 | 59: bed
77 | 60: dining table
78 | 61: toilet
79 | 62: tv
80 | 63: laptop
81 | 64: mouse
82 | 65: remote
83 | 66: keyboard
84 | 67: cell phone
85 | 68: microwave
86 | 69: oven
87 | 70: toaster
88 | 71: sink
89 | 72: refrigerator
90 | 73: book
91 | 74: clock
92 | 75: vase
93 | 76: scissors
94 | 77: teddy bear
95 | 78: hair drier
96 | 79: toothbrush
97 |
98 | # Download script/URL (optional)
99 | download: https://ultralytics.com/assets/coco128.zip
100 |
--------------------------------------------------------------------------------
/yolov5/data/hyps/hyp.Objects365.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Hyperparameters for Objects365 training
3 | # python train.py --weights yolov5m.pt --data Objects365.yaml --evolve
4 | # See Hyperparameter Evolution tutorial for details https://github.com/ultralytics/yolov5#tutorials
5 |
6 | lr0: 0.00258
7 | lrf: 0.17
8 | momentum: 0.779
9 | weight_decay: 0.00058
10 | warmup_epochs: 1.33
11 | warmup_momentum: 0.86
12 | warmup_bias_lr: 0.0711
13 | box: 0.0539
14 | cls: 0.299
15 | cls_pw: 0.825
16 | obj: 0.632
17 | obj_pw: 1.0
18 | iou_t: 0.2
19 | anchor_t: 3.44
20 | anchors: 3.2
21 | fl_gamma: 0.0
22 | hsv_h: 0.0188
23 | hsv_s: 0.704
24 | hsv_v: 0.36
25 | degrees: 0.0
26 | translate: 0.0902
27 | scale: 0.491
28 | shear: 0.0
29 | perspective: 0.0
30 | flipud: 0.0
31 | fliplr: 0.5
32 | mosaic: 1.0
33 | mixup: 0.0
34 | copy_paste: 0.0
35 |
--------------------------------------------------------------------------------
/yolov5/data/hyps/hyp.VOC.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Hyperparameters for VOC training
3 | # python train.py --batch 128 --weights yolov5m6.pt --data VOC.yaml --epochs 50 --img 512 --hyp hyp.scratch-med.yaml --evolve
4 | # See Hyperparameter Evolution tutorial for details https://github.com/ultralytics/yolov5#tutorials
5 |
6 | # YOLOv5 Hyperparameter Evolution Results
7 | # Best generation: 467
8 | # Last generation: 996
9 | # metrics/precision, metrics/recall, metrics/mAP_0.5, metrics/mAP_0.5:0.95, val/box_loss, val/obj_loss, val/cls_loss
10 | # 0.87729, 0.85125, 0.91286, 0.72664, 0.0076739, 0.0042529, 0.0013865
11 |
12 | lr0: 0.00334
13 | lrf: 0.15135
14 | momentum: 0.74832
15 | weight_decay: 0.00025
16 | warmup_epochs: 3.3835
17 | warmup_momentum: 0.59462
18 | warmup_bias_lr: 0.18657
19 | box: 0.02
20 | cls: 0.21638
21 | cls_pw: 0.5
22 | obj: 0.51728
23 | obj_pw: 0.67198
24 | iou_t: 0.2
25 | anchor_t: 3.3744
26 | fl_gamma: 0.0
27 | hsv_h: 0.01041
28 | hsv_s: 0.54703
29 | hsv_v: 0.27739
30 | degrees: 0.0
31 | translate: 0.04591
32 | scale: 0.75544
33 | shear: 0.0
34 | perspective: 0.0
35 | flipud: 0.0
36 | fliplr: 0.5
37 | mosaic: 0.85834
38 | mixup: 0.04266
39 | copy_paste: 0.0
40 | anchors: 3.412
41 |
--------------------------------------------------------------------------------
/yolov5/data/hyps/hyp.no-augmentation.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Hyperparameters when using Albumentations frameworks
3 | # python train.py --hyp hyp.no-augmentation.yaml
4 | # See https://github.com/ultralytics/yolov5/pull/3882 for YOLOv5 + Albumentations Usage examples
5 |
6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf)
8 | momentum: 0.937 # SGD momentum/Adam beta1
9 | weight_decay: 0.0005 # optimizer weight decay 5e-4
10 | warmup_epochs: 3.0 # warmup epochs (fractions ok)
11 | warmup_momentum: 0.8 # warmup initial momentum
12 | warmup_bias_lr: 0.1 # warmup initial bias lr
13 | box: 0.05 # box loss gain
14 | cls: 0.3 # cls loss gain
15 | cls_pw: 1.0 # cls BCELoss positive_weight
16 | obj: 0.7 # obj loss gain (scale with pixels)
17 | obj_pw: 1.0 # obj BCELoss positive_weight
18 | iou_t: 0.20 # IoU training threshold
19 | anchor_t: 4.0 # anchor-multiple threshold
20 | # anchors: 3 # anchors per output layer (0 to ignore)
21 | # this parameters are all zero since we want to use albumentation framework
22 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
23 | hsv_h: 0 # image HSV-Hue augmentation (fraction)
24 | hsv_s: 0 # image HSV-Saturation augmentation (fraction)
25 | hsv_v: 0 # image HSV-Value augmentation (fraction)
26 | degrees: 0.0 # image rotation (+/- deg)
27 | translate: 0 # image translation (+/- fraction)
28 | scale: 0 # image scale (+/- gain)
29 | shear: 0 # image shear (+/- deg)
30 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
31 | flipud: 0.0 # image flip up-down (probability)
32 | fliplr: 0.0 # image flip left-right (probability)
33 | mosaic: 0.0 # image mosaic (probability)
34 | mixup: 0.0 # image mixup (probability)
35 | copy_paste: 0.0 # segment copy-paste (probability)
36 |
--------------------------------------------------------------------------------
/yolov5/data/hyps/hyp.scratch-high.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Hyperparameters for high-augmentation COCO training from scratch
3 | # python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300
4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials
5 |
6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf)
8 | momentum: 0.937 # SGD momentum/Adam beta1
9 | weight_decay: 0.0005 # optimizer weight decay 5e-4
10 | warmup_epochs: 3.0 # warmup epochs (fractions ok)
11 | warmup_momentum: 0.8 # warmup initial momentum
12 | warmup_bias_lr: 0.1 # warmup initial bias lr
13 | box: 0.05 # box loss gain
14 | cls: 0.3 # cls loss gain
15 | cls_pw: 1.0 # cls BCELoss positive_weight
16 | obj: 0.7 # obj loss gain (scale with pixels)
17 | obj_pw: 1.0 # obj BCELoss positive_weight
18 | iou_t: 0.20 # IoU training threshold
19 | anchor_t: 4.0 # anchor-multiple threshold
20 | # anchors: 3 # anchors per output layer (0 to ignore)
21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction)
25 | degrees: 0.0 # image rotation (+/- deg)
26 | translate: 0.1 # image translation (+/- fraction)
27 | scale: 0.9 # image scale (+/- gain)
28 | shear: 0.0 # image shear (+/- deg)
29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
30 | flipud: 0.0 # image flip up-down (probability)
31 | fliplr: 0.5 # image flip left-right (probability)
32 | mosaic: 1.0 # image mosaic (probability)
33 | mixup: 0.1 # image mixup (probability)
34 | copy_paste: 0.1 # segment copy-paste (probability)
35 |
--------------------------------------------------------------------------------
/yolov5/data/hyps/hyp.scratch-low.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Hyperparameters for low-augmentation COCO training from scratch
3 | # python train.py --batch 64 --cfg yolov5n6.yaml --weights '' --data coco.yaml --img 640 --epochs 300 --linear
4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials
5 |
6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
7 | lrf: 0.01 # final OneCycleLR learning rate (lr0 * lrf)
8 | momentum: 0.937 # SGD momentum/Adam beta1
9 | weight_decay: 0.0005 # optimizer weight decay 5e-4
10 | warmup_epochs: 3.0 # warmup epochs (fractions ok)
11 | warmup_momentum: 0.8 # warmup initial momentum
12 | warmup_bias_lr: 0.1 # warmup initial bias lr
13 | box: 0.05 # box loss gain
14 | cls: 0.5 # cls loss gain
15 | cls_pw: 1.0 # cls BCELoss positive_weight
16 | obj: 1.0 # obj loss gain (scale with pixels)
17 | obj_pw: 1.0 # obj BCELoss positive_weight
18 | iou_t: 0.20 # IoU training threshold
19 | anchor_t: 4.0 # anchor-multiple threshold
20 | # anchors: 3 # anchors per output layer (0 to ignore)
21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction)
25 | degrees: 0.0 # image rotation (+/- deg)
26 | translate: 0.1 # image translation (+/- fraction)
27 | scale: 0.5 # image scale (+/- gain)
28 | shear: 0.0 # image shear (+/- deg)
29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
30 | flipud: 0.0 # image flip up-down (probability)
31 | fliplr: 0.5 # image flip left-right (probability)
32 | mosaic: 1.0 # image mosaic (probability)
33 | mixup: 0.0 # image mixup (probability)
34 | copy_paste: 0.0 # segment copy-paste (probability)
35 |
--------------------------------------------------------------------------------
/yolov5/data/hyps/hyp.scratch-med.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Hyperparameters for medium-augmentation COCO training from scratch
3 | # python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300
4 | # See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials
5 |
6 | lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
7 | lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf)
8 | momentum: 0.937 # SGD momentum/Adam beta1
9 | weight_decay: 0.0005 # optimizer weight decay 5e-4
10 | warmup_epochs: 3.0 # warmup epochs (fractions ok)
11 | warmup_momentum: 0.8 # warmup initial momentum
12 | warmup_bias_lr: 0.1 # warmup initial bias lr
13 | box: 0.05 # box loss gain
14 | cls: 0.3 # cls loss gain
15 | cls_pw: 1.0 # cls BCELoss positive_weight
16 | obj: 0.7 # obj loss gain (scale with pixels)
17 | obj_pw: 1.0 # obj BCELoss positive_weight
18 | iou_t: 0.20 # IoU training threshold
19 | anchor_t: 4.0 # anchor-multiple threshold
20 | # anchors: 3 # anchors per output layer (0 to ignore)
21 | fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
22 | hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
23 | hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
24 | hsv_v: 0.4 # image HSV-Value augmentation (fraction)
25 | degrees: 0.0 # image rotation (+/- deg)
26 | translate: 0.1 # image translation (+/- fraction)
27 | scale: 0.9 # image scale (+/- gain)
28 | shear: 0.0 # image shear (+/- deg)
29 | perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
30 | flipud: 0.0 # image flip up-down (probability)
31 | fliplr: 0.5 # image flip left-right (probability)
32 | mosaic: 1.0 # image mosaic (probability)
33 | mixup: 0.1 # image mixup (probability)
34 | copy_paste: 0.0 # segment copy-paste (probability)
35 |
--------------------------------------------------------------------------------
/yolov5/data/images/bus.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/data/images/bus.jpg
--------------------------------------------------------------------------------
/yolov5/data/images/zidane.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/data/images/zidane.jpg
--------------------------------------------------------------------------------
/yolov5/data/scripts/download_weights.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
3 | # Download latest models from https://github.com/ultralytics/yolov5/releases
4 | # Example usage: bash data/scripts/download_weights.sh
5 | # parent
6 | # └── yolov5
7 | # ├── yolov5s.pt ← downloads here
8 | # ├── yolov5m.pt
9 | # └── ...
10 |
11 | python - <= cls >= 0, f'incorrect class index {cls}'
123 |
124 | # Write YOLO label
125 | if id not in shapes:
126 | shapes[id] = Image.open(file).size
127 | box = xyxy2xywhn(box[None].astype(np.float), w=shapes[id][0], h=shapes[id][1], clip=True)
128 | with open((labels / id).with_suffix('.txt'), 'a') as f:
129 | f.write(f"{cls} {' '.join(f'{x:.6f}' for x in box[0])}\n") # write label.txt
130 | except Exception as e:
131 | print(f'WARNING: skipping one label for {file}: {e}')
132 |
133 |
134 | # Download manually from https://challenge.xviewdataset.org
135 | dir = Path(yaml['path']) # dataset root dir
136 | # urls = ['https://d307kc0mrhucc3.cloudfront.net/train_labels.zip', # train labels
137 | # 'https://d307kc0mrhucc3.cloudfront.net/train_images.zip', # 15G, 847 train images
138 | # 'https://d307kc0mrhucc3.cloudfront.net/val_images.zip'] # 5G, 282 val images (no labels)
139 | # download(urls, dir=dir, delete=False)
140 |
141 | # Convert labels
142 | convert_labels(dir / 'xView_train.geojson')
143 |
144 | # Move images
145 | images = Path(dir / 'images')
146 | images.mkdir(parents=True, exist_ok=True)
147 | Path(dir / 'train_images').rename(dir / 'images' / 'train')
148 | Path(dir / 'val_images').rename(dir / 'images' / 'val')
149 |
150 | # Split
151 | autosplit(dir / 'images' / 'train')
152 |
--------------------------------------------------------------------------------
/yolov5/models/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/models/__init__.py
--------------------------------------------------------------------------------
/yolov5/models/__pycache__/__init__.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/models/__pycache__/__init__.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/models/__pycache__/common.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/models/__pycache__/common.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/models/__pycache__/experimental.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/models/__pycache__/experimental.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/models/__pycache__/yolo.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/models/__pycache__/yolo.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/models/experimental.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Experimental modules."""
3 |
4 | import math
5 |
6 | import numpy as np
7 | import torch
8 | import torch.nn as nn
9 |
10 | from utils.downloads import attempt_download
11 |
12 |
13 | class Sum(nn.Module):
14 | """Weighted sum of 2 or more layers https://arxiv.org/abs/1911.09070."""
15 |
16 | def __init__(self, n, weight=False):
17 | """Initializes a module to sum outputs of layers with number of inputs `n` and optional weighting, supporting 2+
18 | inputs.
19 | """
20 | super().__init__()
21 | self.weight = weight # apply weights boolean
22 | self.iter = range(n - 1) # iter object
23 | if weight:
24 | self.w = nn.Parameter(-torch.arange(1.0, n) / 2, requires_grad=True) # layer weights
25 |
26 | def forward(self, x):
27 | """Processes input through a customizable weighted sum of `n` inputs, optionally applying learned weights."""
28 | y = x[0] # no weight
29 | if self.weight:
30 | w = torch.sigmoid(self.w) * 2
31 | for i in self.iter:
32 | y = y + x[i + 1] * w[i]
33 | else:
34 | for i in self.iter:
35 | y = y + x[i + 1]
36 | return y
37 |
38 |
39 | class MixConv2d(nn.Module):
40 | """Mixed Depth-wise Conv https://arxiv.org/abs/1907.09595."""
41 |
42 | def __init__(self, c1, c2, k=(1, 3), s=1, equal_ch=True):
43 | """Initializes MixConv2d with mixed depth-wise convolutional layers, taking input and output channels (c1, c2),
44 | kernel sizes (k), stride (s), and channel distribution strategy (equal_ch).
45 | """
46 | super().__init__()
47 | n = len(k) # number of convolutions
48 | if equal_ch: # equal c_ per group
49 | i = torch.linspace(0, n - 1e-6, c2).floor() # c2 indices
50 | c_ = [(i == g).sum() for g in range(n)] # intermediate channels
51 | else: # equal weight.numel() per group
52 | b = [c2] + [0] * n
53 | a = np.eye(n + 1, n, k=-1)
54 | a -= np.roll(a, 1, axis=1)
55 | a *= np.array(k) ** 2
56 | a[0] = 1
57 | c_ = np.linalg.lstsq(a, b, rcond=None)[0].round() # solve for equal weight indices, ax = b
58 |
59 | self.m = nn.ModuleList(
60 | [nn.Conv2d(c1, int(c_), k, s, k // 2, groups=math.gcd(c1, int(c_)), bias=False) for k, c_ in zip(k, c_)]
61 | )
62 | self.bn = nn.BatchNorm2d(c2)
63 | self.act = nn.SiLU()
64 |
65 | def forward(self, x):
66 | """Performs forward pass by applying SiLU activation on batch-normalized concatenated convolutional layer
67 | outputs.
68 | """
69 | return self.act(self.bn(torch.cat([m(x) for m in self.m], 1)))
70 |
71 |
72 | class Ensemble(nn.ModuleList):
73 | """Ensemble of models."""
74 |
75 | def __init__(self):
76 | """Initializes an ensemble of models to be used for aggregated predictions."""
77 | super().__init__()
78 |
79 | def forward(self, x, augment=False, profile=False, visualize=False):
80 | """Performs forward pass aggregating outputs from an ensemble of models.."""
81 | y = [module(x, augment, profile, visualize)[0] for module in self]
82 | # y = torch.stack(y).max(0)[0] # max ensemble
83 | # y = torch.stack(y).mean(0) # mean ensemble
84 | y = torch.cat(y, 1) # nms ensemble
85 | return y, None # inference, train output
86 |
87 |
88 | def attempt_load(weights, device=None, inplace=True, fuse=True):
89 | """
90 | Loads and fuses an ensemble or single YOLOv5 model from weights, handling device placement and model adjustments.
91 |
92 | Example inputs: weights=[a,b,c] or a single model weights=[a] or weights=a.
93 | """
94 | from models.yolo import Detect, Model
95 |
96 | model = Ensemble()
97 | for w in weights if isinstance(weights, list) else [weights]:
98 | ckpt = torch.load(attempt_download(w), map_location="cpu") # load
99 | ckpt = (ckpt.get("ema") or ckpt["model"]).to(device).float() # FP32 model
100 |
101 | # Model compatibility updates
102 | if not hasattr(ckpt, "stride"):
103 | ckpt.stride = torch.tensor([32.0])
104 | if hasattr(ckpt, "names") and isinstance(ckpt.names, (list, tuple)):
105 | ckpt.names = dict(enumerate(ckpt.names)) # convert to dict
106 |
107 | model.append(ckpt.fuse().eval() if fuse and hasattr(ckpt, "fuse") else ckpt.eval()) # model in eval mode
108 |
109 | # Module updates
110 | for m in model.modules():
111 | t = type(m)
112 | if t in (nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model):
113 | m.inplace = inplace
114 | if t is Detect and not isinstance(m.anchor_grid, list):
115 | delattr(m, "anchor_grid")
116 | setattr(m, "anchor_grid", [torch.zeros(1)] * m.nl)
117 | elif t is nn.Upsample and not hasattr(m, "recompute_scale_factor"):
118 | m.recompute_scale_factor = None # torch 1.11.0 compatibility
119 |
120 | # Return model
121 | if len(model) == 1:
122 | return model[-1]
123 |
124 | # Return detection ensemble
125 | print(f"Ensemble created with {weights}\n")
126 | for k in "names", "nc", "yaml":
127 | setattr(model, k, getattr(model[0], k))
128 | model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride
129 | assert all(model[0].nc == m.nc for m in model), f"Models have different class counts: {[m.nc for m in model]}"
130 | return model
131 |
--------------------------------------------------------------------------------
/yolov5/models/hub/anchors.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Default anchors for COCO data
3 |
4 | # P5 -------------------------------------------------------------------------------------------------------------------
5 | # P5-640:
6 | anchors_p5_640:
7 | - [10, 13, 16, 30, 33, 23] # P3/8
8 | - [30, 61, 62, 45, 59, 119] # P4/16
9 | - [116, 90, 156, 198, 373, 326] # P5/32
10 |
11 | # P6 -------------------------------------------------------------------------------------------------------------------
12 | # P6-640: thr=0.25: 0.9964 BPR, 5.54 anchors past thr, n=12, img_size=640, metric_all=0.281/0.716-mean/best, past_thr=0.469-mean: 9,11, 21,19, 17,41, 43,32, 39,70, 86,64, 65,131, 134,130, 120,265, 282,180, 247,354, 512,387
13 | anchors_p6_640:
14 | - [9, 11, 21, 19, 17, 41] # P3/8
15 | - [43, 32, 39, 70, 86, 64] # P4/16
16 | - [65, 131, 134, 130, 120, 265] # P5/32
17 | - [282, 180, 247, 354, 512, 387] # P6/64
18 |
19 | # P6-1280: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1280, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 19,27, 44,40, 38,94, 96,68, 86,152, 180,137, 140,301, 303,264, 238,542, 436,615, 739,380, 925,792
20 | anchors_p6_1280:
21 | - [19, 27, 44, 40, 38, 94] # P3/8
22 | - [96, 68, 86, 152, 180, 137] # P4/16
23 | - [140, 301, 303, 264, 238, 542] # P5/32
24 | - [436, 615, 739, 380, 925, 792] # P6/64
25 |
26 | # P6-1920: thr=0.25: 0.9950 BPR, 5.55 anchors past thr, n=12, img_size=1920, metric_all=0.281/0.714-mean/best, past_thr=0.468-mean: 28,41, 67,59, 57,141, 144,103, 129,227, 270,205, 209,452, 455,396, 358,812, 653,922, 1109,570, 1387,1187
27 | anchors_p6_1920:
28 | - [28, 41, 67, 59, 57, 141] # P3/8
29 | - [144, 103, 129, 227, 270, 205] # P4/16
30 | - [209, 452, 455, 396, 358, 812] # P5/32
31 | - [653, 922, 1109, 570, 1387, 1187] # P6/64
32 |
33 | # P7 -------------------------------------------------------------------------------------------------------------------
34 | # P7-640: thr=0.25: 0.9962 BPR, 6.76 anchors past thr, n=15, img_size=640, metric_all=0.275/0.733-mean/best, past_thr=0.466-mean: 11,11, 13,30, 29,20, 30,46, 61,38, 39,92, 78,80, 146,66, 79,163, 149,150, 321,143, 157,303, 257,402, 359,290, 524,372
35 | anchors_p7_640:
36 | - [11, 11, 13, 30, 29, 20] # P3/8
37 | - [30, 46, 61, 38, 39, 92] # P4/16
38 | - [78, 80, 146, 66, 79, 163] # P5/32
39 | - [149, 150, 321, 143, 157, 303] # P6/64
40 | - [257, 402, 359, 290, 524, 372] # P7/128
41 |
42 | # P7-1280: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1280, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 19,22, 54,36, 32,77, 70,83, 138,71, 75,173, 165,159, 148,334, 375,151, 334,317, 251,626, 499,474, 750,326, 534,814, 1079,818
43 | anchors_p7_1280:
44 | - [19, 22, 54, 36, 32, 77] # P3/8
45 | - [70, 83, 138, 71, 75, 173] # P4/16
46 | - [165, 159, 148, 334, 375, 151] # P5/32
47 | - [334, 317, 251, 626, 499, 474] # P6/64
48 | - [750, 326, 534, 814, 1079, 818] # P7/128
49 |
50 | # P7-1920: thr=0.25: 0.9968 BPR, 6.71 anchors past thr, n=15, img_size=1920, metric_all=0.273/0.732-mean/best, past_thr=0.463-mean: 29,34, 81,55, 47,115, 105,124, 207,107, 113,259, 247,238, 222,500, 563,227, 501,476, 376,939, 749,711, 1126,489, 801,1222, 1618,1227
51 | anchors_p7_1920:
52 | - [29, 34, 81, 55, 47, 115] # P3/8
53 | - [105, 124, 207, 107, 113, 259] # P4/16
54 | - [247, 238, 222, 500, 563, 227] # P5/32
55 | - [501, 476, 376, 939, 749, 711] # P6/64
56 | - [1126, 489, 801, 1222, 1618, 1227] # P7/128
57 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov3-spp.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # darknet53 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [32, 3, 1]], # 0
17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
18 | [-1, 1, Bottleneck, [64]],
19 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
20 | [-1, 2, Bottleneck, [128]],
21 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8
22 | [-1, 8, Bottleneck, [256]],
23 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16
24 | [-1, 8, Bottleneck, [512]],
25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
26 | [-1, 4, Bottleneck, [1024]], # 10
27 | ]
28 |
29 | # YOLOv3-SPP head
30 | head: [
31 | [-1, 1, Bottleneck, [1024, False]],
32 | [-1, 1, SPP, [512, [5, 9, 13]]],
33 | [-1, 1, Conv, [1024, 3, 1]],
34 | [-1, 1, Conv, [512, 1, 1]],
35 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large)
36 |
37 | [-2, 1, Conv, [256, 1, 1]],
38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
39 | [[-1, 8], 1, Concat, [1]], # cat backbone P4
40 | [-1, 1, Bottleneck, [512, False]],
41 | [-1, 1, Bottleneck, [512, False]],
42 | [-1, 1, Conv, [256, 1, 1]],
43 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium)
44 |
45 | [-2, 1, Conv, [128, 1, 1]],
46 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
47 | [[-1, 6], 1, Concat, [1]], # cat backbone P3
48 | [-1, 1, Bottleneck, [256, False]],
49 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small)
50 |
51 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
52 | ]
53 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov3-tiny.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 14, 23, 27, 37, 58] # P4/16
9 | - [81, 82, 135, 169, 344, 319] # P5/32
10 |
11 | # YOLOv3-tiny backbone
12 | backbone:
13 | # [from, number, module, args]
14 | [
15 | [-1, 1, Conv, [16, 3, 1]], # 0
16 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 1-P1/2
17 | [-1, 1, Conv, [32, 3, 1]],
18 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 3-P2/4
19 | [-1, 1, Conv, [64, 3, 1]],
20 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 5-P3/8
21 | [-1, 1, Conv, [128, 3, 1]],
22 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 7-P4/16
23 | [-1, 1, Conv, [256, 3, 1]],
24 | [-1, 1, nn.MaxPool2d, [2, 2, 0]], # 9-P5/32
25 | [-1, 1, Conv, [512, 3, 1]],
26 | [-1, 1, nn.ZeroPad2d, [[0, 1, 0, 1]]], # 11
27 | [-1, 1, nn.MaxPool2d, [2, 1, 0]], # 12
28 | ]
29 |
30 | # YOLOv3-tiny head
31 | head: [
32 | [-1, 1, Conv, [1024, 3, 1]],
33 | [-1, 1, Conv, [256, 1, 1]],
34 | [-1, 1, Conv, [512, 3, 1]], # 15 (P5/32-large)
35 |
36 | [-2, 1, Conv, [128, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4
39 | [-1, 1, Conv, [256, 3, 1]], # 19 (P4/16-medium)
40 |
41 | [[19, 15], 1, Detect, [nc, anchors]], # Detect(P4, P5)
42 | ]
43 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov3.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # darknet53 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [32, 3, 1]], # 0
17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
18 | [-1, 1, Bottleneck, [64]],
19 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
20 | [-1, 2, Bottleneck, [128]],
21 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8
22 | [-1, 8, Bottleneck, [256]],
23 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16
24 | [-1, 8, Bottleneck, [512]],
25 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
26 | [-1, 4, Bottleneck, [1024]], # 10
27 | ]
28 |
29 | # YOLOv3 head
30 | head: [
31 | [-1, 1, Bottleneck, [1024, False]],
32 | [-1, 1, Conv, [512, 1, 1]],
33 | [-1, 1, Conv, [1024, 3, 1]],
34 | [-1, 1, Conv, [512, 1, 1]],
35 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large)
36 |
37 | [-2, 1, Conv, [256, 1, 1]],
38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
39 | [[-1, 8], 1, Concat, [1]], # cat backbone P4
40 | [-1, 1, Bottleneck, [512, False]],
41 | [-1, 1, Bottleneck, [512, False]],
42 | [-1, 1, Conv, [256, 1, 1]],
43 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium)
44 |
45 | [-2, 1, Conv, [128, 1, 1]],
46 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
47 | [[-1, 6], 1, Concat, [1]], # cat backbone P3
48 | [-1, 1, Bottleneck, [256, False]],
49 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small)
50 |
51 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
52 | ]
53 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5-bifpn.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 BiFPN head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14, 6], 1, Concat, [1]], # cat P4 <--- BiFPN change
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5-fpn.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 FPN head
29 | head: [
30 | [-1, 3, C3, [1024, False]], # 10 (P5/32-large)
31 |
32 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
33 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
34 | [-1, 1, Conv, [512, 1, 1]],
35 | [-1, 3, C3, [512, False]], # 14 (P4/16-medium)
36 |
37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
38 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
39 | [-1, 1, Conv, [256, 1, 1]],
40 | [-1, 3, C3, [256, False]], # 18 (P3/8-small)
41 |
42 | [[18, 14, 10], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
43 | ]
44 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5-p2.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
8 |
9 | # YOLOv5 v6.0 backbone
10 | backbone:
11 | # [from, number, module, args]
12 | [
13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
15 | [-1, 3, C3, [128]],
16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
17 | [-1, 6, C3, [256]],
18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
19 | [-1, 9, C3, [512]],
20 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
21 | [-1, 3, C3, [1024]],
22 | [-1, 1, SPPF, [1024, 5]], # 9
23 | ]
24 |
25 | # YOLOv5 v6.0 head with (P2, P3, P4, P5) outputs
26 | head: [
27 | [-1, 1, Conv, [512, 1, 1]],
28 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
29 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
30 | [-1, 3, C3, [512, False]], # 13
31 |
32 | [-1, 1, Conv, [256, 1, 1]],
33 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
34 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
35 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
36 |
37 | [-1, 1, Conv, [128, 1, 1]],
38 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
39 | [[-1, 2], 1, Concat, [1]], # cat backbone P2
40 | [-1, 1, C3, [128, False]], # 21 (P2/4-xsmall)
41 |
42 | [-1, 1, Conv, [128, 3, 2]],
43 | [[-1, 18], 1, Concat, [1]], # cat head P3
44 | [-1, 3, C3, [256, False]], # 24 (P3/8-small)
45 |
46 | [-1, 1, Conv, [256, 3, 2]],
47 | [[-1, 14], 1, Concat, [1]], # cat head P4
48 | [-1, 3, C3, [512, False]], # 27 (P4/16-medium)
49 |
50 | [-1, 1, Conv, [512, 3, 2]],
51 | [[-1, 10], 1, Concat, [1]], # cat head P5
52 | [-1, 3, C3, [1024, False]], # 30 (P5/32-large)
53 |
54 | [[21, 24, 27, 30], 1, Detect, [nc, anchors]], # Detect(P2, P3, P4, P5)
55 | ]
56 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5-p34.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.50 # layer channel multiple
7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
8 |
9 | # YOLOv5 v6.0 backbone
10 | backbone:
11 | # [from, number, module, args]
12 | [
13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
15 | [-1, 3, C3, [128]],
16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
17 | [-1, 6, C3, [256]],
18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
19 | [-1, 9, C3, [512]],
20 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
21 | [-1, 3, C3, [1024]],
22 | [-1, 1, SPPF, [1024, 5]], # 9
23 | ]
24 |
25 | # YOLOv5 v6.0 head with (P3, P4) outputs
26 | head: [
27 | [-1, 1, Conv, [512, 1, 1]],
28 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
29 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
30 | [-1, 3, C3, [512, False]], # 13
31 |
32 | [-1, 1, Conv, [256, 1, 1]],
33 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
34 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
35 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
36 |
37 | [-1, 1, Conv, [256, 3, 2]],
38 | [[-1, 14], 1, Concat, [1]], # cat head P4
39 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
40 |
41 | [[17, 20], 1, Detect, [nc, anchors]], # Detect(P3, P4)
42 | ]
43 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5-p6.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
8 |
9 | # YOLOv5 v6.0 backbone
10 | backbone:
11 | # [from, number, module, args]
12 | [
13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
15 | [-1, 3, C3, [128]],
16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
17 | [-1, 6, C3, [256]],
18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
19 | [-1, 9, C3, [512]],
20 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32
21 | [-1, 3, C3, [768]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64
23 | [-1, 3, C3, [1024]],
24 | [-1, 1, SPPF, [1024, 5]], # 11
25 | ]
26 |
27 | # YOLOv5 v6.0 head with (P3, P4, P5, P6) outputs
28 | head: [
29 | [-1, 1, Conv, [768, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
31 | [[-1, 8], 1, Concat, [1]], # cat backbone P5
32 | [-1, 3, C3, [768, False]], # 15
33 |
34 | [-1, 1, Conv, [512, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
36 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
37 | [-1, 3, C3, [512, False]], # 19
38 |
39 | [-1, 1, Conv, [256, 1, 1]],
40 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
41 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
42 | [-1, 3, C3, [256, False]], # 23 (P3/8-small)
43 |
44 | [-1, 1, Conv, [256, 3, 2]],
45 | [[-1, 20], 1, Concat, [1]], # cat head P4
46 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium)
47 |
48 | [-1, 1, Conv, [512, 3, 2]],
49 | [[-1, 16], 1, Concat, [1]], # cat head P5
50 | [-1, 3, C3, [768, False]], # 29 (P5/32-large)
51 |
52 | [-1, 1, Conv, [768, 3, 2]],
53 | [[-1, 12], 1, Concat, [1]], # cat head P6
54 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge)
55 |
56 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
57 | ]
58 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5-p7.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors: 3 # AutoAnchor evolves 3 anchors per P output layer
8 |
9 | # YOLOv5 v6.0 backbone
10 | backbone:
11 | # [from, number, module, args]
12 | [
13 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
14 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
15 | [-1, 3, C3, [128]],
16 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
17 | [-1, 6, C3, [256]],
18 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
19 | [-1, 9, C3, [512]],
20 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32
21 | [-1, 3, C3, [768]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64
23 | [-1, 3, C3, [1024]],
24 | [-1, 1, Conv, [1280, 3, 2]], # 11-P7/128
25 | [-1, 3, C3, [1280]],
26 | [-1, 1, SPPF, [1280, 5]], # 13
27 | ]
28 |
29 | # YOLOv5 v6.0 head with (P3, P4, P5, P6, P7) outputs
30 | head: [
31 | [-1, 1, Conv, [1024, 1, 1]],
32 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
33 | [[-1, 10], 1, Concat, [1]], # cat backbone P6
34 | [-1, 3, C3, [1024, False]], # 17
35 |
36 | [-1, 1, Conv, [768, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
38 | [[-1, 8], 1, Concat, [1]], # cat backbone P5
39 | [-1, 3, C3, [768, False]], # 21
40 |
41 | [-1, 1, Conv, [512, 1, 1]],
42 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
43 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
44 | [-1, 3, C3, [512, False]], # 25
45 |
46 | [-1, 1, Conv, [256, 1, 1]],
47 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
48 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
49 | [-1, 3, C3, [256, False]], # 29 (P3/8-small)
50 |
51 | [-1, 1, Conv, [256, 3, 2]],
52 | [[-1, 26], 1, Concat, [1]], # cat head P4
53 | [-1, 3, C3, [512, False]], # 32 (P4/16-medium)
54 |
55 | [-1, 1, Conv, [512, 3, 2]],
56 | [[-1, 22], 1, Concat, [1]], # cat head P5
57 | [-1, 3, C3, [768, False]], # 35 (P5/32-large)
58 |
59 | [-1, 1, Conv, [768, 3, 2]],
60 | [[-1, 18], 1, Concat, [1]], # cat head P6
61 | [-1, 3, C3, [1024, False]], # 38 (P6/64-xlarge)
62 |
63 | [-1, 1, Conv, [1024, 3, 2]],
64 | [[-1, 14], 1, Concat, [1]], # cat head P7
65 | [-1, 3, C3, [1280, False]], # 41 (P7/128-xxlarge)
66 |
67 | [[29, 32, 35, 38, 41], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6, P7)
68 | ]
69 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5-panet.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 PANet head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5l6.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [19, 27, 44, 40, 38, 94] # P3/8
9 | - [96, 68, 86, 152, 180, 137] # P4/16
10 | - [140, 301, 303, 264, 238, 542] # P5/32
11 | - [436, 615, 739, 380, 925, 792] # P6/64
12 |
13 | # YOLOv5 v6.0 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [
17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
19 | [-1, 3, C3, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
21 | [-1, 6, C3, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
23 | [-1, 9, C3, [512]],
24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32
25 | [-1, 3, C3, [768]],
26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64
27 | [-1, 3, C3, [1024]],
28 | [-1, 1, SPPF, [1024, 5]], # 11
29 | ]
30 |
31 | # YOLOv5 v6.0 head
32 | head: [
33 | [-1, 1, Conv, [768, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5
36 | [-1, 3, C3, [768, False]], # 15
37 |
38 | [-1, 1, Conv, [512, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
41 | [-1, 3, C3, [512, False]], # 19
42 |
43 | [-1, 1, Conv, [256, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small)
47 |
48 | [-1, 1, Conv, [256, 3, 2]],
49 | [[-1, 20], 1, Concat, [1]], # cat head P4
50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium)
51 |
52 | [-1, 1, Conv, [512, 3, 2]],
53 | [[-1, 16], 1, Concat, [1]], # cat head P5
54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large)
55 |
56 | [-1, 1, Conv, [768, 3, 2]],
57 | [[-1, 12], 1, Concat, [1]], # cat head P6
58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge)
59 |
60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
61 | ]
62 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5m6.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.67 # model depth multiple
6 | width_multiple: 0.75 # layer channel multiple
7 | anchors:
8 | - [19, 27, 44, 40, 38, 94] # P3/8
9 | - [96, 68, 86, 152, 180, 137] # P4/16
10 | - [140, 301, 303, 264, 238, 542] # P5/32
11 | - [436, 615, 739, 380, 925, 792] # P6/64
12 |
13 | # YOLOv5 v6.0 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [
17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
19 | [-1, 3, C3, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
21 | [-1, 6, C3, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
23 | [-1, 9, C3, [512]],
24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32
25 | [-1, 3, C3, [768]],
26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64
27 | [-1, 3, C3, [1024]],
28 | [-1, 1, SPPF, [1024, 5]], # 11
29 | ]
30 |
31 | # YOLOv5 v6.0 head
32 | head: [
33 | [-1, 1, Conv, [768, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5
36 | [-1, 3, C3, [768, False]], # 15
37 |
38 | [-1, 1, Conv, [512, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
41 | [-1, 3, C3, [512, False]], # 19
42 |
43 | [-1, 1, Conv, [256, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small)
47 |
48 | [-1, 1, Conv, [256, 3, 2]],
49 | [[-1, 20], 1, Concat, [1]], # cat head P4
50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium)
51 |
52 | [-1, 1, Conv, [512, 3, 2]],
53 | [[-1, 16], 1, Concat, [1]], # cat head P5
54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large)
55 |
56 | [-1, 1, Conv, [768, 3, 2]],
57 | [[-1, 12], 1, Concat, [1]], # cat head P6
58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge)
59 |
60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
61 | ]
62 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5n6.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.25 # layer channel multiple
7 | anchors:
8 | - [19, 27, 44, 40, 38, 94] # P3/8
9 | - [96, 68, 86, 152, 180, 137] # P4/16
10 | - [140, 301, 303, 264, 238, 542] # P5/32
11 | - [436, 615, 739, 380, 925, 792] # P6/64
12 |
13 | # YOLOv5 v6.0 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [
17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
19 | [-1, 3, C3, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
21 | [-1, 6, C3, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
23 | [-1, 9, C3, [512]],
24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32
25 | [-1, 3, C3, [768]],
26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64
27 | [-1, 3, C3, [1024]],
28 | [-1, 1, SPPF, [1024, 5]], # 11
29 | ]
30 |
31 | # YOLOv5 v6.0 head
32 | head: [
33 | [-1, 1, Conv, [768, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5
36 | [-1, 3, C3, [768, False]], # 15
37 |
38 | [-1, 1, Conv, [512, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
41 | [-1, 3, C3, [512, False]], # 19
42 |
43 | [-1, 1, Conv, [256, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small)
47 |
48 | [-1, 1, Conv, [256, 3, 2]],
49 | [[-1, 20], 1, Concat, [1]], # cat head P4
50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium)
51 |
52 | [-1, 1, Conv, [512, 3, 2]],
53 | [[-1, 16], 1, Concat, [1]], # cat head P5
54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large)
55 |
56 | [-1, 1, Conv, [768, 3, 2]],
57 | [[-1, 12], 1, Concat, [1]], # cat head P6
58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge)
59 |
60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
61 | ]
62 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5s-LeakyReLU.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | activation: nn.LeakyReLU(0.1) # <----- Conv() activation used throughout entire YOLOv5 model
6 | depth_multiple: 0.33 # model depth multiple
7 | width_multiple: 0.50 # layer channel multiple
8 | anchors:
9 | - [10, 13, 16, 30, 33, 23] # P3/8
10 | - [30, 61, 62, 45, 59, 119] # P4/16
11 | - [116, 90, 156, 198, 373, 326] # P5/32
12 |
13 | # YOLOv5 v6.0 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [
17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
19 | [-1, 3, C3, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
21 | [-1, 6, C3, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
23 | [-1, 9, C3, [512]],
24 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
25 | [-1, 3, C3, [1024]],
26 | [-1, 1, SPPF, [1024, 5]], # 9
27 | ]
28 |
29 | # YOLOv5 v6.0 head
30 | head: [
31 | [-1, 1, Conv, [512, 1, 1]],
32 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
33 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
34 | [-1, 3, C3, [512, False]], # 13
35 |
36 | [-1, 1, Conv, [256, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
38 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
39 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
40 |
41 | [-1, 1, Conv, [256, 3, 2]],
42 | [[-1, 14], 1, Concat, [1]], # cat head P4
43 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
44 |
45 | [-1, 1, Conv, [512, 3, 2]],
46 | [[-1, 10], 1, Concat, [1]], # cat head P5
47 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
48 |
49 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
50 | ]
51 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5s-ghost.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.50 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, GhostConv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3Ghost, [128]],
19 | [-1, 1, GhostConv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3Ghost, [256]],
21 | [-1, 1, GhostConv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3Ghost, [512]],
23 | [-1, 1, GhostConv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3Ghost, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, GhostConv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3Ghost, [512, False]], # 13
34 |
35 | [-1, 1, GhostConv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3Ghost, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, GhostConv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3Ghost, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, GhostConv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3Ghost, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5s-transformer.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.50 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3TR, [1024]], # 9 <--- C3TR() Transformer module
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5s6.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.50 # layer channel multiple
7 | anchors:
8 | - [19, 27, 44, 40, 38, 94] # P3/8
9 | - [96, 68, 86, 152, 180, 137] # P4/16
10 | - [140, 301, 303, 264, 238, 542] # P5/32
11 | - [436, 615, 739, 380, 925, 792] # P6/64
12 |
13 | # YOLOv5 v6.0 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [
17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
19 | [-1, 3, C3, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
21 | [-1, 6, C3, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
23 | [-1, 9, C3, [512]],
24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32
25 | [-1, 3, C3, [768]],
26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64
27 | [-1, 3, C3, [1024]],
28 | [-1, 1, SPPF, [1024, 5]], # 11
29 | ]
30 |
31 | # YOLOv5 v6.0 head
32 | head: [
33 | [-1, 1, Conv, [768, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5
36 | [-1, 3, C3, [768, False]], # 15
37 |
38 | [-1, 1, Conv, [512, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
41 | [-1, 3, C3, [512, False]], # 19
42 |
43 | [-1, 1, Conv, [256, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small)
47 |
48 | [-1, 1, Conv, [256, 3, 2]],
49 | [[-1, 20], 1, Concat, [1]], # cat head P4
50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium)
51 |
52 | [-1, 1, Conv, [512, 3, 2]],
53 | [[-1, 16], 1, Concat, [1]], # cat head P5
54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large)
55 |
56 | [-1, 1, Conv, [768, 3, 2]],
57 | [[-1, 12], 1, Concat, [1]], # cat head P6
58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge)
59 |
60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
61 | ]
62 |
--------------------------------------------------------------------------------
/yolov5/models/hub/yolov5x6.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.33 # model depth multiple
6 | width_multiple: 1.25 # layer channel multiple
7 | anchors:
8 | - [19, 27, 44, 40, 38, 94] # P3/8
9 | - [96, 68, 86, 152, 180, 137] # P4/16
10 | - [140, 301, 303, 264, 238, 542] # P5/32
11 | - [436, 615, 739, 380, 925, 792] # P6/64
12 |
13 | # YOLOv5 v6.0 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [
17 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
19 | [-1, 3, C3, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
21 | [-1, 6, C3, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
23 | [-1, 9, C3, [512]],
24 | [-1, 1, Conv, [768, 3, 2]], # 7-P5/32
25 | [-1, 3, C3, [768]],
26 | [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64
27 | [-1, 3, C3, [1024]],
28 | [-1, 1, SPPF, [1024, 5]], # 11
29 | ]
30 |
31 | # YOLOv5 v6.0 head
32 | head: [
33 | [-1, 1, Conv, [768, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
35 | [[-1, 8], 1, Concat, [1]], # cat backbone P5
36 | [-1, 3, C3, [768, False]], # 15
37 |
38 | [-1, 1, Conv, [512, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
40 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
41 | [-1, 3, C3, [512, False]], # 19
42 |
43 | [-1, 1, Conv, [256, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
45 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
46 | [-1, 3, C3, [256, False]], # 23 (P3/8-small)
47 |
48 | [-1, 1, Conv, [256, 3, 2]],
49 | [[-1, 20], 1, Concat, [1]], # cat head P4
50 | [-1, 3, C3, [512, False]], # 26 (P4/16-medium)
51 |
52 | [-1, 1, Conv, [512, 3, 2]],
53 | [[-1, 16], 1, Concat, [1]], # cat head P5
54 | [-1, 3, C3, [768, False]], # 29 (P5/32-large)
55 |
56 | [-1, 1, Conv, [768, 3, 2]],
57 | [[-1, 12], 1, Concat, [1]], # cat head P6
58 | [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge)
59 |
60 | [[23, 26, 29, 32], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
61 | ]
62 |
--------------------------------------------------------------------------------
/yolov5/models/segment/yolov5l-seg.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/segment/yolov5m-seg.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.67 # model depth multiple
6 | width_multiple: 0.75 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/segment/yolov5n-seg.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.25 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/segment/yolov5s-seg.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.5 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/segment/yolov5x-seg.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.33 # model depth multiple
6 | width_multiple: 1.25 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Segment, [nc, anchors, 32, 256]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/yolov5l.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/yolov5m.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.67 # model depth multiple
6 | width_multiple: 0.75 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/yolov5n.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.25 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/yolov5s.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.50 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/models/yolov5x.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.33 # model depth multiple
6 | width_multiple: 1.25 # layer channel multiple
7 | anchors:
8 | - [10, 13, 16, 30, 33, 23] # P3/8
9 | - [30, 61, 62, 45, 59, 119] # P4/16
10 | - [116, 90, 156, 198, 373, 326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [
16 | [-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
17 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
18 | [-1, 3, C3, [128]],
19 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
20 | [-1, 6, C3, [256]],
21 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
22 | [-1, 9, C3, [512]],
23 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
24 | [-1, 3, C3, [1024]],
25 | [-1, 1, SPPF, [1024, 5]], # 9
26 | ]
27 |
28 | # YOLOv5 v6.0 head
29 | head: [
30 | [-1, 1, Conv, [512, 1, 1]],
31 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
32 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
33 | [-1, 3, C3, [512, False]], # 13
34 |
35 | [-1, 1, Conv, [256, 1, 1]],
36 | [-1, 1, nn.Upsample, [None, 2, "nearest"]],
37 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
38 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
39 |
40 | [-1, 1, Conv, [256, 3, 2]],
41 | [[-1, 14], 1, Concat, [1]], # cat head P4
42 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
43 |
44 | [-1, 1, Conv, [512, 3, 2]],
45 | [[-1, 10], 1, Concat, [1]], # cat head P5
46 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
47 |
48 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov5/requirements.txt:
--------------------------------------------------------------------------------
1 | # YOLOv5 requirements
2 | # Usage: pip install -r requirements.txt
3 |
4 | # Base ------------------------------------------------------------------------
5 | gitpython>=3.1.30
6 | matplotlib>=3.3
7 | numpy>=1.23.5
8 | opencv-python>=4.1.1
9 | Pillow>=9.4.0
10 | psutil # system resources
11 | PyYAML>=5.3.1
12 | requests>=2.23.0
13 | scipy>=1.4.1
14 | thop>=0.1.1 # FLOPs computation
15 | torch>=1.8.0 # see https://pytorch.org/get-started/locally (recommended)
16 | torchvision>=0.9.0
17 | tqdm>=4.64.0
18 | ultralytics>=8.0.232
19 | # protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012
20 |
21 | # Logging ---------------------------------------------------------------------
22 | # tensorboard>=2.4.1
23 | # clearml>=1.2.0
24 | # comet
25 |
26 | # Plotting --------------------------------------------------------------------
27 | pandas>=1.1.4
28 | seaborn>=0.11.0
29 |
30 | # Export ----------------------------------------------------------------------
31 | # coremltools>=6.0 # CoreML export
32 | # onnx>=1.10.0 # ONNX export
33 | # onnx-simplifier>=0.4.1 # ONNX simplifier
34 | # nvidia-pyindex # TensorRT export
35 | # nvidia-tensorrt # TensorRT export
36 | # scikit-learn<=1.1.2 # CoreML quantization
37 | # tensorflow>=2.4.0,<=2.13.1 # TF exports (-cpu, -aarch64, -macos)
38 | # tensorflowjs>=3.9.0 # TF.js export
39 | # openvino-dev>=2023.0 # OpenVINO export
40 |
41 | # Deploy ----------------------------------------------------------------------
42 | setuptools>=65.5.1 # Snyk vulnerability fix
43 | # tritonclient[all]~=2.24.0
44 |
45 | # Extras ----------------------------------------------------------------------
46 | # ipython # interactive notebook
47 | # mss # screenshots
48 | # albumentations>=1.0.3
49 | # pycocotools>=2.0.6 # COCO mAP
50 | wheel>=0.38.0 # not directly required, pinned by Snyk to avoid a vulnerability
51 |
--------------------------------------------------------------------------------
/yolov5/runs/detect/exp/images.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/runs/detect/exp/images.jpg
--------------------------------------------------------------------------------
/yolov5/utils/__init__.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """utils/initialization."""
3 |
4 | import contextlib
5 | import platform
6 | import threading
7 |
8 |
9 | def emojis(str=""):
10 | """Returns an emoji-safe version of a string, stripped of emojis on Windows platforms."""
11 | return str.encode().decode("ascii", "ignore") if platform.system() == "Windows" else str
12 |
13 |
14 | class TryExcept(contextlib.ContextDecorator):
15 | # YOLOv5 TryExcept class. Usage: @TryExcept() decorator or 'with TryExcept():' context manager
16 | def __init__(self, msg=""):
17 | """Initializes TryExcept with an optional message, used as a decorator or context manager for error handling."""
18 | self.msg = msg
19 |
20 | def __enter__(self):
21 | """Enter the runtime context related to this object for error handling with an optional message."""
22 | pass
23 |
24 | def __exit__(self, exc_type, value, traceback):
25 | """Context manager exit method that prints an error message with emojis if an exception occurred, always returns
26 | True.
27 | """
28 | if value:
29 | print(emojis(f"{self.msg}{': ' if self.msg else ''}{value}"))
30 | return True
31 |
32 |
33 | def threaded(func):
34 | """Decorator @threaded to run a function in a separate thread, returning the thread instance."""
35 |
36 | def wrapper(*args, **kwargs):
37 | thread = threading.Thread(target=func, args=args, kwargs=kwargs, daemon=True)
38 | thread.start()
39 | return thread
40 |
41 | return wrapper
42 |
43 |
44 | def join_threads(verbose=False):
45 | """
46 | Joins all daemon threads, optionally printing their names if verbose is True.
47 |
48 | Example: atexit.register(lambda: join_threads())
49 | """
50 | main_thread = threading.current_thread()
51 | for t in threading.enumerate():
52 | if t is not main_thread:
53 | if verbose:
54 | print(f"Joining thread {t.name}")
55 | t.join()
56 |
57 |
58 | def notebook_init(verbose=True):
59 | """Initializes notebook environment by checking requirements, cleaning up, and displaying system info."""
60 | print("Checking setup...")
61 |
62 | import os
63 | import shutil
64 |
65 | from ultralytics.utils.checks import check_requirements
66 |
67 | from utils.general import check_font, is_colab
68 | from utils.torch_utils import select_device # imports
69 |
70 | check_font()
71 |
72 | import psutil
73 |
74 | if check_requirements("wandb", install=False):
75 | os.system("pip uninstall -y wandb") # eliminate unexpected account creation prompt with infinite hang
76 | if is_colab():
77 | shutil.rmtree("/content/sample_data", ignore_errors=True) # remove colab /sample_data directory
78 |
79 | # System info
80 | display = None
81 | if verbose:
82 | gb = 1 << 30 # bytes to GiB (1024 ** 3)
83 | ram = psutil.virtual_memory().total
84 | total, used, free = shutil.disk_usage("/")
85 | with contextlib.suppress(Exception): # clear display if ipython is installed
86 | from IPython import display
87 |
88 | display.clear_output()
89 | s = f"({os.cpu_count()} CPUs, {ram / gb:.1f} GB RAM, {(total - free) / gb:.1f}/{total / gb:.1f} GB disk)"
90 | else:
91 | s = ""
92 |
93 | select_device(newline=False)
94 | print(emojis(f"Setup complete ✅ {s}"))
95 | return display
96 |
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/__init__.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/__init__.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/augmentations.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/augmentations.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/autoanchor.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/autoanchor.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/dataloaders.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/dataloaders.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/downloads.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/downloads.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/general.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/general.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/metrics.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/metrics.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/plots.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/plots.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/__pycache__/torch_utils.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/__pycache__/torch_utils.cpython-310.pyc
--------------------------------------------------------------------------------
/yolov5/utils/activations.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Activation functions."""
3 |
4 | import torch
5 | import torch.nn as nn
6 | import torch.nn.functional as F
7 |
8 |
9 | class SiLU(nn.Module):
10 | @staticmethod
11 | def forward(x):
12 | """
13 | Applies the Sigmoid-weighted Linear Unit (SiLU) activation function.
14 |
15 | https://arxiv.org/pdf/1606.08415.pdf.
16 | """
17 | return x * torch.sigmoid(x)
18 |
19 |
20 | class Hardswish(nn.Module):
21 | @staticmethod
22 | def forward(x):
23 | """
24 | Applies the Hardswish activation function, compatible with TorchScript, CoreML, and ONNX.
25 |
26 | Equivalent to x * F.hardsigmoid(x)
27 | """
28 | return x * F.hardtanh(x + 3, 0.0, 6.0) / 6.0 # for TorchScript, CoreML and ONNX
29 |
30 |
31 | class Mish(nn.Module):
32 | """Mish activation https://github.com/digantamisra98/Mish."""
33 |
34 | @staticmethod
35 | def forward(x):
36 | """Applies the Mish activation function, a smooth alternative to ReLU."""
37 | return x * F.softplus(x).tanh()
38 |
39 |
40 | class MemoryEfficientMish(nn.Module):
41 | class F(torch.autograd.Function):
42 | @staticmethod
43 | def forward(ctx, x):
44 | """Applies the Mish activation function, a smooth ReLU alternative, to the input tensor `x`."""
45 | ctx.save_for_backward(x)
46 | return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x)))
47 |
48 | @staticmethod
49 | def backward(ctx, grad_output):
50 | """Computes the gradient of the Mish activation function with respect to input `x`."""
51 | x = ctx.saved_tensors[0]
52 | sx = torch.sigmoid(x)
53 | fx = F.softplus(x).tanh()
54 | return grad_output * (fx + x * sx * (1 - fx * fx))
55 |
56 | def forward(self, x):
57 | """Applies the Mish activation function to the input tensor `x`."""
58 | return self.F.apply(x)
59 |
60 |
61 | class FReLU(nn.Module):
62 | """FReLU activation https://arxiv.org/abs/2007.11824."""
63 |
64 | def __init__(self, c1, k=3): # ch_in, kernel
65 | """Initializes FReLU activation with channel `c1` and kernel size `k`."""
66 | super().__init__()
67 | self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1, bias=False)
68 | self.bn = nn.BatchNorm2d(c1)
69 |
70 | def forward(self, x):
71 | """
72 | Applies FReLU activation with max operation between input and BN-convolved input.
73 |
74 | https://arxiv.org/abs/2007.11824
75 | """
76 | return torch.max(x, self.bn(self.conv(x)))
77 |
78 |
79 | class AconC(nn.Module):
80 | """
81 | ACON activation (activate or not) function.
82 |
83 | AconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is a learnable parameter
84 | See "Activate or Not: Learning Customized Activation" https://arxiv.org/pdf/2009.04759.pdf.
85 | """
86 |
87 | def __init__(self, c1):
88 | """Initializes AconC with learnable parameters p1, p2, and beta for channel-wise activation control."""
89 | super().__init__()
90 | self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
91 | self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
92 | self.beta = nn.Parameter(torch.ones(1, c1, 1, 1))
93 |
94 | def forward(self, x):
95 | """Applies AconC activation function with learnable parameters for channel-wise control on input tensor x."""
96 | dpx = (self.p1 - self.p2) * x
97 | return dpx * torch.sigmoid(self.beta * dpx) + self.p2 * x
98 |
99 |
100 | class MetaAconC(nn.Module):
101 | """
102 | ACON activation (activate or not) function.
103 |
104 | AconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is a learnable parameter
105 | See "Activate or Not: Learning Customized Activation" https://arxiv.org/pdf/2009.04759.pdf.
106 | """
107 |
108 | def __init__(self, c1, k=1, s=1, r=16):
109 | """Initializes MetaAconC with params: channel_in (c1), kernel size (k=1), stride (s=1), reduction (r=16)."""
110 | super().__init__()
111 | c2 = max(r, c1 // r)
112 | self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
113 | self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
114 | self.fc1 = nn.Conv2d(c1, c2, k, s, bias=True)
115 | self.fc2 = nn.Conv2d(c2, c1, k, s, bias=True)
116 | # self.bn1 = nn.BatchNorm2d(c2)
117 | # self.bn2 = nn.BatchNorm2d(c1)
118 |
119 | def forward(self, x):
120 | """Applies a forward pass transforming input `x` using learnable parameters and sigmoid activation."""
121 | y = x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True)
122 | # batch-size 1 bug/instabilities https://github.com/ultralytics/yolov5/issues/2891
123 | # beta = torch.sigmoid(self.bn2(self.fc2(self.bn1(self.fc1(y))))) # bug/unstable
124 | beta = torch.sigmoid(self.fc2(self.fc1(y))) # bug patch BN layers removed
125 | dpx = (self.p1 - self.p2) * x
126 | return dpx * torch.sigmoid(beta * dpx) + self.p2 * x
127 |
--------------------------------------------------------------------------------
/yolov5/utils/autobatch.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Auto-batch utils."""
3 |
4 | from copy import deepcopy
5 |
6 | import numpy as np
7 | import torch
8 |
9 | from utils.general import LOGGER, colorstr
10 | from utils.torch_utils import profile
11 |
12 |
13 | def check_train_batch_size(model, imgsz=640, amp=True):
14 | """Checks and computes optimal training batch size for YOLOv5 model, given image size and AMP setting."""
15 | with torch.cuda.amp.autocast(amp):
16 | return autobatch(deepcopy(model).train(), imgsz) # compute optimal batch size
17 |
18 |
19 | def autobatch(model, imgsz=640, fraction=0.8, batch_size=16):
20 | """Estimates optimal YOLOv5 batch size using `fraction` of CUDA memory."""
21 | # Usage:
22 | # import torch
23 | # from utils.autobatch import autobatch
24 | # model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False)
25 | # print(autobatch(model))
26 |
27 | # Check device
28 | prefix = colorstr("AutoBatch: ")
29 | LOGGER.info(f"{prefix}Computing optimal batch size for --imgsz {imgsz}")
30 | device = next(model.parameters()).device # get model device
31 | if device.type == "cpu":
32 | LOGGER.info(f"{prefix}CUDA not detected, using default CPU batch-size {batch_size}")
33 | return batch_size
34 | if torch.backends.cudnn.benchmark:
35 | LOGGER.info(f"{prefix} ⚠️ Requires torch.backends.cudnn.benchmark=False, using default batch-size {batch_size}")
36 | return batch_size
37 |
38 | # Inspect CUDA memory
39 | gb = 1 << 30 # bytes to GiB (1024 ** 3)
40 | d = str(device).upper() # 'CUDA:0'
41 | properties = torch.cuda.get_device_properties(device) # device properties
42 | t = properties.total_memory / gb # GiB total
43 | r = torch.cuda.memory_reserved(device) / gb # GiB reserved
44 | a = torch.cuda.memory_allocated(device) / gb # GiB allocated
45 | f = t - (r + a) # GiB free
46 | LOGGER.info(f"{prefix}{d} ({properties.name}) {t:.2f}G total, {r:.2f}G reserved, {a:.2f}G allocated, {f:.2f}G free")
47 |
48 | # Profile batch sizes
49 | batch_sizes = [1, 2, 4, 8, 16]
50 | try:
51 | img = [torch.empty(b, 3, imgsz, imgsz) for b in batch_sizes]
52 | results = profile(img, model, n=3, device=device)
53 | except Exception as e:
54 | LOGGER.warning(f"{prefix}{e}")
55 |
56 | # Fit a solution
57 | y = [x[2] for x in results if x] # memory [2]
58 | p = np.polyfit(batch_sizes[: len(y)], y, deg=1) # first degree polynomial fit
59 | b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size)
60 | if None in results: # some sizes failed
61 | i = results.index(None) # first fail index
62 | if b >= batch_sizes[i]: # y intercept above failure point
63 | b = batch_sizes[max(i - 1, 0)] # select prior safe point
64 | if b < 1 or b > 1024: # b outside of safe range
65 | b = batch_size
66 | LOGGER.warning(f"{prefix}WARNING ⚠️ CUDA anomaly detected, recommend restart environment and retry command.")
67 |
68 | fraction = (np.polyval(p, b) + r + a) / t # actual fraction predicted
69 | LOGGER.info(f"{prefix}Using batch-size {b} for {d} {t * fraction:.2f}G/{t:.2f}G ({fraction * 100:.0f}%) ✅")
70 | return b
71 |
--------------------------------------------------------------------------------
/yolov5/utils/aws/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/aws/__init__.py
--------------------------------------------------------------------------------
/yolov5/utils/aws/mime.sh:
--------------------------------------------------------------------------------
1 | # AWS EC2 instance startup 'MIME' script https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/
2 | # This script will run on every instance restart, not only on first start
3 | # --- DO NOT COPY ABOVE COMMENTS WHEN PASTING INTO USERDATA ---
4 |
5 | Content-Type: multipart/mixed; boundary="//"
6 | MIME-Version: 1.0
7 |
8 | --//
9 | Content-Type: text/cloud-config; charset="us-ascii"
10 | MIME-Version: 1.0
11 | Content-Transfer-Encoding: 7bit
12 | Content-Disposition: attachment; filename="cloud-config.txt"
13 |
14 | #cloud-config
15 | cloud_final_modules:
16 | - [scripts-user, always]
17 |
18 | --//
19 | Content-Type: text/x-shellscript; charset="us-ascii"
20 | MIME-Version: 1.0
21 | Content-Transfer-Encoding: 7bit
22 | Content-Disposition: attachment; filename="userdata.txt"
23 |
24 | #!/bin/bash
25 | # --- paste contents of userdata.sh here ---
26 | --//
27 |
--------------------------------------------------------------------------------
/yolov5/utils/aws/resume.py:
--------------------------------------------------------------------------------
1 | # Resume all interrupted trainings in yolov5/ dir including DDP trainings
2 | # Usage: $ python utils/aws/resume.py
3 |
4 | import os
5 | import sys
6 | from pathlib import Path
7 |
8 | import torch
9 | import yaml
10 |
11 | FILE = Path(__file__).resolve()
12 | ROOT = FILE.parents[2] # YOLOv5 root directory
13 | if str(ROOT) not in sys.path:
14 | sys.path.append(str(ROOT)) # add ROOT to PATH
15 |
16 | port = 0 # --master_port
17 | path = Path("").resolve()
18 | for last in path.rglob("*/**/last.pt"):
19 | ckpt = torch.load(last)
20 | if ckpt["optimizer"] is None:
21 | continue
22 |
23 | # Load opt.yaml
24 | with open(last.parent.parent / "opt.yaml", errors="ignore") as f:
25 | opt = yaml.safe_load(f)
26 |
27 | # Get device count
28 | d = opt["device"].split(",") # devices
29 | nd = len(d) # number of devices
30 | ddp = nd > 1 or (nd == 0 and torch.cuda.device_count() > 1) # distributed data parallel
31 |
32 | if ddp: # multi-GPU
33 | port += 1
34 | cmd = f"python -m torch.distributed.run --nproc_per_node {nd} --master_port {port} train.py --resume {last}"
35 | else: # single-GPU
36 | cmd = f"python train.py --resume {last}"
37 |
38 | cmd += " > /dev/null 2>&1 &" # redirect output to dev/null and run in daemon thread
39 | print(cmd)
40 | os.system(cmd)
41 |
--------------------------------------------------------------------------------
/yolov5/utils/aws/userdata.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # AWS EC2 instance startup script https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
3 | # This script will run only once on first instance start (for a re-start script see mime.sh)
4 | # /home/ubuntu (ubuntu) or /home/ec2-user (amazon-linux) is working dir
5 | # Use >300 GB SSD
6 |
7 | cd home/ubuntu
8 | if [ ! -d yolov5 ]; then
9 | echo "Running first-time script." # install dependencies, download COCO, pull Docker
10 | git clone https://github.com/ultralytics/yolov5 -b master && sudo chmod -R 777 yolov5
11 | cd yolov5
12 | bash data/scripts/get_coco.sh && echo "COCO done." &
13 | sudo docker pull ultralytics/yolov5:latest && echo "Docker done." &
14 | python -m pip install --upgrade pip && pip install -r requirements.txt && python detect.py && echo "Requirements done." &
15 | wait && echo "All tasks done." # finish background tasks
16 | else
17 | echo "Running re-start script." # resume interrupted runs
18 | i=0
19 | list=$(sudo docker ps -qa) # container list i.e. $'one\ntwo\nthree\nfour'
20 | while IFS= read -r id; do
21 | ((i++))
22 | echo "restarting container $i: $id"
23 | sudo docker start $id
24 | # sudo docker exec -it $id python train.py --resume # single-GPU
25 | sudo docker exec -d $id python utils/aws/resume.py # multi-scenario
26 | done <<<"$list"
27 | fi
28 |
--------------------------------------------------------------------------------
/yolov5/utils/callbacks.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Callback utils."""
3 |
4 | import threading
5 |
6 |
7 | class Callbacks:
8 | """Handles all registered callbacks for YOLOv5 Hooks."""
9 |
10 | def __init__(self):
11 | """Initializes a Callbacks object to manage registered YOLOv5 training event hooks."""
12 | self._callbacks = {
13 | "on_pretrain_routine_start": [],
14 | "on_pretrain_routine_end": [],
15 | "on_train_start": [],
16 | "on_train_epoch_start": [],
17 | "on_train_batch_start": [],
18 | "optimizer_step": [],
19 | "on_before_zero_grad": [],
20 | "on_train_batch_end": [],
21 | "on_train_epoch_end": [],
22 | "on_val_start": [],
23 | "on_val_batch_start": [],
24 | "on_val_image_end": [],
25 | "on_val_batch_end": [],
26 | "on_val_end": [],
27 | "on_fit_epoch_end": [], # fit = train + val
28 | "on_model_save": [],
29 | "on_train_end": [],
30 | "on_params_update": [],
31 | "teardown": [],
32 | }
33 | self.stop_training = False # set True to interrupt training
34 |
35 | def register_action(self, hook, name="", callback=None):
36 | """
37 | Register a new action to a callback hook.
38 |
39 | Args:
40 | hook: The callback hook name to register the action to
41 | name: The name of the action for later reference
42 | callback: The callback to fire
43 | """
44 | assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}"
45 | assert callable(callback), f"callback '{callback}' is not callable"
46 | self._callbacks[hook].append({"name": name, "callback": callback})
47 |
48 | def get_registered_actions(self, hook=None):
49 | """
50 | Returns all the registered actions by callback hook.
51 |
52 | Args:
53 | hook: The name of the hook to check, defaults to all
54 | """
55 | return self._callbacks[hook] if hook else self._callbacks
56 |
57 | def run(self, hook, *args, thread=False, **kwargs):
58 | """
59 | Loop through the registered actions and fire all callbacks on main thread.
60 |
61 | Args:
62 | hook: The name of the hook to check, defaults to all
63 | args: Arguments to receive from YOLOv5
64 | thread: (boolean) Run callbacks in daemon thread
65 | kwargs: Keyword Arguments to receive from YOLOv5
66 | """
67 |
68 | assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}"
69 | for logger in self._callbacks[hook]:
70 | if thread:
71 | threading.Thread(target=logger["callback"], args=args, kwargs=kwargs, daemon=True).start()
72 | else:
73 | logger["callback"](*args, **kwargs)
74 |
--------------------------------------------------------------------------------
/yolov5/utils/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Builds ultralytics/yolov5:latest image on DockerHub https://hub.docker.com/r/ultralytics/yolov5
3 | # Image is CUDA-optimized for YOLOv5 single/multi-GPU training and inference
4 |
5 | # Start FROM PyTorch image https://hub.docker.com/r/pytorch/pytorch
6 | FROM pytorch/pytorch:2.0.0-cuda11.7-cudnn8-runtime
7 |
8 | # Downloads to user config dir
9 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/
10 |
11 | # Install linux packages
12 | ENV DEBIAN_FRONTEND noninteractive
13 | RUN apt update
14 | RUN TZ=Etc/UTC apt install -y tzdata
15 | RUN apt install --no-install-recommends -y gcc git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg
16 | # RUN alias python=python3
17 |
18 | # Security updates
19 | # https://security.snyk.io/vuln/SNYK-UBUNTU1804-OPENSSL-3314796
20 | RUN apt upgrade --no-install-recommends -y openssl
21 |
22 | # Create working directory
23 | RUN rm -rf /usr/src/app && mkdir -p /usr/src/app
24 | WORKDIR /usr/src/app
25 |
26 | # Copy contents
27 | COPY . /usr/src/app
28 |
29 | # Install pip packages
30 | COPY requirements.txt .
31 | RUN python3 -m pip install --upgrade pip wheel
32 | RUN pip install --no-cache -r requirements.txt albumentations comet gsutil notebook \
33 | coremltools onnx onnx-simplifier onnxruntime 'openvino-dev>=2023.0'
34 | # tensorflow tensorflowjs \
35 |
36 | # Set environment variables
37 | ENV OMP_NUM_THREADS=1
38 |
39 | # Cleanup
40 | ENV DEBIAN_FRONTEND teletype
41 |
42 |
43 | # Usage Examples -------------------------------------------------------------------------------------------------------
44 |
45 | # Build and Push
46 | # t=ultralytics/yolov5:latest && sudo docker build -f utils/docker/Dockerfile -t $t . && sudo docker push $t
47 |
48 | # Pull and Run
49 | # t=ultralytics/yolov5:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all $t
50 |
51 | # Pull and Run with local directory access
52 | # t=ultralytics/yolov5:latest && sudo docker pull $t && sudo docker run -it --ipc=host --gpus all -v "$(pwd)"/datasets:/usr/src/datasets $t
53 |
54 | # Kill all
55 | # sudo docker kill $(sudo docker ps -q)
56 |
57 | # Kill all image-based
58 | # sudo docker kill $(sudo docker ps -qa --filter ancestor=ultralytics/yolov5:latest)
59 |
60 | # DockerHub tag update
61 | # t=ultralytics/yolov5:latest tnew=ultralytics/yolov5:v6.2 && sudo docker pull $t && sudo docker tag $t $tnew && sudo docker push $tnew
62 |
63 | # Clean up
64 | # sudo docker system prune -a --volumes
65 |
66 | # Update Ubuntu drivers
67 | # https://www.maketecheasier.com/install-nvidia-drivers-ubuntu/
68 |
69 | # DDP test
70 | # python -m torch.distributed.run --nproc_per_node 2 --master_port 1 train.py --epochs 3
71 |
72 | # GCP VM from Image
73 | # docker.io/ultralytics/yolov5:latest
74 |
--------------------------------------------------------------------------------
/yolov5/utils/docker/Dockerfile-arm64:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Builds ultralytics/yolov5:latest-arm64 image on DockerHub https://hub.docker.com/r/ultralytics/yolov5
3 | # Image is aarch64-compatible for Apple M1 and other ARM architectures i.e. Jetson Nano and Raspberry Pi
4 |
5 | # Start FROM Ubuntu image https://hub.docker.com/_/ubuntu
6 | FROM arm64v8/ubuntu:22.10
7 |
8 | # Downloads to user config dir
9 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/
10 |
11 | # Install linux packages
12 | ENV DEBIAN_FRONTEND noninteractive
13 | RUN apt update
14 | RUN TZ=Etc/UTC apt install -y tzdata
15 | RUN apt install --no-install-recommends -y python3-pip git zip curl htop gcc libgl1 libglib2.0-0 libpython3-dev
16 | # RUN alias python=python3
17 |
18 | # Install pip packages
19 | COPY requirements.txt .
20 | RUN python3 -m pip install --upgrade pip wheel
21 | RUN pip install --no-cache -r requirements.txt albumentations gsutil notebook \
22 | coremltools onnx onnxruntime
23 | # tensorflow-aarch64 tensorflowjs \
24 |
25 | # Create working directory
26 | RUN mkdir -p /usr/src/app
27 | WORKDIR /usr/src/app
28 |
29 | # Copy contents
30 | COPY . /usr/src/app
31 | ENV DEBIAN_FRONTEND teletype
32 |
33 |
34 | # Usage Examples -------------------------------------------------------------------------------------------------------
35 |
36 | # Build and Push
37 | # t=ultralytics/yolov5:latest-arm64 && sudo docker build --platform linux/arm64 -f utils/docker/Dockerfile-arm64 -t $t . && sudo docker push $t
38 |
39 | # Pull and Run
40 | # t=ultralytics/yolov5:latest-arm64 && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/datasets:/usr/src/datasets $t
41 |
--------------------------------------------------------------------------------
/yolov5/utils/docker/Dockerfile-cpu:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | # Builds ultralytics/yolov5:latest-cpu image on DockerHub https://hub.docker.com/r/ultralytics/yolov5
3 | # Image is CPU-optimized for ONNX, OpenVINO and PyTorch YOLOv5 deployments
4 |
5 | # Start FROM Ubuntu image https://hub.docker.com/_/ubuntu
6 | FROM ubuntu:23.10
7 |
8 | # Downloads to user config dir
9 | ADD https://ultralytics.com/assets/Arial.ttf https://ultralytics.com/assets/Arial.Unicode.ttf /root/.config/Ultralytics/
10 |
11 | # Install linux packages
12 | # g++ required to build 'tflite_support' and 'lap' packages, libusb-1.0-0 required for 'tflite_support' package
13 | RUN apt update \
14 | && apt install --no-install-recommends -y python3-pip git zip curl htop libgl1 libglib2.0-0 libpython3-dev gnupg g++ libusb-1.0-0
15 | # RUN alias python=python3
16 |
17 | # Remove python3.11/EXTERNALLY-MANAGED or use 'pip install --break-system-packages' avoid 'externally-managed-environment' Ubuntu nightly error
18 | RUN rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED
19 |
20 | # Install pip packages
21 | COPY requirements.txt .
22 | RUN python3 -m pip install --upgrade pip wheel
23 | RUN pip install --no-cache -r requirements.txt albumentations gsutil notebook \
24 | coremltools onnx onnx-simplifier onnxruntime 'openvino-dev>=2023.0' \
25 | # tensorflow tensorflowjs \
26 | --extra-index-url https://download.pytorch.org/whl/cpu
27 |
28 | # Create working directory
29 | RUN mkdir -p /usr/src/app
30 | WORKDIR /usr/src/app
31 |
32 | # Copy contents
33 | COPY . /usr/src/app
34 |
35 |
36 | # Usage Examples -------------------------------------------------------------------------------------------------------
37 |
38 | # Build and Push
39 | # t=ultralytics/yolov5:latest-cpu && sudo docker build -f utils/docker/Dockerfile-cpu -t $t . && sudo docker push $t
40 |
41 | # Pull and Run
42 | # t=ultralytics/yolov5:latest-cpu && sudo docker pull $t && sudo docker run -it --ipc=host -v "$(pwd)"/datasets:/usr/src/datasets $t
43 |
--------------------------------------------------------------------------------
/yolov5/utils/downloads.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Download utils."""
3 |
4 | import logging
5 | import subprocess
6 | import urllib
7 | from pathlib import Path
8 |
9 | import requests
10 | import torch
11 |
12 |
13 | def is_url(url, check=True):
14 | """Determines if a string is a URL and optionally checks its existence online, returning a boolean."""
15 | try:
16 | url = str(url)
17 | result = urllib.parse.urlparse(url)
18 | assert all([result.scheme, result.netloc]) # check if is url
19 | return (urllib.request.urlopen(url).getcode() == 200) if check else True # check if exists online
20 | except (AssertionError, urllib.request.HTTPError):
21 | return False
22 |
23 |
24 | def gsutil_getsize(url=""):
25 | """
26 | Returns the size in bytes of a file at a Google Cloud Storage URL using `gsutil du`.
27 |
28 | Returns 0 if the command fails or output is empty.
29 | """
30 | output = subprocess.check_output(["gsutil", "du", url], shell=True, encoding="utf-8")
31 | return int(output.split()[0]) if output else 0
32 |
33 |
34 | def url_getsize(url="https://ultralytics.com/images/bus.jpg"):
35 | """Returns the size in bytes of a downloadable file at a given URL; defaults to -1 if not found."""
36 | response = requests.head(url, allow_redirects=True)
37 | return int(response.headers.get("content-length", -1))
38 |
39 |
40 | def curl_download(url, filename, *, silent: bool = False) -> bool:
41 | """Download a file from a url to a filename using curl."""
42 | silent_option = "sS" if silent else "" # silent
43 | proc = subprocess.run(
44 | [
45 | "curl",
46 | "-#",
47 | f"-{silent_option}L",
48 | url,
49 | "--output",
50 | filename,
51 | "--retry",
52 | "9",
53 | "-C",
54 | "-",
55 | ]
56 | )
57 | return proc.returncode == 0
58 |
59 |
60 | def safe_download(file, url, url2=None, min_bytes=1e0, error_msg=""):
61 | """
62 | Downloads a file from a URL (or alternate URL) to a specified path if file is above a minimum size.
63 |
64 | Removes incomplete downloads.
65 | """
66 | from utils.general import LOGGER
67 |
68 | file = Path(file)
69 | assert_msg = f"Downloaded file '{file}' does not exist or size is < min_bytes={min_bytes}"
70 | try: # url1
71 | LOGGER.info(f"Downloading {url} to {file}...")
72 | torch.hub.download_url_to_file(url, str(file), progress=LOGGER.level <= logging.INFO)
73 | assert file.exists() and file.stat().st_size > min_bytes, assert_msg # check
74 | except Exception as e: # url2
75 | if file.exists():
76 | file.unlink() # remove partial downloads
77 | LOGGER.info(f"ERROR: {e}\nRe-attempting {url2 or url} to {file}...")
78 | # curl download, retry and resume on fail
79 | curl_download(url2 or url, file)
80 | finally:
81 | if not file.exists() or file.stat().st_size < min_bytes: # check
82 | if file.exists():
83 | file.unlink() # remove partial downloads
84 | LOGGER.info(f"ERROR: {assert_msg}\n{error_msg}")
85 | LOGGER.info("")
86 |
87 |
88 | def attempt_download(file, repo="ultralytics/yolov5", release="v7.0"):
89 | """Downloads a file from GitHub release assets or via direct URL if not found locally, supporting backup
90 | versions.
91 | """
92 | from utils.general import LOGGER
93 |
94 | def github_assets(repository, version="latest"):
95 | # Return GitHub repo tag (i.e. 'v7.0') and assets (i.e. ['yolov5s.pt', 'yolov5m.pt', ...])
96 | if version != "latest":
97 | version = f"tags/{version}" # i.e. tags/v7.0
98 | response = requests.get(f"https://api.github.com/repos/{repository}/releases/{version}").json() # github api
99 | return response["tag_name"], [x["name"] for x in response["assets"]] # tag, assets
100 |
101 | file = Path(str(file).strip().replace("'", ""))
102 | if not file.exists():
103 | # URL specified
104 | name = Path(urllib.parse.unquote(str(file))).name # decode '%2F' to '/' etc.
105 | if str(file).startswith(("http:/", "https:/")): # download
106 | url = str(file).replace(":/", "://") # Pathlib turns :// -> :/
107 | file = name.split("?")[0] # parse authentication https://url.com/file.txt?auth...
108 | if Path(file).is_file():
109 | LOGGER.info(f"Found {url} locally at {file}") # file already exists
110 | else:
111 | safe_download(file=file, url=url, min_bytes=1e5)
112 | return file
113 |
114 | # GitHub assets
115 | assets = [f"yolov5{size}{suffix}.pt" for size in "nsmlx" for suffix in ("", "6", "-cls", "-seg")] # default
116 | try:
117 | tag, assets = github_assets(repo, release)
118 | except Exception:
119 | try:
120 | tag, assets = github_assets(repo) # latest release
121 | except Exception:
122 | try:
123 | tag = subprocess.check_output("git tag", shell=True, stderr=subprocess.STDOUT).decode().split()[-1]
124 | except Exception:
125 | tag = release
126 |
127 | if name in assets:
128 | file.parent.mkdir(parents=True, exist_ok=True) # make parent dir (if required)
129 | safe_download(
130 | file,
131 | url=f"https://github.com/{repo}/releases/download/{tag}/{name}",
132 | min_bytes=1e5,
133 | error_msg=f"{file} missing, try downloading from https://github.com/{repo}/releases/{tag}",
134 | )
135 |
136 | return str(file)
137 |
--------------------------------------------------------------------------------
/yolov5/utils/flask_rest_api/README.md:
--------------------------------------------------------------------------------
1 | # Flask REST API
2 |
3 | [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) [API](https://en.wikipedia.org/wiki/API)s are commonly used to expose Machine Learning (ML) models to other services. This folder contains an example REST API created using Flask to expose the YOLOv5s model from [PyTorch Hub](https://pytorch.org/hub/ultralytics_yolov5/).
4 |
5 | ## Requirements
6 |
7 | [Flask](https://palletsprojects.com/p/flask/) is required. Install with:
8 |
9 | ```shell
10 | $ pip install Flask
11 | ```
12 |
13 | ## Run
14 |
15 | After Flask installation run:
16 |
17 | ```shell
18 | $ python3 restapi.py --port 5000
19 | ```
20 |
21 | Then use [curl](https://curl.se/) to perform a request:
22 |
23 | ```shell
24 | $ curl -X POST -F image=@zidane.jpg 'http://localhost:5000/v1/object-detection/yolov5s'
25 | ```
26 |
27 | The model inference results are returned as a JSON response:
28 |
29 | ```json
30 | [
31 | {
32 | "class": 0,
33 | "confidence": 0.8900438547,
34 | "height": 0.9318675399,
35 | "name": "person",
36 | "width": 0.3264600933,
37 | "xcenter": 0.7438579798,
38 | "ycenter": 0.5207948685
39 | },
40 | {
41 | "class": 0,
42 | "confidence": 0.8440024257,
43 | "height": 0.7155083418,
44 | "name": "person",
45 | "width": 0.6546785235,
46 | "xcenter": 0.427829951,
47 | "ycenter": 0.6334488392
48 | },
49 | {
50 | "class": 27,
51 | "confidence": 0.3771208823,
52 | "height": 0.3902671337,
53 | "name": "tie",
54 | "width": 0.0696444362,
55 | "xcenter": 0.3675483763,
56 | "ycenter": 0.7991207838
57 | },
58 | {
59 | "class": 27,
60 | "confidence": 0.3527112305,
61 | "height": 0.1540903747,
62 | "name": "tie",
63 | "width": 0.0336618312,
64 | "xcenter": 0.7814827561,
65 | "ycenter": 0.5065554976
66 | }
67 | ]
68 | ```
69 |
70 | An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given in `example_request.py`
71 |
--------------------------------------------------------------------------------
/yolov5/utils/flask_rest_api/example_request.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Perform test request."""
3 |
4 | import pprint
5 |
6 | import requests
7 |
8 | DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s"
9 | IMAGE = "zidane.jpg"
10 |
11 | # Read image
12 | with open(IMAGE, "rb") as f:
13 | image_data = f.read()
14 |
15 | response = requests.post(DETECTION_URL, files={"image": image_data}).json()
16 |
17 | pprint.pprint(response)
18 |
--------------------------------------------------------------------------------
/yolov5/utils/flask_rest_api/restapi.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Run a Flask REST API exposing one or more YOLOv5s models."""
3 |
4 | import argparse
5 | import io
6 |
7 | import torch
8 | from flask import Flask, request
9 | from PIL import Image
10 |
11 | app = Flask(__name__)
12 | models = {}
13 |
14 | DETECTION_URL = "/v1/object-detection/"
15 |
16 |
17 | @app.route(DETECTION_URL, methods=["POST"])
18 | def predict(model):
19 | """Predict and return object detections in JSON format given an image and model name via a Flask REST API POST
20 | request.
21 | """
22 | if request.method != "POST":
23 | return
24 |
25 | if request.files.get("image"):
26 | # Method 1
27 | # with request.files["image"] as f:
28 | # im = Image.open(io.BytesIO(f.read()))
29 |
30 | # Method 2
31 | im_file = request.files["image"]
32 | im_bytes = im_file.read()
33 | im = Image.open(io.BytesIO(im_bytes))
34 |
35 | if model in models:
36 | results = models[model](im, size=640) # reduce size=320 for faster inference
37 | return results.pandas().xyxy[0].to_json(orient="records")
38 |
39 |
40 | if __name__ == "__main__":
41 | parser = argparse.ArgumentParser(description="Flask API exposing YOLOv5 model")
42 | parser.add_argument("--port", default=5000, type=int, help="port number")
43 | parser.add_argument("--model", nargs="+", default=["yolov5s"], help="model(s) to run, i.e. --model yolov5n yolov5s")
44 | opt = parser.parse_args()
45 |
46 | for m in opt.model:
47 | models[m] = torch.hub.load("ultralytics/yolov5", m, force_reload=True, skip_validation=True)
48 |
49 | app.run(host="0.0.0.0", port=opt.port) # debug=True causes Restarting with stat
50 |
--------------------------------------------------------------------------------
/yolov5/utils/google_app_engine/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM gcr.io/google-appengine/python
2 |
3 | # Create a virtualenv for dependencies. This isolates these packages from
4 | # system-level packages.
5 | # Use -p python3 or -p python3.7 to select python version. Default is version 2.
6 | RUN virtualenv /env -p python3
7 |
8 | # Setting these environment variables are the same as running
9 | # source /env/bin/activate.
10 | ENV VIRTUAL_ENV /env
11 | ENV PATH /env/bin:$PATH
12 |
13 | RUN apt-get update && apt-get install -y python-opencv
14 |
15 | # Copy the application's requirements.txt and run pip to install all
16 | # dependencies into the virtualenv.
17 | ADD requirements.txt /app/requirements.txt
18 | RUN pip install -r /app/requirements.txt
19 |
20 | # Add the application source code.
21 | ADD . /app
22 |
23 | # Run a WSGI server to serve the application. gunicorn must be declared as
24 | # a dependency in requirements.txt.
25 | CMD gunicorn -b :$PORT main:app
26 |
--------------------------------------------------------------------------------
/yolov5/utils/google_app_engine/additional_requirements.txt:
--------------------------------------------------------------------------------
1 | # add these requirements in your app on top of the existing ones
2 | pip==23.3
3 | Flask==2.3.2
4 | gunicorn==19.10.0
5 | werkzeug>=3.0.1 # not directly required, pinned by Snyk to avoid a vulnerability
6 |
--------------------------------------------------------------------------------
/yolov5/utils/google_app_engine/app.yaml:
--------------------------------------------------------------------------------
1 | runtime: custom
2 | env: flex
3 |
4 | service: yolov5app
5 |
6 | liveness_check:
7 | initial_delay_sec: 600
8 |
9 | manual_scaling:
10 | instances: 1
11 | resources:
12 | cpu: 1
13 | memory_gb: 4
14 | disk_size_gb: 20
15 |
--------------------------------------------------------------------------------
/yolov5/utils/loggers/clearml/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/loggers/clearml/__init__.py
--------------------------------------------------------------------------------
/yolov5/utils/loggers/clearml/hpo.py:
--------------------------------------------------------------------------------
1 | from clearml import Task
2 |
3 | # Connecting ClearML with the current process,
4 | # from here on everything is logged automatically
5 | from clearml.automation import HyperParameterOptimizer, UniformParameterRange
6 | from clearml.automation.optuna import OptimizerOptuna
7 |
8 | task = Task.init(
9 | project_name="Hyper-Parameter Optimization",
10 | task_name="YOLOv5",
11 | task_type=Task.TaskTypes.optimizer,
12 | reuse_last_task_id=False,
13 | )
14 |
15 | # Example use case:
16 | optimizer = HyperParameterOptimizer(
17 | # This is the experiment we want to optimize
18 | base_task_id="",
19 | # here we define the hyper-parameters to optimize
20 | # Notice: The parameter name should exactly match what you see in the UI: /
21 | # For Example, here we see in the base experiment a section Named: "General"
22 | # under it a parameter named "batch_size", this becomes "General/batch_size"
23 | # If you have `argparse` for example, then arguments will appear under the "Args" section,
24 | # and you should instead pass "Args/batch_size"
25 | hyper_parameters=[
26 | UniformParameterRange("Hyperparameters/lr0", min_value=1e-5, max_value=1e-1),
27 | UniformParameterRange("Hyperparameters/lrf", min_value=0.01, max_value=1.0),
28 | UniformParameterRange("Hyperparameters/momentum", min_value=0.6, max_value=0.98),
29 | UniformParameterRange("Hyperparameters/weight_decay", min_value=0.0, max_value=0.001),
30 | UniformParameterRange("Hyperparameters/warmup_epochs", min_value=0.0, max_value=5.0),
31 | UniformParameterRange("Hyperparameters/warmup_momentum", min_value=0.0, max_value=0.95),
32 | UniformParameterRange("Hyperparameters/warmup_bias_lr", min_value=0.0, max_value=0.2),
33 | UniformParameterRange("Hyperparameters/box", min_value=0.02, max_value=0.2),
34 | UniformParameterRange("Hyperparameters/cls", min_value=0.2, max_value=4.0),
35 | UniformParameterRange("Hyperparameters/cls_pw", min_value=0.5, max_value=2.0),
36 | UniformParameterRange("Hyperparameters/obj", min_value=0.2, max_value=4.0),
37 | UniformParameterRange("Hyperparameters/obj_pw", min_value=0.5, max_value=2.0),
38 | UniformParameterRange("Hyperparameters/iou_t", min_value=0.1, max_value=0.7),
39 | UniformParameterRange("Hyperparameters/anchor_t", min_value=2.0, max_value=8.0),
40 | UniformParameterRange("Hyperparameters/fl_gamma", min_value=0.0, max_value=4.0),
41 | UniformParameterRange("Hyperparameters/hsv_h", min_value=0.0, max_value=0.1),
42 | UniformParameterRange("Hyperparameters/hsv_s", min_value=0.0, max_value=0.9),
43 | UniformParameterRange("Hyperparameters/hsv_v", min_value=0.0, max_value=0.9),
44 | UniformParameterRange("Hyperparameters/degrees", min_value=0.0, max_value=45.0),
45 | UniformParameterRange("Hyperparameters/translate", min_value=0.0, max_value=0.9),
46 | UniformParameterRange("Hyperparameters/scale", min_value=0.0, max_value=0.9),
47 | UniformParameterRange("Hyperparameters/shear", min_value=0.0, max_value=10.0),
48 | UniformParameterRange("Hyperparameters/perspective", min_value=0.0, max_value=0.001),
49 | UniformParameterRange("Hyperparameters/flipud", min_value=0.0, max_value=1.0),
50 | UniformParameterRange("Hyperparameters/fliplr", min_value=0.0, max_value=1.0),
51 | UniformParameterRange("Hyperparameters/mosaic", min_value=0.0, max_value=1.0),
52 | UniformParameterRange("Hyperparameters/mixup", min_value=0.0, max_value=1.0),
53 | UniformParameterRange("Hyperparameters/copy_paste", min_value=0.0, max_value=1.0),
54 | ],
55 | # this is the objective metric we want to maximize/minimize
56 | objective_metric_title="metrics",
57 | objective_metric_series="mAP_0.5",
58 | # now we decide if we want to maximize it or minimize it (accuracy we maximize)
59 | objective_metric_sign="max",
60 | # let us limit the number of concurrent experiments,
61 | # this in turn will make sure we do dont bombard the scheduler with experiments.
62 | # if we have an auto-scaler connected, this, by proxy, will limit the number of machine
63 | max_number_of_concurrent_tasks=1,
64 | # this is the optimizer class (actually doing the optimization)
65 | # Currently, we can choose from GridSearch, RandomSearch or OptimizerBOHB (Bayesian optimization Hyper-Band)
66 | optimizer_class=OptimizerOptuna,
67 | # If specified only the top K performing Tasks will be kept, the others will be automatically archived
68 | save_top_k_tasks_only=5, # 5,
69 | compute_time_limit=None,
70 | total_max_jobs=20,
71 | min_iteration_per_job=None,
72 | max_iteration_per_job=None,
73 | )
74 |
75 | # report every 10 seconds, this is way too often, but we are testing here
76 | optimizer.set_report_period(10 / 60)
77 | # You can also use the line below instead to run all the optimizer tasks locally, without using queues or agent
78 | # an_optimizer.start_locally(job_complete_callback=job_complete_callback)
79 | # set the time limit for the optimization process (2 hours)
80 | optimizer.set_time_limit(in_minutes=120.0)
81 | # Start the optimization process in the local environment
82 | optimizer.start_locally()
83 | # wait until process is done (notice we are controlling the optimization process in the background)
84 | optimizer.wait()
85 | # make sure background optimization stopped
86 | optimizer.stop()
87 |
88 | print("We are done, good bye")
89 |
--------------------------------------------------------------------------------
/yolov5/utils/loggers/comet/comet_utils.py:
--------------------------------------------------------------------------------
1 | import logging
2 | import os
3 | from urllib.parse import urlparse
4 |
5 | try:
6 | import comet_ml
7 | except ImportError:
8 | comet_ml = None
9 |
10 | import yaml
11 |
12 | logger = logging.getLogger(__name__)
13 |
14 | COMET_PREFIX = "comet://"
15 | COMET_MODEL_NAME = os.getenv("COMET_MODEL_NAME", "yolov5")
16 | COMET_DEFAULT_CHECKPOINT_FILENAME = os.getenv("COMET_DEFAULT_CHECKPOINT_FILENAME", "last.pt")
17 |
18 |
19 | def download_model_checkpoint(opt, experiment):
20 | """Downloads YOLOv5 model checkpoint from Comet ML experiment, updating `opt.weights` with download path."""
21 | model_dir = f"{opt.project}/{experiment.name}"
22 | os.makedirs(model_dir, exist_ok=True)
23 |
24 | model_name = COMET_MODEL_NAME
25 | model_asset_list = experiment.get_model_asset_list(model_name)
26 |
27 | if len(model_asset_list) == 0:
28 | logger.error(f"COMET ERROR: No checkpoints found for model name : {model_name}")
29 | return
30 |
31 | model_asset_list = sorted(
32 | model_asset_list,
33 | key=lambda x: x["step"],
34 | reverse=True,
35 | )
36 | logged_checkpoint_map = {asset["fileName"]: asset["assetId"] for asset in model_asset_list}
37 |
38 | resource_url = urlparse(opt.weights)
39 | checkpoint_filename = resource_url.query
40 |
41 | if checkpoint_filename:
42 | asset_id = logged_checkpoint_map.get(checkpoint_filename)
43 | else:
44 | asset_id = logged_checkpoint_map.get(COMET_DEFAULT_CHECKPOINT_FILENAME)
45 | checkpoint_filename = COMET_DEFAULT_CHECKPOINT_FILENAME
46 |
47 | if asset_id is None:
48 | logger.error(f"COMET ERROR: Checkpoint {checkpoint_filename} not found in the given Experiment")
49 | return
50 |
51 | try:
52 | logger.info(f"COMET INFO: Downloading checkpoint {checkpoint_filename}")
53 | asset_filename = checkpoint_filename
54 |
55 | model_binary = experiment.get_asset(asset_id, return_type="binary", stream=False)
56 | model_download_path = f"{model_dir}/{asset_filename}"
57 | with open(model_download_path, "wb") as f:
58 | f.write(model_binary)
59 |
60 | opt.weights = model_download_path
61 |
62 | except Exception as e:
63 | logger.warning("COMET WARNING: Unable to download checkpoint from Comet")
64 | logger.exception(e)
65 |
66 |
67 | def set_opt_parameters(opt, experiment):
68 | """
69 | Update the opts Namespace with parameters from Comet's ExistingExperiment when resuming a run.
70 |
71 | Args:
72 | opt (argparse.Namespace): Namespace of command line options
73 | experiment (comet_ml.APIExperiment): Comet API Experiment object
74 | """
75 | asset_list = experiment.get_asset_list()
76 | resume_string = opt.resume
77 |
78 | for asset in asset_list:
79 | if asset["fileName"] == "opt.yaml":
80 | asset_id = asset["assetId"]
81 | asset_binary = experiment.get_asset(asset_id, return_type="binary", stream=False)
82 | opt_dict = yaml.safe_load(asset_binary)
83 | for key, value in opt_dict.items():
84 | setattr(opt, key, value)
85 | opt.resume = resume_string
86 |
87 | # Save hyperparameters to YAML file
88 | # Necessary to pass checks in training script
89 | save_dir = f"{opt.project}/{experiment.name}"
90 | os.makedirs(save_dir, exist_ok=True)
91 |
92 | hyp_yaml_path = f"{save_dir}/hyp.yaml"
93 | with open(hyp_yaml_path, "w") as f:
94 | yaml.dump(opt.hyp, f)
95 | opt.hyp = hyp_yaml_path
96 |
97 |
98 | def check_comet_weights(opt):
99 | """
100 | Downloads model weights from Comet and updates the weights path to point to saved weights location.
101 |
102 | Args:
103 | opt (argparse.Namespace): Command Line arguments passed
104 | to YOLOv5 training script
105 |
106 | Returns:
107 | None/bool: Return True if weights are successfully downloaded
108 | else return None
109 | """
110 | if comet_ml is None:
111 | return
112 |
113 | if isinstance(opt.weights, str) and opt.weights.startswith(COMET_PREFIX):
114 | api = comet_ml.API()
115 | resource = urlparse(opt.weights)
116 | experiment_path = f"{resource.netloc}{resource.path}"
117 | experiment = api.get(experiment_path)
118 | download_model_checkpoint(opt, experiment)
119 | return True
120 |
121 | return None
122 |
123 |
124 | def check_comet_resume(opt):
125 | """
126 | Restores run parameters to its original state based on the model checkpoint and logged Experiment parameters.
127 |
128 | Args:
129 | opt (argparse.Namespace): Command Line arguments passed
130 | to YOLOv5 training script
131 |
132 | Returns:
133 | None/bool: Return True if the run is restored successfully
134 | else return None
135 | """
136 | if comet_ml is None:
137 | return
138 |
139 | if isinstance(opt.resume, str) and opt.resume.startswith(COMET_PREFIX):
140 | api = comet_ml.API()
141 | resource = urlparse(opt.resume)
142 | experiment_path = f"{resource.netloc}{resource.path}"
143 | experiment = api.get(experiment_path)
144 | set_opt_parameters(opt, experiment)
145 | download_model_checkpoint(opt, experiment)
146 |
147 | return True
148 |
149 | return None
150 |
--------------------------------------------------------------------------------
/yolov5/utils/loggers/comet/optimizer_config.json:
--------------------------------------------------------------------------------
1 | {
2 | "algorithm": "random",
3 | "parameters": {
4 | "anchor_t": {
5 | "type": "discrete",
6 | "values": [2, 8]
7 | },
8 | "batch_size": {
9 | "type": "discrete",
10 | "values": [16, 32, 64]
11 | },
12 | "box": {
13 | "type": "discrete",
14 | "values": [0.02, 0.2]
15 | },
16 | "cls": {
17 | "type": "discrete",
18 | "values": [0.2]
19 | },
20 | "cls_pw": {
21 | "type": "discrete",
22 | "values": [0.5]
23 | },
24 | "copy_paste": {
25 | "type": "discrete",
26 | "values": [1]
27 | },
28 | "degrees": {
29 | "type": "discrete",
30 | "values": [0, 45]
31 | },
32 | "epochs": {
33 | "type": "discrete",
34 | "values": [5]
35 | },
36 | "fl_gamma": {
37 | "type": "discrete",
38 | "values": [0]
39 | },
40 | "fliplr": {
41 | "type": "discrete",
42 | "values": [0]
43 | },
44 | "flipud": {
45 | "type": "discrete",
46 | "values": [0]
47 | },
48 | "hsv_h": {
49 | "type": "discrete",
50 | "values": [0]
51 | },
52 | "hsv_s": {
53 | "type": "discrete",
54 | "values": [0]
55 | },
56 | "hsv_v": {
57 | "type": "discrete",
58 | "values": [0]
59 | },
60 | "iou_t": {
61 | "type": "discrete",
62 | "values": [0.7]
63 | },
64 | "lr0": {
65 | "type": "discrete",
66 | "values": [1e-5, 0.1]
67 | },
68 | "lrf": {
69 | "type": "discrete",
70 | "values": [0.01, 1]
71 | },
72 | "mixup": {
73 | "type": "discrete",
74 | "values": [1]
75 | },
76 | "momentum": {
77 | "type": "discrete",
78 | "values": [0.6]
79 | },
80 | "mosaic": {
81 | "type": "discrete",
82 | "values": [0]
83 | },
84 | "obj": {
85 | "type": "discrete",
86 | "values": [0.2]
87 | },
88 | "obj_pw": {
89 | "type": "discrete",
90 | "values": [0.5]
91 | },
92 | "optimizer": {
93 | "type": "categorical",
94 | "values": ["SGD", "Adam", "AdamW"]
95 | },
96 | "perspective": {
97 | "type": "discrete",
98 | "values": [0]
99 | },
100 | "scale": {
101 | "type": "discrete",
102 | "values": [0]
103 | },
104 | "shear": {
105 | "type": "discrete",
106 | "values": [0]
107 | },
108 | "translate": {
109 | "type": "discrete",
110 | "values": [0]
111 | },
112 | "warmup_bias_lr": {
113 | "type": "discrete",
114 | "values": [0, 0.2]
115 | },
116 | "warmup_epochs": {
117 | "type": "discrete",
118 | "values": [5]
119 | },
120 | "warmup_momentum": {
121 | "type": "discrete",
122 | "values": [0, 0.95]
123 | },
124 | "weight_decay": {
125 | "type": "discrete",
126 | "values": [0, 0.001]
127 | }
128 | },
129 | "spec": {
130 | "maxCombo": 0,
131 | "metric": "metrics/mAP_0.5",
132 | "objective": "maximize"
133 | },
134 | "trials": 1
135 | }
136 |
--------------------------------------------------------------------------------
/yolov5/utils/loggers/wandb/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/loggers/wandb/__init__.py
--------------------------------------------------------------------------------
/yolov5/utils/segment/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/utils/segment/__init__.py
--------------------------------------------------------------------------------
/yolov5/utils/segment/augmentations.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Image augmentation functions."""
3 |
4 | import math
5 | import random
6 |
7 | import cv2
8 | import numpy as np
9 |
10 | from ..augmentations import box_candidates
11 | from ..general import resample_segments, segment2box
12 |
13 |
14 | def mixup(im, labels, segments, im2, labels2, segments2):
15 | """
16 | Applies MixUp augmentation blending two images, labels, and segments with a random ratio.
17 |
18 | See https://arxiv.org/pdf/1710.09412.pdf
19 | """
20 | r = np.random.beta(32.0, 32.0) # mixup ratio, alpha=beta=32.0
21 | im = (im * r + im2 * (1 - r)).astype(np.uint8)
22 | labels = np.concatenate((labels, labels2), 0)
23 | segments = np.concatenate((segments, segments2), 0)
24 | return im, labels, segments
25 |
26 |
27 | def random_perspective(
28 | im, targets=(), segments=(), degrees=10, translate=0.1, scale=0.1, shear=10, perspective=0.0, border=(0, 0)
29 | ):
30 | # torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10))
31 | # targets = [cls, xyxy]
32 |
33 | height = im.shape[0] + border[0] * 2 # shape(h,w,c)
34 | width = im.shape[1] + border[1] * 2
35 |
36 | # Center
37 | C = np.eye(3)
38 | C[0, 2] = -im.shape[1] / 2 # x translation (pixels)
39 | C[1, 2] = -im.shape[0] / 2 # y translation (pixels)
40 |
41 | # Perspective
42 | P = np.eye(3)
43 | P[2, 0] = random.uniform(-perspective, perspective) # x perspective (about y)
44 | P[2, 1] = random.uniform(-perspective, perspective) # y perspective (about x)
45 |
46 | # Rotation and Scale
47 | R = np.eye(3)
48 | a = random.uniform(-degrees, degrees)
49 | # a += random.choice([-180, -90, 0, 90]) # add 90deg rotations to small rotations
50 | s = random.uniform(1 - scale, 1 + scale)
51 | # s = 2 ** random.uniform(-scale, scale)
52 | R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s)
53 |
54 | # Shear
55 | S = np.eye(3)
56 | S[0, 1] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # x shear (deg)
57 | S[1, 0] = math.tan(random.uniform(-shear, shear) * math.pi / 180) # y shear (deg)
58 |
59 | # Translation
60 | T = np.eye(3)
61 | T[0, 2] = random.uniform(0.5 - translate, 0.5 + translate) * width # x translation (pixels)
62 | T[1, 2] = random.uniform(0.5 - translate, 0.5 + translate) * height # y translation (pixels)
63 |
64 | # Combined rotation matrix
65 | M = T @ S @ R @ P @ C # order of operations (right to left) is IMPORTANT
66 | if (border[0] != 0) or (border[1] != 0) or (M != np.eye(3)).any(): # image changed
67 | if perspective:
68 | im = cv2.warpPerspective(im, M, dsize=(width, height), borderValue=(114, 114, 114))
69 | else: # affine
70 | im = cv2.warpAffine(im, M[:2], dsize=(width, height), borderValue=(114, 114, 114))
71 |
72 | # Visualize
73 | # import matplotlib.pyplot as plt
74 | # ax = plt.subplots(1, 2, figsize=(12, 6))[1].ravel()
75 | # ax[0].imshow(im[:, :, ::-1]) # base
76 | # ax[1].imshow(im2[:, :, ::-1]) # warped
77 |
78 | # Transform label coordinates
79 | n = len(targets)
80 | new_segments = []
81 | if n:
82 | new = np.zeros((n, 4))
83 | segments = resample_segments(segments) # upsample
84 | for i, segment in enumerate(segments):
85 | xy = np.ones((len(segment), 3))
86 | xy[:, :2] = segment
87 | xy = xy @ M.T # transform
88 | xy = xy[:, :2] / xy[:, 2:3] if perspective else xy[:, :2] # perspective rescale or affine
89 |
90 | # clip
91 | new[i] = segment2box(xy, width, height)
92 | new_segments.append(xy)
93 |
94 | # filter candidates
95 | i = box_candidates(box1=targets[:, 1:5].T * s, box2=new.T, area_thr=0.01)
96 | targets = targets[i]
97 | targets[:, 1:5] = new[i]
98 | new_segments = np.array(new_segments)[i]
99 |
100 | return im, targets, new_segments
101 |
--------------------------------------------------------------------------------
/yolov5/utils/triton.py:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
2 | """Utils to interact with the Triton Inference Server."""
3 |
4 | import typing
5 | from urllib.parse import urlparse
6 |
7 | import torch
8 |
9 |
10 | class TritonRemoteModel:
11 | """
12 | A wrapper over a model served by the Triton Inference Server.
13 |
14 | It can be configured to communicate over GRPC or HTTP. It accepts Torch Tensors as input and returns them as
15 | outputs.
16 | """
17 |
18 | def __init__(self, url: str):
19 | """
20 | Keyword arguments:
21 | url: Fully qualified address of the Triton server - for e.g. grpc://localhost:8000
22 | """
23 |
24 | parsed_url = urlparse(url)
25 | if parsed_url.scheme == "grpc":
26 | from tritonclient.grpc import InferenceServerClient, InferInput
27 |
28 | self.client = InferenceServerClient(parsed_url.netloc) # Triton GRPC client
29 | model_repository = self.client.get_model_repository_index()
30 | self.model_name = model_repository.models[0].name
31 | self.metadata = self.client.get_model_metadata(self.model_name, as_json=True)
32 |
33 | def create_input_placeholders() -> typing.List[InferInput]:
34 | return [
35 | InferInput(i["name"], [int(s) for s in i["shape"]], i["datatype"]) for i in self.metadata["inputs"]
36 | ]
37 |
38 | else:
39 | from tritonclient.http import InferenceServerClient, InferInput
40 |
41 | self.client = InferenceServerClient(parsed_url.netloc) # Triton HTTP client
42 | model_repository = self.client.get_model_repository_index()
43 | self.model_name = model_repository[0]["name"]
44 | self.metadata = self.client.get_model_metadata(self.model_name)
45 |
46 | def create_input_placeholders() -> typing.List[InferInput]:
47 | return [
48 | InferInput(i["name"], [int(s) for s in i["shape"]], i["datatype"]) for i in self.metadata["inputs"]
49 | ]
50 |
51 | self._create_input_placeholders_fn = create_input_placeholders
52 |
53 | @property
54 | def runtime(self):
55 | """Returns the model runtime."""
56 | return self.metadata.get("backend", self.metadata.get("platform"))
57 |
58 | def __call__(self, *args, **kwargs) -> typing.Union[torch.Tensor, typing.Tuple[torch.Tensor, ...]]:
59 | """
60 | Invokes the model.
61 |
62 | Parameters can be provided via args or kwargs. args, if provided, are assumed to match the order of inputs of
63 | the model. kwargs are matched with the model input names.
64 | """
65 | inputs = self._create_inputs(*args, **kwargs)
66 | response = self.client.infer(model_name=self.model_name, inputs=inputs)
67 | result = []
68 | for output in self.metadata["outputs"]:
69 | tensor = torch.as_tensor(response.as_numpy(output["name"]))
70 | result.append(tensor)
71 | return result[0] if len(result) == 1 else result
72 |
73 | def _create_inputs(self, *args, **kwargs):
74 | """Creates input tensors from args or kwargs, not both; raises error if none or both are provided."""
75 | args_len, kwargs_len = len(args), len(kwargs)
76 | if not args_len and not kwargs_len:
77 | raise RuntimeError("No inputs provided.")
78 | if args_len and kwargs_len:
79 | raise RuntimeError("Cannot specify args and kwargs at the same time")
80 |
81 | placeholders = self._create_input_placeholders_fn()
82 | if args_len:
83 | if args_len != len(placeholders):
84 | raise RuntimeError(f"Expected {len(placeholders)} inputs, got {args_len}.")
85 | for input, value in zip(placeholders, args):
86 | input.set_data_from_numpy(value.cpu().numpy())
87 | else:
88 | for input in placeholders:
89 | value = kwargs[input.name]
90 | input.set_data_from_numpy(value.cpu().numpy())
91 | return placeholders
92 |
--------------------------------------------------------------------------------
/yolov5/yolov5s.pt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saaachis/WeSee/2b83645a961cdefa42febde4dccd6b8a5c98cf1d/yolov5/yolov5s.pt
--------------------------------------------------------------------------------