Uncertainty Estimation for Impact Echo Defect Detection Using Evidential Deep Learning
If you use this package, please be kind and cite our hard work.
Create virtual environment:
chmod +x setup_env.sh && ./setup_env.shOr manually:
# Create a new virtual environment with Python 3.12.11
uv venv --python 3.12.11
# Activate the environment
source .venv/bin/activate # macOS/Linux
# Install dependencies
uv pip install -r requirements-uv.txtpython train_evidential_model.pypython test.py├── dataloaders/ # Data loading and augmentation
├── models/
│ ├── evidential_model.py # Evidential IENet architecture
│ ├── standard_model.py # Standard IENet (softmax baseline)
│ ├── mc_dropout.py # MC Dropout inference
│ └── deep_ensemble.py # Deep Ensemble inference
├── losses/ # Evidential loss functions
├── training/ # Training and evaluation loops
├── testing/ # Test analysis and visualization
├── train_evidential_model.py # Train evidential model
├── train_baselines.py # Train MC Dropout + Ensemble baselines
├── evaluate_uq_comparison.py # UQ method comparison
├── evaluate_calibration.py # ECE, Brier score, reliability diagrams
├── evaluate_multi_seed.py # Multi-seed stability evaluation
├── evaluate_ablation.py # Loss function ablation study
├── figures/ # Generated figures (reliability diagrams)
├── data/ # Training/test datasets
├── weights/ # Saved model checkpoints (gitignored)
└── results/ # Evaluation results
- models/evidential_model.py - Evidential IENet architecture
- models/standard_model.py - Standard IENet (softmax baseline for MC Dropout / Ensembles)
- models/mc_dropout.py - MC Dropout inference (T=50 forward passes)
- models/deep_ensemble.py - Deep Ensemble inference (M=5 models)
- losses/evidential_loss.py - Loss function implementations
- training/trainer.py - Training and evaluation functions
- train_evidential_model.py - Main evidential model training script
- train_baselines.py - Train MC Dropout and Deep Ensemble baselines
from models.evidential_model import create_model
import torch
# Create model
model = create_model(input_length=860, num_classes=2)
# Use it
x = torch.randn(32, 1, 860) # batch_size=32, channels=1, length=860
evidence, defect_features = model(x)from losses.evidential_loss import evidential_loss
import torch
evidence = torch.randn(32, 2) # batch_size=32, num_classes=2
targets = torch.randint(0, 2, (32,)) # batch_size=32
epoch = 10
loss, nll, kl_div, penalty = evidential_loss(evidence, targets, epoch)from training.trainer import train_evidential_classifier
avg_loss, avg_nll, avg_kl, avg_penalty, accuracy = train_evidential_classifier(
model, train_loader, optimizer, device, epoch, class_weights=None
)from training.trainer import evaluate_evidential_classifier
results = evaluate_evidential_classifier(model, test_loader, device)
accuracy, predictions, uncertainties, epistemic, aleatoric, confidences, targets, alphas = resultsThis project uses uv for fast Python package management. UV is a modern, Rust-based package manager that's significantly faster than pip/conda.
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | shOr with Homebrew:
brew install uvOr with pip:
pip install uvFor other installation methods, see: https://docs.astral.sh/uv/getting-started/installation/
# Create a new virtual environment with Python 3.12.11
uv venv --python 3.12.11
# Activate the environment
source .venv/bin/activate # macOS/Linux
# or
.venv\Scripts\activate # Windows# Install PyTorch first (for MPS/CUDA support)
uv pip install torch torchvision torchaudio
# Install core dependencies
uv pip install numpy scipy scikit-learn pandas matplotlib
uv pip install tensorboard tqdm
# Install audio processing libraries
uv pip install librosa soundfile audioread resampy soxr
uv pip install audiomentations torch-audiomentations
# Install deep learning utilities
uv pip install transformers datasets evaluate huggingface-hub
uv pip install torchinfo
# Optional: Install Jupyter for notebooks
uv pip install ipykernel jupyterpython -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'MPS available: {torch.backends.mps.is_available()}')"
python -c "import audiomentations; print('Audiomentations OK')"If you want to use the existing requirements.txt (converted for pip):
# Install all dependencies
uv pip install -r requirements-uv.txtOnce the environment is set up:
# Train the evidential model
python train_evidential_model.pyStep 1: Train baseline models (MC Dropout + Deep Ensemble)
Trains a standard model for MC Dropout (seed=42) and 5 ensemble members (seeds: 42, 123, 456, 789, 1024) using the same hyperparameters as the evidential model (AdamW, lr=1e-4, cosine annealing, 100 epochs, early stopping patience=25).
python train_baselines.pySaved weights: weights/standard_mc_dropout_best.pth, weights/ensemble_member_{0-4}_best.pth
Step 2: UQ method comparison (Table: Evidential vs MC Dropout vs Deep Ensemble)
Evaluates all three methods on DS1 (in-distribution) and DS3 (domain shift). Reports accuracy, precision, recall, F1, misclassification AUROC, and inference time.
python evaluate_uq_comparison.pyStep 3: Calibration analysis (ECE, Brier score, reliability diagrams)
Computes Expected Calibration Error and Brier score for all three methods. Generates reliability diagram PDFs in figures/.
python evaluate_calibration.pyOutput: figures/reliability_diagram_ds1.pdf, figures/reliability_diagram_ds3.pdf
Step 4: Multi-seed stability evaluation
Trains 5 evidential models with different random seeds and reports mean +/- std for all metrics.
python evaluate_multi_seed.pyStep 5: Loss function ablation study
Trains 6 ablation variants (Full, NLL-only, NLL+KL, NLL+Penalty, Full with beta=0.1, Full with beta=1.0) and evaluates each on DS1 and DS3.
python evaluate_ablation.pyRun all experiments sequentially:
python train_baselines.py && \
python evaluate_uq_comparison.py && \
python evaluate_calibration.py && \
python evaluate_multi_seed.py && \
python evaluate_ablation.pyResults are saved as .pth files in weights/ and printed as LaTeX-formatted tables to the terminal.
python test.pyIf you use something in this repository, please be kind and cite our work through:
@article{HOXHA2025139829,
title = {Contrastive learning for robust defect mapping in concrete slabs using impact echo},
journal = {Construction and Building Materials},
volume = {461},
pages = {139829},
year = {2025},
issn = {0950-0618},
doi = {https://doi.org/10.1016/j.conbuildmat.2024.139829},
url = {https://www.sciencedirect.com/science/article/pii/S0950061824049717},
author = {Ejup Hoxha and Jinglun Feng and Agnimitra Sengupta and David Kirakosian and Yang He and Bo Shang and Ardian Gjinofci and Jizhong Xiao},
keywords = {Impact echo, Bridge decks, Contrastive learning, Concrete defects}
}
and
@ARTICLE{10168232,
author={Hoxha, Ejup and Feng, Jinglun and Sanakov, Diar and Xiao, Jizhong},
journal={IEEE Robotics and Automation Letters},
title={Robotic Inspection and Subsurface Defect Mapping Using Impact-Echo and Ground Penetrating Radar},
year={2023},
volume={8},
number={8},
pages={4943-4950},
doi={10.1109/LRA.2023.3290386}}
@unpublished{hoxha_under_review_uncertainty_ie,
author = {Ejup Hoxha and Agnimitra Sengupta and Yang He and Jinglun Feng and Bo Shang and Jizhong Xiao},
title = {Evidential Deep Learning for Uncertainty-aware Autonomous Defect Detection in Concrete Structures using Impact Echo},
note = {Under Review},
year = {2026}
}
This project is licensed under the MIT License - see the LICENSE file for details.
- MPS (Apple Silicon): Automatically detected and used if available
- CUDA (NVIDIA): Install CUDA-specific PyTorch from https://pytorch.org
- CPU: Works but slower, consider using smaller batch sizes
# Update UV to latest version
uv self update
# Clear UV cache
uv cache clean# Ensure you have the latest PyTorch
uv pip install --upgrade torch torchvision torchaudio# Install system dependencies first (macOS)
brew install libsndfile
# Then retry
uv pip install audiomentations# Verify environment is activated
which python # Should show .venv/bin/python
# Reinstall problematic package
uv pip install --reinstall <package-name>If you're currently using conda (ieenv):
# Export conda packages (for reference)
conda list --export > conda-packages.txt
# Deactivate conda
conda deactivate
# Create and activate UV environment
uv venv --python 3.12.11
source .venv/bin/activate
# Install dependencies as shown above
uv pip install -r requirements-uv.txt- 10-100x faster than pip for package installation
- Deterministic dependency resolution
- Compatible with pip and PyPI
- Modern Rust-based implementation
- Smaller disk footprint than conda
- UV Documentation: https://docs.astral.sh/uv/
- PyTorch Installation: https://pytorch.org/get-started/locally/
- Audiomentations: https://github.com/iver56/audiomentations