Create conda environment

March 13, 2026 Β· View on GitHub

English | δΈ­ζ–‡

SARNet: Go Closer to See Better πŸ”

Camouflaged Object Detection via Object Area Amplification and Figure-Ground Conversion

Paper Stars Issues License

Highlights β€’ Architecture β€’ Results β€’ Visualization β€’ Quick Start β€’ Citation

Motivation
Figure 1: The proposed Search-Amplify-Recognize (SAR) paradigm. Unlike previous Search-Identify approaches, SARNet introduces an Amplify stage via OAA modules and a Recognize stage via FGC modules to progressively detect well-camouflaged objects.


πŸ‘‹ Why This Project?

New to Camouflaged Object Detection (COD)? You're in the right place!

SARNet is designed to be a beginner-friendly yet research-grade COD project. Whether you're a student exploring COD for the first time or a researcher looking for a solid baseline, this repo has everything you need:

  • πŸ“– Clean & Well-Commented Code β€” Every module is clearly documented, making it easy to understand the full pipeline from data loading to model inference.
  • 🎨 Ready-to-Use Visualization Tools β€” We open-source the scripts to generate feature map heatmaps and prediction overlays (see Visualization), so you can visually understand how the model works β€” not just look at numbers.
  • 🧩 Modular Architecture β€” The OAA and FGC modules are self-contained and easy to plug into your own network for experimentation.
  • πŸš€ End-to-End Workflow β€” Training, inference, evaluation, and visualization are all included. Just clone, configure paths, and run!
  • πŸ“Š Automatic Evaluation β€” Metrics (S-measure, F-measure, MAE, E-measure) are computed and saved to Excel automatically after inference.

πŸ’‘ If this is your first COD project, we recommend starting with the Quick Start section and then exploring the Visualization tools to build intuition about how camouflaged objects are detected.

✨ Highlights

  • 🎯 Object Area Amplification (OAA) β€” Fuses adjacent-level features to amplify target region representations, enabling the network to "go closer" to camouflaged objects.
  • πŸ”„ Figure-Ground Conversion (FGC) β€” Progressively refines predictions by selectively attending to foreground/background regions that deeper layers missed.
  • πŸ† State-of-the-Art β€” Achieves competitive performance on 4 major COD benchmarks (CAMO, CHAMELEON, COD10K, NC4K).
  • ⚑ PVTv2 Backbone β€” Leverages Pyramid Vision Transformer V2 for powerful multi-scale feature extraction.
  • 🎨 Open-Source Visualization Tools β€” We provide ready-to-use scripts for feature map heatmap generation and prediction overlay visualization (see Visualization).

πŸ— Architecture

SARNet Architecture
Figure 3: Overall architecture of SARNet. The PVTv2 backbone extracts multi-scale features, which are then processed by Object Area Amplification (OAA) modules to fuse and amplify target features. Figure-Ground Conversion modules (FFGC, EFGC) progressively refine predictions by attending to foreground/background regions.

Key Design Insights:

ModuleRoleMechanism
OAAObject Area AmplificationFuses current-level & deeper features via dual-branch Conv+Upsample+Concat
FGC (bg mode)Background-aware RefinementMorphological dilation βˆ’ prediction β†’ attends to missed regions
FGC (fg mode)Foreground-aware RefinementUses prediction map as attention weights for foreground enhancement
CBRChannel ReductionConv β†’ BatchNorm β†’ ReLU on the deepest features

πŸ“Š Results

Quantitative Comparison on COD Benchmarks

All metrics are reported using the same evaluation protocol. ↑ means higher is better, ↓ means lower is better.

DatasetS-measure ↑weighted F ↑MAE ↓mean E ↑mean F ↑
CAMO0.7960.7000.0750.8500.754
CHAMELEON0.8880.8300.0320.9450.859
COD10K0.8150.6670.0370.8860.720
NC4K0.8430.7520.0480.8970.787

πŸ’‘ Please refer to the paper for full comparison tables with other methods.

Qualitative Comparison

Visual Comparison
Figure 6: Visual comparison with state-of-the-art methods. SARNet produces more accurate and complete segmentation masks, especially for objects with complex camouflage patterns. Our method effectively handles challenging cases such as small objects, objects with similar texture to the background, and multiple camouflaged instances.

🎨 Visualization

πŸ“’ We open-source all visualization tools used in the paper! You can reproduce the feature heatmaps and prediction overlays shown below using the provided scripts in the display_heatmaps/ directory.

Feature Map Heatmaps

Feature Map Heatmaps
Figure 7: Feature map visualization at different stages. The heatmaps demonstrate how OAA and FGC modules progressively focus on camouflaged objects. Warmer colors indicate higher activation, showing that deeper features attend to broader regions while refined features precisely localize object boundaries.

Generate feature map heatmaps with the open-source script:

cd display_heatmaps && python heatmap.py

The script loads intermediate feature maps, applies colormap transformations, and overlays heatmaps on the original images. See display_heatmaps/heatmap.py for details.

Feature Visualization Analysis

Feature Visualization
Figure 8: Detailed feature visualization showing the effect of OAA and FGC modules. (a-b) Features before/after OAA demonstrate amplified object area attention. (c-d) Features before/after FGC show refined figure-ground separation.

