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: ndarray, bbox2: ndarray, eps: float = 1e-06) -> np.ndarray
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
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 62 |
|
ultralytics.data.split_dota.load_yolo_dota
load_yolo_dota(data_root: str, split: str = 'train') -> List[Dict[str, Any]]
Load DOTA dataset annotations and image information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_root
|
str
|
Data root directory. |
required |
split
|
str
|
The split data set, could be 'train' or 'val'. |
'train'
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
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
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 98 |
|
ultralytics.data.split_dota.get_windows
get_windows(
im_size: Tuple[int, int],
crop_sizes: Tuple[int, ...] = (1024,),
gaps: Tuple[int, ...] = (200,),
im_rate_thr: float = 0.6,
eps: float = 0.01,
) -> np.ndarray
Get the coordinates of sliding windows for image cropping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im_size
|
Tuple[int, int]
|
Original image size, (H, W). |
required |
crop_sizes
|
Tuple[int, ...]
|
Crop size of windows. |
(1024,)
|
gaps
|
Tuple[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
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 145 146 147 148 149 150 151 |
|
ultralytics.data.split_dota.get_window_obj
get_window_obj(
anno: Dict[str, Any], windows: ndarray, iof_thr: float = 0.7
) -> List[np.ndarray]
Get objects for each window based on IoF threshold.
Source code in ultralytics/data/split_dota.py
154 155 156 157 158 159 160 161 162 163 164 165 |
|
ultralytics.data.split_dota.crop_and_save
crop_and_save(
anno: Dict[str, Any],
windows: ndarray,
window_objs: List[ndarray],
im_dir: str,
lb_dir: str,
allow_background_images: bool = True,
) -> None
Crop images and save new labels for each window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
anno
|
Dict[str, Any]
|
Annotation dict, including 'filepath', 'label', 'ori_size' as its keys. |
required |
windows
|
ndarray
|
Array of windows coordinates with shape (N, 4). |
required |
window_objs
|
List[ndarray]
|
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
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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
ultralytics.data.split_dota.split_images_and_labels
split_images_and_labels(
data_root: str,
save_dir: str,
split: str = "train",
crop_sizes: Tuple[int, ...] = (1024,),
gaps: Tuple[int, ...] = (200,),
) -> None
Split both images and labels for a given dataset split.
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' or 'val'. |
'train'
|
crop_sizes
|
Tuple[int, ...]
|
Tuple of crop sizes. |
(1024,)
|
gaps
|
Tuple[int, ...]
|
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
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
ultralytics.data.split_dota.split_trainval
split_trainval(
data_root: str,
save_dir: str,
crop_size: int = 1024,
gap: int = 200,
rates: Tuple[float, ...] = (1.0,),
) -> None
Split train and val sets of DOTA dataset with multiple scaling rates.
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[float, ...]
|
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
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
ultralytics.data.split_dota.split_test
split_test(
data_root: str,
save_dir: str,
crop_size: int = 1024,
gap: int = 200,
rates: Tuple[float, ...] = (1.0,),
) -> None
Split test set of DOTA dataset, 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[float, ...]
|
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
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|