# chetak963/camouflage-detection architecture

> Architecture diagram of the GitHub repository chetak963/camouflage-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chetak963/camouflage-detection
- Repository: https://github.com/chetak963/camouflage-detection

## Overview

1. **Project type and purpose**
   - This repository is a **camouflage object detection / segmentation** project.
   - The core task is **pixel-wise segmentation** of hidden objects using an **improved PraNet**-style architecture.

2. **Top-level execution surfaces**
   - `app.py` appears to be the **demo/application entrypoint**, consistent with the README’s Streamlit-style hosted web app.
   - `main.py` is the other top-level runner, likely used for **local execution orchestration** outside the demo UI.
   - `config.py` centralizes runtime settings such as paths, model options, and training/inference parameters.

3. **Core model boundary**
   - `src/model_pranet.py` contains the **PraNet-based network definition**.
   - `src/model.py` likely wraps or extends the core architecture with the project’s improvements:
     - **ResNet50 backbone**
     - **SE attention**
     - **reverse attention**
     - **deep supervision**
   - This is the main inference boundary: inputs become multi-scale segmentation masks.

4. **Data subsystem**
   - `src/dataset.py` is the data ingestion layer.
   - It likely handles the COD10K dataset layout, image/mask pairing, and any preprocessing or augmentation needed for training and evaluation.
   - The dataset lives externally under `data/COD10K/`, so the repo depends on a **local filesystem dataset mount** rather than a remote API.

5. **Training pipeline**
   - `src/train.py` is the training orchestration layer.
   - It likely connects:
     - dataset loading
     - model construction
     - loss computation
     - optimizer/scheduler steps
     - checkpoint saving
   - This is the main subsystem where model learning happens and where the architecture’s multi-loss / deep-supervision design is exercised.

6. **Evaluation pipeline**
   - `src/evaluate.py` handles offline model assessment.
   - The README emphasizes **Mean IoU** and **Dice score**, so evaluation likely converts model masks into segmentation metrics at one or more thresholds or scales.
   - This is the boundary between trained model outputs and quantitative quality reporting.

7. **Prediction/inference pipeline**
   - `src/predict.py` is the inference-only path.
   - It likely loads a saved checkpoint and runs segmentation on individual images or batches, producing masks for the UI/demo or for local inspection.
   - This module is the clearest separation between training-time logic and runtime prediction.

8. **Data flow through the system**
   - **COD10K images + masks** enter through `dataset.py`.
   - Samples are passed to the **PraNet-derived model** in `model.py` / `model_pranet.py`.
   - The model produces **segmentation masks** at one or multiple scales.
   - Training uses these outputs to compute losses; evaluation converts them into **IoU/Dice metrics**; prediction exposes them as final mask outputs.

9. **Architectural pattern**
   - The repository is organized as a **small ML application** with:
     - reusable core logic in `src/`
     - thin top-level entrypoints in the root
     - a shared config layer
   - The boundaries are cleanly split into **data**, **model**, **training**, **evaluation**, and **inference/demo** concerns.

10. **Deployment/runtime footprint**
   - The README indicates a **web demo hosted on Hugging Face Spaces**, so the app layer is likely designed for lightweight inference on uploaded images.
   - There are no signs of external databases, queues, or services; the system is primarily **single-process ML inference/training** plus a static local dataset dependency.

11. **What to show in an architecture diagram**
   - Show `config.py` as a shared dependency feeding all runtime components.
   - Show `dataset.py` feeding `train.py` and `evaluate.py`.
   - Show `model.py` / `model_pranet.py` as the central compute block.
   - Show `predict.py` feeding `app.py` for the demo path.
   - Show the COD10K dataset as an external local input source and the trained checkpoint as the main persisted artifact.

