alemorm commited on
Commit
0072403
1 Parent(s): 37a1653

Create a custom data definition

Browse files
Files changed (1) hide show
  1. 3d-brain-mri.py +108 -0
3d-brain-mri.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
+ _CITATION = """\
28
+ @InProceedings{huggingface:dataset,
29
+ title = {The University of California San Francisco Preoperative Diffuse Glioma MRI (UCSF-PDGM) (Version 4) [Dataset]},
30
+ author={Calabrese, E., Villanueva-Meyer, J., Rudie, J., Rauschecker, A., Baid, U., Bakas, S., Cha, S., Mongan, J., & Hess, C},
31
+ year={2022}
32
+ }
33
+ """
34
+
35
+
36
+ # TODO: Add description of the dataset here
37
+ # You can copy an official description
38
+ _DESCRIPTION = """\
39
+ This dataset is based on the UCSF-PDGM: The University of California San Francisco Preoperative Diffuse Glioma MRI research dataset.
40
+ """
41
+
42
+ # TODO: Add a link to an official homepage for the dataset here
43
+ _HOMEPAGE = "https://www.cancerimagingarchive.net/collection/ucsf-pdgm/"
44
+
45
+ # TODO: Add the licence for the dataset here if you can find it
46
+ _LICENSE = "CC BY 4.0"
47
+
48
+ # TODO: Add link to the official dataset URLs here
49
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
50
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
51
+ _URLS = {
52
+ "data": "https://huggingface.co/datasets/determined-ai/3d-brain-mri/blob/main/dataset-3d-brain.zip"
53
+ }
54
+
55
+
56
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
57
+ class BrainMRI(datasets.GeneratorBasedBuilder):
58
+ """TODO: Short description of my dataset."""
59
+
60
+ VERSION = datasets.Version("1.0.0")
61
+
62
+ # This is an example of a dataset with multiple configurations.
63
+ # If you don't want/need to define several sub-sets in your dataset,
64
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
65
+
66
+ # If you need to make complex sub-parts in the datasets with configurable options
67
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
68
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
69
+
70
+ # You will be able to load one or the other configurations in the following list with
71
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
72
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
73
+ BUILDER_CONFIGS = [
74
+ datasets.BuilderConfig(name="data", version=VERSION, description="This is the data")
75
+ ]
76
+
77
+ DEFAULT_CONFIG_NAME = "data" # It's not mandatory to have a default configuration. Just use one if it make sense.
78
+
79
+ def _info(self):
80
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
81
+ return datasets.DatasetInfo(
82
+ # This is the description that will appear on the datasets page.
83
+ description=_DESCRIPTION,
84
+ # This defines the different columns of the dataset and their types
85
+ # Homepage of the dataset for documentation
86
+ homepage=_HOMEPAGE,
87
+ # License for the dataset if available
88
+ license=_LICENSE,
89
+ # Citation for the dataset
90
+ citation=_CITATION,
91
+ )
92
+
93
+ def _split_generators(self, dl_manager):
94
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
95
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
96
+
97
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
98
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
99
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
100
+ urls = _URLS[self.config.name]
101
+ data_dir = dl_manager.download_and_extract(urls)
102
+ return
103
+
104
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
105
+ def _generate_examples(self, filepath, split):
106
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
107
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
108
+ pass