Views
No views yet
LiquidAI/LFM2.5-VL-450M on the TurkishCodeMan/Sentinel2-Turkey-VLM dataset.1import torch
2from PIL import Image
3from transformers import AutoProcessor, AutoModelForImageTextToText
4
5model_id = "TurkishCodeMan/LFM2.5-VL-450M-Pre-Disaster-Detection"
6processor = AutoProcessor.from_pretrained(model_id)
7model = AutoModelForImageTextToText.from_pretrained(model_id, device_map="auto", dtype="bfloat16")
8
9# Load your RGB and CIR images, then merge them horizontally
10# merged_image = merge_images(rgb, cir)
11
12SYSTEM_PROMPT = """Extract the following from the image:
13
14risk_level: The fire risk level of the forest based on the right side CIR image, select from Low, Medium, or High
15dry_vegetation_present: Is dry vegetation present (which appears as greyish/brownish/non-red in the right side CIR image)?, select from true, or false
16steep_terrain: Is the terrain steep based on the images?, select from true, or false
17water_body_present: Is there a water body (lake, river) present in the left RGB image?, select from true, or false
18image_quality_limited: Is the image quality limited or very cloudy?, select from true, or false
19
20Respond with only a JSON object. Do not include any text outside the JSON."""
21
22conversation = [
23 {"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]},
24 {"role": "user", "content": [{"type": "image", "image": merged_image}]}
25]
26
27inputs = processor.apply_chat_template(conversation, return_tensors="pt", return_dict=True, tokenize=True, add_generation_prompt=True)
28inputs = {k: v.to(model.device) for k, v in inputs.items()}
29
30with torch.no_grad():
31 output_ids = model.generate(**inputs, max_new_tokens=150, temperature=0.1)
32
33generated_ids = output_ids[0][inputs["input_ids"].shape[1]:]
34generated_text = processor.decode(generated_ids, skip_special_tokens=True).strip()
35print(generated_text)