U-Net shadow prediction — pretrained checkpoint
Pretrained checkpoint for the sun-conditioned U-Net proposed in:
Tjaša Repič, Domen Kavran, Domen Mongus, Niko Lukač. Napovedovanje senčenja v geoprostorskih podatkih z globokim modelom U-Net (Shadow Prediction in Geospatial Data Using a Deep U-Net Model). ERK 2025, Portorož, pp. 382–386.
What this model does
Cast shadows over terrain and buildings are normally computed by ray-casting over a digital surface model (DSM). That is exact but expensive at high resolution, and it has to be repeated for every sun position.
This model predicts the binary shadow mask directly. It takes a 3-channel raster tile — elevation, slope and aspect — and the Sun's spherical position. An auxiliary branch embeds the solar azimuth and elevation into a 64-dimensional vector, which is tiled over the bottleneck feature map and concatenated with it (1024 + 64 = 1088 channels), so the decoder is conditioned on the illumination geometry. One trained network covers every hour of the year.
Inference takes about 237 ms per 256 × 256 tile, compared with about 300 ms for the ray-casting simulation.
What's included
best_model.pt — a plain torch.save(model.state_dict()). There is no bundled config, tokenizer or processor; the architecture is fixed and defined in NN.ipynb in the code repository.
Trained on a 750 m × 1000 m area of Maribor, Slovenia, at 1 m resolution, with one simulated shadow mask per hour of the year (8,760 masks). Tiles are 256 × 256 with stride 128, split randomly 60/20/20, trained with Adam at learning rate 1e-4, batch size 32, binary cross-entropy on logits, and early stopping on validation F1.
Results
Evaluated at threshold 0.5 on the held-out test split:
| Tile size | Test IoU | Test F1 |
|---|---|---|
| 128 × 128 | 92.1 % | 96.2 % |
| 256 × 256 | 90.4 % | 95.9 % |
| 512 × 512 | 84.2 % | 92.3 % |
Accuracy is highest when shadows are long and well defined (winter, morning and afternoon: IoU up to 0.98) and lowest around noon in summer, when shadows are short and low in contrast (IoU 0.64–0.69).
Limitations
- Spatial leakage. The split is random over (tile, hour) samples, not spatial, so the same tile appears in train and test at different hours. The scores measure generalisation to new lighting conditions at a known location, not to new terrain.
- One city. Trained only on one urban area of Maribor. Performance on other terrain types is untested.
- Fixed resolution. Trained at 1 m pixels. Other resolutions would need retraining.
How to use
This is a plain PyTorch state_dict, not a transformers-compatible model. Loading it needs the model class and data pipeline from the code repository:
git clone https://github.com/SAMPA-Project/unet-shadow-prediction-repic
cd unet-shadow-prediction-repic
pip install torch numpy tifffile pillow matplotlib tqdm jupyter
# download this checkpoint into the repo root, and the data from
# Zenodo (10.5281/zenodo.22896236) into data/ — see the README
To load the checkpoint manually:
import torch
from NN import UNet # or copy the UNet class out of NN.ipynb
model = UNet()
state = torch.load("best_model.pt", map_location="cpu")
model.load_state_dict(state["model_state"]) # checkpoints store model_state / optimizer_state / epoch
model.eval()
# terrain: (B, 3, 256, 256) — min-max normalised elevation, slope, aspect
# sun: (B, 2) — azimuth and elevation in degrees
logits = model(terrain, sun)
shadow = torch.sigmoid(logits) > 0.5
Citation
If you use this model, please cite the paper and, if you use the underlying data, the dataset:
@inproceedings{repic2025napovedovanje,
title = {Napovedovanje sen{\v{c}}enja v geoprostorskih podatkih z globokim modelom {U-Net}},
author = {Repi{\v{c}}, Tja{\v{s}}a and Kavran, Domen and Mongus, Domen and Luka{\v{c}}, Niko},
booktitle = {Zbornik {E}lektrotehni{\v{s}}ke in ra{\v{c}}unalni{\v{s}}ke konference {ERK} 2025},
address = {Portoro{\v{z}}, Slovenia},
pages = {382--386},
year = {2025}
}
Data: 10.5281/zenodo.22896236