Repairing Deep Neural Networks Based on Behavior Imitation
The increasing use of deep neural networks (DNNs) in safety-critical systems
has raised concerns about their potential for exhibiting ill-behaviors. While
DNN verification and testing provide post hoc conclusions regarding unexpected
behaviors, they do not prevent the erroneous behaviors from occurring. To
address this issue, DNN repair/patch aims to eliminate unexpected predictions
generated by defective DNNs. Two typical DNN repair paradigms are retraining
and fine-tuning. However, existing methods focus on the high-level abstract
interpretation or inference of state spaces, ignoring the underlying neurons'
outputs. This renders patch processes computationally prohibitive and limited
to piecewise linear (PWL) activation functions to great extent. To address
these shortcomings, we propose a behavior-imitation based repair framework,
BIRDNN, which integrates the two repair paradigms for the first time. BIRDNN
corrects incorrect predictions of negative samples by imitating the closest
expected behaviors of positive samples during the retraining repair procedure.
For the fine-tuning repair process, BIRDNN analyzes the behavior differences of
neurons on positive and negative samples to identify the most responsible
neurons for the erroneous behaviors. To tackle more challenging domain-wise
repair problems (DRPs), we synthesize BIRDNN with a domain behavior
characterization technique to repair buggy DNNs in a probably approximated
correct style. We also implement a prototype tool based on BIRDNN and evaluate
it on ACAS Xu DNNs. Our experimental results show that BIRDNN can successfully
repair buggy DNNs with significantly higher efficiency than state-of-the-art
repair tools. Additionally, BIRDNN is highly compatible with different
activation functions.
Zhen Liang, Taoran Wu, Changyuan Zhao, Wanwei Liu, Bai Xue, Wenjing Yang, Ji Wang
# Repairing Deep Neural Networks Based on Behavior Imitation

###### Abstract

The increasing use of deep neural networks (DNNs) in safety-critical systems has raised concerns about their potential for exhibiting ill-behaviors. While DNN verification and testing provide post hoc conclusions regarding unexpected behaviors, they do not prevent the erroneous behaviors from occurring. To address this issue, DNN repair/patch aims to eliminate unexpected predictions generated by defective DNNs. Two typical DNN repair paradigms are retraining and fine-tuning. However, existing methods focus on the high-level abstract interpretation or inference of state spaces, ignoring the underlying neurons' outputs. This renders patch processes computationally prohibitive and limited to piecewise linear (PWL) activation functions to great extent. To address these shortcomings, we propose a behavior-imitation based repair framework, BIRDNN, which integrates the two repair paradigms for the first time. BIRDNN corrects incorrect predictions of negative samples by imitating the closest expected behaviors of positive samples during the retraining repair procedure. For the fine-tuning repair process, BIRDNN analyzes the behavior differences of neurons on positive and negative samples to identify the most responsible neurons for the erroneous behaviors. To tackle more challenging domain-wise repair problems (DRPs), we synthesize BIRDNN with a domain behavior characterization technique to repair buggy DNNs in a probably approximated correct style. We also implement a prototype tool based on BIRDNN and evaluate it on ACAS Xu DNNs. Our experimental results show that BIRDNN can successfully repair buggy DNNs with significantly higher efficiency than state-of-the-art repair tools. Additionally, BIRDNN is highly compatible with different activation functions.

 DNN repair/patch, behavior imitation, retraining, fine-tuning, fault localization

## I Introduction

Deep neural networks (DNNs) have become a leading candidate computation model for deep learning in recent years and have achieved enormous success in various domains, including computer vision [1] and natural language processing [2, 3]. Despite their popularity and success, DNNs are not infallible and can produce erroneous outputs, such as incorrect predictions, classifications, or identifications. These unexpected errors can lead to system failures [4, 5, 6], wrongful arrests [7, 8], and even loss of life [9]. As a result, the unexpected behaviors of DNNs make their application in safety-critical domains, such as autonomous vehicles, a significant and pressing concern.

To earn users' trust and alleviate their concerns, it is critical to ensure that DNNs meet specific requirements and produce expected outputs before deployment. Recent advancements in _DNN verification_, _DNN testing_, and _DNN property-guided training_ have highlighted the importance of this issue. Diverse DNN verification techniques [10, 11] have been proposed to verify whether a given DNN adheres to specific properties such as robustness [12] or safety [13]. These techniques range from abstract interpretation [14, 15, 16, 17], SMT/SAT theory [18, 19] to linear programming [20, 21, 22]. Meanwhile, DNN testing [23, 24] evaluates the behaviors of DNNs through numerous test cases and has made significant progress in coverage criteria [25] and case generation [26, 27] recently. However, both verification and testing are post hoc analyses, and their qualitative or quantitative results do not provide comfort when properties are violated. Conversely, property-guided training methods [28, 29] focus on training DNNs that are correct-by-construction during the training phase. Moreover, much attention is being paid to training methods for developing robust DNNs.

Although pre-trained DNNs are highly effective in many applications, they can struggle to handle erroneous behaviors. This leads us to the main topic of our paper: DNN repair, which is also sometimes called DNN patching. When a DNN is found to be behaving poorly (as detected by DNN verification or testing), DNN repair or patching aims to eliminate these unexpected behaviors while minimizing the impact on performance. There are currently two main repair paradigms.

On the one hand, DNN retraining is a powerful tool for correcting erroneous outputs of DNNs and is similar to property-guided training. Retraining-based methods [30, 31] remove mistakes by evolving existing buggy DNNs, while property-guided training avoids specification violations from the beginning. The key to successful DNN retraining is balancing the need to maintain original performance while eliminating unexpected behaviors, achieved by using appropriate loss functions. However, retraining can be computationally expensive,
and original training datasets are not always publicly available. Additionally, undifferentiated parameter updates during retraining can introduce new bad behaviors.

On the other hand, unlike the global and aimless parameter modification in DNN retraining, _DNN fine-tuning_[32] devotes to repairing buggy DNNs locally, intentionally and slightly, i.e., patching a specific subset of the DNN parameters to get rid of erroneous predictions. Initially, fine-tuning based methods [33, 34] typically convert the adjustment of DNN parameters located in a DNN layer (arbitrary or well-selected) into a constraint solving problem of parameters and minimize parameter modifications then. Compared to the adjustment of parameters on a single layer, some recent work has taken fault localization into account [35, 36], which is utilized to determine a parameter subset that has a more significant impact on error behaviors, to make fine-tuning processes more intentionally. The fine-tuning methods generally outperform the retraining ones due to their slight and local modifications.

When considering either the retraining based or the fine-tuning based DNN repair methods, current attention is primarily directed towards high-level abstract interpretation or inference of state spaces of DNN layers, while neglecting behaviors of the underlying neurons. This leads to existing repair methods being computationally prohibitive and restricting the range of repaired DNNs. For instance, repairing DNNs through linear mapping regions necessitates the expensive calculation of the sets of polytope abstract domains, and non-piecewise linear activation functions are limited in the effectiveness.

