Reference datasets
This file describes methods associated with dataset creation and metadata.
DatasetFactory
Base class for creating datasets.
Attributes:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
summary |
dict
|
Summary of the dataset. |
root |
str
|
Root directory for the data. |
update_wrong_labels(bool) |
str
|
Whether |
unknown_name |
str
|
Name of the unknown class. |
outdated_dataset |
bool
|
Tracks whether dataset was replaced by a new version. |
determined_by_df |
bool
|
Specifies whether dataset is completely determined by its dataframe. |
saved_to_system_folder |
bool
|
Specifies whether dataset is saved to system (hidden) folders. |
transform |
Callable
|
Applied transform when loading the image. |
img_load |
str
|
Applied transform when loading the image. |
labels_string |
List[str]
|
List of labels in strings. |
Source code in wildlife_datasets/datasets/datasets.py
12 13 14 15 16 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 62 63 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 98 99 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 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 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 218 219 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 261 262 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 300 301 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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
|
__getitem__(idx)
Load an image with iloc idx
with transforms self.transform
and self.img_load
applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Index of the image. |
required |
Returns:
Type | Description |
---|---|
Image
|
Loaded image. |
Source code in wildlife_datasets/datasets/datasets.py
100 101 102 103 104 105 106 107 108 109 110 111 |
|
__init__(root=None, df=None, update_wrong_labels=True, transform=None, img_load='full', remove_unknown=False, **kwargs)
Initializes the class.
If df
is specified, it copies it. Otherwise, it creates it
by the create_catalogue
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
Optional[str]
|
Root directory for the data. |
None
|
df |
Optional[DataFrame]
|
A full dataframe of the data. |
None
|
update_wrong_labels |
bool
|
Whether |
True
|
transform |
Optional[Callable]
|
Applied transform when loading the image. |
None
|
img_load |
str
|
Applied transform when loading the image. |
'full'
|
remove_unknown |
bool
|
Whether unknown identities should be removed. |
False
|
Source code in wildlife_datasets/datasets/datasets.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
apply_segmentation(img, idx)
Applies segmentation or bounding box when loading an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
Image
|
Loaded image. |
required |
idx |
int
|
Index of the image. |
required |
Returns:
Type | Description |
---|---|
Image
|
Loaded image. |
Source code in wildlife_datasets/datasets/datasets.py
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 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 218 219 220 221 222 223 224 225 |
|
check_files_exist(col)
Checks if paths in a given column exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
col |
Series
|
A column of a dataframe. |
required |
Source code in wildlife_datasets/datasets/datasets.py
586 587 588 589 590 591 592 593 594 595 |
|
check_files_names(col)
Checks if paths contain .
Parameters:
Name | Type | Description | Default |
---|---|---|---|
col |
Series
|
A column of a dataframe. |
required |
Source code in wildlife_datasets/datasets/datasets.py
597 598 599 600 601 602 603 604 605 606 607 608 |
|
check_required_columns(df)
Check if all required columns are present.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
Source code in wildlife_datasets/datasets/datasets.py
451 452 453 454 455 456 457 458 459 460 |
|
check_types_column(col, col_name, allowed_types)
Checks if the column col
is in the format allowed_types
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
col |
Series
|
Column to be checked. |
required |
col_name |
str
|
Column name used only for raising exceptions. |
required |
allowed_types |
List[str]
|
List of strings with allowed values:
|
required |
Source code in wildlife_datasets/datasets/datasets.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
|
check_types_columns(df)
Checks if columns are in correct formats.
The format are specified in requirements
, which is list
of tuples. The first value is the name of the column
and the second value is a list of formats. The column
must be at least one of the formats.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
Source code in wildlife_datasets/datasets/datasets.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
check_unique_id(df)
Checks if values in the id column are unique.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
Source code in wildlife_datasets/datasets/datasets.py
576 577 578 579 580 581 582 583 584 |
|
create_catalogue()
Creates the dataframe.
Raises:
Type | Description |
---|---|
NotImplementedError
|
Needs to be implemented by subclasses. |
Source code in wildlife_datasets/datasets/datasets.py
336 337 338 339 340 341 342 343 |
|
display_name()
classmethod
Returns name of the dataset without the v2 ending.
Returns:
Type | Description |
---|---|
str
|
Name of the dataset. |
Source code in wildlife_datasets/datasets/datasets.py
304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
download(root, force=False, **kwargs)
classmethod
Downloads the data. Wrapper around cls._download
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
str
|
Where the data should be stored. |
required |
force |
bool
|
It the root exists, whether it should be overwritten. |
False
|
Source code in wildlife_datasets/datasets/datasets.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
extract(root, **kwargs)
classmethod
Extract the data. Wrapper around cls._extract
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
str
|
Where the data should be stored. |
required |
Source code in wildlife_datasets/datasets/datasets.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
finalize_catalogue(df)
Reorders the dataframe and check file paths.
Reorders the columns and removes constant columns. Checks if columns are in correct formats. Checks if ids are unique and if all files exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A full dataframe of the data, slightly modified. |
Source code in wildlife_datasets/datasets/datasets.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
fix_labels(df)
Fixes labels in dataframe.
Automatically called in finalize_catalogue
.
Source code in wildlife_datasets/datasets/datasets.py
345 346 347 348 349 350 351 |
|
fix_labels_remove_identity(df, identities_to_remove, col='identity')
Removes all instances of identities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
identities_to_remove |
List
|
List of identities to remove. |
required |
col |
str
|
Column to remove from. |
'identity'
|
Returns:
Type | Description |
---|---|
DataFrame
|
A full dataframe of the data. |
Source code in wildlife_datasets/datasets/datasets.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
fix_labels_replace_identity(df, replace_identity, col='identity')
Replaces all instances of identities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
replace_identity |
List[Tuple]
|
List of (old_identity, new_identity) |
required |
col |
str
|
Column to replace in. |
'identity'
|
Returns:
Type | Description |
---|---|
DataFrame
|
A full dataframe of the data. |
Source code in wildlife_datasets/datasets/datasets.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
fix_labels_replace_images(df, replace_identity, col='identity')
Replaces specified images with specified identities.
It looks for a subset of image_name in df['path'].
It may cause problems with os.path.sep
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
replace_identity |
List[Tuple]
|
List of (image_name, old_identity, new_identity). |
required |
col |
str
|
Column to replace in. |
'identity'
|
Returns:
Type | Description |
---|---|
DataFrame
|
A full dataframe of the data. |
Source code in wildlife_datasets/datasets/datasets.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
|
get_data(root, force=False, **kwargs)
classmethod
Downloads and extracts the data. Wrapper around cls._download
and cls._extract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
str
|
Where the data should be stored. |
required |
force |
bool
|
It the root exists, whether it should be overwritten. |
False
|
Source code in wildlife_datasets/datasets/datasets.py
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 |
|
get_image(idx)
Load an image with iloc idx
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Index of the image. |
required |
Returns:
Type | Description |
---|---|
Image
|
Loaded image. |
Source code in wildlife_datasets/datasets/datasets.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
load_image(path)
Load an image with path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the image. |
required |
Returns:
Type | Description |
---|---|
Image
|
Loaded image. |
Source code in wildlife_datasets/datasets/datasets.py
131 132 133 134 135 136 137 138 139 140 141 |
|
plot_grid(n_rows=5, n_cols=8, offset=10, img_min=100, rotate=True, header_cols=None, idx=None, background_color=(0, 0, 0), **kwargs)
Plots a grid of size (n_rows, n_cols) with images from the dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_rows |
int
|
The number of rows in the grid. |
5
|
n_cols |
int
|
The number of columns in the grid. |
8
|
offset |
float
|
The offset between images. |
10
|
img_min |
float
|
The minimal size of the plotted images. |
100
|
rotate |
bool
|
Rotates the images to have the same orientation. |
True
|
header_cols |
Optional[List[str]]
|
List of headers for each column. |
None
|
idx |
Optional[Union[List[bool], List[int]]]
|
List of indices to plot. None plots random images. Index -1 plots an empty image. |
None
|
background_color |
Tuple[int]
|
Background color of the grid. |
(0, 0, 0)
|
Source code in wildlife_datasets/datasets/datasets.py
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
|
remove_constant_columns(df)
Removes columns with a single unique value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A full dataframe of the data, slightly modified. |
Source code in wildlife_datasets/datasets/datasets.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
reorder_df(df)
Reorders rows and columns in the dataframe.
Rows are sorted based on id.
Columns are reorder based on the default_order
list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
A full dataframe of the data. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
A full dataframe of the data, slightly modified. |
Source code in wildlife_datasets/datasets/datasets.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
Metadata
Class for storing metadata.
Attributes:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
A dataframe of the metadata. |
Source code in wildlife_datasets/datasets/summary.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
__init__(path)
Loads the metadata from a csv file into a dataframe.
The animals
column is converted to a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path of the csv file. |
required |
Source code in wildlife_datasets/datasets/summary.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Utils
bbox_segmentation(bbox)
Convert bounding box to segmentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox |
List[float]
|
Bounding box in the form [x, y, w, h]. |
required |
Returns:
Type | Description |
---|---|
List[float]
|
Segmentation mask in the form [x1, y1, x2, y2, ...]. |
Source code in wildlife_datasets/datasets/utils.py
94 95 96 97 98 99 100 101 102 103 104 |
|
create_id(string_col)
Creates unique ids from string based on MD5 hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_col |
Series
|
List of ids. |
required |
Returns:
Type | Description |
---|---|
Series
|
List of encoded ids. |
Source code in wildlife_datasets/datasets/utils.py
80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
crop_black(img)
Crops black borders from an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
Image
|
Image to be cropped. |
required |
Returns:
Type | Description |
---|---|
Image
|
Cropped image. |
Source code in wildlife_datasets/datasets/utils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
data_directory(dir)
Changes context such that data directory is used as current work directory. Data directory is created if it does not exist.
Source code in wildlife_datasets/datasets/utils.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
find_images(root, img_extensions=('.png', '.jpg', '.jpeg'))
Finds all image files in folder and subfolders.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root |
str
|
The root folder where to look for images. |
required |
img_extensions |
Tuple[str, ...]
|
Image extensions to look for, by default ('.png', '.jpg', '.jpeg'). |
('.png', '.jpg', '.jpeg')
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe of relative paths of the images. |
Source code in wildlife_datasets/datasets/utils.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
is_annotation_bbox(segmentation, bbox, tol=0)
Checks whether segmentation is bounding box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segmentation |
List[float]
|
Segmentation mask in the form [x1, y1, x2, y2, ...]. |
required |
bbox |
List[float]
|
Bounding box in the form [x, y, w, h]. |
required |
tol |
float
|
Tolerance for difference. |
0
|
Returns:
Type | Description |
---|---|
bool
|
True if segmentation is bounding box within tolerance. |
Source code in wildlife_datasets/datasets/utils.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
load_image(path, max_size=None)
Loads an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path of the image. |
required |
max_size |
int
|
Maximal size of the image or None (no restriction). |
None
|
Returns:
Type | Description |
---|---|
Image
|
Loaded image. |
Source code in wildlife_datasets/datasets/utils.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
segmentation_bbox(segmentation)
Convert segmentation to bounding box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segmentation |
List[float]
|
Segmentation mask in the form [x1, y1, x2, y2, ...]. |
required |
Returns:
Type | Description |
---|---|
List[float]
|
Bounding box in the form [x, y, w, h]. |
Source code in wildlife_datasets/datasets/utils.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|