Prediction Overlay

Overlay prediction maps on original images for qualitative analysis:

cd display_heatmaps && python combine.py

The script generates side-by-side comparisons of input images, ground truth masks, and model predictions. See display_heatmaps/combine.py for details.


πŸ“¦ Pretrained Models & Prediction Maps

ResourceBackboneDownload
Pretrained ModelPVTv2-B3Google Drive
Prediction Mapsβ€”Google Drive

πŸš€ Quick Start

1. Environment Setup

# Clone the repository
git clone https://github.com/Haozhe-Xing/SARNet.git
cd SARNet

# Create conda environment
conda create -n sarnet python=3.8.13 -y
conda activate sarnet

# Install dependencies
pip install -r requirements.txt

Requirements: Python 3.8 Β· PyTorch Β· PVTv2 pretrained weights (download)

2. Dataset Preparation

Download COD10K and organize as:

<your_data_root>/
└── COD10K/
    β”œβ”€β”€ TrainDataset1/
    β”‚   β”œβ”€β”€ Imgs/          # Training images (.jpg)
    β”‚   └── GT/            # Ground truth masks (.png)
    └── TestDataset/
        β”œβ”€β”€ CHAMELEON/
        β”‚   β”œβ”€β”€ Imgs/
        β”‚   └── GT/
        β”œβ”€β”€ CAMO/
        β”‚   β”œβ”€β”€ Imgs/
        β”‚   └── GT/
        β”œβ”€β”€ COD10K/
        β”‚   β”œβ”€β”€ Imgs/
        β”‚   └── GT/
        └── NC4K/
            β”œβ”€β”€ Imgs/
            └── GT/

Then update the root path in config.py.

3. Training

python train.py
βš™οΈ Training Configuration (click to expand)
ParameterDefaultDescription
pvt_namepvt_v2_b3PVTv2 backbone variant
args['scale']384Input image resolution
args['epoch_num']100Number of training epochs
args['lr']1e-3Initial learning rate
args['optimizer']SGDOptimizer (SGD / Adam)
args['train_batch_size']2Training batch size
args['lr_decay']0.9Polynomial LR decay power

4. Inference & Evaluation

python new_infer.py

Evaluation metrics (S-measure, weighted F-measure, MAE, E-measure, F-measure) are automatically saved to an Excel file.

5. Visualization

We provide open-source visualization tools for reproducing all visual results in the paper. See the Visualization section for detailed examples and instructions.

# Feature map heatmaps (reproduces Fig. 7 & Fig. 8 in the paper)
cd display_heatmaps && python heatmap.py

# Overlay predictions on images (reproduces visual comparisons)
cd display_heatmaps && python combine.py

πŸ“ Project Structure

SARNet/
β”œβ”€β”€ SARNet.py             # 🧠 Core network (OAA + FGC modules)
β”œβ”€β”€ pvtv2.py              # 🦴 PVTv2 backbone encoder
β”œβ”€β”€ train.py              # πŸ‹οΈ Training pipeline
β”œβ”€β”€ new_infer.py          # πŸ” Inference & evaluation
β”œβ”€β”€ config.py             # βš™οΈ Path configuration
β”œβ”€β”€ datasets.py           # πŸ“‚ Dataset utilities
β”œβ”€β”€ loss.py               # πŸ“‰ Loss functions (Structure, IoU, Dice)
β”œβ”€β”€ joint_transforms.py   # πŸ”„ Joint image-mask augmentations
β”œβ”€β”€ metric_caller.py      # πŸ“ Metric computation
β”œβ”€β”€ excel_recorder.py     # πŸ“Š Excel metric recording
β”œβ”€β”€ misc.py               # πŸ”§ Utility functions
β”œβ”€β”€ excel.py              # πŸ“ LaTeX table formatter
β”œβ”€β”€ requirements.txt      # πŸ“‹ Python dependencies
└── display_heatmaps/     # 🎨 Visualization tools
    β”œβ”€β”€ heatmap.py        #    Feature map heatmap generation
    └── combine.py        #    Prediction overlay visualization

πŸ“– Citation

If you find this work helpful for your research, please consider citing our paper and giving a ⭐:

@article{xing2023go,
  title     = {Go Closer to See Better: Camouflaged Object Detection via Object Area Amplification and Figure-Ground Conversion},
  author    = {Xing, Haozhe and Wang, Haiyu and Li, Yanye and Ling, Haibin},
  journal   = {IEEE Transactions on Circuits and Systems for Video Technology},
  volume    = {33},
  number    = {10},
  pages     = {5595--5608},
  year      = {2023},
  publisher = {IEEE},
  doi       = {10.1109/TCSVT.2023.3255304}
}

πŸ™ Acknowledgments

We sincerely thank the following open-source projects:

  • PVTv2 β€” Pyramid Vision Transformer backbone
  • PFNet β€” Loss functions and utility code
  • py-sod-metrics β€” Evaluation metrics library

πŸ“¬ Contact

If you have any questions, please feel free to open an issue or contact us.


If you find this project useful, please consider giving it a ⭐.
It helps others discover this work!