code: def scales_for_resolution(
      resolution: tuple | list, n_stages: int | None = None
  ):
      """
      A helper function to compute a schedule of scale at different downsampling levels,
      given the input resolution.
  
      .. code-block:: python
  
          scales_for_resolution(resolution=[1,1,5], n_stages=5)
  
      Args:
          resolution: input image resolution (in mm)
          n_stages: optionally the number of stages of the network
      """
  
      ndim = len(resolution)
      res = np.array(resolution)
      if not all(res > 0):
          raise ValueError("Resolution must be positive")
  
      nl = np.floor(np.log2(np.max(res) / res)).astype(np.int32)
      scales = [
          tuple(np.where(2**i >= 2**nl, 1, 2))
          for i in range(max(nl))
      ]
      if n_stages and n_stages > max(nl):
          scales = scales + [(2,) * ndim] * (n_stages - max(nl))
      else:
          scales = scales[:n_stages]
      return scales
  
imports: from __future__ import annotations
  from collections.abc import Callable
  from typing import Union
  import numpy
  import torch
  import torch.nn
  from monai.networks.blocks.upsample import UpSample
  from monai.networks.layers.factories import Act, Conv, Norm, split_args
  from monai.networks.layers.utils import get_act_layer, get_norm_layer
  from monai.utils import UpsampleMode, has_option
label_desc: Use image node_id 1 for calling a global function with example usage: scales_for_resolution(resolution, n_stages) and returns: scales