code: def create_tower_spec(
      phoenix_spec,
      inputs,
      architecture,
      dimension,
      is_frozen,
      lengths=None,
      allow_auxiliary_head=False,
  ):
      """Creates the logits for the tower.
  
      Args:
        phoenix_spec: The trial's `phoenix_spec_pb2.PhoenixSpec` proto.
        inputs: The list of `tf.Tensors` of the tower.
        architecture: The list of `block_builder.BlockType` of the tower
          architecture.
        dimension: int - the output tensor last axis dimension.
        is_frozen: Whether the tower should be frozen.
        lengths: A tensor of shape [batch] holding the sequence length for a
          sequential problem (rnn).
        allow_auxiliary_head: Whether to allow creating an auxiliary head if
          possible. Only applicable for CNNs.
  
      Returns:
        A LogitsSpec containing the main and auxiliary logits and the architecture
        of the underlying tower.
      """
  
      # Discard inputs[0] since this is the raw features.
      all_layer_tensors = inputs
      pre_logits = inputs[-1]
      logits_weight = 1.0
      aux_logits = None
      aux_logits_weight = None
      logits = None
      if phoenix_spec.disable_last_dense_layer:
          logits = pre_logits
          if pre_logits.get_shape().as_list()[-1] != dimension:
              logging.warning(
                  "PhoenixSpec.disable_last_dense_layer is turned on, "
                  "and we are getting non-consistent logits size from the "
                  "last block. The block is providing tensor with last "
                  "dimension %s, and number of classes is %s",
                  pre_logits.get_shape().as_list()[-1],
                  dimension,
              )
      elif (
          phoenix_spec.problem_type
          == phoenix_spec_pb2.PhoenixSpec.RNN_ALL_ACTIVATIONS
      ):
          logits = tf.keras.layers.Dense(dimension, name="conv1d")(
              pre_logits
          )
      elif (
          phoenix_spec.problem_type
          == phoenix_spec_pb2.PhoenixSpec.RNN_LAST_ACTIVATIONS
      ):
          if lengths is not None:
              logits = utils.last_activations_in_sequence(
                  tf.keras.layers.Dense(dimension, name="conv1d")(
                      pre_logits
                  )
              )
          else:
              logging.warning(
                  "Length is missing for rnn_last problem type."
              )
              logits = tf.compat.v1.layers.conv1d(
                  inputs=pre_logits, filters=dimension, kernel_size=1
              )
      elif (
          phoenix_spec.problem_type == phoenix_spec_pb2.PhoenixSpec.CNN
          or phoenix_spec.problem_type
          == phoenix_spec_pb2.PhoenixSpec.DNN
      ):
          logits = tf.keras.layers.Dense(dimension, name="dense")(
              pre_logits
          )
      else:
          raise ValueError(
              "phoenix_spec.problem_type must be either DNN, CNN, "
              "RNN_LAST_ACTIVATIONS, or RNN_ALL_ACTIVATIONS."
          )
  
      if phoenix_spec.problem_type == phoenix_spec_pb2.PhoenixSpec.CNN:
          if allow_auxiliary_head and phoenix_spec.use_auxiliary_head:
              reductions = []
              flattens = []
              for i, block in enumerate(architecture):
                  name = block_builder.BlockType(block).name
                  if "DOWNSAMPLE" in name or "REDUCTION" in name:
                      reductions.append(i)
                  # Some blocks reduce and flatten.
                  if "FLATTEN" in name:
                      flattens.append(i)
              if reductions:
                  # Add the auxiliary head right before the reduction cell.
                  idx = reductions[-1]
                  aux_logits = _build_nas_aux_head(
                      inputs[idx],
                      dimension,
                      phoenix_spec.cnn_data_format,
                  )
                  if aux_logits is not None:
                      aux_logits_weight = (
                          phoenix_spec.auxiliary_head_loss_weight
                      )
              if flattens and aux_logits is None:
                  idx = flattens[-1]
                  aux_logits = tf.keras.layers.Dense(
                      dimension, name="aux_dense"
                  )(inputs[idx])
                  aux_logits_weight = (
                      phoenix_spec.auxiliary_head_loss_weight
                  )
  
      logits = tf.identity(logits, name="logits")
      if aux_logits is not None:
          aux_logits = tf.identity(aux_logits, name="aux_logits")
  
      # TODO(b/172564129): Remove from eval graph.
      if is_frozen:
          logits = tf.stop_gradient(logits)
          if aux_logits is not None:
              aux_logits = tf.stop_gradient(aux_logits)
  
      return TowerSpec(
          logits_spec=LogitsSpec(
              logits, logits_weight, aux_logits, aux_logits_weight
          ),
          architecture=[
              block_builder.BlockType(block).name
              for block in architecture
          ],
          layer_tensors=all_layer_tensors,
      )
  
imports: import collections
  import os
  import string
  import time
  from absl import flags
  from absl import logging
  from model_search import block
  from model_search import block_builder
  from model_search import hparam
  from model_search import utils
  from model_search.proto import hparam_pb2
  from model_search.proto import phoenix_spec_pb2
  from model_search.proto import transfer_learning_spec_pb2
  import numpy
  import tensorflow.compat.v2
  import tf_slim
  from google.protobuf import text_format
label_desc: Use image node_id 19 for calling a global function with example usage: create_tower_spec(phoenix_spec, inputs, architecture, dimension, is_frozen, lengths, allow_auxiliary_head) and returns: TowerSpec