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