Papers
Topics
Authors
Recent
Search
2000 character limit reached

Cross-Entropy Masking (CEM) Loss for RSCD

Updated 8 July 2026
  • CEM loss is a masked BCE variant that retains all change pixels while randomly dropping a fraction of no-change pixels to address class imbalance in change detection.
  • It integrates with SAM fine-tuning, spatial-temporal feature enhancement, and multi-scale decoder fusion to robustly detect changes at multiple scales.
  • Empirical evaluations show consistent mF1 and mIoU gains, including a 2.60-point increase on S2Looking, with optimal performance at δ = 0.3.

Searching arXiv for the specified paper and related context. Cross-Entropy Masking (CEM) loss is a masked variant of binary cross-entropy (BCE) introduced for remote sensing change detection (RSCD) in the framework "Adapting SAM via Cross-Entropy Masking for Class Imbalance in Remote Sensing Change Detection" (Naveed et al., 14 Aug 2025). It was proposed alongside fine-tuning of the Segment anything model (SAM) encoder, spatial-temporal feature enhancement (STFE), and multi-scale decoder fusion (MSDF) to detect changes robustly at multiple scales. The loss is designed for the class-imbalanced setting typical of change detection, where the overwhelming majority of pixels belong to the no-change class. Its core mechanism is to retain all change pixels in the loss while randomly dropping a fraction of no-change pixels, then normalizing by the number of retained pixels. Within SAM-CEM-CD, this formulation is reported to outperform state-of-the-art methods on Levir-CD, WHU-CD, CLCD, and S2Looking, including a 2.60-point increase in change-class mF1_1 on S2Looking relative to the prior SAM-CD baseline (Naveed et al., 14 Aug 2025).

1. Formal definition

Let NN denote the total number of pixels in a training batch after flattening spatial dimensions. For pixel ii, the ground-truth label is yi{0,1}y_i \in \{0,1\}, where $1$ denotes change and $0$ denotes no-change, and the predicted probability is y^i(0,1)\hat{y}_i \in (0,1), produced by a sigmoid (Naveed et al., 14 Aug 2025).

The per-pixel BCE term is

i=[yilogy^i+(1yi)log(1y^i)].\ell_i = -\big[y_i \log \hat{y}_i + (1-y_i)\log(1-\hat{y}_i)\big].

CEM introduces an independent random variable RiUniform(0,1)R_i \sim \mathrm{Uniform}(0,1) for each pixel and a dropout probability δ[0,1]\delta \in [0,1]. The binary mask NN0 is defined as

NN1

All change pixels are therefore always kept, while no-change pixels are skipped with probability NN2. The resulting normalized masked loss is

NN3

Because NN4 counts only retained pixels, the loss is normalized to keep the gradient scale of each mini-batch roughly comparable across different values of NN5. When NN6, NN7 for all pixels and NN8 reduces exactly to standard BCE. As NN9, almost all no-change pixels are discarded and optimization becomes dominated by change pixels.

2. Motivation in remote sensing change detection

The stated motivation is the severe class imbalance of change detection datasets, where the write-up characterizes the typical distribution as approximately ii0 no-change pixels and ii1 change pixels (Naveed et al., 14 Aug 2025). Under this regime, a vanilla BCE objective tends to encourage predictions of no-change almost everywhere, because the dominant class contributes most of the loss.

CEM addresses this imbalance through stochastic subsampling of the majority class. Rather than amplifying the rare class through explicit weighting, it removes a fraction of no-change pixels from the loss computation and thereby forces the model to pay more attention to change pixels. The proposal uses a binary retain/drop mask rather than a soft mask. The write-up notes that a soft mask with ii2 is conceivable, but reports that simple Bernoulli dropout was found effective and easy to tune.

This design is tightly coupled to the paper’s broader adaptation of SAM for RSCD. The encoder is fine-tuned for change detection, while STFE and MSDF are introduced to strengthen spatial-temporal interaction and multi-scale decoding. Within that setting, CEM functions as the loss-level component that specifically targets imbalance, whereas the architectural modules target representation and decoding capacity. A plausible implication is that the method separates architectural handling of scale and temporal correspondence from optimization-level handling of class skew.

3. Relation to BCE, weighted losses, and focal loss

The paper positions CEM against several established strategies for imbalance handling, specifically BCE+Dice, focal loss, and weighted BCE (Naveed et al., 14 Aug 2025). The key distinction is operational. Weighted BCE rescales positive and negative terms globally. Focal loss down-weights easy pixels with high confidence but still includes all negatives in the summation. CEM instead subsamples negatives outright through the mask ii3.

On Levir-CD, the reported ablation is as follows:

Loss mFii4 (%) mIoU (%)
BCE+Dice (0.7/0.3) 95.74 92.08
Focal (ii5) 95.78 92.16
Weighted-BCE (ii6) 95.87 92.31
Weighted-BCE (ii7) 95.66 91.95
CEM (ii8) 95.98 92.51

The write-up states that CEM gave the largest empirical gain, approximately ii9 to yi{0,1}y_i \in \{0,1\}0 absolute on Fyi{0,1}y_i \in \{0,1\}1 and IoU, and did not require tuning per-class weights. It also advances a theoretical interpretation: CEM reduces the variance of the gradient contributions from the dominant class, leading to better exploration of the rare class during optimization. This suggests that the method should be understood less as a reweighting rule than as a stochastic estimator of a class-balanced objective over retained pixels.

A common misconception is to equate CEM with focal loss because both reduce the influence of easy negatives. The distinction is explicit: focal loss keeps all negatives but attenuates their contribution, whereas CEM removes a random fraction of no-change pixels from the loss altogether.

