classification
ClassificationDataModule(data_path, dataset=ImageClassificationListDataset, name='classification_datamodule', num_workers=8, batch_size=32, seed=42, val_size=0.2, test_size=0.2, num_data_class=None, exclude_filter=None, include_filter=None, label_map=None, load_aug_images=False, aug_name=None, n_aug_to_take=4, replace_str_from=None, replace_str_to=None, train_transform=None, val_transform=None, test_transform=None, train_split_file=None, test_split_file=None, val_split_file=None, class_to_idx=None, **kwargs)
¶
Bases: BaseDataModule
Base class single folder based classification datamodules. If there is no nested folders, use this class.
Parameters:
-
data_path
(
str
) –Path to the data main folder.
-
name
(
str
, default:'classification_datamodule'
) –The name for the data module. Defaults to "classification_datamodule".
-
num_workers
(
int
, default:8
) –Number of workers for dataloaders. Defaults to 16.
-
batch_size
(
int
, default:32
) –Batch size. Defaults to 32.
-
seed
(
int
, default:42
) –Random generator seed. Defaults to 42.
-
dataset
(
type[ImageClassificationListDataset]
, default:ImageClassificationListDataset
) –Dataset class.
-
val_size
(
float | None
, default:0.2
) –The validation split. Defaults to 0.2.
-
test_size
(
float
, default:0.2
) –The test split. Defaults to 0.2.
-
exclude_filter
(
list[str] | None
, default:None
) –The filter for excluding folders. Defaults to None.
-
include_filter
(
list[str] | None
, default:None
) –The filter for including folders. Defaults to None.
-
label_map
(
dict[str, Any] | None
, default:None
) –The mapping for labels. Defaults to None.
-
num_data_class
(
int | None
, default:None
) –The number of samples per class. Defaults to None.
-
train_transform
(
Compose | None
, default:None
) –Transformations for train dataset. Defaults to None.
-
val_transform
(
Compose | None
, default:None
) –Transformations for validation dataset. Defaults to None.
-
test_transform
(
Compose | None
, default:None
) –Transformations for test dataset. Defaults to None.
-
train_split_file
(
str | None
, default:None
) –The file with train split. Defaults to None.
-
val_split_file
(
str | None
, default:None
) –The file with validation split. Defaults to None.
-
test_split_file
(
str | None
, default:None
) –The file with test split. Defaults to None.
-
class_to_idx
(
dict[str, int] | None
, default:None
) –The mapping from class name to index. Defaults to None.
-
**kwargs
(
Any
, default:{}
) –Additional arguments for BaseDataModule.
Source code in quadra/datamodules/classification.py
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 |
|
predict_dataloader()
¶
Returns a dataloader used for predictions.
Source code in quadra/datamodules/classification.py
418 419 420 |
|
setup(stage=None)
¶
Setup data module based on stages of training.
Source code in quadra/datamodules/classification.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
test_dataloader()
¶
Returns the test dataloader.
Raises:
-
ValueError
–If test dataset is not initialized.
Returns:
-
DataLoader
–test dataloader.
Source code in quadra/datamodules/classification.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
train_dataloader()
¶
Returns the train dataloader.
Raises:
-
ValueError
–If train dataset is not initialized.
Returns:
-
DataLoader
–Train dataloader.
Source code in quadra/datamodules/classification.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
val_dataloader()
¶
Returns the validation dataloader.
Raises:
-
ValueError
–If validation dataset is not initialized.
Returns:
-
DataLoader
–val dataloader.
Source code in quadra/datamodules/classification.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
MultilabelClassificationDataModule(data_path, images_and_labels_file=None, train_split_file=None, test_split_file=None, val_split_file=None, name='multilabel_datamodule', dataset=MultilabelClassificationDataset, num_classes=None, num_workers=16, batch_size=64, test_batch_size=64, seed=42, val_size=0.2, test_size=0.2, train_transform=None, val_transform=None, test_transform=None, class_to_idx=None, **kwargs)
¶
Bases: BaseDataModule
Base class for all multi-label modules.
Parameters:
-
data_path
(
str
) –Path to the data main folder.
-
images_and_labels_file
(
str | None
, default:None
) –a path to a txt file containing the relative (to
data_path
) path of images with their relative labels, in a comma-separated way. E.g.:- path1,l1,l2,l3
- path2,l4,l5
- ...
One of
images_and_label
and bothtrain_split_file
andtest_split_file
must be set. Defaults to None. -
name
(
str
, default:'multilabel_datamodule'
) –The name for the data module. Defaults to "multilabel_datamodule".
-
dataset
(
Callable
, default:MultilabelClassificationDataset
) –a callable returning a torch.utils.data.Dataset class.
-
num_classes
(
int | None
, default:None
) –the number of classes in the dataset. This is used to create one-hot encoded targets. Defaults to None.
-
num_workers
(
int
, default:16
) –Number of workers for dataloaders. Defaults to 16.
-
batch_size
(
int
, default:64
) –Training batch size. Defaults to 64.
-
test_batch_size
(
int
, default:64
) –Testing batch size. Defaults to 64.
-
seed
(
int
, default:42
) –Random generator seed. Defaults to SegmentationEvalua2.
-
val_size
(
float | None
, default:0.2
) –The validation split. Defaults to 0.2.
-
test_size
(
float | None
, default:0.2
) –The test split. Defaults to 0.2.
-
train_transform
(
Compose | None
, default:None
) –Transformations for train dataset. Defaults to None.
-
val_transform
(
Compose | None
, default:None
) –Transformations for validation dataset. Defaults to None.
-
test_transform
(
Compose | None
, default:None
) –Transformations for test dataset. Defaults to None.
-
train_split_file
(
str | None
, default:None
) –The file with train split. Defaults to None.
-
val_split_file
(
str | None
, default:None
) –The file with validation split. Defaults to None.
-
test_split_file
(
str | None
, default:None
) –The file with test split. Defaults to None.
-
class_to_idx
(
dict[str, int] | None
, default:None
) –a clss to idx dictionary. Defaults to None.
Source code in quadra/datamodules/classification.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
|
predict_dataloader()
¶
Returns a dataloader used for predictions.
Source code in quadra/datamodules/classification.py
1001 1002 1003 |
|
setup(stage=None)
¶
Setup data module based on stages of training.
Source code in quadra/datamodules/classification.py
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
|
test_dataloader()
¶
Returns the test dataloader.
Raises:
-
ValueError
–If test dataset is not initialized.
Returns:
-
DataLoader
–test dataloader.
Source code in quadra/datamodules/classification.py
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 |
|
train_dataloader()
¶
Returns the train dataloader.
Raises:
-
ValueError
–If train dataset is not initialized.
Returns:
-
DataLoader
–Train dataloader.
Source code in quadra/datamodules/classification.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 |
|
val_dataloader()
¶
Returns the validation dataloader.
Raises:
-
ValueError
–If validation dataset is not initialized.
Returns:
-
DataLoader
–val dataloader.
Source code in quadra/datamodules/classification.py
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 |
|
SklearnClassificationDataModule(data_path, exclude_filter=None, include_filter=None, val_size=0.2, class_to_idx=None, label_map=None, seed=42, batch_size=32, num_workers=6, train_transform=None, val_transform=None, test_transform=None, roi=None, n_splits=1, phase='train', cache=False, limit_training_data=None, train_split_file=None, test_split_file=None, name='sklearn_classification_datamodule', dataset=ImageClassificationListDataset, **kwargs)
¶
Bases: BaseDataModule
A generic Data Module for classification with frozen torch backbone and sklearn classifier.
It can also handle k-fold cross validation.
Parameters:
-
name
(
str
, default:'sklearn_classification_datamodule'
) –The name for the data module. Defaults to "sklearn_classification_datamodule".
-
data_path
(
str
) –Path to images main folder
-
exclude_filter
(
list[str] | None
, default:None
) –List of string filter to be used to exclude images. If None no filter will be applied.
-
include_filter
(
list[str] | None
, default:None
) –List of string filter to be used to include images. Only images that satisfied at list one of the filter will be included.
-
val_size
(
float
, default:0.2
) –The validation split. Defaults to 0.2.
-
class_to_idx
(
dict[str, int] | None
, default:None
) –Dictionary of conversion btw folder name and index. Only file whose label is in dictionary key list will be considered. If None all files will be considered and a custom conversion is created.
-
seed
(
int
, default:42
) –Fixed seed for random operations
-
batch_size
(
int
, default:32
) –Dimension of batches for dataloader
-
num_workers
(
int
, default:6
) –Number of workers for dataloader
-
train_transform
(
Compose | None
, default:None
) –Albumentation transformations for training set
-
val_transform
(
Compose | None
, default:None
) –Albumentation transformations for validation set
-
test_transform
(
Compose | None
, default:None
) –Albumentation transformations for test set
-
roi
(
tuple[int, int, int, int] | None
, default:None
) –Optional cropping region
-
n_splits
(
int
, default:1
) –Number of dataset subdivision (default 1 -> train/test). Use a value >= 2 for cross validation.
-
phase
(
str
, default:'train'
) –Either train or test
-
cache
(
bool
, default:False
) –If true disable shuffling in all dataloader to enable feature caching
-
limit_training_data
(
int | None
, default:None
) –if defined, each class will be donwsampled to this number. It must be >= 2 to allow splitting
-
label_map
(
dict[str, Any] | None
, default:None
) –Dictionary of conversion btw folder name and label.
-
train_split_file
(
str | None
, default:None
) –Optional path to a csv file containing the train split samples.
-
test_split_file
(
str | None
, default:None
) –Optional path to a csv file containing the test split samples.
-
**kwargs
(
Any
, default:{}
) –Additional arguments for BaseDataModule
Source code in quadra/datamodules/classification.py
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 |
|
full_dataloader()
¶
Return a dataloader to perform training on the entire dataset.
Returns:
-
DataLoader
–dataloader to perform training on the entire dataset after evaluation. This is useful
-
DataLoader
–to perform a final training on the entire dataset after the evaluation phase.
Source code in quadra/datamodules/classification.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
|
predict_dataloader()
¶
Returns a dataloader used for predictions.
Source code in quadra/datamodules/classification.py
605 606 607 |
|
setup(stage)
¶
Setup data module based on stages of training.
Source code in quadra/datamodules/classification.py
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 |
|
test_dataloader()
¶
Returns the test dataloader.
Raises:
-
ValueError
–If test dataset is not initialized.
Returns:
-
DataLoader
–test dataloader.
Source code in quadra/datamodules/classification.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
|
train_dataloader()
¶
Returns a list of train dataloader.
Raises:
-
ValueError
–If train dataset is not initialized.
Returns:
-
list[DataLoader]
–list of train dataloader.
Source code in quadra/datamodules/classification.py
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 |
|
val_dataloader()
¶
Returns a list of validation dataloader.
Raises:
-
ValueError
–If validation dataset is not initialized.
Returns:
-
list[DataLoader]
–List of validation dataloader.
Source code in quadra/datamodules/classification.py
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 |
|