code: def _get_output_head(
      head_params: HeadParameters,
      head_idx: int,
      head_type_index: int,
      agent_params: AgentParameters,
      spaces: SpacesDefinition,
      network_name: str,
      is_local: bool,
  ) -> Head:
      """
      Given a head type, creates the head and returns it
      :param head_params: the parameters of the head to create
      :param head_idx: the head index
      :param head_type_index: the head type index (same index if head_param.num_output_head_copies>0)
      :param agent_params: agent parameters
      :param spaces: state and action space definitions
      :param network_name: name of the network
      :param is_local:
      :return: head block
      """
      head_params = _sanitize_activation(head_params)
      if isinstance(head_params, PPOHeadParameters):
          module = PPOHead(
              agent_parameters=agent_params,
              spaces=spaces,
              network_name=network_name,
              head_type_idx=head_type_index,
              loss_weight=head_params.loss_weight,
              is_local=is_local,
              activation_function=head_params.activation_function,
              dense_layer=head_params.dense_layer,
          )
      elif isinstance(head_params, VHeadParameters):
          module = VHead(
              agent_parameters=agent_params,
              spaces=spaces,
              network_name=network_name,
              head_type_idx=head_type_index,
              loss_weight=head_params.loss_weight,
              is_local=is_local,
              activation_function=head_params.activation_function,
              dense_layer=head_params.dense_layer,
          )
      elif isinstance(head_params, PPOVHeadParameters):
          module = PPOVHead(
              agent_parameters=agent_params,
              spaces=spaces,
              network_name=network_name,
              head_type_idx=head_type_index,
              loss_weight=head_params.loss_weight,
              is_local=is_local,
              activation_function=head_params.activation_function,
              dense_layer=head_params.dense_layer,
          )
      elif isinstance(head_params, QHeadParameters):
          module = QHead(
              agent_parameters=agent_params,
              spaces=spaces,
              network_name=network_name,
              head_type_idx=head_type_index,
              loss_weight=head_params.loss_weight,
              is_local=is_local,
              activation_function=head_params.activation_function,
              dense_layer=head_params.dense_layer,
          )
      else:
          raise KeyError(
              "Unsupported head type: {}".format(type(head_params))
          )
  
      return module
  
imports: import copy
  from itertools import chain
  from typing import List, Tuple, Union
  from types import ModuleType
  import numpy
  import mxnet
  from mxnet import nd, sym
  from mxnet.gluon import HybridBlock
  from mxnet.ndarray import NDArray
  from mxnet.symbol import Symbol
  from rl_coach.base_parameters import NetworkParameters
  from rl_coach.architectures.embedder_parameters import InputEmbedderParameters
  from rl_coach.architectures.head_parameters import HeadParameters, PPOHeadParameters
  from rl_coach.architectures.head_parameters import PPOVHeadParameters, VHeadParameters, QHeadParameters
  from rl_coach.architectures.middleware_parameters import MiddlewareParameters
  from rl_coach.architectures.middleware_parameters import FCMiddlewareParameters, LSTMMiddlewareParameters
  from rl_coach.architectures.mxnet_components.architecture import MxnetArchitecture
  from rl_coach.architectures.mxnet_components.embedders import ImageEmbedder, TensorEmbedder, VectorEmbedder
  from rl_coach.architectures.mxnet_components.heads import Head, HeadLoss, PPOHead, PPOVHead, VHead, QHead
  from rl_coach.architectures.mxnet_components.middlewares import FCMiddleware, LSTMMiddleware
  from rl_coach.architectures.mxnet_components import utils
  from rl_coach.base_parameters import AgentParameters, Device, DeviceType, EmbeddingMergerType
  from rl_coach.spaces import SpacesDefinition, PlanarMapsObservationSpace, TensorObservationSpace
label_desc: Use image node_id 5 for calling a global function with example usage: _get_output_head(head_params, head_idx, head_type_index, agent_params, spaces, network_name, is_local) and returns: module