Skip to content

Commit

Permalink
6766 data analyser label argmax (#6852)
Browse files Browse the repository at this point in the history
Fixes #6766

### Description
the label might have been processed during the GPU transform,
in the retry on CPU, the argmax should be skipped in this case.

### 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).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] 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 <[email protected]>
  • Loading branch information
wyli authored Aug 10, 2023
1 parent 3990cd4 commit 7a760e6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion monai/apps/auto3dseg/data_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,11 @@ def _get_all_case_stats(
batch_data = batch_data[0]
try:
batch_data[self.image_key] = batch_data[self.image_key].to(device)
_label_argmax = False
if self.label_key is not None:
label = batch_data[self.label_key]
label = torch.argmax(label, dim=0) if label.shape[0] > 1 else label[0]
_label_argmax = True # track if label is argmaxed
batch_data[self.label_key] = label.to(device)
d = summarizer(batch_data)
except BaseException as err:
Expand All @@ -348,7 +350,8 @@ def _get_all_case_stats(
batch_data[self.image_key] = batch_data[self.image_key].to("cpu")
if self.label_key is not None:
label = batch_data[self.label_key]
label = torch.argmax(label, dim=0) if label.shape[0] > 1 else label[0]
if not _label_argmax:
label = torch.argmax(label, dim=0) if label.shape[0] > 1 else label[0]
batch_data[self.label_key] = label.to("cpu")
d = summarizer(batch_data)

Expand Down

0 comments on commit 7a760e6

Please sign in to comment.