Main entry points: [`src/model.py`](https://github.com/chetak963/camouflage-detection/blob/main/src/model.py) (Model), [`config.py`](https://github.com/chetak963/camouflage-detection/blob/main/config.py) (Config), [`src/train.py`](https://github.com/chetak963/camouflage-detection/blob/main/src/train.py) (Train), [`src/predict.py`](https://github.com/chetak963/camouflage-detection/blob/main/src/predict.py) (Predict)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_app_py["App<br/>entrypoint<br/>[app.py]"]
  node_main_py["Main<br/>entrypoint<br/>[main.py]"]
  node_config_py["Config<br/>settings<br/>[config.py]"]
end

subgraph group_src["Core src"]
  node_dataset_py["Dataset<br/>data-loader<br/>[dataset.py]"]
  node_train_py["Train<br/>[train.py]"]
  node_evaluate_py["Evaluate<br/>metrics-pipeline<br/>[evaluate.py]"]
  node_predict_py["Predict<br/>inference-pipeline<br/>[predict.py]"]
  node_model_py["Model<br/>improved-praNet<br/>[model.py]"]
  node_model_pranet_py["PraNet<br/>segmentation-backbone<br/>[model_pranet.py]"]
  node_backbone["ResNet50<br/>feature-extractor"]
  node_attention{{"SE attn<br/>attention-block"}}
  node_decoder["Reverse attn<br/>decoder"]
  node_deep_supervision(("Deep sup<br/>aux-loss-path"))
end

subgraph group_external["External assets"]
  node_cod10k[("COD10K<br/>dataset")]
  node_checkpoint["Checkpoint<br/>artifact"]
end

node_config_py -->|"configures"| node_main_py
node_config_py -->|"configures"| node_app_py
node_config_py -->|"paths"| node_dataset_py
node_config_py -->|"params"| node_train_py
node_config_py -->|"params"| node_evaluate_py
node_config_py -->|"params"| node_predict_py
node_cod10k -->|"loads"| node_dataset_py
node_dataset_py -->|"batches"| node_train_py
node_dataset_py -->|"samples"| node_evaluate_py
node_main_py -->|"runs"| node_train_py
node_main_py -->|"runs"| node_evaluate_py
node_main_py -->|"runs"| node_predict_py
node_predict_py -->|"serves"| node_app_py
node_predict_py -->|"loads"| node_checkpoint
node_train_py -->|"builds"| node_model_py
node_evaluate_py -->|"loads"| node_model_py
node_predict_py -->|"loads"| node_model_py
node_model_py -->|"extends"| node_model_pranet_py
node_model_py -->|"uses"| node_backbone
node_model_py -->|"uses"| node_attention
node_model_py -->|"uses"| node_decoder
node_model_py -->|"emits"| node_deep_supervision
node_train_py -->|"writes"| node_checkpoint
node_train_py -->|"optimizes"| node_deep_supervision

click node_app_py "https://github.com/chetak963/camouflage-detection/blob/main/app.py"
click node_main_py "https://github.com/chetak963/camouflage-detection/blob/main/main.py"
click node_config_py "https://github.com/chetak963/camouflage-detection/blob/main/config.py"
click node_dataset_py "https://github.com/chetak963/camouflage-detection/blob/main/src/dataset.py"
click node_train_py "https://github.com/chetak963/camouflage-detection/blob/main/src/train.py"
click node_evaluate_py "https://github.com/chetak963/camouflage-detection/blob/main/src/evaluate.py"
click node_predict_py "https://github.com/chetak963/camouflage-detection/blob/main/src/predict.py"
click node_model_py "https://github.com/chetak963/camouflage-detection/blob/main/src/model.py"
click node_model_pranet_py "https://github.com/chetak963/camouflage-detection/blob/main/src/model_pranet.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_py,node_main_py,node_config_py toneBlue
class node_dataset_py,node_train_py,node_evaluate_py,node_predict_py,node_model_py,node_model_pranet_py,node_backbone,node_attention,node_decoder,node_deep_supervision toneAmber
class node_cod10k,node_checkpoint toneMint
```

## Components

### Runtime

Top-level entrypoints and shared configuration

- [App](https://github.com/chetak963/camouflage-detection/blob/main/app.py): entrypoint · Demo application entrypoint for hosted inference · `app.py`
- [Main](https://github.com/chetak963/camouflage-detection/blob/main/main.py): entrypoint · Local orchestration entrypoint · `main.py`
- [Config](https://github.com/chetak963/camouflage-detection/blob/main/config.py): settings · Shared runtime and model configuration · `config.py`

### Core src

Data, model, training, evaluation, and inference modules

- [Dataset](https://github.com/chetak963/camouflage-detection/blob/main/src/dataset.py): data-loader · COD10K sample loading and preprocessing · `src/dataset.py`
- [Train](https://github.com/chetak963/camouflage-detection/blob/main/src/train.py): training-pipeline · Model optimization and checkpointing · `src/train.py`
- [Evaluate](https://github.com/chetak963/camouflage-detection/blob/main/src/evaluate.py): metrics-pipeline · Offline segmentation scoring · `src/evaluate.py`
- [Predict](https://github.com/chetak963/camouflage-detection/blob/main/src/predict.py): inference-pipeline · Checkpoint-based mask generation · `src/predict.py`
- [Model](https://github.com/chetak963/camouflage-detection/blob/main/src/model.py): improved-praNet · Project-specific segmentation network wrapper · `src/model.py`
- [PraNet](https://github.com/chetak963/camouflage-detection/blob/main/src/model_pranet.py): segmentation-backbone · Core PraNet-style network definition · `src/model_pranet.py`
- **ResNet50**: feature-extractor · Encoder backbone used by the model
- **SE attn**: attention-block · Channel attention enhancement
- **Reverse attn**: decoder · Multi-scale reverse-attention decoding
- **Deep sup**: aux-loss-path · Auxiliary multi-scale supervision outputs

### External assets

Local dataset and persisted artifacts

- **COD10K**: dataset · Local camouflage image-mask corpus
- **Checkpoint**: artifact · Saved trained model weights

## Connections

- Config → Main: configures · Provides runtime settings
- Config → App: configures · Provides demo/runtime settings
- Config → Dataset: paths · Supplies dataset and preprocessing options
- Config → Train: params · Supplies training hyperparameters
- Config → Evaluate: params · Supplies evaluation settings
- Config → Predict: params · Supplies inference settings
- COD10K → Dataset: loads · Image-mask pairs enter through the dataset layer
- Dataset → Train: batches · Feeds training samples
- Dataset → Evaluate: samples · Feeds evaluation samples
- Main → Train: runs · Local execution can launch training
- Main → Evaluate: runs · Local execution can launch evaluation
- Main → Predict: runs · Local execution can launch inference
- Predict → App: serves · Demo app uses prediction for uploaded images
- Predict → Checkpoint: loads · Consumes saved weights for inference
- Train → Model: builds · Constructs the project model
- Evaluate → Model: loads · Uses the trained model for scoring
- Predict → Model: loads · Uses the trained model for inference
- Model → PraNet: extends · Wraps the PraNet core with project improvements
- Model → ResNet50: uses · Encoder feature extraction
- Model → SE attn: uses · Adds SE attention
- Model → Reverse attn: uses · Performs reverse-attention decoding
- Model → Deep sup: emits · Produces multi-scale auxiliary outputs
- Train → Checkpoint: writes · Persists learned weights
- Train → Deep sup: optimizes · Training uses auxiliary losses from multiple scales
