code: def image_encoder(
      image_feat,
      hparams,
      name="image_encoder",
      save_weights_to=None,
      make_image_summary=True,
  ):
      """A stack of self attention layers."""
  
      x = image_feat
      with tf.variable_scope(name):
          for layer in range(
              hparams.num_encoder_layers or hparams.num_hidden_layers
          ):
              with tf.variable_scope("layer_%d" % layer):
                  with tf.variable_scope("self_attention"):
                      y = vqa_layers.multihead_attention(
                          common_layers.layer_preprocess(x, hparams),
                          None,
                          None,
                          hparams.attention_key_channels
                          or hparams.image_hidden_size,
                          hparams.attention_value_channels
                          or hparams.image_hidden_size,
                          hparams.image_hidden_size,
                          hparams.num_heads,
                          hparams.attention_dropout,
                          attention_type=hparams.self_attention_type,
                          save_weights_to=save_weights_to,
                          max_relative_position=None,
                          make_image_summary=make_image_summary,
                          dropout_broadcast_dims=None,
                          max_length=None,
                          vars_3d=False,
                          scale_otproduct=hparams.scale_dotproduct,
                      )
                      utils.collect_named_outputs(
                          "norms",
                          "image_feat_self_attention",
                          tf.norm(y, axis=-1),
                      )
                      x = common_layers.layer_postprocess(x, y, hparams)
                      utils.collect_named_outputs(
                          "norms",
                          "image_feat_self_attention_zero_add",
                          tf.norm(x, axis=-1),
                      )
                  with tf.variable_scope("ffn"):
                      y = common_layers.dense_relu_dense(
                          common_layers.layer_preprocess(x, hparams),
                          hparams.image_filter_size,
                          hparams.image_hidden_size,
                          dropout=hparams.relu_dropout,
                          dropout_broadcast_dims=None,
                      )
                      utils.collect_named_outputs(
                          "norms", "image_feat_ffn", tf.norm(y, axis=-1)
                      )
                      x = common_layers.layer_postprocess(x, y, hparams)
                      utils.collect_named_outputs(
                          "norms",
                          "image_feat_ffn_zero_add",
                          tf.norm(x, axis=-1),
                      )
          # if normalization is done in layer_preprocess, then it should also be done
          # on the output, since the output can grow very large, being the sum of
          # a whole stack of unnormalized layer outputs.
          return common_layers.layer_preprocess(x, hparams)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import vqa_layers
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  from tensorflow.contrib import rnn
  from tensorflow.contrib.layers.python.layers import utils
  from tensorflow.contrib.slim.python.slim.nets.resnet_v1 import resnet_v1_152
  from tensorflow.contrib.slim.python.slim.nets.resnet_v2 import resnet_v2_152
label_desc: Use image node_id 1 for calling a global function with example usage: image_encoder(image_feat, hparams, name, save_weights_to, make_image_summary) and returns: common_layers