---
title: 'AttentionUNet-OBIA: Hybrid Forest Mapping'
url: https://www.emergentmind.com/topics/attentionunet-obia
type: topic
---

# AttentionUNet-OBIA: Hybrid Forest Mapping

AttentionUNet-OBIA is a hybrid forest cover mapping methodology that integrates a deep learning model—AttentionUNet—with Object-Based Image Analysis (OBIA) for high-resolution multispectral remote sensing image analysis. Developed within the "ForCM" pipeline for Sentinel-2 imagery, it achieves state-of-the-art accuracy for forest/non-forest classification in the Amazon Rainforest, providing both pixel-wise discrimination and object-level interpretability with open-source tools [2512.23196].

## 1. Architecture and Attention Mechanism

The core of AttentionUNet-OBIA is a UNet-style encoder–decoder architecture augmented with attention gates (AG). The input consists of $512 \times 512 \times C$ images ($C=$ 3 or 4 bands). The model comprises four encoding stages, a bottleneck, and four decoding stages that symmetrically mirror the encoder. Each encoder level $\ell$ applies two consecutive $3\times3$ convolutions with ReLU activations (optionally batch-normalized), doubling feature channels at each downsampling (e.g., $64 \to 128 \to 256 \to 512$). Spatial resolution is reduced by $2 \times 2$ max-pooling (stride 2). The bottleneck contains two $3\times3$ convolutions at 1024 channels.

Decoding consists of $2\times2$ transposed convolution (up-convolution) to increase spatial resolution and halve channel count. At each decoder level $\ell$, an attention gate receives the upsampled decoder signal $g^\ell$ and the encoder skip feature $x^\ell$. The AG formula follows Oktay et al. (2018):

\begin{align*}
f_x &= W_x\,x^\ell, \quad f_g = W_g\,g^\ell \\
\Psi_\text{int} &= \operatorname{ReLU}(f_x + f_g + b) \\
\alpha^\ell &= \sigma(\psi^T \Psi_\text{int} + b_\psi) \\
x^{\ell\,\prime} &= \alpha^\ell \odot x^\ell
\end{align*}

where $W_x, W_g, \psi$ are learned convolutions, $\sigma$ the sigmoid, and $\odot$ element-wise multiplication. The AG output $x^{\ell\,\prime}$ emphasizes salient features and suppresses irrelevant regions before skip connection concatenation. The final feature map passes through a $1\times1$ convolution, followed by sigmoid activation, yielding a pixel-wise probability map $p(x,y) \in [0, 1]$.

## 2. Data Preprocessing and Input Modalities

Input data are Sentinel-2 Level-2A images, pre-corrected for atmospheric effects using ESA Sen2Cor. Band selection includes both three-band (RGB) and four-band (RGB plus NIR, all at 10 m) sets. Input normalization policies are:

- Three-band images: divide by 255, cast to float32, yielding values in $[0, 1]$.
- Four-band images: cast to float32, per-band divided by maximum reflectance ($\sim 10\,000$), then rescaled to $[0,1]$.

No additional spectral indices such as NDVI are computed; only raw bands are provided to the model.

## 3. OBIA: Segmentation and Feature Extraction

Post-prediction, OBIA is performed in QGIS (v3.34.5, Orfeo Toolbox v8.1.2) using mean-shift segmentation, chosen for robust unsupervised object delineation. Mean-shift parameters are set to spatial radius $sp = 5$, range radius $sr = 5$, and minimum object size $\approx 50$ pixels (trial-and-error selected). Each resulting image object $O_i$ yields a feature vector $f_i = [\mu_R, \mu_G, \mu_B, (\mu_{NIR}), \bar{p}_i]$, where $\mu_X$ are mean band reflectances and $\bar{p}_i$ is the mean AttentionUNet pixelwise probability within $O_i$. Optional features (not used in this work) include area, perimeter, compactness, and texture.

## 4. Fusion, Classification, and Post-processing

