class_docstr: interface to Image Captioner
class_docstr_tok: ["interface","to","Image","Captioner"]
docstr: ```
  Performs image captioning
  
  This method supports a single image or a list of images. If the input is an image, the return
  type is a string. If text is a list, a list of strings is returned
  Args:
      images: image|list
  Returns:
      list of captions
  ```
docstr_tok: ["``","`","Performs","image","captioning","This","method","supports","a","single","image","or","a","list","of","images",".","If","the","input","is","an","image",",","the","return","type","is","a","string",".","If","text","is","a","list",",","a","list","of","strings","is","returned","Args",":","images",":","image|list","Returns",":","list","of","captions","``","`"]
code: def caption(self, images):
      """
      ```
      Performs image captioning
  
      This method supports a single image or a list of images. If the input is an image, the return
      type is a string. If text is a list, a list of strings is returned
      Args:
          images: image|list
      Returns:
          list of captions
      ```
      """
      # Convert single element to list
      values = [images] if not isinstance(images, list) else images
  
      # Open images if file strings
      values = [
          I.Image.open(image) if isinstance(image, str) else image
          for image in values
      ]
  
      # Feature extraction
      pixels = self.extractor(
          images=values, return_tensors="pt"
      ).pixel_values
      pixels = pixels.to(self.torch_device)
  
      # Run model
      import torch
  
      with torch.no_grad():
          outputs = self.model.generate(
              pixels,
              max_length=16,
              num_beams=4,
              return_dict_in_generate=True,
          ).sequences
  
      # Tokenize outputs into text results
      captions = self.tokenizer.batch_decode(
          outputs, skip_special_tokens=True
      )
      captions = [caption.strip() for caption in captions]
  
      # Return single element if single element passed in
      return captions[0] if not isinstance(images, list) else captions
  
imports: from ...None import imports
  from ...torch_base import TorchBase
label_desc: Use image node_id 2 for calling the ImageCaptioner obj's underlying member method code with example usage: obj.caption(images) and returns: unknown