Source-linked AI summary

Identifying Implementation Bugs in Machine Learning based Image Classifiers using Metamorphic Testing

Anurag Dwarakanath, Manish Ahuja, Samarth Sikand, Raghotham M. Rao, R. P. Jagadeesh Chandra Bose, Neville Dubash, Sanjay Podder

arXiv:1808.05353v1cs.SEcs.LG

TL;DR

The paper addresses the difficulty and expense of verifying ML applications when conventional expected outputs are unavailable or insufficient for identifying implementation bugs. It uses metamorphic relations for SVM and ResNet image classifiers, and mutation testing found that 71% of implementation bugs were caught. The approach is demonstrated across two applications, with GPU non-determinism remaining an unresolved limitation.

  • Problem

    Verifying ML applications is difficult and expensive because expected outputs may be unavailable, while incorrect predictions can have multiple causes, including implementation bugs.

  • Method

    The paper develops metamorphic relations that compare outputs from related inputs to identify implementation bugs in SVM and ResNet image classifiers.

  • Results

    71% of implementation bugs were caught: the SVM relations caught 12 of 12 mutants, while the ResNet relations caught 8 of 16.

  • Takeaways & Limitations

    Metamorphic testing provides an approach for reasoning about implementation correctness in ML image classifiers without relying solely on expected outputs.

  • Takeaways & Limitations

    ResNet remained stochastic on GPU even after fixing random seeds, and the cause of its GPU non-determinism could not be determined.

Abstract

from arXiv · show

We have recently witnessed tremendous success of Machine Learning (ML) in practical applications. Computer vision, speech recognition and language translation have all seen a near human level performance. We expect, in the near future, most business applications will have some form of ML. However, testing such applications is extremely challenging and would be very expensive if we follow today's methodologies. In this work, we present an articulation of the challenges in testing ML based applications. We then present our solution approach, based on the concept of Metamorphic Testing, which aims to identify implementation bugs in ML based image classifiers. We have developed metamorphic relations for an application based on Support Vector Machine and a Deep Learning based application. Empirical validation showed that our approach was able to catch 71% of the implementation bugs in the ML applications.

1 INTRODUCTION

Testing ML applications with conventional input-output expectations is difficult because inputs are vast, expected outputs are often unavailable, and isolated errors do not establish implementation bugs. The paper proposes metamorphic relations for SVM and ResNet classifiers and reports that mutation testing caught 71% of implementation bugs.

  • Conventional verification tests whether a program’s output matches an expected output for supplied input-output test cases.
  • ML applications are difficult to verify because they accept many possible inputs and expected outputs may be unknown or expensive to create.
  • An incorrect classification does not by itself establish an implementation bug because ML applications are not expected to be perfectly accurate.
  • Incorrect ML outputs may result from training data, architecture, learned functions, or implementation bugs, so implementation faults should be checked before collecting more data.
  • Metamorphic Testing creates a related second input and checks whether the corresponding outputs satisfy a defined Metamorphic Relation.
  • 71% of artificially introduced implementation bugs were caught by the proposed approach across two ML image-classification applications.The study used mutation testing to evaluate SVM and ResNet applications.

2 RELATED WORK

Prior work tested several ML algorithms and explored formal verification, validation, and failure-case discovery, but important gaps remained in non-linear SVMs and deep-learning classifiers. The paper positions metamorphic testing as a verification approach focused specifically on implementation bugs.

  • Earlier metamorphic-testing studies covered Naive Bayes, linear-kernel SVM, and k-nearest neighbor, but not commonly used non-linear SVM kernels or deep-learning classifiers.
  • A prior deep-learning metamorphic-testing study developed relations from typical expectations, without justifications or empirical validation.
  • Formal verification approaches can face scalability, language-learning, and specification-correctness challenges when applied to machine learning.
  • Some deep-learning testing approaches validate real-world failure cases by targeting deficient training data or poor learning algorithms rather than implementation bugs.

3 IDENTIFYING IMPLEMENTATION BUGS IN ML BASED APPLICATIONS

The paper validates its metamorphic properties on two publicly available image-classification applications: handwritten-digit recognition with SVM and image classification with ResNet.

  • The methodology designs metamorphic properties and validates them on publicly available machine-learning applications.
  • The first application performs handwritten-digit recognition using SVMs with linear and non-linear kernels.
  • The second application performs image classification using Residual Networks, a type of deep convolutional neural network.

3.1 Metamorphic Relations for Application 1: Digit Recognition using SVM

