Skip to content

imagenette

ImagenetteClassificationDataModule(data_path, name='imagenette_classification_datamodule', imagenette_version='320', force_download=False, class_to_idx=None, **kwargs)

Bases: ClassificationDataModule

Initializes the classification data module for Imagenette dataset.

Parameters:

  • data_path (str) –

    Path to the dataset.

  • name (str, default: 'imagenette_classification_datamodule' ) –

    Name of the dataset.

  • imagenette_version (str, default: '320' ) –

    Version of the Imagenette dataset. Can be 320 or 160 or full.

  • force_download (bool, default: False ) –

    If True, the dataset will be downloaded even if the data_path already exists. The data_path will be deleted and recreated.

  • class_to_idx (dict[str, int] | None, default: None ) –

    Dictionary mapping class names to class indices.

  • **kwargs (Any, default: {} ) –

    Keyword arguments for the ClassificationDataModule.

Source code in quadra/datamodules/generic/imagenette.py
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
def __init__(
    self,
    data_path: str,
    name: str = "imagenette_classification_datamodule",
    imagenette_version: str = "320",
    force_download: bool = False,
    class_to_idx: dict[str, int] | None = None,
    **kwargs: Any,
):
    if imagenette_version not in ["320", "160", "full"]:
        raise ValueError(f"imagenette_version must be one of 320, 160 or full. Got {imagenette_version} instead.")

    if imagenette_version == "full":
        imagenette_version = ""
    else:
        imagenette_version = f"-{imagenette_version}"

    self.download_url = f"https://s3.amazonaws.com/fast-ai-imageclas/imagenette2{imagenette_version}.tgz"
    self.force_download = force_download
    self.imagenette_version = imagenette_version

    if class_to_idx is None:
        class_to_idx = DEFAULT_CLASS_TO_IDX

    super().__init__(
        data_path=data_path,
        name=name,
        test_split_file=None,
        train_split_file=None,
        val_size=None,
        class_to_idx=class_to_idx,
        **kwargs,
    )

download_data(download_url, force_download=False)

Download the Imagenette dataset.

Parameters:

  • download_url (str) –

    Dataset download url.

  • force_download (bool, default: False ) –

    If True, the dataset will be downloaded even if the data_path already exists. The data_path will be removed.

Source code in quadra/datamodules/generic/imagenette.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def download_data(self, download_url: str, force_download: bool = False) -> None:
    """Download the Imagenette dataset.

    Args:
        download_url: Dataset download url.
        force_download: If True, the dataset will be downloaded even if the data_path already exists. The data_path
            will be removed.
    """
    if os.path.exists(self.data_path):
        if force_download:
            log.info("The path %s already exists. Removing it and downloading the dataset again.", self.data_path)
            shutil.rmtree(self.data_path)
        else:
            log.info("The path %s already exists. Skipping download.", self.data_path)
            return

    log.info("Downloading and extracting Imagenette dataset to %s", self.data_path)
    download_and_extract_archive(download_url, self.data_path, remove_finished=True)

ImagenetteSSLDataModule(*args, name='imagenette_ssl', **kwargs)

Bases: ImagenetteClassificationDataModule, SSLDataModule

Initializes the SSL data module for Imagenette dataset.

Source code in quadra/datamodules/generic/imagenette.py
138
139
140
141
142
143
144
def __init__(
    self,
    *args: Any,
    name="imagenette_ssl",
    **kwargs: Any,
):
    super().__init__(*args, name=name, **kwargs)  # type: ignore[misc]