code: def _check_spec(spec, image_format):
      """Check that an InOutSpec is suitable for a CNNModule.
  
      Args:
          spec (garage.InOutSpec): Specification of inputs and outputs.  The
              input should be in 'NCHW' format: [batch_size, channel, height,
              width].  Will print a warning if the channel size is not 1 or 3.
              If output_space is specified, then a final linear layer will be
              inserted to map to that dimensionality.  If output_space is None,
              it will be filled in with the computed output space.
          image_format (str): Either 'NCHW' or 'NHWC'. Should match the input
              specification. Gym uses NHWC by default, but PyTorch uses NCHW by
              default.
  
      Returns:
          tuple[int, int, int]: The input channels, height, and width.
  
      Raises:
          ValueError: If spec isn't suitable for a CNNModule.
  
      """
      # pylint: disable=no-else-raise
      input_space = spec.input_space
      output_space = spec.output_space
      # Don't use isinstance, since akro.Space is guaranteed to inherit from
      # gym.Space
      if getattr(input_space, "shape", None) is None:
          raise ValueError(
              f"input_space to CNNModule is {input_space}, but should be an "
              f"akro.Box or akro.Image"
          )
      elif len(input_space.shape) != 3:
          raise ValueError(
              f"Input to CNNModule is {input_space}, but should have three "
              f"dimensions."
          )
      if output_space is not None and not (
          hasattr(output_space, "shape")
          and len(output_space.shape) == 1
      ):
          raise ValueError(
              f"output_space to CNNModule is {output_space}, but should be "
              f"an akro.Box with a single dimension or None"
          )
      if image_format == "NCHW":
          in_channels = spec.input_space.shape[0]
          height = spec.input_space.shape[1]
          width = spec.input_space.shape[2]
      elif image_format == "NHWC":
          height = spec.input_space.shape[0]
          width = spec.input_space.shape[1]
          in_channels = spec.input_space.shape[2]
      else:
          raise ValueError(
              f"image_format has value {image_format!r}, but must be either "
              f"'NCHW' or 'NHWC'"
          )
      if in_channels not in (1, 3):
          warnings.warn(
              f"CNNModule input has {in_channels} channels, but "
              f"1 or 3 channels are typical. Consider changing the CNN "
              f"image_format."
          )
      return in_channels, height, width
  
file_path: garage/src/garage/torch/modules/cnn_module.py
imports: import warnings
  import akro
  import numpy
  import torch
  from torch import nn
  from garage import InOutSpec
  from garage.torch import expand_var, NonLinearity, output_height_2d, output_width_2d
label_desc: Use image node_id 1 for calling a global function with example usage: _check_spec(spec, image_format) and returns: in_channels,  height,  width