Skip to content

Commit

Permalink
Merge pull request #495 from DeepRegNet/481-improve-error-check-when-…
Browse files Browse the repository at this point in the history
…data-path-is-wrong

Issue #481: check dataset is not empty for h5 and nifti
  • Loading branch information
mathpluscode authored Nov 2, 2020
2 parents dae8a6d + 49b675c commit 0c3ddac
Show file tree
Hide file tree
Showing 5 changed files with 554 additions and 637 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ straightforward as possible.
- Added max_epochs argument for training to overwrite configuration.
- Added log_root argument for training and prediction to customize the log file
location.
- Added more meaningful error messages for data loading.
- Added integration tests for all demos.
- Added environment.yml file for Conda environment creation.
- Added Dockerfile.
Expand Down
7 changes: 6 additions & 1 deletion deepreg/dataset/loader/h5_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, dir_paths: List[str], name: str, grouped: bool):
self.h5_files = None
self.data_path_splits = None
self.set_data_structure()
self.group_struct = None
if self.grouped:
self.group_struct = None
self.set_group_structure()

def set_data_structure(self):
Expand Down Expand Up @@ -61,6 +61,11 @@ def set_data_structure(self):
else:
# each element is (dir_path, data_key)
data_path_splits += [(dir_path, k) for k in sorted(h5_file.keys())]
if len(data_path_splits) == 0:
raise ValueError(
f"No data collected from {self.dir_paths} in H5FileLoader, "
f"please verify the path is correct."
)
self.h5_files = h5_files
self.data_path_splits = data_path_splits

Expand Down
7 changes: 6 additions & 1 deletion deepreg/dataset/loader/nifti_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def __init__(self, dir_paths: List[str], name: str, grouped: bool):
)
self.data_path_splits = None
self.set_data_structure()
self.group_struct = None
if self.grouped:
self.group_struct = None
self.set_group_structure()

def set_data_structure(self):
Expand Down Expand Up @@ -70,6 +70,11 @@ def set_data_structure(self):
data_path_splits += [
(dir_path, file_path, suffix) for file_path, suffix in data_paths
]
if len(data_path_splits) == 0:
raise ValueError(
f"No data collected from {self.dir_paths} in NiftiFileLoader, "
f"please verify the path is correct."
)
self.data_path_splits = sorted(data_path_splits)

def set_group_structure(self):
Expand Down
Loading

0 comments on commit 0c3ddac

Please sign in to comment.