Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataAnalyzer with histogram_only=True #6873

Closed
wyli opened this issue Aug 15, 2023 · 0 comments · Fixed by #6874
Closed

DataAnalyzer with histogram_only=True #6873

wyli opened this issue Aug 15, 2023 · 0 comments · Fixed by #6874
Assignees
Labels
bug Something isn't working Contribution wanted

Comments

@wyli
Copy link
Contributor

wyli commented Aug 15, 2023

Describe the bug
using DataAnalyzer with histogram_only=True raises error:

2023-08-15 15:15:52,439 - INFO - Found 0 GPUs for data analyzing!
2023-08-15 15:15:52,441 - INFO - device=cuda:0 but CUDA device is not available, using CPU instead.
  0%|                                                                                                                                                      | 0/10 [00:08<?, ?it/s]
Traceback (most recent call last):
  File "/workspace/demo21/data/analyzer.py", line 184, in <module>
    datastas = analyzer.get_all_case_stats(transform_list=label_transform)
  File "/usr/local/lib/python3.10/dist-packages/monai/apps/auto3dseg/data_analyzer.py", line 228, in get_all_case_stats
    result_bycase = self._get_all_case_stats(0, 1, None, key, transform_list)
  File "/usr/local/lib/python3.10/dist-packages/monai/apps/auto3dseg/data_analyzer.py", line 359, in _get_all_case_stats
    DataStatsKeys.BY_CASE_IMAGE_PATH: d[DataStatsKeys.BY_CASE_IMAGE_PATH],
KeyError: image_filepath

the root cause is that when skipping certain analyzers, the output stats keys won't exist

if not self.histogram_only:
self.add_analyzer(FilenameStats(image_key, DataStatsKeys.BY_CASE_IMAGE_PATH), None)
self.add_analyzer(FilenameStats(label_key, DataStatsKeys.BY_CASE_LABEL_PATH), None)
self.add_analyzer(ImageStats(image_key), ImageStatsSumm(average=average))

but the _get_all_case_stats assumes the stats keys

stats_by_cases = {
DataStatsKeys.BY_CASE_IMAGE_PATH: d[DataStatsKeys.BY_CASE_IMAGE_PATH],
DataStatsKeys.BY_CASE_LABEL_PATH: d[DataStatsKeys.BY_CASE_LABEL_PATH],
DataStatsKeys.IMAGE_STATS: d[DataStatsKeys.IMAGE_STATS],
}

@wyli wyli added bug Something isn't working Contribution wanted labels Aug 15, 2023
wyli added a commit to wyli/MONAI that referenced this issue Aug 15, 2023
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
@wyli wyli self-assigned this Aug 15, 2023
wyli added a commit that referenced this issue Aug 16, 2023
Fixes #6873 

### Description
- fixes data analyzer
- replace `"image_stats"` with `DataStatsKeys.IMAGE_STATS`

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Contribution wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant