advsecurenet.datasets package



advsecurenet.datasets.base_dataset module

class advsecurenet.datasets.base_dataset.BaseDataset(preprocess_config: PreprocessConfig | None = None)

Bases: Dataset, ABC

A base class for PyTorch datasets.

Parameters:

preprocess_config (Optional[PreprocessConfig], optional) – The preprocessing configuration for the dataset. Defaults to None.

_dataset

The underlying PyTorch dataset.

Type:

TorchDataset

mean

The mean values of the dataset.

Type:

List[float]

std

The standard deviation values of the dataset.

Type:

List[float]

input_size

The input size of the dataset.

Type:

Tuple[int, int]

name

The name of the dataset.

Type:

str

num_classes

The number of classes in the dataset.

Type:

int

num_input_channels

The number of input channels in the dataset.

Type:

int

data_type

The type of the dataset (train or test).

Type:

DataType

Note

This module uses v2 of the torchvision transforms. Please refer to the official PyTorch documentation for more information about the possible transforms.

abstract get_dataset_class()

Returns the dataset class.

get_transforms()

Returns the data transforms to be applied to the dataset.

load_dataset(root: str | None = None, train: bool | None = True, download: bool | None = True, **kwargs) DatasetWrapper

Loads the dataset.

Parameters:
  • root (str, optional) – The root directory where the dataset should be stored. Defaults to ‘./data’.

  • train (bool, optional) – If True, loads the training data. Otherwise, loads the test data. Defaults to True.

  • download (bool, optional) – If True, downloads the dataset from the internet. Defaults to True.

  • **kwargs – Arbitrary keyword arguments for the dataset.

Returns:

The dataset loaded into memory.

Return type:

DatasetWrapper

class advsecurenet.datasets.base_dataset.DatasetWrapper(dataset, name)

Bases: Dataset

A wrapper class for PyTorch datasets that allows for easy access to the underlying dataset and having customized parameters.

class advsecurenet.datasets.base_dataset.ImageFolderBaseDataset

Bases: object

A mixin class for datasets that use the ImageFolder format.

get_dataset_class()

Returns the dataset class.

advsecurenet.datasets.dataset_factory module

class advsecurenet.datasets.dataset_factory.DatasetFactory

Bases: object

A factory class to create datasets.

static available_datasets() list

Returns a list of available datasets.

Returns:

A list of available datasets.

Return type:

list

static create_dataset(dataset_type: DatasetType | str, preprocess_config: PreprocessConfig | None = None, return_loaded: bool | None = False, **kwargs) BaseDataset | tuple[BaseDataset, BaseDataset]

Returns a dataset for the given dataset type.

Parameters:
  • dataset_type (Union[DatasetType, str]) – The dataset type to create.

  • return_loaded (bool) – Whether to load the train and test datasets and return them immediately. Default is False.

  • **kwargs – Arbitrary keyword arguments to be passed to the dataset class.

Returns:

The dataset for the given dataset type.

Return type:

BaseDataset

advsecurenet.datasets.targeted_adv_dataset module

class advsecurenet.datasets.targeted_adv_dataset.AdversarialDataset(base_dataset: BaseDataset, target_labels: List[int] | Tensor | None = None, target_images: List[Tensor] | Tensor | None = None)

Bases: BaseDataset

A dataset class that wraps a base dataset and allows for targeted adversarial attacks.

Parameters:
  • base_dataset (Dataset) – The base dataset to wrap.

  • target_labels (Optional[List[int]], optional) – The target labels for the adversarial attack. Defaults to None.

  • target_images (Optional[List[torch.Tensor]], optional) – The target images for the adversarial attack. Defaults to None.

get_dataset_class()

Returns the dataset class.