Reference for ultralytics/data/split_dota.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/data/split_dota.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.data.split_dota.bbox_iof
bbox_iof(polygon1, bbox2, eps=1e-06)
Calculate Intersection over Foreground (IoF) between polygons and bounding boxes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon1
|
ndarray
|
Polygon coordinates with shape (n, 8). |
required |
bbox2
|
ndarray
|
Bounding boxes with shape (n, 4). |
required |
eps
|
float
|
Small value to prevent division by zero. |
1e-06
|
Returns:
Type | Description |
---|---|
ndarray
|
IoF scores with shape (n, 1) or (n, m) if bbox2 is (m, 4). |
Notes
Polygon format: [x1, y1, x2, y2, x3, y3, x4, y4]. Bounding box format: [x_min, y_min, x_max, y_max].
Source code in ultralytics/data/split_dota.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
ultralytics.data.split_dota.load_yolo_dota
load_yolo_dota(data_root, split='train')
Load DOTA dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_root
|
str
|
Data root directory. |
required |
split
|
str
|
The split data set, could be |
'train'
|
Returns:
Type | Description |
---|---|
List[Dict]
|
List of annotation dictionaries containing image information. |
Notes
The directory structure assumed for the DOTA dataset: - data_root - images - train - val - labels - train - val
Source code in ultralytics/data/split_dota.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
ultralytics.data.split_dota.get_windows
get_windows(
im_size, crop_sizes=(1024,), gaps=(200,), im_rate_thr=0.6, eps=0.01
)
Get the coordinates of windows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im_size
|
tuple
|
Original image size, (h, w). |
required |
crop_sizes
|
List[int]
|
Crop size of windows. |
(1024,)
|
gaps
|
List[int]
|
Gap between crops. |
(200,)
|
im_rate_thr
|
float
|
Threshold of windows areas divided by image areas. |
0.6
|
eps
|
float
|
Epsilon value for math operations. |
0.01
|
Returns:
Type | Description |
---|---|
ndarray
|
Array of window coordinates with shape (n, 4) where each row is [x_start, y_start, x_stop, y_stop]. |
Source code in ultralytics/data/split_dota.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
ultralytics.data.split_dota.get_window_obj
get_window_obj(anno, windows, iof_thr=0.7)
Get objects for each window.
Source code in ultralytics/data/split_dota.py
147 148 149 150 151 152 153 154 155 156 157 158 |
|
ultralytics.data.split_dota.crop_and_save
crop_and_save(
anno, windows, window_objs, im_dir, lb_dir, allow_background_images=True
)
Crop images and save new labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
anno
|
dict
|
Annotation dict, including |
required |
windows
|
ndarray
|
Array of windows coordinates with shape (n, 4). |
required |
window_objs
|
list
|
A list of labels inside each window. |
required |
im_dir
|
str
|
The output directory path of images. |
required |
lb_dir
|
str
|
The output directory path of labels. |
required |
allow_background_images
|
bool
|
Whether to include background images without labels. |
True
|
Notes
The directory structure assumed for the DOTA dataset: - data_root - images - train - val - labels - train - val
Source code in ultralytics/data/split_dota.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
ultralytics.data.split_dota.split_images_and_labels
split_images_and_labels(
data_root, save_dir, split="train", crop_sizes=(1024,), gaps=(200,)
)
Split both images and labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_root
|
str
|
Root directory of the dataset. |
required |
save_dir
|
str
|
Directory to save the split dataset. |
required |
split
|
str
|
The split data set, could be |
'train'
|
crop_sizes
|
tuple
|
Tuple of crop sizes. |
(1024,)
|
gaps
|
tuple
|
Tuple of gaps between crops. |
(200,)
|
Notes
The directory structure assumed for the DOTA dataset: - data_root - images - split - labels - split and the output directory structure is: - save_dir - images - split - labels - split
Source code in ultralytics/data/split_dota.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
ultralytics.data.split_dota.split_trainval
split_trainval(data_root, save_dir, crop_size=1024, gap=200, rates=(1.0,))
Split train and val set of DOTA.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_root
|
str
|
Root directory of the dataset. |
required |
save_dir
|
str
|
Directory to save the split dataset. |
required |
crop_size
|
int
|
Base crop size. |
1024
|
gap
|
int
|
Base gap between crops. |
200
|
rates
|
tuple
|
Scaling rates for crop_size and gap. |
(1.0,)
|
Notes
The directory structure assumed for the DOTA dataset: - data_root - images - train - val - labels - train - val and the output directory structure is: - save_dir - images - train - val - labels - train - val
Source code in ultralytics/data/split_dota.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
ultralytics.data.split_dota.split_test
split_test(data_root, save_dir, crop_size=1024, gap=200, rates=(1.0,))
Split test set of DOTA, labels are not included within this set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_root
|
str
|
Root directory of the dataset. |
required |
save_dir
|
str
|
Directory to save the split dataset. |
required |
crop_size
|
int
|
Base crop size. |
1024
|
gap
|
int
|
Base gap between crops. |
200
|
rates
|
tuple
|
Scaling rates for crop_size and gap. |
(1.0,)
|
Notes
The directory structure assumed for the DOTA dataset: - data_root - images - test and the output directory structure is: - save_dir - images - test
Source code in ultralytics/data/split_dota.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|