Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into config_default
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
  • Loading branch information
wyli committed Jul 23, 2023
2 parents 495c33a + 644c9e5 commit 90bf848
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
steps:
- name: Import
run: |
rm -rf /opt/hostedtoolcache
export CUDA_VISIBLE_DEVICES=$(python -m tests.utils | tail -n 1)
echo $CUDA_VISIBLE_DEVICES
python -c 'import monai; monai.config.print_debug_info()'
Expand Down
14 changes: 8 additions & 6 deletions monai/apps/auto3dseg/data_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class DataAnalyzer:
the DataAnalyzer will skip looking for labels and all label-related operations.
hist_bins: bins to compute histogram for each image channel.
hist_range: ranges to compute histogram for each image channel.
fmt: format used to save the analysis results. Defaults to "yaml".
fmt: format used to save the analysis results. Currently support ``"json"`` and ``"yaml"``, defaults to "yaml".
histogram_only: whether to only compute histograms. Defaults to False.
extra_params: other optional arguments. Currently supported arguments are :
'allowed_shape_difference' (default 5) can be used to change the default tolerance of
Expand Down Expand Up @@ -164,6 +164,7 @@ def _check_data_uniformity(keys: list[str], result: dict) -> bool:
constant_props = [result[DataStatsKeys.SUMMARY][DataStatsKeys.IMAGE_STATS][key] for key in keys]
for prop in constant_props:
if "stdev" in prop and np.any(prop["stdev"]):
logger.debug(f"summary image_stats {prop} has non-zero stdev {prop['stdev']}.")
return False

return True
Expand Down Expand Up @@ -242,15 +243,16 @@ def get_all_case_stats(self, key="training", transform_list=None):
if not self._check_data_uniformity([ImageStatsKeys.SPACING], result):
logger.info("Data spacing is not completely uniform. MONAI transforms may provide unexpected result")
if self.output_path:
logger.info(f"Writing data stats to {self.output_path}.")
ConfigParser.export_config_file(
result, self.output_path, fmt=self.fmt, default_flow_style=None, sort_keys=False
)
by_case_path = self.output_path.replace(f".{self.fmt}", f"_by_case.{self.fmt}")
if by_case_path == self.output_path: # self.output_path not ended with self.fmt?
by_case_path += f".by_case.{self.fmt}"
logger.info(f"Writing by-case data stats to {by_case_path}, this may take a while.")
ConfigParser.export_config_file(
result_bycase,
self.output_path.replace(".yaml", "_by_case.yaml"),
fmt=self.fmt,
default_flow_style=None,
sort_keys=False,
result_bycase, by_case_path, fmt=self.fmt, default_flow_style=None, sort_keys=False
)
# release memory
if self.device.type == "cuda":
Expand Down
4 changes: 2 additions & 2 deletions monai/bundle/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ def export_config_file(cls, config: dict, filepath: PathLike, fmt: str = "json",
"""
_filepath: str = str(Path(filepath))
writer = look_up_option(fmt.lower(), {"json", "yaml"})
writer = look_up_option(fmt.lower(), {"json", "yaml", "yml"})
with open(_filepath, "w") as f:
if writer == "json":
json.dump(config, f, **kwargs)
return
if writer == "yaml":
if writer == "yaml" or writer == "yml":
return yaml.safe_dump(config, f, **kwargs)
raise ValueError(f"only support JSON or YAML config file so far, got {writer}.")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_auto3dseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def setUp(self):
work_dir = self.test_dir.name
self.dataroot_dir = os.path.join(work_dir, "sim_dataroot")
self.datalist_file = os.path.join(work_dir, "sim_datalist.json")
self.datastat_file = os.path.join(work_dir, "datastats.yaml")
self.datastat_file = os.path.join(work_dir, "datastats.yml")
ConfigParser.export_config_file(sim_datalist, self.datalist_file)

@parameterized.expand(SIM_CPU_TEST_CASES)
Expand Down

0 comments on commit 90bf848

Please sign in to comment.