This repository contains the implementation of various deep learning models configuration to detect fences using multimodal imagery (RGB and DSM). The project, related to the paper Where are the fences? Large-scale fence detection using deep learning and multimodal aerial imagery, explores the impact of different fusion strategies, loss functions, and sampling techniques on model performance. It also includes tools for dataset visualization and evaluation. This work is the first one to address fence detection using aerial imagery.
- Multiple architectures: UNet, UNetLateFusion, UNetConcatenate, and D-LinkNet.
- Multimodal input support (RGB + DSM).
- Flexible loss functions: Dice Loss, Binary Cross-Entropy (BCE), and Combined Loss (Dice + BCE).
- Sampling strategies: random and geographic.
- Tools for dataset visualization and validation.
The segmentation models are based on the UNet architecture and its multimodal extensions (e.g., Late Fusion). Below is the structure of the proposed UNetLateFusion model:
βββ Departments/ # GPKG dataset for geographic stratification (train, val, test)
βββ LICENSE # Code license
βββ README.md
βββ data_loader.py # Data loading pipeline for RGB, DSM, and masks, adapted to each network
βββ graphical_validation.py # Dataset visualization tool for inspecting masks and features (launch it separately)
βββ loss.py # Implementation of Dice Loss, BCE, and Combined Loss
βββ main.py # Script for training models (modify each path/variable in the config function)
βββ main_test.py # Script for testing and evaluating models (modify each path/variable in the config function)
βββ model.py # Implementation of UNet, UNetLateFusion, UNetConcatenate, and D-LinkNet
βββ requirements.txt # Python dependencies
βββ test.py # Evaluation metrics and patch analysis
βββ train.py # Training logic and scheduler implementation
The project expects the following directory structure for the dataset:
/dataset/
βββ ortho/ # RGB orthophotos
βββ lidar/ # DSM (Digital Surface Model)
βββ fences_3m/ # Binary masks (3-meter buffer for fences)
βββ fences_2m/ # Binary masks (2-meter buffer for fences)
You can download it here: MultiFranceFences
The Departments/ folder contains a GeoPackage (GPKG) file, which ensures balanced geographic stratification for training, validation, and testing splits. This is critical for evaluating generalization across regions.
The graphical_validation.py script is designed to help you visually inspect the dataset quality, including masks, RGB, and DSM alignment. Run the script as follows:
python graphical_validation.pyIt saves the name of the patch and the tag (valid or not) in a CSV file.
The training script (main.py) is built around a flexible Config class. Key parameters include:
- Models:
UNet,UNetLateFusion,UNetConcatenate,D-LinkNet. - Input modalities: RGB, DSM, or both.
- Sampling strategies: random or geographic.
- Loss functions: Dice Loss, BCE, or Combined Loss.
- Learning rate and scheduler: Supports dynamic learning rate reduction.
The code is commented. You can adapt the class depending on your needs. It is developed in order to use multi-GPU with nn.DataParallel.
To start training, modify the Config class in main.py and execute:
python main.pyModel checkpoints are saved in the models/ directory with automatically generated filenames based on the configuration.
To evaluate a trained model, use the main_test.py script and modify the path to the .pth file:
python main_test.pyThis will:
- Compute predictions and save them as GeoTIFF files.
- Generate classification metrics (precision, recall, IoU, Dice coefficient).
- Identify the best and worst-performing patches.
The script outputs:
- Evaluation metrics in a text file.
- Visualizations of predictions and ground truths for selected patches.
Install dependencies using:
pip install -r requirements.txtKey libraries:
- PyTorch
- segmentation-models-pytorch
- GDAL
- NumPy
- Matplotlib
If you use this work, please cite:
@article{wenger2025fences,
title = {Where are the fences? Large-scale fence detection using deep learning and multimodal aerial imagery},
journal = {Remote Sensing Applications: Society and Environment},
volume = {39},
pages = {101658},
year = {2025},
issn = {2352-9385},
doi = {https://doi.org/10.1016/j.rsase.2025.101658},
url = {https://www.sciencedirect.com/science/article/pii/S2352938525002113},
author = {Romain Wenger and Eric Maire and Caryl Buton and Sylvain Moulherat and Cybill Staentzel}
}
This project is licensed under the MIT License. See the LICENSE file for details.
