Image Annotation & Captioning
Collection
Trained based on Flux-generated images and their enhanced prompt captioning and annotations in a simple JSON format. • 3 items • Updated • 1
# Load model directly
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("prithivMLmods/Caption-Pro")
model = AutoModelForImageTextToText.from_pretrained("prithivMLmods/Caption-Pro")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))Caption-Pro is an advanced image caption and annotation generator optimized for generating detailed, structured JSON outputs. Built upon a powerful vision-language architecture with enhanced OCR and multilingual support, Caption-Pro extracts high-quality captions and annotations from images for seamless integration into your applications.
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
# Load the Caption-Pro model with optimized parameters
model = Qwen2VLForConditionalGeneration.from_pretrained(
"prithivMLmods/Caption-Pro", torch_dtype="auto", device_map="auto"
)
# Recommended acceleration for performance optimization:
# model = Qwen2VLForConditionalGeneration.from_pretrained(
# "prithivMLmods/Caption-Pro",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
# device_map="auto",
# )
# Load the default processor for Caption-Pro
processor = AutoProcessor.from_pretrained("prithivMLmods/Caption-Pro")
# Define the input messages with both an image and a text prompt
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://flux-generated.com/sample_image.jpeg",
},
{"type": "text", "text": "Provide detailed captions and annotations for this image in JSON format."},
],
}
]
# Prepare the input for inference
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# Generate the output
generated_ids = model.generate(**inputs, max_new_tokens=256)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
Annotation-Ready Training Data
Optical Character Recognition (OCR)
Structured JSON Output
Image & Text Processing
Conversational Annotation Generation
Secure and Efficient Model Weights
Caption-Pro streamlines the process of generating image captions and annotations, making it an ideal solution for applications that require detailed visual content analysis and structured data integration.
Base model
Qwen/Qwen2-VL-2B
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="prithivMLmods/Caption-Pro") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)