Views
No views yet
microsoft/Florence-2-large model. The model has been tuned on a 38,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.1from transformers import AutoModelForCausalLM, AutoProcessor, AutoConfig
2import torch
3
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5
6model = AutoModelForCausalLM.from_pretrained("thwri/CogFlorence-2-Large-Freeze", trust_remote_code=True).to(device).eval()
7processor = AutoProcessor.from_pretrained("thwri/CogFlorence-2-Large-Freeze", trust_remote_code=True)
8
9# Function to run the model on an example
10def run_example(task_prompt, image):
11 prompt = task_prompt
12
13 # Ensure the image is in RGB mode
14 if image.mode != "RGB":
15 image = image.convert("RGB")
16
17 inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
18 generated_ids = model.generate(
19 input_ids=inputs["input_ids"],
20 pixel_values=inputs["pixel_values"],
21 max_new_tokens=1024,
22 num_beams=3,
23 do_sample=True
24 )
25 generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
26 parsed_answer = processor.post_process_generation(generated_text, task=task_prompt, image_size=(image.width, image.height))
27 return parsed_answer
28
29from PIL import Image
30import requests
31import copy
32
33url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
34image = Image.open(requests.get(url, stream=True).raw)
35result = run_example("<MORE_DETAILED_CAPTION>" , image)
36print(result)
37
38# {'<MORE_DETAILED_CAPTION>': 'a turquoise volkswagen beetle parked on a cobblestone street in front of a yellow wall with two wooden doors. the car's body is painted in a vibrant shade of teal, with a glossy finish that reflects the sunlight, and the wheels are polished with a silver hubcap. the building behind the car has a weathered, aged appearance, with visible cracks and peeling paint. the sky above is clear and blue, suggesting a sunny day.'}