4. Hyper-parameters and optimization behavior

The principal hyper-parameter is the dropout probability yi{0,1}y_i \in \{0,1\}2, defined as the fraction of no-change pixels to remove from the loss (Naveed et al., 14 Aug 2025). The recommended value is yi{0,1}y_i \in \{0,1\}3, corresponding to dropping yi{0,1}y_i \in \{0,1\}4 of no-change pixels.

The Levir-CD ablation for yi{0,1}y_i \in \{0,1\}5 is reported as:

yi{0,1}y_i \in \{0,1\}6 mFyi{0,1}y_i \in \{0,1\}7 mIoU
0.2 95.93 92.41
0.3 95.98 92.51
0.4 95.94 92.44
0.5 95.86 92.29
0.6 95.80 92.19

The best result occurs at yi{0,1}y_i \in \{0,1\}8. Performance declines as yi{0,1}y_i \in \{0,1\}9 increases beyond that point, indicating that excessive removal of no-change pixels can degrade discrimination. This suggests that the loss relies on a controlled reduction of negative evidence rather than near-complete suppression of the majority class.

Normalization by $1$0 is a central design choice. The write-up states that this keeps the magnitude of $1$1 comparable to vanilla CE regardless of $1$2, aiding training stability. Reproducibility is addressed directly: the random seed used to sample $1$3 should be fixed, and over multiple runs the authors observed variance below $1$4 on mF$1$5. Masking is applied independently at the pixel level. Region-wise or super-pixel masking is mentioned only as an untested alternative.

5. Empirical role within SAM-CEM-CD

CEM is evaluated as one component of a larger RSCD system that combines a fine-tuned SAM encoder with STFE and MSDF (Naveed et al., 14 Aug 2025). The datasets are Levir-CD, WHU-CD, CLCD, and S2Looking, and all evaluations use Precision, Recall, F$1$6, mIoU, and OA.

Relative to the prior SAM-CD baseline, the reported mF$1$7 improvements are:

Dataset Prior SAM-CD mF$1$8 (%) SAM-CEM-CD mF$1$9 (%)
Levir-CD 95.50 95.98
WHU-CD 96.15 97.23
CLCD 86.89 87.76
S2Looking (change class) 65.13 67.73

These correspond to gains of $0$0, $0$1, $0$2, and $0$3 percentage points, respectively. The largest increase is reported on S2Looking, which the abstract describes as a large complex dataset.

The paper also isolates the contribution of CEM on Levir-CD through architectural ablation. The sequence is reported as follows: SAM + STFE + UNet-Decoder yields 95.87 mF$0$4; adding Multi-Scale Decoder Fusion yields 95.92; adding CEM with $0$5 yields 95.98. The stated conclusion is that CEM contributes a consistent approximately $0$6 to $0$7 boost on top of sophisticated architectural choices. In context, CEM is therefore presented not as a substitute for architectural adaptation, but as a complementary optimization component.

6. Implementation pattern and practical considerations

The write-up provides a PyTorch-style integration recipe in which predictions and labels are flattened, per-pixel BCE is computed, uniform random values are sampled, the binary mask is assembled from always-kept positives and retained negatives, and the final loss is formed by masked summation divided by the masked count (Naveed et al., 14 Aug 2025). The implementation assumes predictions are already in $0$8 after a sigmoid.

Several practical recommendations are given. Mask sampling and loss computation should be placed on the GPU to avoid CPU–GPU synchronization overhead. Predicted probabilities should be clipped with a small $0$9 to avoid y^i(0,1)\hat{y}_i \in (0,1)0. During training, the retained-pixel ratio y^i(0,1)\hat{y}_i \in (0,1)1 should be monitored; the expected value is described as approximately y^i(0,1)\hat{y}_i \in (0,1)2. If training is unstable, the write-up recommends lowering y^i(0,1)\hat{y}_i \in (0,1)3, or warming up with vanilla BCE by setting y^i(0,1)\hat{y}_i \in (0,1)4 for the first few epochs.

The summary characterization is that CEM is a simple, hyper-parameter-light modification of BCE that subsamples the majority class during loss computation. The same summary states that it requires only one extra line of code while yielding consistent gains on highly imbalanced segmentation tasks such as remote-sensing change detection. In operational terms, its simplicity derives from preserving the standard per-pixel BCE expression and inserting stochastic masking only at the reduction stage.

7. Scope, interpretation, and limitations

CEM is formulated for binary change detection with labels y^i(0,1)\hat{y}_i \in (0,1)5, and the exposition is specific to RSCD datasets in which change pixels are rare (Naveed et al., 14 Aug 2025). Its empirical support in the paper is therefore tied to highly imbalanced binary segmentation. A plausible implication is that its behavior in settings with weaker imbalance, multiclass outputs, or structured masking constraints would require separate validation.

The method should not be interpreted as a soft-attention mechanism over pixels. The mask is binary and stochastic, not learned and not continuous. It should also not be interpreted as a claim that no-change pixels are unimportant; rather, a fraction of them is randomly omitted from each loss evaluation while the retained subset continues to supply negative supervision.

Another limitation is that only pixel-wise independent masking is studied. The write-up explicitly notes that masking by region or super-pixel was not explored. Similarly, although the paper compares CEM with BCE+Dice, focal loss, and weighted BCE on Levir-CD, broader cross-dataset loss ablations are not detailed in the technical note. The present evidence therefore supports CEM most directly as a practical majority-class subsampling strategy for the specific SAM-based RSCD pipeline evaluated in the paper.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Cross-Entropy Masking (CEM) Loss.