Skip to content

anomaly

AnomalyDatasetArguments dataclass

Anomaly dataset arguments.

Parameters:

  • train_samples (int) –

    number of train samples

  • val_samples (tuple[int, int]) –

    number of validation samples (good, bad)

  • test_samples (tuple[int, int]) –

    number of test samples (good, bad)

anomaly_dataset(tmp_path, dataset_arguments)

Fixture used to dinamically generate anomaly dataset. By default images are random grayscales with size 10x10.

Parameters:

Returns:

Source code in quadra/utils/tests/fixtures/dataset/anomaly.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@pytest.fixture
def anomaly_dataset(tmp_path: Path, dataset_arguments: AnomalyDatasetArguments) -> tuple[str, AnomalyDatasetArguments]:
    """Fixture used to dinamically generate anomaly dataset. By default images are random grayscales with size 10x10.

    Args:
        tmp_path: path to temporary directory
        dataset_arguments: dataset arguments

    Returns:
        path to anomaly dataset
    """
    yield _build_anomaly_dataset(tmp_path, dataset_arguments)
    if tmp_path.exists():
        shutil.rmtree(tmp_path)

base_anomaly_dataset(tmp_path, request)

Generate base anomaly dataset with the following parameters
  • train_samples: 10
  • val_samples: (10, 10)
  • test_samples: (10, 10).

Parameters:

  • tmp_path (Path) –

    Path to temporary directory

  • request (Any) –

    Pytest SubRequest object

Yields:

Source code in quadra/utils/tests/fixtures/dataset/anomaly.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@pytest.fixture(
    params=[AnomalyDatasetArguments(**{"train_samples": 10, "val_samples": (1, 1), "test_samples": (1, 1)})]
)
def base_anomaly_dataset(tmp_path: Path, request: Any) -> tuple[str, AnomalyDatasetArguments]:
    """Generate base anomaly dataset with the following parameters:
        - train_samples: 10
        - val_samples: (10, 10)
        - test_samples: (10, 10).

    Args:
        tmp_path: Path to temporary directory
        request: Pytest SubRequest object

    Yields:
        Path to anomaly dataset and dataset arguments
    """
    yield _build_anomaly_dataset(tmp_path, request.param)
    if tmp_path.exists():
        shutil.rmtree(tmp_path)