Skip to content

About

Deep learning framework for automatic segmentation and quantitative assessment of bone weathering.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

WeatheringFormer

Deep learning framework for automatic segmentation and quantitative assessment of weathering damage on fossil bones.

Python PyTorch DOI License


Contents


Features

  • 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

Overview

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.

Framework Overview

Framework Overview


Pipeline

The WeatheringFormer workflow consists of:

  1. Bone extraction using the Mask R-CNN model developed in Leoni et al., 2025 as the first module.
  2. Weathering segmentation using SegFormer.
  3. Removal of spurious detections.
  4. Fracture thickness estimation using the Euclidean Distance Transform.
  5. Multi-scale damage integration.
  6. Generation of heatmaps and Global Damage Index (GDI).

Repository Structure

WeatheringFormer/
│
├── dataset_preparation/
├── examples/
├── models/
├── pretrained_weights/
├── sample/
├── tools/
├── train_utils/
├── weights/
│
├── ensemble.py
├── weathering_map.py
├── environment.yml
└── README.md

Installation

Before You Begin

Git Large File Storage (Git LFS)

WeatheringFormer stores pretrained model weights using Git LFS.

Install Git LFS before cloning or pulling the repository:

git lfs install

After cloning, download the model weights with:

git lfs pull

If Git LFS is not installed, the .pth files will be downloaded as small pointer files instead of the actual model weights.


1. Clone the repository

Clone the repository to your local machine and enter the project directory.

git clone https://github.com/Ronaldoaleoni/WeatheringFormer.git
cd WeatheringFormer

2. Create the Conda environment

The repository includes an environment.yml file containing all dependencies required to run WeatheringFormer.

Create the environment with:

conda env create -f environment.yml

This 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

3. Activate the environment

conda activate weatheringformer

Replace weatheringformer with the environment name defined in environment.yml if it is different.


4. Verify the installation

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.


Requirements

WeatheringFormer uses Conda for dependency management.

If Conda is not installed, install either:

  • Anaconda
  • Miniconda

before proceeding with the installation.

Model Weights

The repository contains two types of model weights.

Trained models (weights/)

These checkpoints reproduce the experiments described in the accompanying manuscript (currently in preparation).

Pretrained backbones (pretrained_weights/)

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.

Dataset Preparation

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.

weathering_image_processing.ipynb

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/

data_cleaning.ipynb

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/

mask_check.ipynb

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]

Dataset preparation workflow

The recommended preprocessing workflow is:

  1. Annotate the original bone images.
  2. Generate overlapping image and mask patches using weathering_image_processing.ipynb.
  3. Remove nearly empty patches using data_cleaning.ipynb.
  4. Verify the integrity of the generated masks with mask_check.ipynb.
  5. Train the segmentation model.

Running Inference

python weathering_map.py

The script generates:

  • segmentation masks;
  • overlay images;
  • weathering heatmaps;
  • Global Damage Index (GDI);
  • metrics_report.csv.

Running Ensemble Inference

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.py

The 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.

Sample Dataset

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.


Results

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.

Quantitative Results

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

Citation

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}
}

References

This project builds upon or incorporates methodologies from the following works:

  1. Li, H., et al. (2024). CrackSegFormer: A Transformer-based framework for automated crack segmentation.

  2. Leoni, R. A. (2025). BoneColorRecognition: Mask R-CNN framework for automatic fossil bone extraction.

  3. Xie, E., Wang, W., Yu, Z., et al. (2021). SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers. NeurIPS 2021.

  4. Vaswani, A., et al. (2017). Attention Is All You Need. Advances in Neural Information Processing Systems.

Archived Version

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

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).

About

Deep learning framework for automatic segmentation and quantitative assessment of bone weathering.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages