This repository contains the example code of "DiffSAC: Diffusion-guided Sampling for Consensus-based Robust Estimation" for 2D line fitting task. We will release the full code after the paper is accepted.
DiffSAC leverages diffusion models to perform robust geometric estimation, specifically focusing on line detection from point cloud data. The method uses a transformer-based diffusion model to iteratively refine consensus labels for identifying which points belong to geometric structures.
pip install torch torchvision numpy scipy scikit-learn wandb tqdm
DiffSAC/
├── checkpoint.py # Gradient checkpointing utilities
├── dataset.py # Dataset loading and preprocessing
├── diffusion.py # Main diffusion model implementation
├── train_line.py # Training script for line detection
├── transformer.py # Transformer backbone with timestep embedding
└── utils.py # Evaluation metrics and utilities
Your dataset should be organized as follows:
Dataset_line/
├── train/
│ └── 06/
│ ├── data/ # .npz files containing points and lines
│ └── images/ # .jpg images (optional)
├── val/
│ └── 06/
│ ├── data/
│ └── images/
Each .npz
file should contain:
points
: Array of 2D points with shape (N, 2)lines
: Ground truth lines with shape (M, 4) representing line endpoints
python train_line.py \
--lr 0.0001 \
--batch_size 32 \
--epochs 100 \
--timesteps 1000 \
--train_data ../Dataset_line/train/06 \
--val_data ../Dataset_line/val/06 \
--wandb_mode online
--lr
: Learning rate--batch_size
: Batch size for training--epochs
: Number of training epochs--timesteps
: Number of diffusion timesteps--seed
: Random seed for reproducibility--eval_interval
: Evaluation frequency in epochs--checkpoint
: Path to resume training from checkpoint--wandb_mode
: Weights & Biases logging mode
- Backbone: Point Diffusion Transformer with multi-head attention
- Noise Schedule: Cosine variance schedule for stable training
- Embedding: Sinusoidal timestep embeddings
- PointDiffusionTransformer: Transformer-based denoising network
- Gradient Checkpointing: Memory-efficient training
- Cosine Noise Schedule: Improved diffusion process stability
- AUC Evaluation: Area Under Curve metric for line detection accuracy
The model is evaluated using AUC (Area Under Curve) metric with a cutoff threshold of 0.5. The evaluation computes the similarity between predicted and ground truth lines using 2-point line representation.
- AUC@0.5: Primary evaluation metric
- Optimizer: AdamW with default parameters
- Loss Function: MSE loss between predicted and actual noise
- Data Augmentation: Random shuffling of point order
- Mixed Precision: Supported via gradient checkpointing
- Logging: Weights & Biases integration
- Robust Estimation: Handles outliers and noise in point data
- Transformer Architecture: Self-attention mechanism for global context
- Diffusion Process: Iterative refinement of consensus labels
- Memory Efficient: Gradient checkpointing for large models
- Reproducible: Comprehensive seed setting across all libraries