CFCamo: A Counterfactual Detect-or-Abstain Framework for Camouflaged Object Detection
Paper • 2606.11231 • Published
How to use cfcamo/cfcamo-rl-full with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="cfcamo/cfcamo-rl-full")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
pipe(text=messages) # Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("cfcamo/cfcamo-rl-full")
model = AutoModelForMultimodalLM.from_pretrained("cfcamo/cfcamo-rl-full")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use cfcamo/cfcamo-rl-full with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "cfcamo/cfcamo-rl-full"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "cfcamo/cfcamo-rl-full",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'docker model run hf.co/cfcamo/cfcamo-rl-full
How to use cfcamo/cfcamo-rl-full with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "cfcamo/cfcamo-rl-full" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "cfcamo/cfcamo-rl-full",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "cfcamo/cfcamo-rl-full" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "cfcamo/cfcamo-rl-full",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image in one sentence."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'How to use cfcamo/cfcamo-rl-full with Docker Model Runner:
docker model run hf.co/cfcamo/cfcamo-rl-full
Qwen3-VL-4B-Instruct fine-tuned with Counterfactual Sequence Policy Optimization (CSPO) and a Counterfactual Paired Reward (CPR) to detect camouflaged objects on natural images and abstain on target-absent counterfactuals. This is the paper-main full fine-tuning checkpoint (step 126, ε=0.5 on the 4040-pair RL set).
from transformers import AutoModelForImageTextToText, AutoProcessor
from PIL import Image
ckpt = "cfcamo/cfcamo-rl-full" # or a local path
processor = 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])
Output is one of:
<think>...</think><bbox>[x1,y1,x2,y2]</bbox> # single box
<think>...</think><bbox>[[...],[...]]</bbox> # multi-box
<think>...</think><no_camouflage/> # abstain
Box coordinates are in [0, 1000] normalized image space.
git clone https://github.com/suhang2000/CFCamo && cd CFCamo
pip install -e ".[eval]"
huggingface-cli download --repo-type dataset cfcamo/CF-COD --local-dir data/cfcod
# (place upstream COD into data/cfcod/<source>/{Imgs,GT}/ — see dataset card)
huggingface-cli download cfcamo/cfcamo-rl-full --local-dir checkpoints/cfcamo-rl-full
python scripts/eval/eval_cfcod.py \
--cf-manifest data/cfcod/test/cf_manifest_test.jsonl \
--data-root data/cfcod \
--models "CFCamo=checkpoints/cfcamo-rl-full" \
--out-dir results/cfcod_eval
@article{li2026cfcamo,
title = {{CFCamo}: A Counterfactual Detect-or-Abstain Framework for Camouflaged Object Detection},
author = {Li, Suhang and Yoshie, Osamu and Ieiri, Yuya},
journal = {arXiv preprint arXiv:2606.11231},
year = {2026}
}
Base model
Qwen/Qwen3-VL-4B-Instruct