BasicDataset
anomaly_match.datasets.BasicDataset
¶
Basic PyTorch dataset wrapper for image loading and augmentation.
BasicDataset(data, filenames, targets=None, num_classes=None, transform=None, use_strong_transform=False, strong_transform=None, num_channels=3)
¶
Bases: Dataset
BasicDataset returns a pair of image and labels (targets).
If targets are not given, BasicDataset returns None as the label. This class supports strong augmentation for Fixmatch, and returns both weakly and strongly augmented images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray | list | Tensor
|
x_data as numpy array or torch tensor |
required |
filenames
|
list[str]
|
filenames of x_data |
required |
targets
|
Tensor | list | None
|
y_data (if not exist, None) |
None
|
num_classes
|
int | None
|
number of label classes |
None
|
transform
|
Callable | None
|
basic transformation of data |
None
|
use_strong_transform
|
bool
|
If True, this dataset returns both weakly and strongly augmented images. |
False
|
strong_transform
|
Callable | None
|
list of transformation functions for strong augmentation |
None
|
num_channels
|
int
|
number of image channels |
3
|
Source code in anomaly_match/datasets/BasicDataset.py
__getitem__(idx)
¶
Return augmented image, target, and filename.
If strong augmentation is not used, return weak_augment_image, target, filename. Otherwise return weak_augment_image, strong_augment_image, target.