from transformers import AutoModelForImageTextToText, AutoProcessorfrom PIL import Image ckpt = "cfcamo/cfcamo-rl-full" # or a local pathprocessor = AutoProcessor.from_pretrained(ckpt)model = AutoModelForImageTextToText.from_pretrained( ckpt, torch_dtype="auto", device_map="auto",).eval() SYS = ( "You are a camouflaged object detector. Output in this exact format:\n\n" "<think>your reasoning here</think>\n" "followed by ONE of:\n" " - <bbox>[x1,y1,x2,y2]</bbox> for a single camouflaged object\n" " - <bbox>[[x1,y1,x2,y2],[x3,y3,x4,y4]]</bbox> for multiple objects\n" " - <no_camouflage/> if no camouflaged object is present\n\n" "Coordinates are normalized to [0, 1000] where 1000 = full image dimension.")USR = ( "Identify and locate any camouflaged object in the image.\n\n" "In <think></think>, briefly consider scene textures, visual anomalies, " "and if any object blends in. Then output ONE of:\n" "- <bbox>[x1,y1,x2,y2]</bbox> for one object, or [[x1,y1,x2,y2],...] for multiple\n" "- <no_camouflage/> if no camouflaged object") image = Image.open("path/to/image.jpg").convert("RGB")messages = [ {"role": "system", "content": SYS}, {"role": "user", "content": [ {"type": "image", "image": image}, {"type": "text", "text": USR}, ]},]inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt",).to(model.device)out = model.generate(**inputs, max_new_tokens=512, do_sample=False)print(processor.batch_decode(out[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)[0])