Views
No views yet
microsoft/Florence-2-large model. The model has been tuned on a 40,000 image subset of the Ejafa/ye-pop dataset, with captions generated using THUDM/cogvlm2-llama3-chat-19B.Ejafa/ye-pop dataset. This dataset contains a wide array of images with varying subjects, providing a robust training ground for improving the model's captioning abilities.THUDM/cogvlm2-llama3-chat-19B and then post-processed with google/gemma-2-9b to remove vagueness.1from transformers import AutoModelForCausalLM, AutoProcessor, AutoConfig
2import torch
3device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
4model = AutoModelForCausalLM.from_pretrained("thwri/CogFlorence-2.2-Large", trust_remote_code=True).to(device).eval()
5processor = AutoProcessor.from_pretrained("thwri/CogFlorence-2.2-Large", trust_remote_code=True)
6# Function to run the model on an example
7def run_example(task_prompt, image):
8 prompt = task_prompt
9 # Ensure the image is in RGB mode
10 if image.mode != "RGB":
11 image = image.convert("RGB")
12 inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
13 generated_ids = model.generate(
14 input_ids=inputs["input_ids"],
15 pixel_values=inputs["pixel_values"],
16 max_new_tokens=1024,
17 num_beams=3,
18 do_sample=True
19 )
20 generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
21 parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
22 return parsed_answer
23from PIL import Image
24import requests
25import copy
26url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
27image = Image.open(requests.get(url, stream=True).raw)
28result = run_example("<MORE_DETAILED_CAPTION>" , image)
29print(result)
30# {'<MORE_DETAILED_CAPTION>': 'A vivid portrayal of a classic Volkswagen Beetle parked on a cobblestone street. The car is painted a vibrant turquoise, contrasting with the muted yellow of the building behind it. The building has two wooden doors, one with a white frame and the other with a dark brown finish. The sky is clear, and the sun casts a warm glow on the scene, highlighting the car's details. The image evokes a nostalgic and nostalgic mood, capturing a moment in time without posed elements.'}