Generalizing Neural Networks by Reflecting Deviating Data in Production

Yan Xiao, Yun Lin, Ivan Beschastnikh, Changsheng Sun, David S. Rosenblum, Jin Song DongarXiv 2021 · OpenReview

Deep Neural Networks (DNNs) are highly effective but notoriously brittle when encountering production data that deviates from the training distribution. This paper proposes InputReflector, a novel runtime approach to address "semantically-preserving deviations"—inputs that remain human-recognizable but cause model failure due to environmental noise like blur or lighting changes. By utilizing auxiliary Siamese and Quadruplet networks, InputReflector identifies deviated data and "reflects" it back to the nearest training sample, correcting mispredictions without retraining the base model. Experimental results across MNIST, Fashion-MNIST, and CIFAR-10 show an accuracy improvement from approximately 50% to over 84% on deviated datasets.

The Problem: The "Missing Middle" of Data Drift

Deep learning models typically assume that production data follows the same distribution as training data. However, real-world conditions often introduce noise—such as smudged lenses, varying brightness, or stylistic differences—that lead to performance degradation. Traditional remedies include data augmentation, which is computationally expensive and potentially detrimental to clean-data performance, or Out-of-Distribution (OOD) detection, which simply flags unknown inputs without providing a corrective path.

InputReflector targets the "missing middle": data that is deviated but still contains the necessary semantic information for correct classification.

Examples of InputReflector correcting mispredictions by reflecting deviated inputs (e.g., blurred or distorted) to their nearest training set counterparts.

Methodology: Distribution Analysis and Sample Reflection

The InputReflector framework operates as an auxiliary pipeline alongside a "black-box" deployed DNN. It consists of two primary components:

  1. Distribution Analyzer: This stage uses a Siamese Network trained with a modified triplet loss to categorize inputs into three zones: In-Distribution (ID), Out-of-Distribution (OOD), and Deviated. By employing two thresholds ($K_{in}$ and $K_{out}$), the system can specifically isolate deviated samples that require correction.
  2. Sample Reflector: When an input is flagged as "Deviated," a Quadruplet Network maps the input into a high-dimensional embedding space where similar images are tightly clustered. The system then performs a nearest-neighbor search within the original training set to find a "proxy" image. The label of this clean proxy is used as the final prediction.

Key Results and Performance

The authors evaluated InputReflector using MNIST, Fashion-MNIST, and CIFAR-10, simulating production deviations through transformations like blur, brightness, contrast, and zoom.

  • Detection and Correction: The Distribution Analyzer achieved a 77.19% detection accuracy for deviated inputs. On these samples, where the original models averaged only 50.08% accuracy, InputReflector boosted performance to 84.63%.
  • System Integrity: Crucially, InputReflector maintains 100% of the original model's performance on In-Distribution data, as the reflection mechanism only triggers for detected deviations. This avoids the "poisoning" effect sometimes seen with heavy data augmentation.
  • Efficiency: The system introduces a deployment overhead of 2.86s, significantly outperforming existing "advice" systems like SelfChecker (34.33s), making it more viable for real-time production environments.

Conclusion

InputReflector demonstrates that "reflecting" deviated data is a robust and efficient alternative to retraining or simple OOD rejection. By separating the concerns of high-accuracy fitting (base model) and generalizability (auxiliary models), engineers can better handle the unpredictable nature of production environments. Future work will explore scaling nearest-neighbor searches using vector databases and extending the concept to non-visual domains like Natural Language Processing.

Summary updated

Abstract

Trained with a sufficiently large training and testing dataset, Deep Neural Networks (DNNs) are expected to generalize. However, inputs may deviate from the training dataset distribution in real deployments. This is a fundamental issue with using a finite dataset. Even worse, real inputs may change over time from the expected distribution. Taken together, these issues may lead deployed DNNs to mis-predict in production. In this work, we present a runtime approach that mitigates DNN mis-predictions caused by the unexpected runtime inputs to the DNN. In contrast to previous work that considers the structure and parameters of the DNN itself, our approach treats the DNN as a blackbox and focuses on the inputs to the DNN. Our approach has two steps. First, it recognizes and distinguishes "unseen" semantically-preserving inputs. For this we use a distribution analyzer based on the distance metric learned by a Siamese network. Second, our approach transforms those unexpected inputs into inputs from the training set that are identified as having similar semantics. We call this process input reflection and formulate it as a search problem over the embedding space on the training set. This embedding space is learned by a Quadruplet network as an auxiliary model for the subject model to improve the generalization. We implemented a tool called InputReflector based on the above two-step approach and evaluated it with experiments on three DNN models trained on CIFAR-10, MNIST, and FMINST image datasets. The results show that InputReflector can effectively distinguish inputs that retain semantics of the distribution (e.g., blurred, brightened, contrasted, and zoomed images) and out-of-distribution inputs from normal inputs.
BibTeX
@misc{xiao2021generalizing,
  author = {Yan Xiao and Yun Lin and Ivan Beschastnikh and Changsheng Sun and David S. Rosenblum and Jin Song Dong},
  title = {{Generalizing Neural Networks by Reflecting Deviating Data in Production}},
  year = {2021},
  eprint = {2110.02718},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2110.02718},
}
Figure