Length of captions

#14
by Gandharv - opened

How much long of a caption can this model generate. Is there a way to increase the length of captions, making it more detailed?

Salesforce org

Hi @Gandharv
You can probably use sampling methods when calling generate, please have a look at https://huggingface.co/docs/transformers/generation_strategies for further details
You can also control the length of the generated text by setting max_new_tokens

Hi @Gandharv and @ybelkada
I tried max_new_tokens but it did not change the length.

Salesforce org

Hi @ppujari
Can you try using sampling methods?

Hello @ybelkada Thank you for your quick reply. Trying now the sampling approach. Will update you soon.

@ppujari did you have any success with the sampling approach?

You can do this

captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
captioner(image, max_new_tokens=200, generate_kwargs={"min_length": 40})

You can also do this:

out = model.generate(**inputs, max_new_tokens=200, min_length=40)

But I found it only made the results worse.

Sign up or log in to comment