andreped commited on
Commit
958909d
1 Parent(s): 3146ddd

Fixed generator and added generate_examples method

Browse files
Files changed (1) hide show
  1. AeroPath.py +33 -8
AeroPath.py CHANGED
@@ -82,6 +82,8 @@ class AeroPath(datasets.GeneratorBasedBuilder):
82
 
83
  DEFAULT_CONFIG_NAME = "zenodo" # It's not mandatory to have a default configuration. Just use one if it make sense.
84
 
 
 
85
  def get_data_paths(self):
86
  return
87
 
@@ -94,9 +96,9 @@ class AeroPath(datasets.GeneratorBasedBuilder):
94
  if self.config.name == "zenodo": # This is the name of the configuration selected in BUILDER_CONFIGS above
95
  features = datasets.Features(
96
  {
97
- "sentence": datasets.Value("string"),
98
- "option1": datasets.Value("string"),
99
- "answer": datasets.Value("string")
100
  # These are the features of your dataset like images, labels ...
101
  }
102
  )
@@ -118,6 +120,9 @@ class AeroPath(datasets.GeneratorBasedBuilder):
118
  # Citation for the dataset
119
  citation=_CITATION,
120
  )
 
 
 
121
 
122
  def _split_generators(self, dl_manager):
123
  # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
@@ -127,9 +132,29 @@ class AeroPath(datasets.GeneratorBasedBuilder):
127
  # 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.
128
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
129
  urls = _URLS[self.config.name]
130
- data_dir = dl_manager.download_and_extract(urls)
131
-
132
- print("data_dir:", data_dir)
133
-
134
- return [os.path.join(data_dir, x) for x in os.listdir(data_dir)]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
 
82
 
83
  DEFAULT_CONFIG_NAME = "zenodo" # It's not mandatory to have a default configuration. Just use one if it make sense.
84
 
85
+ self.data_dir = None
86
+
87
  def get_data_paths(self):
88
  return
89
 
 
96
  if self.config.name == "zenodo": # This is the name of the configuration selected in BUILDER_CONFIGS above
97
  features = datasets.Features(
98
  {
99
+ "ct": datasets.Value("string"),
100
+ "airways": datasets.Value("string"),
101
+ "lungs": datasets.Value("string")
102
  # These are the features of your dataset like images, labels ...
103
  }
104
  )
 
120
  # Citation for the dataset
121
  citation=_CITATION,
122
  )
123
+
124
+ def get_data_dir(self):
125
+ return self.data_dir
126
 
127
  def _split_generators(self, dl_manager):
128
  # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
 
132
  # 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.
133
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
134
  urls = _URLS[self.config.name]
135
+ self.data_dir = dl_manager.download_and_extract(urls)
136
+
137
+ print("data_dir:", self.data_dir)
138
+
139
+ return [
140
+ datasets.SplitGenerator(
141
+ name=datasets.Split.TEST,
142
+ # These kwargs will be passed to _generate_examples
143
+ gen_kwargs={
144
+ "split": "test",
145
+ },
146
+ ),
147
+ ]
148
+
149
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
150
+ def _generate_examples(self, split):
151
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
152
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
153
+ for patient_id in os.listdir(self.data_dir):
154
+ curr_path = os.path.join(self.data_dir, patient_id)
155
+ yield patient_id, {
156
+ "ct": os.path.join(curr_path, patient_id, "_CT_HR.nii.gz")
157
+ "airways": os.path.join(curr_path, patient_id, "_CT_HR_label_airways.nii.gz")
158
+ "lungs": os.path.join(curr_path, patient_id, "_CT_HR_label_lungs.nii.gz")
159
+ }
160