arXiv:2611.08157cs.CVNov 2026

Manuscript Offprint

arXiv:2611.08157

Improving Context-Shift Robustness of Convolutional Networks via Context-Regularized Cross-Entropy

Jinen Setpal, Chaoyue Liu

Abstract

Image classification models often encounter objects in diverse and unpredictable contexts at test time, which may differ substantially from those seen during training. This phenomenon, termed context shift, exposes a key fragility in neural networks: when models rely on non-causal contextual cues for prediction, shifts in context can lead to significant performance degradation. In this paper, we propose a novel training framework to improve the robustness of convolutional neural networks under context shift. Our approach leverages spatial feature attribution to guide models toward making predictions that rely less on contextual regions and more on object-relevant features. As a first step, recognizing a theoretical limitation of existing feature attribution methods we introduce a new variant, ContrastiveCAMs, which produces more faithful attribution maps of model predictions. Building on ContrastiveCAMs, we further propose Context-Regularized Cross-Entropy (CR-CE), a modification of the standard cross-entropy loss that regularizes the model's attention by suppressing the influence of contextual regions, thereby improving robustness to context shift. We evaluate the effectiveness of our approach on several medium-to-large scale datasets (Waterbirds, Spawrious, ImageNet/ImageNet-BG, Hard-ImageNet), and report consistent improvements in context-shift robustness.

1 Introduction

The vast applications of convolutional neural networks in safety-critical domains such as medical imaging [38, 33], forensic investigation [26] and self-driving [21] make trustworthy and robust predictions essential for large-scale adoption. It has been demonstrated that existing neural networks, despite achieving remarkable performance on large-scale datasets, heavily rely on supporting context (i.e., background area within the images) to determine their predictions [41, 23, 30]. This sensitivity to surrounding context can degrade performance when the same object appears in a different environment [46, 15, 3, 4], whether due to novel object-context combinations in the test data or adversaries manipulating target-agnostic regions to mislead the model.

We highlight this concern in Figure 1 using the Waterbirds-100 dataset [37] which only has the object-context combinations of waterbird-waterfront and landbird-land. When a waterbird is shown in the context of land, the model predicts the class landbird with high confidence, due to the influence of the context dominating over the influence of the object. The converse also occurs when a landbird appears in a waterfront context. This concerning lack of robustness has been observed across safety-

40th Conference on Neural Information Processing Systems (NeurIPS 2026).

Figure

Figure 1: Context Contributions Can Mislead Predictions. Spatial feature attribution maps reveal that cross-entropy trained models rely heavily on context, causing misclassifications in novel environments. Our approach encourages focus on the object thereby improving context-shift robustness.

critical applications spanning the diagnosis of skin cancer [27], pneumothorax [36], as well as in the generalization capabilities of robot foundation models [48].

In this paper, we aim to improve the context robustness of convolutional neural networks by leveraging spatial feature attributions. We begin by noting a theoretical limitation of existing feature attribution methods: they permit an arbitrary constant shift applied uniformly across all output logits, which undermines their ability to provide faithful explanations. As a result, the attributed contributions from context and object regions may not accurately reflect their true influence, as they can be distorted by this constant shift. We address this limitation by proposing a new variant ContrastiveCAMs, based on a prior method, HiResCAMs [10]. We further theoretically confirm that ContrastiveCAMs provide faithful explanations to the neural networks final predictions.

To address sensitivity to context shifts, we propose a new loss function, Context-Regularized Cross-Entropy (CR-CE), which leverages the proposed feature attribution method, ContrastiveCAMs, to encourage the model to focus on the primary object by suppressing contributions from the surrounding context. This approach requires object-context segmentation during training (crucially, with no segmentation required during inference), which can be readily obtained using existing pretrained segmentation models such as SAM3 [5] and Masked AutoEncoders (MAE) [13, 18]. Notably, the segmentation need not be perfect. In our experiments on the ImageNet dataset, we use MAEs to generate object-context segmentation. Experimental results demonstrate that our method effectively reduces the context contribution to model predictions and improves convolutional networks' robustness to context shifts consistently across a broad class of datasets. Our key contributions are summarized as follows:

  • We identify a theoretical limitation of existing spatial feature attribution methods that hinders explanation faithfulness. We address this limitation by proposing a new method ContrastiveCAMs.
  • We propose a new loss function, Context-Regularized Cross Entropy (CR-CE), that encourages model predictions to focus on the object region rather than the context.
  • Experimental evaluations demonstrate that the proposed training approach effectively attracts the focus of feature attribution towards the object region, thus enhancing context-shift robustness.

Notation. We denote vectors using bold lowercase letters (e.g., v), matrices using uppercase letters (e.g., M), and tensors using bold uppercase letters (e.g., T), with partial indexing implying selection of the subtensor across the remaining subsequent dimensions (e.g., Ti∈Rb×cT_i \in \mathbb{R}^{b \times c} for T∈Ra×b×cT \in \mathbb{R}^{a \times b \times c}). We use the operator ⊙\odot to represent elementwise multiplication, and define [K]:={1,2,…,K}[K] := \{1, 2, \ldots, K\}.

References (44)