class_docstr: Poly-encoder Agent that ingests image features.
  
  Agent that allows encoding image features and adding or concatenating them to the
  context encoding.
class_docstr_tok: ["Poly-encoder","Agent","that","ingests","image","features",".","Agent","that","allows","encoding","image","features","and","adding","or","concatenating","them","to","the","context","encoding","."]
docstr: Return the image features as a Tensor of the correct type.
  
  Fill in missing feature vectors. Here, we require image features to be saved in
  `batch` as a Tensor for passing through the image encoder. This is required for
  data_parallel.
docstr_tok: ["Return","the","image","features","as","a","Tensor","of","the","correct","type",".","Fill","in","missing","feature","vectors",".","Here",",","we","require","image","features","to","be","saved","in","`","batch","`","as","a","Tensor","for","passing","through","the","image","encoder",".","This","is","required","for","data_parallel","."]
code: def batchify_image_features(self, batch: Batch) -> Batch:
      """
      Return the image features as a Tensor of the correct type.
  
      Fill in missing feature vectors. Here, we require image features to be saved in
      `batch` as a Tensor for passing through the image encoder. This is required for
      data_parallel.
      """
  
      # Checks/formatting of batch.image
      bsz = self._get_batch_size(batch)
      if batch.image is None or len(batch.image) == 0:
          batch.image = [None] * bsz
      else:
          assert len(batch.image) == bsz
  
      # Process all image feature vectors, or add in zero vectors if missing
      processed_features_list = []
      processed_zero_features = self._process_image_features(
          torch.zeros((self.image_features_dim,))
      )
      for orig_features in batch.image:
          if isinstance(orig_features, torch.Tensor):
              processed_features_list.append(
                  self._process_image_features(orig_features)
              )
          else:
              if orig_features is not None:
                  warn_once(
                      "Unsupported image feature format. Image features will be ignored!"
                  )
              processed_features_list.append(processed_zero_features)
  
      # Turn into batchsize x image_features_dim for DataParallel
      batch.image = torch.stack(processed_features_list)
  
      return batch
  
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from typing import Any, Dict
  import torch
  from parlai.agents.image_seq2seq.modules import ContextWithImageEncoder
  from parlai.agents.transformer.polyencoder import PolyencoderAgent, PolyEncoderModule
  from parlai.core.torch_agent import Batch
  from parlai.core.torch_image_agent import TorchImageAgent
  from parlai.utils.misc import warn_once
label_desc: Use image node_id 3 for calling the ImagePolyencoderAgent obj's underlying member method code with example usage: obj.batchify_image_features(batch) and returns: batch