Trans10K val IoU 0.9217 · test mean IoU 0.9237 · +0.036 over DeepLabV3+ baseline
SPECTRA is a transparent-object segmentation system that combines a frozen DINOv2 vision backbone with two physics-inspired modules:
- OFCV (Optical Flow Consistency Violation) — gates patch tokens by detecting refraction-induced motion that violates rigid-body flow assumptions.
- BRF (Boundary Resonance Field) — injects a Gabor-bank structural prior at full resolution, sharpening glass edges.
These signals are fused with a lightweight head to produce segmentation masks that are not only accurate but interpretable — you can see why the network thinks a region is glass.
This is a final-year student project. The contribution is interpretable, physics-guided causal conditioning — not state-of-the-art accuracy. See
release/FINAL_SUMMARY.mdfor the full report.
| # | Contribution | Evidence |
|---|---|---|
| 1 | OFCV gating — optical-flow consistency violation maps gate patch tokens before fusion | Without OFCV the network needs 5 epochs to hit the same IoU; with OFCV it gets there by epoch 1 |
| 2 | BRF prior — Gabor-bank boundary resonance map injected at full resolution as a static structural prior | Improves early-epoch convergence and edge fidelity |
| 3 | Robustness behavior — survives heavy corruption | Clean IoU 0.97; at severity-5 motion-blur still scores IoU 0.82 |
| 4 | Per-image transparency maps — interpretable signals you can read | OFCV fires on glass shells, goes dark on opaque inclusions in the same scene |
What this project does NOT claim: SOTA on any public leaderboard. Public baselines have not been benchmarked under matched conditions outside this repo.
| Metric | Value |
|---|---|
| IoU | 0.9217 |
| F-measure | 0.9560 |
| MAE | 0.0293 |
| BER | 0.0265 |
| Test mean IoU (4,428 imgs) | 0.9237 |
Same Trans10K splits, same 10-epoch schedule, same eval pipeline.
| Model | Params (M) | Val IoU | F | MAE | BER | Train (min) |
|---|---|---|---|---|---|---|
| SAM ViT-B (zero-shot) | 91 frozen | 0.1341 | 0.315 | 0.292 | 0.459 | 0 |
| SegFormer-B0 | 3.8 | 0.8680 | 0.926 | 0.057 | 0.047 | 44 |
| U-Net (ResNet-34) | 24.4 | 0.8799 | 0.938 | 0.051 | 0.045 | 44 |
| DeepLabV3+ (ResNet-50) | 39.6 | 0.8856 | 0.935 | 0.047 | 0.040 | 45 |
| SPECTRA (ours) | 26.6 | 0.9217 | 0.956 | 0.029 | 0.027 | 222 |
SPECTRA reaches +0.036 IoU over the strongest baseline (DeepLabV3+), at ~5× the training cost. SAM zero-shot lands at 0.13 — a clean demonstration that foundation models without task-specific training do not solve transparent-object segmentation.
| Variant | E1 IoU | E5 IoU | E1 Δ vs full |
|---|---|---|---|
| full (OFCV + BRF) | 0.8623 | 0.9133 | — |
| no_ofcv | 0.8365 | 0.9147 | -0.026 |
| no_brf | 0.8414 | 0.9164 | -0.021 |
OFCV and BRF help early-epoch convergence and interpretability, not raw clean-data accuracy. The honest framing.
| brightness | low_light | glare | motion_blur | jpeg | noise | fog | colour_jitter |
|---|---|---|---|---|---|---|---|
| 0.872 | 0.966 | 0.859 | 0.815 | 0.960 | 0.756 | 0.969 | 0.969 |
Clean baseline on this subset: 0.969.
git clone https://github.com/lalith557/SPECTRA.git
cd SPECTRA
# Python 3.10+, CUDA 11.8
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
# Optional: PyTorch Geometric (only if use_gnn=True)
pip install torch-geometric -f https://data.pyg.org/whl/torch-2.1.0+cu118.htmlNote: Pretrained weights (
spectra_best.pth, ~320 MB) are not stored in this repo. Host them on HuggingFace, a GitHub Release, or Git LFS and update the path inconfigs/config.yaml.
The full Trans10K dataset (~10,000 images, ~2 GB) is not included in this repository due to GitHub's file-size limits. Download it manually from the original authors and place it under spectra/data/Trans10K/.
Official download sources (all maintained by the original Trans10K authors, Xie et al. 2020):
| Source | Link |
|---|---|
| Trans10K project page (primary) | https://xieenze.github.io/projects/TransLAB/TransLAB.html |
| Official GitHub (download instructions) | https://github.com/xieenze/Segment_Transparent_Objects |
| Google Drive mirror | https://drive.google.com/drive/folders/10nFOG2NSStpO0BPnSAIqRryEqq--Mcga |
Expected folder layout after extraction:
spectra/
└── data/
└── Trans10K/
├── train/
│ ├── images/ (5,000 .jpg)
│ └── masks/ (5,000 .png)
├── validation/
│ ├── images/ (1,000 .jpg)
│ └── masks/ (1,000 .png)
└── test/
├── images/ (4,428 .jpg)
└── masks/ (4,428 .png)
Then verify the path in configs/config.yaml:
data:
root: data/Trans10K
image_size: 448Tip: If you only want to run the demo / web app for inference, you do not need the dataset — only the pretrained checkpoint (
spectra_best.pth).
SPECTRA ships with a Next.js 15 frontend and a FastAPI backend. To run the full web app on your machine, open two terminals in the project root.
# Activate the Python virtual environment (skip if already active)
# Windows:
venv\Scripts\activate
# macOS / Linux:
source venv/bin/activate
# Launch the FastAPI server with auto-reload
uvicorn api.server:app --host 0.0.0.0 --port 8080 --reloadBackend will be live at http://localhost:8080. Quick health check (in any browser or a third terminal):
http://localhost:8080/health
You should see {"status": "ok", "device": "cuda" | "cpu", ...}.
cd web
# One-time only: install Node dependencies (requires Node.js 18+)
npm install
# One-time only: create local env file so the frontend can find the backend
cp .env.local.example .env.local # macOS / Linux
copy .env.local.example .env.local # Windows
# Leave NEXT_PUBLIC_API_URL empty — the Next.js rewrite already proxies /api/* → http://localhost:8080
# Start the dev server
npm run devFrontend will be live at http://localhost:3000. Open it in your browser — you should see the SPECTRA dashboard with six pages: Overview, Demo, Benchmarks, Interpretability, Failures, Research.
- Visit http://localhost:3000/demo.
- Drag and drop any glass-containing image (or pick a seed example).
- The frontend POSTs the image to
http://localhost:8080/predict_full. - Within ~1–2 s you should see the segmentation overlay plus the OFCV, BRF, flow-residual, entropy, and material-confidence heatmaps.
If the heatmaps render but feel sluggish, the backend is running on CPU — install the CUDA build of PyTorch (pip install torch --index-url https://download.pytorch.org/whl/cu118) and restart Terminal 1.
Press Ctrl + C in each terminal. The backend and frontend run as independent processes.
If you only want a quick standalone demo without the full web stack:
python demo/gradio_demo.py \
--config configs/config.yaml \
--checkpoint weights/spectra_best.pthOpen http://127.0.0.1:7860. The interface shows segmentation overlay, OFCV violation map, BRF boundary field, flow residual, uncertainty (entropy), and per-class material confidence.
# Per-epoch metrics on val
python eval/eval_checkpoints.py --config configs/config.yaml \
--checkpoints weights/checkpoint_epoch010.pth \
--out results/eval.json
# 6-panel qualitative figures
python eval/visualize.py --config configs/config.yaml \
--checkpoint weights/spectra_best.pth \
--n_samples 16 --save-dir results/qualitative
# Hard-case sweep (8 corruptions × 5 severities)
python eval/robustness_eval.py --config configs/config.yaml \
--checkpoint weights/spectra_best.pth \
--output results/robustness --n-samples 100
# Top-20 worst predictions + category histogram
python eval/failure_case_analysis.py --config configs/config.yaml \
--checkpoint weights/spectra_best.pth \
--output results/failures# Final 10-epoch run (~3.5 h on RTX 4070 / 8 GB)
python train/train_baseline.py --config configs/config.yaml
# 3-variant ablation (full / no-OFCV / no-BRF, 5 epochs each, ~5 h)
python train/run_ablations_reduced.pyspectra/
├── README.md
├── requirements.txt
├── .gitignore
├── Dockerfile
├── utils.py
│
├── demo/ # Gradio webcam / image / video app
├── models/ # SPECTRA model + DINOv2 backbone
├── modules/ # OFCV detector, BRF, fusion head
├── flow/ # RAFT wrapper + optical-flow utils
├── graph/ # superpixel + MBP-GNN (optional)
├── data/ # Trans10K / GSD / ClearPose loaders [gitignored]
├── inference/ # video inference + viz utilities
├── pretrain/ # physics-contrastive pre-training (scaffolded)
├── api/ # FastAPI deployment endpoint
├── train/ # train_baseline.py, run_ablations_reduced.py, losses.py
├── eval/ # metrics, visualize, robustness, failure analysis
├── benchmarks/ # U-Net / DeepLabV3+ / SegFormer / SAM [gitignored]
├── scripts/ # build_portfolio_visuals.py, build_benchmark_figure.py
├── tests/ # unit tests
├── configs/ # config.yaml
│
├── weights/ # production checkpoints [gitignored]
├── results/ # experimental artefacts + figures [gitignored]
├── release/ # frozen copy of the production run [gitignored]
└── paper/ # PAPER.md + figures
Large folders (venv/, data/, datasets/, results/, weights/, checkpoints/, release/, benchmarks/, web/) are excluded via .gitignore. Host model weights via Git LFS or a GitHub Release attachment.
- Backbone: DINOv2 (frozen ViT)
- Physics modules: OFCV (RAFT optical flow), BRF (Gabor filter bank)
- Framework: PyTorch 2.1 + CUDA 11.8
- Training: Trans10K (4,428-image test split)
- Optional: PyTorch Geometric (MBP-GNN), Segmentation Models PyTorch (baselines), SAM (zero-shot baseline)
- Serving: Gradio (demo) + FastAPI (API)
This is a student project. If you find the code useful:
@misc{gona2026spectra,
author = {Gona, Lalith},
title = {SPECTRA: Causal Physically-Guided Transparent-Object Segmentation},
year = {2026},
howpublished = {Final-project report, Lovely Professional University},
url = {https://github.com/lalith557/SPECTRA}
}As it's an open source you guys can contribute too.