andreped commited on
Commit
111ae49
1 Parent(s): 676970f

Added __init__ to store self.DATA_DIR

Browse files
Files changed (1) hide show
  1. AeroPath.py +8 -9
AeroPath.py CHANGED
@@ -82,10 +82,9 @@ 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
- DATA_DIR = None
86
-
87
- def get_data_paths(self):
88
- return DATA_DIR
89
 
90
  def get_patient(self, patient_id):
91
  if (patient_id < 1) or (patiend_id > 27):
@@ -122,7 +121,7 @@ class AeroPath(datasets.GeneratorBasedBuilder):
122
  )
123
 
124
  def get_data_dir(self):
125
- return 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,9 +131,9 @@ class AeroPath(datasets.GeneratorBasedBuilder):
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
- DATA_DIR = dl_manager.download_and_extract(urls)
136
 
137
- print("data is downloaded to:", DATA_DIR)
138
 
139
  return [
140
  datasets.SplitGenerator(
@@ -150,8 +149,8 @@ class AeroPath(datasets.GeneratorBasedBuilder):
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(DATA_DIR):
154
- curr_path = os.path.join(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"),
 
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 __init__(self, **kwargs):
86
+ super().__init__(**kwargs)
87
+ self.DATA_DIR = None
 
88
 
89
  def get_patient(self, patient_id):
90
  if (patient_id < 1) or (patiend_id > 27):
 
121
  )
122
 
123
  def get_data_dir(self):
124
+ return self.DATA_DIR
125
 
126
  def _split_generators(self, dl_manager):
127
  # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
 
131
  # 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.
132
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
133
  urls = _URLS[self.config.name]
134
+ self.DATA_DIR = dl_manager.download_and_extract(urls)
135
 
136
+ print("data is downloaded to:", self.DATA_DIR)
137
 
138
  return [
139
  datasets.SplitGenerator(
 
149
  def _generate_examples(self, split):
150
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
151
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
152
+ for patient_id in os.listdir(self.DATA_DIR):
153
+ curr_path = os.path.join(self.DATA_DIR, patient_id)
154
  yield patient_id, {
155
  "ct": os.path.join(curr_path, patient_id, "_CT_HR.nii.gz"),
156
  "airways": os.path.join(curr_path, patient_id, "_CT_HR_label_airways.nii.gz"),