The digit-recognition SVM application operates on grayscale 8×8 images and is tested with metamorphic relations designed to preserve specified outputs under data transformations. The relations are justified through the SVM’s dual-form kernel formulation and include feature permutation, instance reordering, shifting, and kernel-specific scaling.

  • Application and data: The application classifies handwritten digits from 0 to 9 using an SVM with either a linear or RBF kernel.Each grayscale example is represented as an array of 64 values from an 8×8 image.
  • Application and data: Testing compares predictions and confidence scores after metamorphic transformations of training or test data.The confidence score is the functional distance from the decision boundary; larger values indicate greater certainty.
  • Metamorphic relations: The developed relations cover feature permutation, training-instance reordering, constant feature shifting for the RBF kernel, and test-feature scaling for the linear kernel.MR-1 and MR-2 change feature or instance order, MR-3 shifts both datasets, and MR-4 scales test instances only.
  • Validity proofs: The SVM proofs rely on its dual formulation, where transformations are analyzed through their effect on the kernel function.The linear kernel uses dot products, while the RBF kernel measures squared distance between instances.
  • MR-1: Feature permutation: MR-1 preserves results because applying the same feature permutation leaves the relevant linear and RBF kernel values unchanged.The relation requires permuting corresponding training and test features consistently, so the test instance retains its class and score.
  • MR-4: Test-feature scaling: MR-4 compares functional distances after scaling test instances by factors of two and three, without requiring their classes to remain unchanged.This relation can be applied to an already trained linear-kernel model.
  • Implementation: Each relation uses one variant that changes every relevant data aspect, with expected outputs matching within a threshold of 10^-6.The stated efficacy of these relations is evaluated separately in Section 4.

3.2 Metamorphic Relations for Application 2: Image Classification using ResNet

The ResNet application classifies CIFAR-10 color images, and the paper develops metamorphic relations that preserve expected behavior under structured data or operation transformations. These relations target implementation verification, while empirical tests support their validity across architectures and datasets.

  • Application background: ResNet classifies 32 × 32 × 3 CIFAR-10 color images into 10 mutually exclusive classes, reporting test loss and classification accuracy.The test loss is computed as cross-entropy between actual and predicted classes.
  • Metamorphic relations: The proposed ResNet relations permute input channels, permute convolution-operation order, normalize test data, and scale test data by a constant.The section specifically introduces four metamorphic relations for the application.
  • MR-2: Convolution-order permutation: For convolution-order permutation, pixel transformations maintain local neighborhoods because CNN layers exploit locality of pixel dependencies.Arbitrary pixel permutations are excluded because they would violate this architectural property.
  • MR-1: Input-channel permutation: RGB-channel permutation uses all 6 channel orders for training and test data, while preserving the locality property of the image representation.The channel variants include the original RGB ordering and five permutations.
  • MR-1: Input-channel permutation: The RGB relation is supported by a convolutional equivalence: jointly permuting input channels and corresponding first-layer weights leaves the convolution output unchanged.The same output implies unchanged subsequent outputs when the corresponding weights are used.
  • Reasoning and validation: The optimization caveat is that gradient descent may not find the correspondingly transformed weights, so empirical evidence is used to support similar convergence behavior.The paper reports tests across three additional datasets and three architectures, with little variation in the loss curves.
  • Empirical evidence: Permuting RGB channels did not significantly change results, and the property held across the tested architectures and datasets.The experiments validating MR-1 and MR-2 are summarized as showing little variation in the relevant loss curves.

4 EMPIRICAL RESULTS

The evaluation used mutation testing to assess metamorphic relations for SVM and ResNet image classifiers. The relations caught all 12 SVM mutants and 8 of 16 ResNet mutants, for 71% overall, while exposing limitations for stochastic and architecture-changing mutants.

  • Evaluation setup: Mutation testing introduced implementation bugs into two image-classification applications and measured whether metamorphic relations caught them.MutPy generated mutants, and a mutant was killed when its outputs violated an MR.
  • SVM results: The SVM experiment retained six relevant mutants, all involving reading class labels from the wrong CSV column, for both linear and RBF kernels.The initial generation produced 52 linear-SVM and 50 RBF-SVM mutants before filtering.
  • SVM results: All 12 SVM mutants were caught; MR-1 and MR-3 each caught all six mutants because they exposed incorrect input-data handling.MR-1 permuted input features, while MR-3 shifted features by a constant.
  • ResNet results: ResNet mutants were evaluated through test-loss outliers, with a threshold of σmax > 9 used to identify variants that did not behave alike.The number of mutants caught was unchanged for thresholds from 5 to 9, and test-only MRs also caught mutants on an already trained model.
  • ResNet results: The ResNet MRs caught 8 of 16 mutants, while no architecture-changing r* mutants were caught because they produced no noticeable output changes.The study notes that detecting such architecture mutants remains an open direction.
  • Discussion: Overall, the MRs caught 20 of 28 mutants, or 71%, but the ResNet validation used only 10% of CIFAR-10 because full training required about 105 CPU hours.The selected subset contained 5,029 training and 1,010 test instances, with training taking approximately 10 hours.

5 CONCLUSION

The paper addresses the challenge of identifying implementation bugs in ML applications when expected outputs are difficult to specify. It develops metamorphic relations for SVM and deep-learning image classifiers and reports that they caught 71% of injected bugs on average.

  • Problem: The paper investigates implementation-bug identification in ML applications, where conventional validation relies on a human tester acting as an oracle.The conclusion frames output verification against a specification as extremely challenging for ML applications.
  • Approach: Metamorphic testing builds relations between subsequent program outputs to reason about implementation correctness without relying solely on input-output test pairs.The relations were developed for an SVM classifier and a deep-learning convolutional neural network.
  • Result: 71% of implementation bugs were caught on average by the developed metamorphic relations.The reported evaluation covered two image-classification applications.
  • Takeaway: The results support further exploration of metamorphic testing for ML applications.The conclusion describes the reported average detection rate as impetus for further exploration.
Loading 1808.05353v1…