class_docstr: Implements the Multi-Aspect Global Context Attention, as described in
  <https://arxiv.org/pdf/1910.02562.pdf>`_.
  
  Args:
  ----
      inplanes: input channels
      headers: number of headers to split channels
      attn_scale: if True, re-scale attention to counteract the variance distibutions
      ratio: bottleneck ratio
      **kwargs
class_docstr_tok: ["Implements","the","Multi-Aspect","Global","Context","Attention",",","as","described","in","<","https",":","\/\/arxiv.org\/pdf\/1910.02562.pdf",">","`","_",".","Args",":","--","--","inplanes",":","input","channels","headers",":","number","of","headers","to","split","channels","attn_scale",":","if","True",",","re-scale","attention","to","counteract","the","variance","distibutions","ratio",":","bottleneck","ratio","*","*","kwargs"]
code: def context_modeling(self, inputs: tf.Tensor) -> tf.Tensor:
      b, h, w, c = (tf.shape(inputs)[i] for i in range(4))
  
      # B, H, W, C -->> B*h, H, W, C/h
      x = tf.reshape(
          inputs,
          shape=(b, h, w, self.headers, self.single_header_inplanes),
      )
      x = tf.transpose(x, perm=(0, 3, 1, 2, 4))
      x = tf.reshape(
          x, shape=(b * self.headers, h, w, self.single_header_inplanes)
      )
  
      # Compute shorcut
      shortcut = x
      # B*h, 1, H*W, C/h
      shortcut = tf.reshape(
          shortcut,
          shape=(
              b * self.headers,
              1,
              h * w,
              self.single_header_inplanes,
          ),
      )
      # B*h, 1, C/h, H*W
      shortcut = tf.transpose(shortcut, perm=[0, 1, 3, 2])
  
      # Compute context mask
      # B*h, H, W, 1
      context_mask = self.conv_mask(x)
      # B*h, 1, H*W, 1
      context_mask = tf.reshape(
          context_mask, shape=(b * self.headers, 1, h * w, 1)
      )
      # scale variance
      if self.attn_scale and self.headers > 1:
          context_mask = context_mask / math.sqrt(
              self.single_header_inplanes
          )
      # B*h, 1, H*W, 1
      context_mask = tf.keras.activations.softmax(context_mask, axis=2)
  
      # Compute context
      # B*h, 1, C/h, 1
      context = tf.matmul(shortcut, context_mask)
      context = tf.reshape(context, shape=(b, 1, c, 1))
      # B, 1, 1, C
      context = tf.transpose(context, perm=(0, 1, 3, 2))
      # Set shape to resolve shape when calling this module in the Sequential MAGCResnet
      batch, chan = (
          inputs.get_shape().as_list()[0],
          inputs.get_shape().as_list()[-1],
      )
      context.set_shape([batch, 1, 1, chan])
      return context
  
file_path: doctr/doctr/models/classification/magc_resnet/tensorflow.py
imports: import math
  from copy import deepcopy
  from functools import partial
  from typing import Any, Dict, List, Optional, Tuple
  import tensorflow
  from tensorflow.keras import layers
  from tensorflow.keras.models import Sequential
  from doctr.datasets import VOCABS
  from ...utils import load_pretrained_params
  from ..resnet.tensorflow import ResNet
label_desc: Use image node_id 2 for calling the MAGC obj's underlying member method code with example usage: obj.context_modeling(inputs) and returns: context