The classification stage fuses AttentionUNet-derived and OBIA-obtained features at object level. From the segmented object set $\{O_i\}$, $\sim 25\%$ are randomly sampled (visually-checked stratification) for manual ground-truth labeling. A linear-kernel Support Vector Machine (SVM, $C = 1$) is trained to map $f_i$ to forest/non-forest labels. Label assignment is performed by evaluating SVM score $s_i$ with a threshold at 0 (or probability 0.5, if calibrated). Post-processing removes objects $< 20$ pixels by morphological opening, followed by boundary smoothing via a $3\times3$ majority filter to reduce salt-and-pepper noise.

## 5. Training Protocol and Hyperparameters

Datasets are split as follows: for 3-band sets, V1: $30$ train/$15$ val/$15$ test; V2: $1123$ train/$100$ val/$100$ test; V3: $280$ train/$115$ val/$100$ test; and for the 4-band set: $499$ train/$100$ val/$20$ test. Training applies binary cross-entropy loss with Adam optimizer ($\beta_1=0.9$, $\beta_2=0.999$), batch size $8$, initial learning rate $1 \times 10^{-4}$, with ReduceLROnPlateau scheduling (factor $0.5$, patience $3$), and no class weighting (class balance assumed). Data augmentation is limited to random horizontal/vertical flips performed on-the-fly. Training epochs: 20 for V1, 10 for V2, V3, and 4-band. Hardware employed: Intel i7-class CPU, 32 GB RAM, NVIDIA GeForce GTX TITAN X 12 GB GPU.

## 6. Evaluation Metrics and Comparative Results

Performance is assessed using mean Intersection over Union (IoU), overall accuracy (OA), precision, recall, and F1-score, computed on randomly selected test images. AttentionUNet-OBIA achieves:

| Metric         | Value      |
|----------------|------------|
| OA             | 95.64 %    |
| IoU            | 0.9064     |
| Precision      | 93.32 %    |
| Recall         | 96.84 %    |
| F1-score       | 0.9504     |

Comparative results show that AttentionUNet-OBIA surpasses traditional OBIA (OA 92.91 %, IoU 0.8992, F1 0.9365) and other DL-OBIA variants such as ResUNet-OBIA (OA 94.54 %, IoU 0.9101, F1 0.9525). Standalone AttentionUNet (no OBIA) attains OA 95.93 % and IoU 0.9168 on the 4-band test set. An example confusion matrix for 1000 test pixels:

|                | Pred Forest | Pred Non-Forest |
|----------------|-------------|-----------------|
| True Forest    |      581    |        19       |
| True Non-Forest|       27    |       373       |

This evaluates to $\kappa \approx 0.91$.

## 7. Workflow Schematic

The pipeline is summarized as follows:

1. Load images and ground-truth masks.
2. Normalize bands to $[0,1]$ (float32).
3. Partition datasets into train/val/test.
4. Construct AttentionUNet:
   - Encoder (levels $1\ldots4$): $\text{Conv}_{3\times3} \to \text{ReLU} \to \text{Conv}_{3\times3} \to \text{ReLU} \to \text{MaxPool}$
   - Bottleneck: $\text{Conv} \to \text{ReLU} \to \text{Conv} \to \text{ReLU}$
   - Decoder ($4\ldots1$): $\text{UpConv} \to \text{AttentionGate} \to \text{Concat} \to$ two $\text{Conv}_{3\times3} \to \text{ReLU}$
   - Output: $1\times1$ Conv (sigmoid).
5. Train with Adam optimizer and BCE loss, 10–20 epochs.
6. Inference: output $p(x,y)$ probability map.
7. Segment objects with mean-shift (QGIS/OTB, $sp=5, sr=5$).
8. For each object $O_i$, compute $\mu$ (bands), $\bar{p}_i$; assemble feature $f_i$.
9. Train linear SVM on labeled $O_i$.
10. Classify all $O_i$ as forest/non-forest.
11. Assign SVM label to all pixels within $O_i$ for final raster.
12. Post-process with small-object removal and majority filter.

A plausible implication is that the approach leverages spatial coherence, spectral consistency, and pixel-level DL inference for highly accurate, interpretable mapping, facilitated by accessible open-source software [2512.23196].

Source: https://www.emergentmind.com/topics/attentionunet-obia