Views
No views yet
saksornr/coco_caption-thai-ipu24-train-sample10k to generate Thai caption from images.saksornr/coco_caption-thai-ipu24-train-sample10k1from PIL import Image
2from unsloth import FastVisionModel
3model, tokenizer = FastVisionModel.from_pretrained(
4 "unsloth/Qwen3-VL-8B-Instruct-unsloth-bnb-4bit",
5 load_in_4bit = True,
6)
7model.load_adapter("KiruruP/Qwen3-VL-8B-ipu10k-thaicaption-lora")
8FastVisionModel.for_inference(model)
9
10instruction = "จงบรรยายภาพนี้เป็นภาษาไทยแบบสั้น กระชับ และเป็นธรรมชาติ"
11messages = [
12 {"role": "user",
13 "content": [
14 {"type": "image"},
15 {"type": "text", "text": instruction}
16 ]}
17]
18input_text = tokenizer.apply_chat_template(messages, add_generation_prompt = True, tokenize = False)
19
20image = Image.open("example.jpg").convert("RGB")
21inputs = tokenizer(
22 image,
23 input_text,
24 add_special_tokens = False,
25 return_tensors = "pt",
26).to("cuda")
27output = model.generate(**inputs, max_new_tokens = 100)
28generated_tokens = outputs[0][inputs.input_ids.shape[1]:] # For filtering prompt in output
29caption = tokenizer.decode(generated_tokens, skip_special_tokens=True).strip()
30print(caption)