code: def attn(image_feat, query, hparams, name="attn"):
    
    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
docs: Attention on image feature with question as query.