Views
No views yet

microsoft/Florence-2-large model. This
model can be used to obtain metadata information about shots which can further be used to curate datasets of different kinds.1from transformers import AutoModelForCausalLM, AutoProcessor
2import torch
3from PIL import Image
4import requests
5
6
7folder_path = "diffusers/shot-categorizer-v0"
8model = (
9 AutoModelForCausalLM.from_pretrained(folder_path, torch_dtype=torch.float16, trust_remote_code=True)
10 .to("cuda")
11 .eval()
12)
13processor = AutoProcessor.from_pretrained(folder_path, trust_remote_code=True)
14
15prompts = ["<COLOR>", "<LIGHTING>", "<LIGHTING_TYPE>", "<COMPOSITION>"]
16img_path = "./assets/image_3.jpg"
17image = Image.open(img_path).convert("RGB")
18
19with torch.no_grad() and torch.inference_mode():
20 for prompt in prompts:
21 inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda", torch.float16)
22 generated_ids = model.generate(
23 input_ids=inputs["input_ids"],
24 pixel_values=inputs["pixel_values"],
25 max_new_tokens=1024,
26 early_stopping=False,
27 do_sample=False,
28 num_beams=3,
29 )
30 generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]
31 parsed_answer = processor.post_process_generation(
32 generated_text, task=prompt, image_size=(image.width, image.height)
33 )
34 print(parsed_answer)
351{'<COLOR>': 'Cool, Saturated, Cyan, Blue'}
2{'<LIGHTING>': 'Soft light, Low contrast'}
3{'<LIGHTING_TYPE>': 'Daylight, Sunny'}
4{'<COMPOSITION>': 'Left heavy'}