docstr: From torch==1.7, torch.argmax changes its mechanism that if there are multiple maximal values then the
  indices of the first maximal value are returned (before this version, the indices of the last maximal value
  are returned).
  Therefore, we can may use of this changes to convert the onehotted labels into un-onehot format directly
  and then check if the result stays the same.
docstr_tok: ["From","torch==1.7",",","torch.argmax","changes","its","mechanism","that","if","there","are","multiple","maximal","values","then","the","indices","of","the","first","maximal","value","are","returned","(","before","this","version",",","the","indices","of","the","last","maximal","value","are","returned",")",".","Therefore",",","we","can","may","use","of","this","changes","to","convert","the","onehotted","labels","into","un-onehot","format","directly","and","then","check","if","the","result","stays","the","same","."]
code: def test_correct_results_before_after_onehot(
      self, _, args, input_image, expected
  ):
      """
      From torch==1.7, torch.argmax changes its mechanism that if there are multiple maximal values then the
      indices of the first maximal value are returned (before this version, the indices of the last maximal value
      are returned).
      Therefore, we can may use of this changes to convert the onehotted labels into un-onehot format directly
      and then check if the result stays the same.
  
      """
      converter = KeepLargestConnectedComponent(**args)
      result = converter(deepcopy(input_image))
  
      if "is_onehot" in args:
          args["is_onehot"] = not args["is_onehot"]
      # if not onehotted, onehot it and make sure result stays the same
      if input_image.shape[0] == 1:
          img = to_onehot(input_image)
          result2 = KeepLargestConnectedComponent(**args)(img)
          result2 = result2.argmax(0)[None]
          assert_allclose(result, result2, type_test="tensor")
      # if onehotted, un-onehot and check result stays the same
      else:
          img = input_image.argmax(0)[None]
          result2 = KeepLargestConnectedComponent(**args)(img)
          assert_allclose(
              result.argmax(0)[None], result2, type_test="tensor"
          )
  
file_path: MONAI/tests/test_keep_largest_connected_component.py
imports: from __future__ import annotations
  import unittest
  from copy import deepcopy
  import torch
  import torch.nn.functional
  from parameterized import parameterized
  from monai.transforms import KeepLargestConnectedComponent
  from monai.transforms.utils_pytorch_numpy_unification import moveaxis
  from monai.utils.type_conversion import convert_to_dst_type
  from tests.utils import TEST_NDARRAYS, assert_allclose
label_desc: Use image node_id 2 for calling the TestKeepLargestConnectedComponent obj's underlying member method code with example usage: obj.test_correct_results_before_after_onehot(_, args, input_image, expected) without return types