Skip to content

Instantly share code, notes, and snippets.

@codezakh
Created February 4, 2024 14:32
Show Gist options
  • Save codezakh/47716b6bbfd33ca3f99629c1b0843b4c to your computer and use it in GitHub Desktop.
Save codezakh/47716b6bbfd33ca3f99629c1b0843b4c to your computer and use it in GitHub Desktop.
Get the answers+confidence from a BLIP-2 model for a VQA task.
outputs = blip2.generate(
pixel_values=pixel_values,
input_ids=input_ids,
attention_mask=attention_mask,
do_sample=False,
num_beams=5,
max_new_tokens=10,
min_length=1,
length_penalty=-1,
return_dict_in_generate=True,
output_scores=True,
)
output_text = blip2_tokenizer.batch_decode(
outputs.sequences, skip_special_tokens=True
)
output_scores = torch.exp(outputs.sequences_scores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment