Skip to content

This repository is the official implementation of CamoDiffusion: Camouflaged Object Detection via Conditional Diffusion Models.

Notifications You must be signed in to change notification settings

Rapisurazurite/CamoDiffusion

Repository files navigation

CamoDiffusion

This repository is the official implementation of CamoDiffusion: Camouflaged Object Detection via Conditional Diffusion Models.

Our implementation is based on the denoising diffusion repository from lucidrains, which is a PyTorch implementation of DDPM.

And we provide our pretrained weight and inference result in release.

Requirements

  • python == 3.9
  • cuda == 11.3

To install requirements:

pip install -r requirements.txt

Dataset

COD (Camouflaged Object Detection) Dataset

Training

To train the model(s) in the paper, run this command:

accelerate launch train.py --config config/camoDiffusion_352x352.yaml --num_epoch=150 --batch_size=32 --gradient_accumulate_every=1

And then finetune it to 384 size:

accelerate launch train.py --config config/camoDiffusion_384x384.yaml --num_epoch=20 --batch_size=28 --gradient_accumulate_every=1 --pretrained model_352/model-best.pt --lr_min=0 --set optimizer.params.lr=1e-5

Evaluation

To test a model, run sample.py with the desired model on different datasets:

accelerate launch sample.py \
  --config config/camoDiffusion_384x384.yaml \
  --results_folder ${RESULT_SAVE_PATH} \
  --checkpoint ${CHECKPOINT_PATH} \
  --num_sample_steps 10 \
  --target_dataset CAMO \
  --time_ensemble

For ease of use, we create a eval.sh script and a use case in the form of a shell script eval.sh. You can edit the script to change the parameters you want to test.

bash scripts/eval.sh

Tips

  1. To implement the ATCN-Skip strategy, modify the config file by changing SimpleDiffSeg to SimpleDiffSeg_Skip. This adjustment allows the ATCN computation to be skipped every alternate time step, minimizing computational redundancy.

  2. The pretrained model weights have been uploaded in the release. The pretrained weights for SOD will be uploaded soon.

Citation

@article{chen2023camodiffusion,
  title={CamoDiffusion: Camouflaged Object Detection via Conditional Diffusion Models},
  author={Chen, Zhongxi and Sun, Ke and Lin, Xianming and Ji, Rongrong},
  journal={arXiv preprint arXiv:2305.17932},
  year={2023}
}
@article{sun2025conditional,
  title={Conditional Diffusion Models for Camouflaged and Salient Object Detection},
  author={Sun, Ke and Chen, Zhongxi and Lin, Xianming and Sun, Xiaoshuai and Liu, Hong and Ji, Rongrong},
  journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
  year={2025},
  publisher={IEEE}
}

About

This repository is the official implementation of CamoDiffusion: Camouflaged Object Detection via Conditional Diffusion Models.

Resources

Stars

Watchers

Forks

Packages

No packages published