code: def attn(
      image_feat,
      query,
      hparams,
      name="attn",
      save_weights_to=None,
      make_image_summary=True,
  ):
      """Attention on image feature with question as query."""
      with tf.variable_scope(name, "attn", values=[image_feat, query]):
          total_key_depth = (
              hparams.attention_key_channels or hparams.hidden_size
          )
          total_value_depth = (
              hparams.attention_value_channels or hparams.hidden_size
          )
          num_heads = hparams.num_heads
          query = tf.expand_dims(query, 1)
          q, k, v = common_attention.compute_qkv(
              query,
              image_feat,
              total_key_depth,
              total_value_depth,
          )
          q = common_attention.split_heads(q, num_heads)
          k = common_attention.split_heads(k, num_heads)
          v = common_attention.split_heads(v, num_heads)
  
          if hparams.scale_dotproduct:
              key_depth_per_head = total_key_depth // num_heads
              q *= key_depth_per_head**-0.5
  
          # image_feat is input as v
          x = common_attention.dot_product_attention(
              q,
              k,
              v,
              None,
              dropout_rate=hparams.attention_dropout,
              image_shapes=None,
              save_weights_to=save_weights_to,
              make_image_summary=make_image_summary,
          )
          x = common_attention.combine_heads(x)
  
          return tf.squeeze(x, axis=1)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from six.moves import range
  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.models.research import vqa_attention
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  from tensorflow.contrib.layers.python.layers import utils
label_desc: Use image node_id 4 for calling a global function with example usage: attn(image_feat, query, hparams, name, save_weights_to, make_image_summary) and returns: tf