To overcome these dilemmas, this paper proposes a behavior-imitation based DNN repair framework, BIRDNN (**B**ehavior-**I**mitation Based **R**epair of **DNNs**). In essence, we investigate the (hidden) states of neurons within DNNs, analyzing neurons' behavior differences between the expected behaviors on positive samples and the unexpected behaviors on negative samples. Resorting to behavior imitation, we present alternative retraining based and fine-tuning based repair methods to patch defective DNNs, and BIRDNN is the first repair framework unifying DNN retraining and DNN fine-tuning together. For the retraining based method, we assign new correct labels to negative sample inputs, imitating the outputs of nearby positive samples, and then retrain original DNNs to improve erroneous behavior. For the fine-tuning based method, fault localization identifies the most responsible neurons for unexpected predictions by analyzing behavior differences on positive and negative samples. Then we utilize particle swarm optimization (PSO) to modify those "guilty" neurons to maintain the original DNN performance while minimizing property violations. Our paper aims to tackle the more difficult domain-wise repair problems (DRPs) and to this end, we also integrate BIRDNN with a sampling based technique to character DNN behaviors over domains, repairing buggy DNNs in a probably approximated correct style.

**Contributions.** Main contributions of this paper are listed as follows.

* Based on the investigation on neuron behaviors and the insight of behavior imitation, we propose a novel DNN repair framework, BIRDNN, which supports alternative retraining style and fine-tuning style repair simultaneously for the first time, to our best knowledge.
* Within BIRDNN, DNNs imitate the expected behaviors of the closest positive samples when encountering negative inputs during retraining procedures. For the fine-tuning method, BIRDNN adopts a straightforward and efficient fault localization strategy on behavior difference analysis to identify the most responsible neurons.
* To tackle the more challenging DRPs, we integrate BIRDNN with a characterization technique of DNN domain behaviors, reducing DRPs to sample-based repair problems and repairing buggy DNNs in a probably approximated correct style.
* We have implemented a prototype tool based on BIRDNN, which is available from [https://github.com/ByteTao5/BIRDNN](https://github.com/ByteTao5/BIRDNN). The experimental results on ACAS Xu DNNs illustrate the effectiveness, efficiency and compatibility of our proposed DNN patch framework.

The remainder of this paper is organized as follows. Section II provides an introduction of necessary background. Afterward, Section III formulates the concerned and addressed domain-wise repair problems. Following this, Section IV detailedly demonstrates our behavior-imitation based DNN repair framework, BIRDNN. Next, Section V implements a prototype tool and reports its effectiveness, efficiency and compatibility on the widely-used ACAS Xu DNNs versus state-of-the-art methods. Section VI supplements some related work and comparisons. Finally, Section VII summarizes this paper and gives possible future directions.

## II Preliminaries

When training or testing DNNs, complex data flows arise and property specifications impose specific requirements on the generated data flows. In the following, we present some preliminaries related to DNNs and property specifications.

### _Deep Neural Networks_

An \(L\)-layer DNN usually contains an input layer, an output layer, and \(L-2\) successive hidden layers. A DNN specified with the parameter set \(\theta\) is denoted by \(\mathcal{N}_{\theta}:\mathbb{R}^{m}\rightarrow\mathbb{R}^{n}\), containing \(m\) and \(n\) neurons in its input and output layers, which are termed the input/output dimensions respectively. That is to say, the layer dimension \(d_{i}\) refers to the number of neurons located on the \(i\)-th DNN layer. Beginning with an input (or, sample) \(\mathbf{x}\in\mathbb{R}^{m}\) on the input layer, it comes into the _forward propagation_[37]. Between two adjacent DNN layers, a non-linear activation function follows an affine transformation, whereas only an affine transformation exists for the last two layers. The common activation functions are ReLU, tanh and Sigmoid, where the first one is piecewise linear (PWL) and the others are strictly non-linear. Generally, PWL functions are easier to tackle due the nice algebraic property. The whole forward propagation process is the composition of the operations between each two adjacent layers and it
generates the output (or, prediction) \(\mathbf{y}:=\mathcal{N}_{\theta}(\mathbf{x})\in\mathbb{R}^{n}\) with respect to the sample \(\mathbf{x}\).

There appears a data flow in DNN \(\mathcal{N}_{\theta}\) when processing the input \(\mathbf{x}\). We name the data flow as the _behavior_ of the DNN \(\mathcal{N}_{\theta}\) on the sample \(\mathbf{x}\) and it consists of the input vector, hidden states for each hidden layer and the output vector. The DNN behaviour on sample \(\mathbf{x}\) can be represented with \(\{\mathcal{N}_{\theta}^{0}(\mathbf{x})\) (i.e., \(\mathbf{x}\)), \(\mathcal{N}_{\theta}^{1}(\mathbf{x})\), \(\cdots\), \(\mathcal{N}_{\theta}^{L-1}\) (i.e., \(\mathbf{y}\) or \(\mathcal{N}_{\theta}(\mathbf{x})\))\(\}\).

### _Property Specifications_

Before the deployment in practical applications, DNNs are required to satisfy certain properties, such as robustness [12, 38], safety [13], reachability [39, 30], fairness [40] and so on, especially in safety-critical domains. Consequently, property specifications emerge as the times demand and they are widely utilized in DNN property-guided training [41] and DNN verification [42] related fields.

A property specification \(\mathcal{P}\) w.r.t. a DNN \(\mathcal{N}_{\theta}\) generally consists of two components, a _pre-condition_\(\varphi\) and a _post-condition_\(\psi\), i.e., \(\mathcal{P}:=\{\varphi;\psi\}\). The pre-condition \(\varphi\) is a constraint on the input domain \(\mathbb{R}^{m}\) and it describes a _predetermined input set_ of \(\mathcal{N}_{\theta}\). Likewise, the post-condition \(\psi\) restricts the output domain \(\mathbb{R}^{n}\), representing a _desired output region_. Then, the specification \(\mathcal{P}\) imposes a behavior requirement for \(\mathcal{N}_{\theta}\) that it should ideally map the predetermined input set into the desired output region (i.e, expected behaviors), or the DNN is buggy. Further, the relation \(\varphi\stackrel{{\mathcal{N}_{\theta}}}{{\rightarrow}}\psi\) refers that DNN \(\mathcal{N}_{\theta}\) satisfies the property specification while \(\varphi\stackrel{{\mathcal{N}_{\theta}}}{{\rightarrow}}\psi\) means the property specification does not hold on the DNN.

For a specification set \(\{\mathcal{P}_{i}\}_{i=1}^{p}\) that the DNN \(\mathcal{N}_{\theta}\) should obey, likewise, \(\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta}}}{{ \rightarrow}}\{\psi_{i}\}_{i=1}^{p}\) and \(\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta}}}{{ \rightarrow}}\{\psi_{i}\}_{i=1}^{p}\) respectively denotes the satisfiability and unsatisfiability of the specification set on DNN \(\mathcal{N}_{\theta}\) and these two relations are defined as

\[\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta}}}{{ \rightarrow}}\{\psi_{i}\}_{i=1}^{p}\Leftrightarrow\varphi_{i}\stackrel{{ \mathcal{N}_{\theta}}}{{\rightarrow}}\psi_{i},\forall i\in\{1,2,\cdots,p\},\]

and

\[\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta}}}{{ \rightarrow}}\{\psi_{i}\}_{i=1}^{p}\Leftrightarrow\varphi_{i}\stackrel{{ \mathcal{N}_{\theta}}}{{\rightarrow}}\psi_{i},\exists i\in\{1,2,\cdots,p\}.\]

That is, a specification set holds on a DNN if and only if each specification in the set holds on the DNN and it does not hold means that at least one specification in the set is violated. The behaviors meeting the relation \(\stackrel{{\mathcal{N}_{\theta}}}{{\rightarrow}}\) (resp. \(\stackrel{{\mathcal{N}_{\theta}}}{{\rightarrow}}\)) are _expected_ (resp. _unexpected_) _behaviors_. Further, the DNNs featuring unexpected behaviors are called _buggy DNNs_.

