class_docstr: BLIP2 T5 model.
  Supported model types:
      - pretrain_flant5xl: pretrained model with FlanT5-XL
      - pretrain_flant5xl_vitL: pretrained model with FlanT5-XL
      - pretrain_flant5xxl: pretrained model with FlanT5-XXL
      - caption_coco_flant5xl: fintuned image captioning model with FlanT5-XL
  Usage:
      >>> from lavis.models import load_model
      >>> model = load_model("blip2_t5", "pretrain_flant5xl")
class_docstr_tok: ["BLIP2","T5","model",".","Supported","model","types",":","-","pretrain_flant5xl",":","pretrained","model","with","FlanT5-XL","-","pretrain_flant5xl_vitL",":","pretrained","model","with","FlanT5-XL","-","pretrain_flant5xxl",":","pretrained","model","with","FlanT5-XXL","-","caption_coco_flant5xl",":","fintuned","image","captioning","model","with","FlanT5-XL","Usage",":",">",">",">","from","lavis.models","import","load_model",">",">",">","model","=","load_model","(","``","blip2_t5","''",",","``","pretrain_flant5xl","''",")"]
code: def predict_answers(
      self,
      samples,
      num_beams=5,
      inference_method="generate",
      max_len=10,
      min_len=1,
      num_ans_candidates=128,
      answer_list=None,
      prompt="",
      length_penalty=-1,
      **kwargs,
  ):
      image = samples["image"]
      with self.maybe_autocast():
          image_embeds = self.ln_vision(self.visual_encoder(image))
      image_embeds = image_embeds.float()
      image_atts = torch.ones(
          image_embeds.size()[:-1], dtype=torch.long
      ).to(image.device)
  
      query_tokens = self.query_tokens.expand(
          image_embeds.shape[0], -1, -1
      )
      query_output = self.Qformer.bert(
          query_embeds=query_tokens,
          encoder_hidden_states=image_embeds,
          encoder_attention_mask=image_atts,
          return_dict=True,
      )
  
      inputs_t5 = self.t5_proj(query_output.last_hidden_state)
      atts_t5 = torch.ones(inputs_t5.size()[:-1], dtype=torch.long).to(
          image.device
      )
  
      if isinstance(samples["text_input"], str):
          samples["text_input"] = [samples["text_input"]]
      if prompt:
          text_input = [
              prompt.format(question)
              for question in samples["text_input"]
          ]
      else:
          text_input = samples["text_input"]
  
      input_tokens = self.t5_tokenizer(
          text_input, padding="longest", return_tensors="pt"
      ).to(image.device)
  
      encoder_atts = torch.cat(
          [atts_t5, input_tokens.attention_mask], dim=1
      )
  
      with self.maybe_autocast(dtype=torch.bfloat16):
          inputs_embeds = self.t5_model.encoder.embed_tokens(
              input_tokens.input_ids
          )
          inputs_embeds = torch.cat([inputs_t5, inputs_embeds], dim=1)
  
          outputs = self.t5_model.generate(
              inputs_embeds=inputs_embeds,
              attention_mask=encoder_atts,
              do_sample=False,
              num_beams=num_beams,
              max_new_tokens=max_len,
              min_length=min_len,
              length_penalty=length_penalty,
          )
          output_text = self.t5_tokenizer.batch_decode(
              outputs, skip_special_tokens=True
          )
  
      if self._apply_lemmatizer:
          output_text = self._lemmatize(output_text)
  
      return output_text
  
file_path: lavis/lavis/models/blip2_models/blip2_t5.py
imports: import logging
  import torch
  import torch.nn
  from torch.cuda.amp import autocast
  from transformers import T5TokenizerFast
  from lavis.common.registry import registry
  from lavis.models.blip2_models.blip2 import Blip2Base, disabled_train
  from lavis.models.blip2_models.modeling_t5 import T5Config, T5ForConditionalGeneration
label_desc: Use image node_id 4 for calling the Blip2T5 obj's underlying member method code with example usage: obj.predict_answers(samples, num_beams, inference_method, max_len, min_len, num_ans_candidates, answer_list, prompt, length_penalty) and returns: output_text