code: def _imsave_before(img, channel_first, auto_scale):
      if not isinstance(img, np.ndarray):
          raise ValueError(
              "the input img for imsave must be numpy.ndarray."
          )
  
      if len(img.shape) not in [2, 3]:
          raise ValueError(
              "Invalid dimension size of input image. (dims: {})".format(
                  len(img.shape)
              )
          )
  
      if img.dtype not in [np.uint8, np.uint16]:
          # consider dtype is float.
          if not auto_scale:
              raise ValueError(
                  "If you want to save image with float values, "
                  "'auto_scale' must be True."
              )
  
          if np.any(img < 0) or np.any(img > 1):
              raise ValueError(
                  "Except for uint8 or uint16, "
                  "all the pixel values of input must be in the range of [0, 1]"
              )
  
          img = np.asarray(img, np.float32)
  
      if channel_first and len(img.shape) == 3:
          img = img.transpose((1, 2, 0))
  
      if len(img.shape) == 3 and img.shape[-1] not in [1, 2, 3, 4]:
          raise ValueError(
              f"Invalid channel size of input image. (channel size: {img.shape[-1]})"
          )
  
      return img
  
file_path: nnabla/python/src/nnabla/utils/image_utils/backend_events/common.py
imports: from __future__ import division, absolute_import
  import numpy
  from nnabla.logger import logger
label_desc: Use image node_id 9 for calling a global function with example usage: _imsave_before(img, channel_first, auto_scale) and returns: img