## III Problem Formulation

Based on aforementioned preliminaries, the _DNN repair problem_ comes readily and it is defined as follows.

**Problem 1**: _(DNN Repair Problem). Given a buggy DNN \(\mathcal{N}_{\theta}\) with respect to a violated specification set \(\{\mathcal{P}_{i}\}_{i=1}^{p}\), i.e., \(\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta}}}{{ \rightarrow}}\{\psi_{i}\}_{i=1}^{p}\), the DNN repair problem refers to modifying the parameter set \(\theta\) to \(\theta^{\prime}\) and the resulting DNN \(\mathcal{N}_{\theta^{\prime}}\) satisfying all the specifications, i.e., \(\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta^{\prime}}} }{{\rightarrow}}\{\psi_{i}\}_{i=1}^{p}\)._

Additionally, various DNN repair problems arise depending on the set types, such as point sets, domain sets or others, described by the pre-conditions and post-conditions. Among these, domain sets prove to be more challenging due to the infinity and non-ergodicity of samples within domains, and only several existing repair tools support to patch DNNs over domains [34]. Consequently, this paper focuses on repairing DNNs with domain-based specifications and refines Problem 1 into the following DNN repair problem.

**Problem 2**: _(Domain-wise Repair Problem, DRP). Given a buggy DNN \(\mathcal{N}_{\theta}\) and \(\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta}}}{{ \rightarrow}}\{\psi_{i}\}_{i=1}^{p}\). For each specification \(\mathcal{P}_{i}\), its pre-condition \(\varphi_{i}\) and post-conditions \(\psi_{i}\) describe domain sets. The domain-wise repair problem (DRP) refers to modifying the parameter set \(\theta\) to \(\theta^{\prime}\) and forming a new neural network \(\mathcal{N}_{\theta^{\prime}}\) satisfying all the domain-based specifications, i.e., \(\{\varphi_{i}\}_{i=1}^{p}\stackrel{{\mathcal{N}_{\theta^{\prime}}} }{{\rightarrow}}\{\psi_{i}\}_{i=1}^{p}\)._

For DRPs, input and output domains can be specified as interval boxes, polytopes, and so on. When the behaviors of a DNN violate the property specifications, the regions in the input set that cause the violation are considered _negative input domains_ (_negative domains_, for short), denoted by \(S_{nd}\). Therefore, domain-wise repair problems, patching a buggy DNN \(\mathcal{N}_{\theta}\) with respect to a given specification set \(\{\mathcal{P}_{i}\}_{i=1}^{n}\), are essentially equivalent to correcting the unexpected behaviours of \(\mathcal{N}_{\theta}\) over \(S_{nd}\) fundamentally.

Actually, a subtle modification on the DNN parameters may result in a non-negligible impact on the original performance and even introduce extra unexpected behaviors. Consequently, in addition to the requirement of correcting the defective DNNs on certain specification set, it is equally significant for DNN repair approaches to preserve the parameter set or original performance of the buggy DNNs to great extent. This requirement is referred as the _minimal patch requirement_.

**Definition 1**: _(Minimal Patch Requirement, MPR). For a DNN repair problem, the generated patch between the original DNN \(\mathcal{N}_{\theta}\) and the modified DNN \(\mathcal{N}_{\theta^{\prime}}\) should be minimized, minimizing the impact on the original performance._

To this end, some seek to minimize the deviation between \(\theta\) and \(\theta^{\prime}\), i.e., minimizing the \(\ell\)-distance \(||\theta^{\prime}-\theta||_{\ell}\)[30, 34]. Yet, some pursues minimizing the performance difference between \(\mathcal{N}_{\theta}\) and \(\mathcal{N}_{\theta^{\prime}}\)[31, 36, 43], such as minimizing the accuracy difference \(|acc(\mathcal{N}_{\theta^{\prime}})-acc(\mathcal{N}_{\theta})|\) for classification tasks. MPR is popularly adopted in DNN repair scenarios, and therefore, in what follows, we focus on tackling Problem 2 with considering MPR simultaneously.

## IV BIRDNN Repair Framework

In this section, we give detailed illustrations on the proposed BIRDNN framework, including the domain behavior description and the behavior-imitation based repair for DRPs, in retraining and fine-tuning styles respectively.

### _Overall Workflows_

The overall workflows of BIRDNN are demonstrated in Fig. 1. Beginning with a buggy DNN, its behaviors over negative domains are characterized from the aspects of positive
and negative samples. Following it, BIRDNN corrects the unexpected predictions of the negative samples towards the nearby expected behaviors during the retraining repair process. Alternatively, BIRDNN localizes the most responsible neurons by investigating their behavior differences for the fine-tuning based approach. Subsequently, a repaired DNN is returned from either the retraining based or the fine-tuning based patch.

### _Domain Behavior Description_

First of all, we start with the sample behaviors. Recall the definitions of expected behaviors and unexpected ones, and thus, the input samples w.r.t. the buggy DNN can be correspondingly categorized into _positive samples_ and _negative samples_. Similarly, we characterize the buggy DNN's behaviors within an input domain from the perspective of positive and negative samples with Monte Carlo sampling. That is, we collect respective sets of positive and negative samples from the negative domains to illustrate the expected and unexpected behaviors over the negative domains, as shown in Fig.1b.

To get rid of the infinity and non-ergodicity of samples within domains, we divide samples within negative domains into the two categories and concentrate on the behaviors of the buggy DNNs on these positive and negative samples when treating the DNN repair problems. The reasons are twofold. On the one hand, the positive and negative predictions generally depict the expected output region and the specification-violated region, depicting the decision boundary of DNNs to some extent. On the other hand, the behaviors of the buggy DNN on the positive samples provide significant guidance for correcting the erroneous behaviors of the original DNNs, i.e., _imitating the expected behaviors of the positive samples_.

A scarce case is that the negative domains absolutely violate the property specification, i.e., we cannot theoretically obtain any positive samples from the negative domains. To overcome this dilemma, we define a relaxed region, termed _domain \(\delta\)-neighbourhood_.

**Definition 2**: _(Domain \(\delta\)-neighbourhood) For an input domain \(D:=[lb_{i},ub_{i}],i\in\{1,2,\cdots,m\}\) and a constant \(\delta>0\), where \(lb_{i}\) (\(ub_{i}\)) is the lower (upper) bound of the \(i\)-th input dimension, its domain \(\delta\)-neighbourhood refers to the region \(\delta_{D}:=[lb_{i}-\delta,ub_{i}+\delta],i\in\{1,2,\cdots,m\}^{*}\)._

The determination of \(\delta\) depends on the value that allows the existence of positive samples in the associated domain \(\delta\)-neighbourhood. Additionally, it is obvious that on the premise that \(\delta\) is a enough small constant, the behaviors of DNNs on the neighborhood samples are similar to the original domain. That is the reason that we collect positive samples in the domain \(\delta\)-neighbourhood, which is the region slightly relaxed from the negative domains specified by the pre-condition.

Back to the domain behavior characterization, the sample-based characterization provides us a probably approximated correct guarantee on repairing buggy DNNs over negative domains. Assuming a sampling process where the probabilities of positive and negative samples are \(q\) and \(1-q\), furthermore, assuming a DNN repair process in which a proportion of \(u\) of negative samples are repaired while a proportion of \(v\) of positive samples disobey the properties, then under a large total sample size, the repaired DNN satisfies the properties with a probability of \(q(1-v)+(1-q)u\).

