MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / MedNISTDataset

Class MedNISTDataset

monai/apps/datasets.py:47–194  ·  view source on GitHub ↗

The Dataset to automatically download MedNIST data and generate items for training, validation or test. It's based on `CacheDataset` to accelerate the training process. Args: root_dir: target directory to download and load MedNIST dataset. section: expected data section

Source from the content-addressed store, hash-verified

45
46
47class MedNISTDataset(Randomizable, CacheDataset):
48 """
49 The Dataset to automatically download MedNIST data and generate items for training, validation or test.
50 It's based on `CacheDataset` to accelerate the training process.
51
52 Args:
53 root_dir: target directory to download and load MedNIST dataset.
54 section: expected data section, can be: `training`, `validation` or `test`.
55 transform: transforms to execute operations on input data.
56 download: whether to download and extract the MedNIST from resource link, default is False.
57 if expected file already exists, skip downloading even set it to True.
58 user can manually copy `MedNIST.tar.gz` file or `MedNIST` folder to root directory.
59 seed: random seed to randomly split training, validation and test datasets, default is 0.
60 val_frac: percentage of validation fraction in the whole dataset, default is 0.1.
61 test_frac: percentage of test fraction in the whole dataset, default is 0.1.
62 cache_num: number of items to be cached. Default is `sys.maxsize`.
63 will take the minimum of (cache_num, data_length x cache_rate, data_length).
64 cache_rate: percentage of cached data in total, default is 1.0 (cache all).
65 will take the minimum of (cache_num, data_length x cache_rate, data_length).
66 num_workers: the number of worker threads if computing cache in the initialization.
67 If num_workers is None then the number returned by os.cpu_count() is used.
68 If a value less than 1 is specified, 1 will be used instead.
69 progress: whether to display a progress bar when downloading dataset and computing the transform cache content.
70 copy_cache: whether to `deepcopy` the cache content before applying the random transforms,
71 default to `True`. if the random transforms don't modify the cached content
72 (for example, randomly crop from the cached image and deepcopy the crop region)
73 or if every cache item is only used once in a `multi-processing` environment,
74 may set `copy=False` for better performance.
75 as_contiguous: whether to convert the cached NumPy array or PyTorch tensor to be contiguous.
76 it may help improve the performance of following logic.
77 runtime_cache: whether to compute cache at the runtime, default to `False` to prepare
78 the cache content at initialization. See: :py:class:`monai.data.CacheDataset`.
79
80 Raises:
81 ValueError: When ``root_dir`` is not a directory.
82 RuntimeError: When ``dataset_dir`` doesn't exist and downloading is not selected (``download=False``).
83
84 """
85
86 resource = "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/MedNIST.tar.gz"
87 md5 = "0bc7306e7427e00ad1c5526a6677552d"
88 compressed_file_name = "MedNIST.tar.gz"
89 dataset_folder_name = "MedNIST"
90
91 def __init__(
92 self,
93 root_dir: PathLike,
94 section: str,
95 transform: Sequence[Callable] | Callable = (),
96 download: bool = False,
97 seed: int = 0,
98 val_frac: float = 0.1,
99 test_frac: float = 0.1,
100 cache_num: int = sys.maxsize,
101 cache_rate: float = 1.0,
102 num_workers: int | None = 1,
103 progress: bool = True,
104 copy_cache: bool = True,

Callers 2

test_valuesMethod · 0.90
test_lr_finderMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_valuesMethod · 0.72
test_lr_finderMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…