Deep learning framework for automatic segmentation and quantitative assessment of weathering damage on fossil bones.
- Features
- Overview
- Pipeline
- Repository Structure
- Installation
- Model Weights
- Dataset Preparation
- Running Inference
- Running Ensemble Inference
- Sample Dataset
- Results
- Citation
- References
- Version
- Copyright
- Semantic segmentation of weathering features
- Sliding-window inference for high-resolution images
- Ensemble inference support
- Automatic heatmap generation
- Global Damage Index (GDI)
- Pretrained models included
- GPU and CPU compatible
WeatheringFormer is based on the CrackSegFormer implementation by Li et al., 2024, but has been extensively modified and extended for the automated analysis of bone weathering.
The project addresses one of the main limitations of traditional weathering analysis: the reliance on qualitative, stage-based classifications obtained through visual inspection. Instead of assigning bones to discrete weathering stages, WeatheringFormer models weathering as a continuous phenomenon through semantic segmentation and a quantitative damage index. The Global Damage Index (GDI) is a continuous metric ranging from 0 to 100 that summarizes the spatial extent and severity of segmented weathering features.
The framework combines:
- SegFormer semantic segmentation;
- Euclidean Distance Transform (EDT);
- Multi-scale Gaussian filtering;
- Global Damage Index (GDI).
The repository includes pretrained models, sample data, inference scripts, and training utilities.
The WeatheringFormer workflow consists of:
- Bone extraction using the Mask R-CNN model developed in Leoni et al., 2025 as the first module.
- Weathering segmentation using SegFormer.
- Removal of spurious detections.
- Fracture thickness estimation using the Euclidean Distance Transform.
- Multi-scale damage integration.
- Generation of heatmaps and Global Damage Index (GDI).
WeatheringFormer/
│
├── dataset_preparation/
├── examples/
├── models/
├── pretrained_weights/
├── sample/
├── tools/
├── train_utils/
├── weights/
│
├── ensemble.py
├── weathering_map.py
├── environment.yml
└── README.md
WeatheringFormer stores pretrained model weights using Git LFS.
Install Git LFS before cloning or pulling the repository:
git lfs installAfter cloning, download the model weights with:
git lfs pullIf Git LFS is not installed, the .pth files will be downloaded as small pointer files instead of the actual model weights.
Clone the repository to your local machine and enter the project directory.
git clone https://github.com/Ronaldoaleoni/WeatheringFormer.git
cd WeatheringFormerThe repository includes an environment.yml file containing all dependencies required to run WeatheringFormer.
Create the environment with:
conda env create -f environment.ymlThis command automatically installs:
- Python 3.9.25
- PyTorch
- TorchVision
- CUDA-compatible packages
- SegFormer dependencies
- Image processing libraries
- All additional Python packages required by the project
conda activate weatheringformerReplace
weatheringformerwith the environment name defined inenvironment.ymlif it is different.
Run the following script to verify that PyTorch detects your GPU correctly.
import torch
print("PyTorch:", torch.__version__)
print("CUDA:", torch.version.cuda)
print("cuDNN:", torch.backends.cudnn.version())
print("GPU available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("Device:", torch.cuda.get_device_name(0))Expected output:
PyTorch: 1.13.1
CUDA: 11.7
cuDNN: 8500
GPU available: True
Device: NVIDIA GeForce RTX 4060 Ti
If GPU available is False, WeatheringFormer will run on the CPU, although inference will be considerably slower.
WeatheringFormer uses Conda for dependency management.
If Conda is not installed, install either:
- Anaconda
- Miniconda
before proceeding with the installation.
The repository contains two types of model weights.
These checkpoints reproduce the experiments described in the accompanying manuscript (currently in preparation).
These correspond to the original ImageNet-pretrained SegFormer backbones and are only required for training or fine-tuning new models.
All model weights are stored using Git LFS due to their size.
The notebooks in this directory provide utilities for preparing datasets prior to training WeatheringFormer. They are optional for inference but required to reproduce the complete training pipeline.
Generates the training dataset from annotated high-resolution images.
Main operations:
- reads RGB images and corresponding semantic masks;
- divides large images into overlapping 512 × 512 patches;
- uses a 256-pixel stride (50% overlap);
- automatically pads images when necessary;
- preserves the correspondence between image and mask tiles;
- supports negative samples when no annotation is available.
Output:
tilled/
├── tilled_images/
└── tilled_masks/
Balances the training dataset by removing nearly empty image tiles.
The notebook:
- counts the number of annotated weathering pixels in each mask;
- removes patches without weathering information;
- randomly retains 5% of empty tiles as negative examples;
- copies retained and discarded samples into separate directories.
This considerably reduces dataset imbalance while maintaining representative background examples.
Output:
filtered_balanced/
├── images/
└── masks/
filtered_trash/
├── images/
└── masks/
Utility notebook for inspecting semantic masks.
It verifies that mask pixel values were exported correctly before training, helping identify annotation or export errors.
Typical output:
Values found in mask:
[0 255]
The recommended preprocessing workflow is:
- Annotate the original bone images.
- Generate overlapping image and mask patches using
weathering_image_processing.ipynb. - Remove nearly empty patches using
data_cleaning.ipynb. - Verify the integrity of the generated masks with
mask_check.ipynb. - Train the segmentation model.
python weathering_map.pyThe script generates:
- segmentation masks;
- overlay images;
- weathering heatmaps;
- Global Damage Index (GDI);
metrics_report.csv.
WeatheringFormer also supports ensemble inference by combining the outputs of the best-performing SegFormer-B0 and SegFormer-B2 models. Instead of relying on a single network, the framework averages the probability maps predicted by both models for each image patch, generating a consensus segmentation. This strategy generally increases prediction robustness and can improve segmentation performance by reducing model-specific errors.
python ensemble.pyThe script produces the same outputs as the single-model inference:
- segmentation masks;
- RGB overlay images;
- weathering heatmaps;
- Global Damage Index (GDI) scores;
metrics_report.csv.
Example images and ground-truth masks are provided in
sample/
├── images/
└── masks/
These files allow users to verify the installation and test the inference pipeline.
| Input Image | Segmentation Prediction | Damage Heatmap (GDI) |
|---|---|---|
Example outputs produced by WeatheringFormer showing the original image, predicted weathering segmentation, and the corresponding Global Damage Index heatmap.
Performance values correspond to the mean ± standard deviation computed over all images in the independent test set.
| Metric | Mean ± SD |
|---|---|
| IoU | 45.59 ± 23.51 |
| Precision | 58.13 ± 28.89 |
| Recall | 65.76 ± 23.71 |
| F1-score | 58.66 ± 26.21 |
| GDI-score | 11.71 ± 11.79 |
If you use WeatheringFormer or its associated computational resources, please cite the archived software release:
@software{ronaldoaleoni_2026_21817415,
author = {Leoni, Ronaldo Araujo and Alves-Silva, Lais and Araújo-Júnior, Hermínio Ismael},
title = {Ronaldoaleoni/WeatheringFormer: WeatheringFormer},
month = aug,
year = 2026,
publisher = {Zenodo},
version = {v1.0.0},
doi = {10.5281/zenodo.21817415},
url = {https://doi.org/10.5281/zenodo.21817415},
github = {https://github.com/Ronaldoaleoni/WeatheringFormer}
}This project builds upon or incorporates methodologies from the following works:
-
Li, H., et al. (2024). CrackSegFormer: A Transformer-based framework for automated crack segmentation.
- Original repository: CrackSegFormer
-
Leoni, R. A. (2025). BoneColorRecognition: Mask R-CNN framework for automatic fossil bone extraction.
- Repository: bonecolorrecognition
-
Xie, E., Wang, W., Yu, Z., et al. (2021). SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers. NeurIPS 2021.
-
Vaswani, A., et al. (2017). Attention Is All You Need. Advances in Neural Information Processing Systems.
The version of the code used in this study corresponds to v1.0.0, which has been archived in Zenodo to ensure its preservation and reproducibility.
DOI: https://doi.org/10.5281/zenodo.21817415
The GitHub repository may receive future updates, while version v1.0.0 remains permanently archived in Zenodo as the reference version for the results presented in this study.
Copyright © 2026 Ronaldo Araujo Leoni.
WeatheringFormer contains substantial original contributions developed by the author, including new inference modules, dataset preparation utilities, evaluation scripts, documentation, figures, the Global Damage Index (GDI), heatmap generation, and modifications and extensions to the original CrackSegFormer training framework.
WeatheringFormer builds upon the CrackSegFormer implementation by Li et al. (2024).