The above-mentioned \(u\) and \(v\) are termed _property improvement_ and _performance drawdown_, catering to repairing buggy DNNs and minimal patch requirement respectively. The Monte Carlo sampling based characterization technique is widely used in statistical model checking [44, 45] and there exist some bounds of the total sample number [46, 47], like Chernoff bound. The sample-based behavior characterization reduces DRPs to sample-based DNN repair problems. Consequently, the main idea of repairing a DNN \(\mathcal{N}_{\theta}\) with respect to a negative input domain set \(S_{nd}\) (Problem 2) is to correct the unexpected behaviors of negative samples on the negative domains. In what follows, we present our repair approaches to DRPs, in aspects of retraining and fine-tuning styles.

Fig. 1: Workflows of BIRDNN framework. Retraining workflows: (a)-(b)-(c)-(e); Fine-tuning workflows: (a)-(b)-(d)-(e).
### _Retraining Approach to DRP_

Overall, the retraining style patch of DRPs is composed of three procedures, that is, sampleCollect, negativeCorrect and retrainDNN, as shown in Alg.1. The positive and negative samples within the negative domains are collected in sampleCollect, together with their output behaviors, and negativeCorrect (i.e., Alg. 2), subsequently, corrects the unexpected behaviors and prepares the repairing dataset via imitating the expected behaviors of the positive samples. Finally, the procedure retrainDNN retrains the original DNN, pursuing eliminating unexpected behaviors and keeping minimal performance drawdown synergistically.

The procedure sampleCollect is shown in Line 1-7 in Alg. 1. We collect sample sets \(S_{p}\) and \(S_{n}\), composed of positive and negative samples from the negative domains extracted from the violated properties. It is notable that maybe a domain \(\delta\)-neighbourhood is needed, and the \(\delta\) value should not only be as small as possible, but ensure a required number of positive samples being sampled. In the meanwhile, we also record their output behaviors \(Y_{p}\) and \(Y_{n}\) concerning the buggy DNN for the subsequent negative behavior correction.

Alg. 2 demonstrate the procedure negativeCorrect detailedly (Line 8 in Alg. 1). Due to the characteristic of the DNN training process, i.e., the loss functions are defined on the output layer. Here, we only focus on the final part of the DNN behaviors, the predictions (i.e., \(\mathcal{N}_{\theta}(\cdot)\) or \(\mathcal{N}_{\theta}^{L-1}(\cdot)\)), and eliminate the negative behaviors via imitating their surrounding positive behaviors. For each negative prediction \(\mathbf{y}_{n}\in Y_{n}\), the top \(k\) closest positive predictions to it are selected and their mean value is assigned as the new label for the corresponding negative sample if the mean value satisfies the post-condition that \(\mathbf{y}_{n}\) violates. Or, the closest positive prediction is chosen as the candidate label for the following DNN retaining. Obviously, the presented label assignment ensures the correctness of the newly assigned label for each negative input sample. With the calibrated labels, the repairing dataset \(\mathcal{D}_{re}\) is done in Line 9 in Alg. 1. This statement is visualized in Fig. 0(c).

When comes to the final procedure retrainNN with training dataset \(\mathcal{D}\) and repairing dataset \(\mathcal{D}_{re}\), Line 11-13 of Alg. 1, it is of vital importance to clarify the formulation of _loss function_ utilized for the retraining process.

#### Iii-C1 Loss formulation for DRPs

