code: def attn(image_feat, query, hparams, name="attn"):
      """Attention on image feature with question as query."""
      with tf.variable_scope(name, "attn", values=[image_feat, query]):
          attn_dim = hparams.attn_dim
          num_glimps = hparams.num_glimps
          num_channels = common_layers.shape_list(image_feat)[-1]
          if len(common_layers.shape_list(image_feat)) == 4:
              image_feat = common_layers.flatten4d3d(image_feat)
          query = tf.expand_dims(query, 1)
          image_proj = common_attention.compute_attention_component(
              image_feat, attn_dim, name="image_proj"
          )
          query_proj = common_attention.compute_attention_component(
              query, attn_dim, name="query_proj"
          )
          h = tf.nn.relu(image_proj + query_proj)
          h_proj = common_attention.compute_attention_component(
              h, num_glimps, name="h_proj"
          )
          p = tf.nn.softmax(h_proj, axis=1)
          image_ave = tf.matmul(image_feat, p, transpose_a=True)
          image_ave = tf.reshape(
              image_ave, [-1, num_channels * num_glimps]
          )
  
          return image_ave
  
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 4 for calling a global function with example usage: attn(image_feat, query, hparams, name) and returns: image_ave