class_docstr: ContextWithImage Module.
  
  Encodes image features and context, and combines by summing or concatenation.
class_docstr_tok: ["ContextWithImage","Module",".","Encodes","image","features","and","context",",","and","combines","by","summing","or","concatenation","."]
docstr: Encode images with context.
  
  Encodes tokens (if given) and images (if given) depending on fusion setting.
  
  :param src_tokens:
      A bsz x seq_len tensor of src_tokens; possibly None
  :param image_features:
      Either a list of (torch.tensor) or a tensor of shape (batch_size,
      self.img_dim)
  
  :return:
      A (full_enc, full_mask) tuple, which represents the encoded context
      and the mask
docstr_tok: ["Encode","images","with","context",".","Encodes","tokens","(","if","given",")","and","images","(","if","given",")","depending","on","fusion","setting",".",":","param","src_tokens",":","A","bsz","x","seq_len","tensor","of","src_tokens",";","possibly","None",":","param","image_features",":","Either","a","list","of","(","torch.tensor",")","or","a","tensor","of","shape","(","batch_size",",","self.img_dim",")",":","return",":","A","(","full_enc",",","full_mask",")","tuple",",","which","represents","the","encoded","context","and","the","mask"]
code: def forward(  # type: ignore
      self,
      src_tokens: Optional[torch.LongTensor],
      image_features: Optional[Union[List[object], torch.Tensor]],
  ) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
      """
      Encode images with context.
  
      Encodes tokens (if given) and images (if given) depending on fusion setting.
  
      :param src_tokens:
          A bsz x seq_len tensor of src_tokens; possibly None
      :param image_features:
          Either a list of (torch.tensor) or a tensor of shape (batch_size,
          self.img_dim)
  
      :return:
          A (full_enc, full_mask) tuple, which represents the encoded context
          and the mask
      """
      if self.fusion is FusionType.LATE:
          return self._forward_late_fusion(src_tokens, image_features)
      elif self.fusion is FusionType.EARLY:
          return self._forward_early_fusion(src_tokens, image_features)
      else:
          raise RuntimeError(f"Unsupported fusion type: {self.fusion}")
  
imports: from enum import Enum
  from functools import reduce
  from typing import List, Tuple, Optional, Union
  import torch
  import torch.nn
  from parlai.agents.transformer.modules import TransformerGeneratorModel, TransformerEncoder
  from parlai.core.dict import DictionaryAgent
  from parlai.core.opt import Opt
label_desc: Use image node_id 4 for calling the ContextWithImageEncoder obj's underlying member method code with example usage: obj.forward(src_tokens, image_features) and returns: self, self