The repairing dataset \(\mathcal{D}_{re}:=\{\mathbf{x}_{re}^{i},\mathbf{l}_{re}^{i}\}_{i=1}^{\#\mathcal{D}_{re}}\) is constructed to eliminate the unexpected behaviors on the negative domain set \(S_{nd}\). The retraining process aims to minimize the discrepancy between the \(\mathcal{N}_{\theta}\)'s predictions and the corrected labels, which is formulated in Eqn. (1)

\[\mathcal{L}_{\text{DRP}}(\theta^{\prime}):=\sum_{i=1}^{\#\mathcal{D}_{re}}|| \mathcal{N}_{\theta^{\prime}}(\mathbf{x}_{re}^{i})-\mathbf{l}_{re}^{i}||_{\ell}, \tag{1}\]

where \(||\cdot||_{\ell}\) is the \(\ell\)-norm distance. It can be seen that the unexpected behaviors on the negative samples are thoroughly eliminated under the condition that the loss function defined in Eqn. (1) is minimized to 0 during the retraining process, which is called provable DNN repair [34].

#### Iii-C2 Loss formulation for MPR

Different from traditional DNN training, MPR requires the modified DNN \(\mathcal{N}_{\theta^{\prime}}\) to preserve the original performance of \(\mathcal{N}_{\theta}\). Consequently, we also take the original input-output dataset \(\mathcal{D}:=\{(\mathbf{x}^{i},\mathbf{l}^{i})\}_{i=1}^{\#\mathcal{D}}\) into account and pursue the minimal performance drawdown by loss function \(\mathcal{L}_{\text{MPR}}(\theta^{\prime})\), which is shown in Eqn.(2).

\[\mathcal{L}_{\text{MPR}}(\theta^{\prime}):=\sum_{i=1}^{\#\mathcal{D}}|| \mathcal{N}_{\theta^{\prime}}(\mathbf{x}^{i})-\mathbf{l}^{i}||_{\ell} \tag{2}\]

Therefore, for procedure retrainDNN, dealing DRPs with MPR is a multi-objectives optimization and the final loss function can be formulated as

\[\underset{\theta^{\prime}}{\text{minimize}}(\alpha\cdot\mathcal{L}_{\text{ DRP}}(\theta^{\prime})+\beta\cdot\mathcal{L}_{\text{MPR}}(\theta^{\prime})) \tag{3}\]

where \(\alpha,\ \beta\in[0,1]\), \(\alpha+\beta=1\) and \(\theta^{\prime}\) is initialized as \(\theta\). The retraining process patches the original DNN \(\mathcal{N}_{\theta}\) without considering MPR when the configuration is \(\alpha=1,\ \beta=0\) and it only focuses on minimal parameter change with the
configuration \(\alpha=0,\ \beta=1\). The procedure retrainDNN terminates if the negative samples meet the specifications or the maximum iteration number is reached, and a repaired DNN \(\mathcal{N}_{\theta^{\prime}}\) is returned in Line 13 of Alg. 1, as shown in Fig. (e)e.

### _Fine-tuning Approach to DRPs._

Except for the retraining based repair for DRPs, BIRDNN also provides an approach of fine-tuning style patch for DRPs. The algorithm is demonstrated in Alg. 3. Likewise, the algorithm can be divided into three procedures, i.e., sampleCollect, behaveAnalyze and fineTuneDNN. After collecting the sets of positive and negative samples in procedure sampleCollect (Line 1-4), procedure behaveAnalyze (Line 6) completes the fault localization by analysing the discrepancies between the behaviors on the negative samples (unexpected behaviors) and those on the positive samples (expected behaviors). Then, fineTuneDNN (Line 9-13) tunes the weights of most responsible neurons for the unexpected behaviors with optimization methods.

Compared with only focusing on the final predictions in Section IV-C, BIRDNN makes a more insightful investigation on neuron behaviors in procedure behaveAnalyze, which is illustrated in Alg. 4. Recall the definition of behaviors, the behaviors of DNN \(\mathcal{N}_{\theta}\) on a negative input sample \(\mathbf{x}_{n}\) and the positive sample set \(S_{p}\) are respectively denoted by

\[\{\mathbf{x}_{n},\mathcal{N}_{\theta}^{1}(\mathbf{x}_{n}),\mathcal{N}_{\theta}^{2}( \mathbf{x}_{n}),\cdots,\mathcal{N}_{\theta}^{L-1}(\mathbf{x}_{n})\}\]

and

\[\{\mathbf{x}_{p}^{j},\mathcal{N}_{\theta}^{1}(\mathbf{x}_{p}^{j}),\mathcal{N}_{\theta }^{2}(\mathbf{x}_{p}^{j}),\cdots,\mathcal{N}_{\theta}^{L-1}(\mathbf{x}_{p}^{j})\}_{j=1 }^{\#S_{p}}.\]

Subsequently, the _layer responsibility_\(\mathbf{r}^{i}\) of the neurons on the \(i\)-th layer for the unexpected behaviors are defined as follows,

\[\mathbf{r}^{i}:=\sum_{j=1}^{\#S_{p}}|\mathcal{N}_{\theta}^{i}(\mathbf{x}_{n})-\mathcal{ N}_{\theta}^{i}(\mathbf{x}_{p}^{j})|,\ i\in\{1,2,\cdots,L-1\}. \tag{4}\]

Further, the _neuron responsibility_\(\mathbf{r}^{ij}\ (0\leq j<d_{i})\) indicates to what extent, the \(j\)-th neuron on the \(i\)-th layer is responsible for the unexpected behaviors, and we name \(\mathbf{R}:=\{\mathbf{r}^{i}\}_{i=1}^{L-1}\) the _responsibility matrix_. Essentially, the main idea of fault localization is also behavior imitation. The responsibility matrix reveals the behavior difference of each neuron over negative and positive samples and the larger a neuron's behavior difference, the more necessary for it to imitate expected behaviors to minimize the discrepancy. Since there is no need to change the input layer when repairing a buggy DNN, and thus it is unnecessary to define the responsibility metric for the input neurons1. Likewise, these statements are visualized in Fig. (d)d.

Footnote 1: Actually, the defined responsibility metric also works for the input neurons.

In addition, we also modify Eqn. (4) to Eqn. (5) to break out the two loop in Alg. 4 (Line 3-5), improving the efficiency of the fault localization further.

\[\mathbf{r}^{i}:=|\sum_{t=1}^{\#S_{n}}\mathcal{N}_{\theta}^{i}(\mathbf{x}_{n})-\sum_{j =1}^{\#S_{p}}\mathcal{N}_{\theta}^{i}(\mathbf{x}_{p}^{j})|,\ i\in\{1,\cdots,L-1\}. \tag{5}\]

After the computation of the responsibility matrix, procedure fineTuneDNN (Line 9-13 in Alg. 3) sorts the responsibility matrix and selects the most responsible (largest) \(r\) neurons, whose weights are to be optimized subsequently. As for the optimization method, we choose Particle Swarm Optimization (PSO) [48] for its convergence speed and accuracy in continuous optimization, and other algorithms are also alternative, like Differential Evolution (DE) [49], Markov Chain Monte Carlo (MCMC) [50] and Pelican Optimization Algorithm [51].

```
1:a buggy DNN \(\mathcal{N}_{\theta}\), positive sample set \(S_{p}\), negative sample set \(S_{n}\), initialized responsibility matrix \(\mathbf{R}\).
2:computed responsibility matrix \(\mathbf{R}\).
3:procedure behaveAnalyze(\(\mathcal{N}_{\theta},S_{p},S_{n},\mathbf{R}\))
4:for\(i\gets 1\)to\(L-1\)do
5:for each\(\mathbf{x}_{n}\) in\(S_{n}\)do
6:for each\(\mathbf{x}_{p}\) in\(S_{p}\)do
7:\(\mathbf{R}^{i}\leftarrow\mathbf{R}^{i}+|\mathcal{N}_{\theta}^{i}(\mathbf{x}_{n})-\mathcal{ N}_{\theta}^{i}(\mathbf{x}_{p})|\)
8:return\(\mathbf{R}\)
```

**Algorithm 4** Fault Localization of Responsible Neurons

Considering multiple particles in the search space, \(\vec{x_{i}}\) and \(\vec{v_{i}}\) stand for the location and velocity of each particle. During each search iteration, PSO updates \(\vec{x_{i}}\) and \(\vec{v_{i}}\) according to a fitness function. The evolution rule update \(\vec{v_{i}}\) based on current velocity \(\vec{v_{i}}\), the best local location previous found \(\vec{p_{i}}\) and the best global location previous found \(\vec{p_{g}}\) and it update \(\vec{x_{i}}\) with current velocity \(\vec{v_{i}}\) and location \(\vec{x_{i}}\) then. The PSO update equation is formulated as follows [52].

\[\begin{split}\vec{v_{i}}&\leftarrow\omega\vec{v_{i}} +R(0,c_{1})(\vec{p_{i}}-\vec{x_{i}})+R(0,c_{2})(\vec{p_{g}}-\vec{x_{i}}),\\ \vec{x_{i}}&\leftarrow\vec{v_{i}}+\vec{v_{i}},\end{split} \tag{6}\]

where \(\omega,\ c_{1},\ c_{2}\) respectively represent the inertia weight, cognitive parameter and social parameter. \(R(0,c)\) refers to a random value sampled from \([0,c]\). More importantly, the fitness function in PSO determines the best location.
Come back to Line 12 of procedure fineTuneDNN, the weights of the most responsible \(r\) neurons are the "particles" for PSO and their locations are initialized as the original value in \(\theta\), their velocities are set as zeros. The fitness function \(\mathcal{F}\) for parameter optimization is defined following.

\[\mathcal{F}:=\alpha\cdot\text{unexpBeh}+\beta\cdot\text{drawDown} \tag{7}\]

where \(\alpha,\ \beta\in[0,1]\) and \(\alpha+\beta=1\). _unexpBeh_ (unexpected behaviors) indicates the percentage of the negative samples violating the specifications and _drawdown_ is the DNN performance loss, such as the dropout of classification accuracy. The construction of Eqn. (7) means the PSO attempts to minimize both the unexpected behaviors and the performance drawdown. Moreover, the algorithm terminates if there generates an intolerable performance degeneration between the original and modified DNNs, corresponding to MPR, or the maximum search number is reached and returns the repaired DNN \(\mathcal{N}_{\theta}\). in Line 13 of Alg. 3, as shown in Fig. 0(e).

## V Experiments

### _Experiment Setup_

In this section, the proposed BIRDNN framework is evaluated and compared with some state-of-the-art DNN repair works on the ACAS Xu DNN repair problem, in aspects of retraining and fine-tuning styles, which are respectively termed _BIRDNN-RT_ and _BIRDNN-FT_ hereafter.

#### V-A1 ACAS Xu DNN repair problem

The ACAS Xu DNN repair problem, patching ACAS Xu DNNs [53] with respect to certain safety properties, is a widely utilized and evaluated DNN domain-wise repair problem. ACAS Xu DNNs contains an array of 45 DNNs (organized as a \(5\times 9\) array) that produce horizontal maneuver advisories of the unmanned version of Airborne Collision Avoidance System X, which is a highly safety-critical system developed by the Federal Aviation Administration. More concretely, these DNNs take a five-dimensional input, representing the scenario around the aircraft, and output a five-dimensional prediction, indicating five possible advisories. The ACAS Xu DNNs are associated with 10 safety properties, \(\phi_{1}\)-\(\phi_{10}\), and their pre-/post-conditions are described as polytope sets, satisfying the definition of DRPs. These safety properties require that the output corresponding to an input within a specific input region must fall in the given safe polytope(s). Some verification works [54, 18] discovery that among these 45 DNNs, there are 35 DNNs violate at least one safety property, e.g., \(N_{2,9}\) violates the safety property \(\phi_{8}\).

We follow the ACAS Xu DNN evaluation cases adopted in previous work Veritex [55], CARE [36] and PRDNN [34]. Herein, as classified in Veritex, we select one simple test case \(N_{3,3}\), and two hard test cases, \(N_{1,9}\) and \(N_{2,9}\) to evaluate the BIRDNN framework. The detailed information of these used DNNs is displayed in Table I (_DNN\({}_{1}\)_, _DNN\({}_{2}\)_ and _DNN\({}_{3}\)_).

#### V-A2 Evaluation platform

All the experiments are conducted on a machine with 12th Gen Intel(R) Core(TM) i9-12900H 2.50 GHz and 16 GB system memory. The codes to reproduce our experimental results are available at [https://github.com/ByteTao5/BIRDNN](https://github.com/ByteTao5/BIRDNN).

#### V-A3 Research questions

We report experimental results to answer the following research questions, demonstrating BIRDNN's effectiveness, efficiency and compatibility:

* _RQ1: Can BIRDNN-RT repair the buggy DNNs successfully? How about its efficiency compared to other retraining based methods?_
* _RQ2: Can BIRDNN-FT repair the buggy DNNs successfully? How about its efficiency compared to other finetuning based methods?_
* _RQ3: What about the compatibility of BIRDNN on DNNs with different activation functions?_

### _Evaluations on BIRDNN-RT_

The retraining performance of BIRDNN-RT on ACAS Xu DNNs is compared with Veritex, a provable retraining repair method. Notably, the original training data of ACAS Xu DNNs are not publicly available online. To make fair comparisons, we follow the experiment settings adopted in Veritex, and we uniformly sample a set of 10K training data and 5K test data from the input space. Veritex does not distinguish the positive and negative samples in the training data explicitly in advance, and the violated safety properties are improved by minimizing the distance between the unsafe output region (exact polytope regions by reachability analysis) and the safety region. In contrast, BIRDNN requires reassigning the negative samples of the training data with the predictions of the nearest positive samples, and we respectively set the proportions of the negative samples and positive samples as 10% and 90% in what follows. Additionally, the weights balancing the original performance and safety improvement are set as \(\alpha=\beta=0.5\). We also introduce an early stop mechanism that the retraining process terminates when the safety improvement keeps stable within 10 successive epochs. The early stop also ensures minimal patch requirement to some extent.

\begin{table}
\begin{tabular}{c c c c c} \hline \hline DNN & \multicolumn{2}{c}{Veritex} & BIRDNN-RT \\ \cline{2-5}  & Accuracy & Time & Accuracy & Time \\ \hline _DNN\({}_{1}\)_ & 100\% & 4.96 & 100\% & **1.3** \\ _DNN\({}_{2}\)_ & 100\% & Timeout* (11250.7) & 100\% & **174.70** \\ _DNN\({}_{3}\)_ & 100\% & 2167.16 & 100\% & **87.45** \\ \hline _literature reported result\({}^{\dagger}\)_: & & & & \\ \hline Time & Accuracy & _DNN\({}_{3}\)_ & _DNN\({}_{4}\)_ & \\ \hline ART & 89.08\% \(\sim\) 98.06\% & 67.5 & 72.6 \\ ART-refinement & 88.82\% \(\sim\) 95.85\% & 82.5 & 88.4 \\ \hline \hline \end{tabular}

* The running time limit is set as 3 hours. Here we provide the running time reported in Veritex [55] in the parentheses.

\(\dagger\) The listed results are recorded in Veritex [55].

\end{table} TABLE I: DNN models used in Experiments.

\begin{table}
\begin{tabular}{c c c c c} \hline \hline DNN & Description & Architecture & \#Param \\ \hline _DNN\({}_{1}\)_ & ACAS Xu, \(N_{3,3}\) & 7-layer Relu FFNN & 13,350 \\ _DNN\({}_{2}\)_ & ACAS Xu, \(N_{1,9}\) & 7-layer Relu FFNN & 13,350 \\ _DNN\({}_{3}\)_ & ACAS Xu, \(N_{2,9}\) & 7-layer Relu FFNN & 13,350 \\ _DNN\({}_{4}\)_ & Modified ACAS Xu, \(N_{1,9}\) & 7-layer Tanh FFNN & 13,350 \\ _DNN\({}_{5}\)_ & Modified ACAS Xu, \(N_{1,9}\) & 7-layer LeakyReLU FFNN & 13,350 \\ _DNN\({}_{6}\)_ & Modified ACAS Xu, \(N_{1,9}\) & 7-layer ELU FFNN & 13,350 \\ \hline \hline \end{tabular}
\end{table} TABLE I: DNN models used in Experiments.
_Repair performance._ The performance of BIRDNN-RT on ACAS Xu DNNs is displayed in Table II, versus the state-of-the-art work, Veritex, in terms of the _Accuracy_ on the test data and the _Running Time_. Because the test set contains both positive and negative samples, the _Accuracy_ indicator combines safety improvement and performance drawdown, and when the accuracy indicator reaches 100%, it means complete repair and no performance loss. Moreover, we also list the performance of ART [56], a DNN property-guided training method, for a more comprehensive reference. It can be observed that both Veritex and BIRDNN-RT repair these buggy DNNs successfully, i.e., with an accuracy of 100% in the test data. As for the running time, Veritex takes a large amount of running time, dominantly by the computation of exact output regions, while BIRDNN-RT significantly reduces the time consumption occupied by Veritex, ranging from 73.8% (\(DNN_{1}\)), 95.96% (\(DNN_{3}\)) to 98.45% (\(DNN_{2}\)). Meanwhile, compared with ART (or ART-refinement) method, which starts from scratch to train safe ACAS Xu DNNs, BIRDNN-RT takes a little more time, while reaching higher accuracy.

_Answer RQ1: BIRDNN-RT can successfully repair the buggy DNNs, almost without no performance loss, and it provides much more efficient solutions to DRPs, compared with state-of-the-art works._

### _Evaluations on BIRDNN-FT_

As for patching ACAS Xu DNNs with fine-tuning based method, in this subsection, we mainly evaluate the performance of BIRDNN-FT from the aspects of _cross-layer repair_ and _layer-wise repair_. The former allows us to localize responsible neurons from multiple layers, while the latter restricts the neurons to be tuned must locate on the same layer. We compare BIRDNN-FT with the state-of-the-art tools, CARE and PRDNN, respectively corresponding to the cross-layer repair and layer-wise repair.

#### Iv-C1 Cross-layer Repair Performance

Likewise, we utilize the same setups utilized by CARE herein. For each DNN, a set of 10K negative data are randomly sampled to improve the safety property, and another set of 10K positive samples are randomly collected to evaluate the drawdown of the original performance. Another two sets of the same settings are collected for the testing. We set the number of the neurons to be repaired as 10. During the running of the PSO algorithm, as generally recommended in [57], the parameters are set as \(\omega=0.8,c_{1}=c_{2}=0.41\), and the particle number and the maximum iteration number are 20 and 100, respectively. Moreover, to reduce the searching time, the search terminates if it fails to find a better optimization location in 10 consecutive iterations. The weight configuration of balancing performance drawdown and safety improvement is \(\alpha=0.6,\beta=0.4\).

_Repair Performance._ The performance on the test data of BIRDNN-FT and CARE are compared in Table III, in aspects of _Improvement_, _Drawdown_, _Localization Time_ (_Loc Time_), and _Total Time_. Improvement and Drawdown indicate the repair performance on safety correction and accuracy maintenance, respectively. Localization Time and Total Time are the running time consumed by the fault localization and the whole patching procedures.

From Table III, it can be seen that BIRDNN-FT repairs all the buggy DNNs successfully without performance drawdown, which is a little better than CARE. CARE provides almost complete repair on these DNNs and its patch also loses no original accuracy. As for the running time, our proposed BIRDNN-FT greatly reduces the time consumption, both the localization time and total time. The behavior-imitation based fault localization of BIRDNN-FT is much more efficient than the causality-based one of CARE, significantly reducing about 99.8% computation time. According to the final repair performance versus CARE, however, the proposed lightweight fault localization does not mean the scarification of safety improvement or original performance. Due to the same optimization algorithm (PSO), by contrast, BIRDNN-FT finds a more appropriate set of responsible neurons resorting to behavior analysis, and it reduces the following search time in the PSO algorithm further, which only takes about 4%\(\sim\)8% of the total time taken by CARE.

#### Iv-C2 Layer-wise Repair Performance

When we consider the responsibility matrix row by row, it provides us an indication of which neurons located on a certain layer are necessary to repairing, i.e., we select responsible neurons only in a given layer for repair, named _layer-wise DNN repair_. PRDNN is one of the most representative layer-wise repair works. It is a provable fine-tuning repair method based on the DNN verification techniques with the polytope domain, and it repairs a specific layer of the buggy DNNs without fault localization. The layer-wise repair performance of BIRDNN-FT and PRDNN on \(DNN_{3}\) are displayed in Table IV. It can be observed that PRDNN only succeeds in repairing the buggy DNN on the output layer and fails on other layers. It results from the program hangs caused by dimensionality curse encountered in the computation of exact linear regions. By contrast, BIRDNN-FT works successfully for every layer and can reach almost complete repair (except \(L_{4}\)) without performance drawdown. Likewise, as for the running time, BIRDNN-FT is more efficient than PRDNN.

Moreover, we list the average improvement (_Ave_Improve_) and average drawdown (_Ave_Drawdown_) of BIRDNN-FT, CARE and PRDNN in Table V on the three DNNs. In

\begin{table}
\begin{tabular}{c c c c c} \hline Method & Item & \(DNN_{1}\) & \(DNN_{2}\) & \(DNN_{3}\) \\ \hline \multirow{4}{*}{CARE} & Improvement & 1.0 & 0.9999 & 0.9935 \\  & Drawdown & 0.0 & 0.0 & 0.0 \\  & Loc Time & 35.96 & 41.33 & 36.24 \\  & Total Time & 201.32 & 370.40 & 197.55 \\ \hline \multirow{4}{*}{BIRDNN-FT} & Improvement & 1.0 & **1.0** & **1.0** \\  & Drawdown & 0.0 & 0.0 & 0.0 \\ \cline{1-1}  & Loc Time & **0.067** & **0.071** & **0.08** \\ \cline{1-1}  & Total Time & **16.80** & **16.74** & **15.95** \\ \hline \end{tabular}
\end{table} TABLE III: Performance Comparisons of BIRDNN-FT and CARE.
particular, PRDNN fails to repair \(\textit{DNN}_{2}\) due to program hangs and the average results are evaluated on repairing \(\textit{DNN}_{1}\) and \(\textit{DNN}_{3}\). As demonstrated in Table V, BIRDNN-FT outperforms the previous methods, CARE and PRDNN, repairing the buggy DNNs completely and with no performance drawdown.

#### V-C3 Hyperparameter Comparisons

Additionally, we make some comparisons on the performance of different hyperparameter selections. We change the balancing weight \(\alpha\) (then \(\beta=1-\alpha\)) to evaluate the cross-layer repair performance of BIRDNN-FT on \(\textit{DNN}_{2}\) and set different repaired neuron numbers for the layer-wise repair on \(\textit{DNN}_{3}\).

The results are shown in Fig. 2. According to Fig. 1(a), the weight \(\alpha\) balancing the performance drawdown and safety improvement only imposes a slight effect on the final results, which coincides with the conclusions reported in CARE. As for the comparisons among different repaired neuron numbers in Fig. 1(b), five neurons are enough for every layer and the cases of one and three neurons fail to repair the buggy DNN on some layers, especially on the fourth and the final layers.

### _Activation Compatibility of BIRDNN_

In this subsection, we make some modifications on the original ACAS Xu DNN \(\textit{DNN}_{2}\) to illustrate the compatibility of BIRDNN. That is, we replace the original PWL activation function ReLU with other different activation functions, Tanh, LeakyReLU and ELU, whose definitions and the coefficient values adopted are displayed in Table VI. Among these Tanh and ELU are non-PWL functions, which means that Veritex and PRDNN cannot tackle them. We term these modified DNNs as \(\textit{DNN}_{4}\), \(\textit{DNN}_{5}\) and \(\textit{DNN}_{6}\), as shown in Table I.

Experiment settings follow the ones utilized in Section V-C and the repair performance of BIRDNN-FT on these DNNs is illustrated in Fig. 3, in terms of safety improvement, performance drawdown and running time. Overall, BIRDNN-FT repairs all the buggy DNNs almost perfectly with little performance drawdown, and the running time is relatively stable. The experimental results demonstrate that BIRDNN possesses excellent compatibility with different activation functions, which is not available for Veritex and PRDNN.

\begin{table}
\begin{tabular}{c c c c} \hline \hline  & CARE & PRDNN & BIRDNN-FT \\ \hline Ave\_Improve & 99.6\% & 97.4\% & **100\%** \\ Ave\_Drawdown & 0.15\% & 0.01\% & **0\%** \\ \hline \hline \end{tabular}
\end{table} TABLE V: Average Performance of BIRDNN-FT, CARE and PRDNN.

\begin{table}
\begin{tabular}{c c c} \hline \hline  & Definition & Coefficient \\ \hline ReLU & \(\max\)\(\begin{bmatrix}x,0\\ \end{bmatrix}\) & \(-\) \\ Tanh & \(\begin{bmatrix}x^{\prime}-e^{-x}\\ e^{\prime}+e^{-x}\\ x,\ x>0\\ (\alpha x,\ x\leq 0\\ \end{bmatrix}\) & \(-\) \\ ELU & \(\begin{bmatrix}x,&x>0\\ \alpha(e^{x}-1),&x<0\\ \end{bmatrix}\) & \(\alpha=0.5\) \\ \hline \hline \end{tabular}
\end{table} TABLE VI: Definitions of Different Activation Functions

\begin{table}
\begin{tabular}{c c c c} \hline \hline  & \multicolumn{2}{c}{PRDNN} & \multicolumn{2}{c}{BIRDNN-FT} \\ \hline  & ImproveAcc & Time & ImprovAcc & Time \\ \hline \(L_{1}\) & \(-^{*}\) & \(-\) & **100\%/100\%** & **17.83** \\ \(L_{2}\) & \(-\) & \(-\) & **100\%/100\%** & **17.30** \\ \(L_{3}\) & \(-\) & \(-\) & **100\%/100\%** & **17.19** \\ \(L_{4}\) & \(-\) & \(-\) & **99.96\%/100\%** & **17.08** \\ \(L_{5}\) & \(-\) & \(-\) & **100\%/100\%** & **17.80** \\ \(L_{6}\) & 100\%/100\% & 20.50 & 100\%/100\% & **19.57** \\ \hline \hline \end{tabular}

* PRDNN fails to repair the layers except for the final (output) layer.

\end{table} TABLE IV: Layer-wise Repair Performance Comparisons of BIRDNN-FT and PRDNN.

\begin{table}
\begin{tabular}{c c c} \hline \hline  & Definition & Coefficient \\ \hline ReLU & \(\max\)\(\begin{bmatrix}x,0\\ \end{bmatrix}\) & \(-\) \\ Tanh & \(\begin{bmatrix}x^{\prime}-e^{-x}\\ e^{\prime}+e^{-x}\\ x,\ x>0\\ (\alpha x,\ x\leq 0\\ \end{bmatrix}\) & \(-\) \\ ELU & \(\begin{bmatrix}x,&x>0\\ \alpha(e^{x}-1),&x<0\\ \end{bmatrix}\) & \(\alpha=0.5\) \\ \hline \hline \end{tabular}
\end{table} TABLE VI: Definitions of Different Activation Functions

Fig. 2: Performance on different hyperparameters.
### _Threats to Validity_

The primary threat is that BIRDNN is essentially a probably approximated correct repair framework. It provides a probabilistic guarantee for DRPs, and this guarantee's confidence is directly related to the sample size.

Another possible threat is the overfitting risk resulting from sample based repair, which widely exists in previous methods. Therefore, different and large-size training/repairing data and test data are adopted to avoid overfitting and evaluate the repaired DNNs' generalization, and we follow their setups.

## VI Related Work

DNN repair has received significant attention in recent decades, and dozens of works on DNN repair have witnessed remarkable advances. In what follows, we introduce the related work from three categories: retraining, fine-tuning without fault localization, and fine-tuning with fault localization.

**Retraining.** Veritex [55] is one of the most relevant works to our research and it presents an approach to repairing unsafe ReLU DNNs via reachability analysis. To patch DNNs against the violated safety properties, the retraining process of Veritex utilizes a loss function to constrain the distance between the exact unsafe output region and the safe domain. Additionally, an extra loss term is combined to minimize the DNN patch and avoid introducing new unexpected behaviors synergistically. In contrast, we assign negative samples with expected labels via behavior imitation, which is more lightweight. Before that, [58] addresses DNN repair problems by introducing a gradient-based and model-agnostic editable training strategy, named editable neural networks (ENNs).

**Fine-tuning without fault localization.** Resorting to DNN verification techniques, [33] utilizes the recent advances to patch a faulty DNN to satisfy specific requirements in a provable minimal manner. Additionally, [59] presents a method to repair feed-forward deep neural networks via reducing the predicate satisfaction formulated from the patch problem into a mixed integer quadratic program (MIQP) to calibrate the weights of a single layer. Furthermore, PRDNN [34], another related work to ours, introduces a novel and equivalent representation of the buggy ReLU DNNs, Decouple DNNs (DDNNs), reducing the DNN repair problem to a linear programming (LP) problem. However, the repair process works aimlessly and modifies the parameters of an arbitrary DNN layer, without fault localization preprocessing. Also, due to the expensive complexity of computing linear polytope regions of DNNs, the dimension of the repaired polytopes is limited, and generally, only one- or two-dimension is feasible. Besides, converting the resultant DDNNs back into standard and equivalent DNNs is largely an open problem.

**Fine-tuning with fault localization.** Closely resembling finding out the erroneous codes in software engineering, fault localization identifies the suspicious (responsible) neuron set responsible for the unexpected DNN behaviors. DeepFault [61] is the first proposed work on fault localization of DNNs, which analyzes pre-trained DNNs against a test set to establish the hit spectrum corresponding to each neuron, and then the suspicious neurons are identified by employing a designed suspiciousness measure. Whereas, instead of DNN repair, this fault localization technique is then utilized to synthesize adversarial inputs. Subsequently, NNrepair [35] explores the activation patterns [62] for the identification of potentially faulty neurons and the repair constraints w.r.t. DNN parameters are solved via concolic execution [63]. Further, Arachen [60] localizes the neural weights which have more impact on negative samples and less impact on positive samples via bidirectional localization, inspired by the fault localization of software engineering. In the following, the selected neuron weights are modified with the differential evolution algorithm. Then it comes to another related work to this paper, CARE [36], which follows the same patch paradigm as Arachen, while, it performs a causality-based fault localization for identifying the responsible neurons and its parameter optimization strategy adopts the particle swarm optimization (PSO)

Fig. 3: Repair performance of BIRDNN on buggy DNNs with different activation functions.

\begin{table}
\begin{tabular}{c|c|c|c|c|c|c|c|c}  & ENN [58] & Vetitex [55] & MMDNN [33] & LRNN [59] & PRDNN [34] & NNrepair [35] & Arachen [60] & CARE [36] & **BIRDNN (Ours)** \\ \hline Retraining & ✓ & ✓ & & & & & & & ✓ \\ \hline Fine-tuning & & & ✓ & ✓ & ✓ & ✓ & ✓ & ✓ \\ \hline Fault Localization & & & & & ✓ & ✓ & ✓ & ✓ \\ \hline Provable Repair\({}^{\star}\) & & \(\triangle\) & & & ✓ & & & \(\triangle\) \\ \hline Acturation Compatibility & ✓ & & & & & ✓ & ✓ & ✓ \\ \hline DRPs\({}^{\dagger}\) & & ✓ & & ✓ & ✓ & & ✓ & ✓ \\ \hline \end{tabular}

* Veritex and BIRDNN (retraining) are provable repair on condition that the loss function value reaches 0 and we mark them with \(\triangle\), instead of ✓.

\(\dagger\) The repair scenarios tackled by each work are identified from the shown evaluation tests, and some may work for the untested cases with modifications.

\end{table} TABLE VII: Comparisons among related work and our proposed repair framework.
algorithm. Nevertheless, the fault localization strategy is less efficient due to the computation of the causality operators.

In summary, the comprehensive comparisons among these related work and BIRDNN are demonstrated in Table VII.

## VII Conclusion

This paper makes a unique insight on the behavior differences of DNN neurons and proposes a DNN repair framework BIRDNN based on behavior imitation, which supports alternative retraining based and fine-tuning based DNN patching for the first time. Besides, BIRDNN tackles domain-wise repair problems in a probably approximated correct style by characterizing DNN behaviors over domains. Experiments on the ACAS Xu DNNs illustrate BIRDNN's effectiveness, efficiency and compatibility. Despite the outstanding performance, improving BIRDNN further to be a provable DNN repair framework is an appealing and challenging future work. A deeper investigation into the behavior differences of DNNs may provide specific directions to modify the neurons (adding or subtracting some values). Additionally, utilizing the proposed fault localization strategy to synthesize adversarial samples is another possible future work.
