Skip to content

Data Analyzer uses "None" as NoneType for label key#5428

Merged
wyli merged 6 commits intoProject-MONAI:devfrom
mingxin-zheng:fix-5247
Oct 31, 2022
Merged

Data Analyzer uses "None" as NoneType for label key#5428
wyli merged 6 commits intoProject-MONAI:devfrom
mingxin-zheng:fix-5247

Conversation

@mingxin-zheng
Copy link
Copy Markdown
Contributor

Signed-off-by: Mingxin Zheng [email protected]

Fixes #5427 .

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • In-line docstrings updated.

@mingxin-zheng mingxin-zheng changed the title Allow Data Analyzer to take label_key is "None" as NoneType Data Analyzer uses "None" as NoneType for label key Oct 28, 2022
@mingxin-zheng mingxin-zheng requested a review from wyli October 28, 2022 14:27
@wyli
Copy link
Copy Markdown
Contributor

wyli commented Oct 28, 2022

I still have the issue using this PR, it's from the hard-coded string "label" in this line:

del d["image"], d["label"]

also this hard-coded ["label"] looks suspicious as well:

SqueezeDimd(keys=["label"], dim=0) if self.label_key else None,

I think they should be something like self.label_key instead of "label".

log:

python -m monai.apps.auto3dseg  DataAnalyzer get_all_case_stats --dataroot="/Users/Documents/bundles/MedNIST/Hand" --datalist="data_list.yaml" --label_key=None  
File ./data_stats.yaml already exists and will be overwritten.
  0%|                                                                                                                                                        | 0/3 [00:00<?, ?it/s]axcodes ('RAS') length is smaller than the number of input spatial dimensions D=2.
Orientation: input spatial shape is (64, 64), num. channels is 1,please make sure the input is in the channel-first format.
axcodes ('RAS') length is smaller than the number of input spatial dimensions D=2.
Orientation: input spatial shape is (64, 64), num. channels is 1,please make sure the input is in the channel-first format.
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:15<00:00,  5.30s/it]
Traceback (most recent call last):
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/Documents/MONAI/monai/apps/auto3dseg/__main__.py", line 22, in <module>
    fire.Fire(
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/Users/Documents/MONAI/monai/apps/auto3dseg/data_analyzer.py", line 265, in get_all_case_stats
    del d["image"], d["label"]
KeyError: 'label'

@mingxin-zheng
Copy link
Copy Markdown
Contributor Author

I still have the issue using this PR, it's from the hard-coded string "label" in this line:

del d["image"], d["label"]

also this hard-coded ["label"] looks suspicious as well:

SqueezeDimd(keys=["label"], dim=0) if self.label_key else None,

I think they should be something like self.label_key instead of "label".

log:

python -m monai.apps.auto3dseg  DataAnalyzer get_all_case_stats --dataroot="/Users/Documents/bundles/MedNIST/Hand" --datalist="data_list.yaml" --label_key=None  
File ./data_stats.yaml already exists and will be overwritten.
  0%|                                                                                                                                                        | 0/3 [00:00<?, ?it/s]axcodes ('RAS') length is smaller than the number of input spatial dimensions D=2.
Orientation: input spatial shape is (64, 64), num. channels is 1,please make sure the input is in the channel-first format.
axcodes ('RAS') length is smaller than the number of input spatial dimensions D=2.
Orientation: input spatial shape is (64, 64), num. channels is 1,please make sure the input is in the channel-first format.
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:15<00:00,  5.30s/it]
Traceback (most recent call last):
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/Documents/MONAI/monai/apps/auto3dseg/__main__.py", line 22, in <module>
    fire.Fire(
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/usr/local/anaconda3/envs/py38/lib/python3.8/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/Users/Documents/MONAI/monai/apps/auto3dseg/data_analyzer.py", line 265, in get_all_case_stats
    del d["image"], d["label"]
KeyError: 'label'

@wyli Since the issue is not caused by the None input as commented in the original ticket, it is obvious that these lines need fixed.

Signed-off-by: Mingxin Zheng <[email protected]>
Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@wyli wyli enabled auto-merge (squash) October 31, 2022 11:02
@wyli
Copy link
Copy Markdown
Contributor

wyli commented Oct 31, 2022

/build

@wyli wyli disabled auto-merge October 31, 2022 12:32
@wyli wyli enabled auto-merge (squash) October 31, 2022 12:33
@wyli wyli merged commit fe60832 into Project-MONAI:dev Oct 31, 2022
KumoLiu pushed a commit that referenced this pull request Nov 2, 2022
Signed-off-by: Mingxin Zheng
<[email protected]>

Fixes #5427 .

### 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).
- [x] New tests added to cover the changes.
- [x] In-line docstrings updated.

Signed-off-by: Mingxin Zheng <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
yiheng-wang-nv pushed a commit to yiheng-wang-nv/MONAI that referenced this pull request Nov 2, 2022
Signed-off-by: Mingxin Zheng
<[email protected]>

Fixes Project-MONAI#5427 .

### 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).
- [x] New tests added to cover the changes.
- [x] In-line docstrings updated.

Signed-off-by: Mingxin Zheng <[email protected]>
Signed-off-by: Yiheng Wang <[email protected]>
@mingxin-zheng mingxin-zheng deleted the fix-5247 branch December 1, 2022 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError: 'label' monai/apps/auto3dseg/data_analyzer.py

2 participants