class_docstr: Merge patches by taking average of the overlapping area
  
  Args:
      merged_shape: the shape of the tensor required to merge the patches.
      cropped_shape: the shape of the final merged output tensor.
          If not provided, it will be the same as `merged_shape`.
      device: the device for aggregator tensors and final results.
      value_dtype: the dtype for value aggregating tensor and the final result.
      count_dtype: the dtype for sample counting tensor.
docstr: Finalize merging by dividing values by counts and return the merged tensor.
  
  Notes:
      To avoid creating a new tensor for the final results (to save memory space),
      after this method is called, `get_values()` method will return the "final" averaged values,
      and not the accumulating values. Also calling `finalize()` multiple times does not have any effect.
  
  Returns:
      torch.tensor: a tensor of merged patches
docstr_tok: ["Finalize","merging","by","dividing","values","by","counts","and","return","the","merged","tensor",".","Notes",":","To","avoid","creating","a","new","tensor","for","the","final","results","(","to","save","memory","space",")",",","after","this","method","is","called",",","`","get_values","(",")","`","method","will","return","the","``","final","''","averaged","values",",","and","not","the","accumulating","values",".","Also","calling","`","finalize","(",")","`","multiple","times","does","not","have","any","effect",".","Returns",":","torch.tensor",":","a","tensor","of","merged","patches"]
code: def finalize(self) -> torch.Tensor:
      """
      Finalize merging by dividing values by counts and return the merged tensor.
  
      Notes:
          To avoid creating a new tensor for the final results (to save memory space),
          after this method is called, `get_values()` method will return the "final" averaged values,
          and not the accumulating values. Also calling `finalize()` multiple times does not have any effect.
  
      Returns:
          torch.tensor: a tensor of merged patches
      """
      # guard against multiple call to finalize
      if not self.is_finalized:
          # use in-place division to save space
          self.values.div_(self.counts)
          # finalize the shape
          self.values = self.values[
              tuple(slice(0, end) for end in self.cropped_shape)
          ]
          # set finalize flag to protect performing in-place division again
          self.is_finalized = True
  
      return self.values
  
imports: from __future__ import annotations
  import threading
  from abc import ABC, abstractmethod
  from collections.abc import Sequence
  from contextlib import nullcontext
  from typing import TYPE_CHECKING, Any
  import numpy
  import torch
  from monai.utils import ensure_tuple_size, optional_import, require_pkg
label_desc: Use image node_id 3 for calling the AvgMerger obj's underlying member method code with example usage: obj.finalize() and returns: self