Inverting Deep Generative models, One layer at a time
Qi Lei, Ajil Jalal, Inderjit S. Dhillon, Alexandros G. Dimakis
Introduction
Modern deep generative models are demonstrating excellent performance as signal priors, frequently outperforming the previous state of the art for various inverse problems including denoising, inpainting, reconstruction from Gaussian projections and phase retrieval (see e.g. and references therein). Consequently, there is substantial work on improving compressed sensing with generative adversarial network (GANs) . Similar ideas have been recently applied also for sparse PCA with a generative prior .
since several recent works leverage inversion as a key step in solving more general inverse problems, see e.g. . Specifically, Shah et al. provide theoretical guarantees on obtaining the optimal solution for (2) with projected gradient descent, provided one could solve (1) exactly. This work provides a provable algorithm to perform this projection step under some assumptions.
Our Contributions: For the realizable case we show that for a single layer solving (1) is equivalent to solving a linear program. For networks more than one layer, however, we show it is NP-hard to simply determine whether exact recovery exists. For a two-layer network we show that the pre-image in the latent space can be a non-convex set.
For realizable inputs and arbitrary depth we show that inversion is possible in polynomial time if the network layers have sufficient expansion and the weights are randomly selected. A similar result was established very recently for gradient descent . We instead propose inversion by layer-wise Gaussian elimination. Our result holds even if each layer is expanding by a constant factor while requires a logarithmic multiplicative expansion in each layer.
For noisy inputs and arbitrary depth we propose two algorithms that rely on iteratively solving linear programs to reconstruct each layer. We establish provable error bounds on the reconstruction error when the weights are random and have constant expansion. We also show empirically that our method matches and sometimes outperforms gradient descent for inversion, especially when the latent dimension becomes larger.
Setup
We use bold lower-case symbols for vectors, e.g. , and for its coordinates. We use upper-case symbols for denote matrices, e.g. , where is its -th row vector. For a indexed set , represents the submatrix of consisting of each -th row of for any .
The central challenge is to determine the signs for the intermediate variables of the hidden layers. We refer to these sign patterns as "ReLU configurations" throughout the paper, indicating which neurons are ‘on’ and which are ‘off’.
Invertibility for ReLU Realizable Networks
In this section we study the realizable case, i.e., when we are given an observation vector for which there exists such that . In particular, we show that the problem is NP-hard for ReLU activations in general, but could be solved in polynomial time with some mild assumptions with high probability. We present our theoretical findings first and all proofs of the paper are presented later in the Appendix.
We start with the simplest one-layer case to find if for any -norm. Since the problem is non-convex, further assumptions of are required for gradient descent to work. When the problem is realizable, however, to find feasible such that , one could invert the function by solving a linear programming:
Its solution set is convex and forms a polytope, but possibly includes uncountable feasible points. Therefore, it becomes unclear how to continue the process of layer-wise inversion unless further assumptions are made. To demonstrate the challenges to generalize the result to deeper nets, we show that the solution set becomes non-convex, and to determine whether there exists any solution is NP-complete.
2 Challenges to Invert a Two or More Layered ReLU Network
As a warm-up, we first present the NP-hardness to recover a binary latent code for a two layer network, and then generalize it to the real-valued case.
We defer the proof to the Appendix, which is constructive and shows the 3SAT problem is reducible to the above two-layer binary code recovery problem. Meanwhile, when the ReLU configuration for each layer is given, the recovery problem becomes to solve a simple linear system. Therefore the problem lies in NP, and together we have NP-completeness. With similar procedure, we could also construct a 4-layer network with real input and prove the following statement:
The conclusion holds naturally for generative models with deeper architecture.
Meanwhile, although the preimage for a single layer is a polytope thus convex, it doesn’t continue to hold for more than one layers, see Example 1. Fortunately, we present next that some moderate conditions guarantee a polynomial time solution with high probability.
3 Inverting Expansive Random Network in Polynomial Time
In the previous section, we indicate that the per layer inversion can be achieved through linear programming (4). With Assumption 1 we will be able to prove that the solution is unique with high probability, and thus Theorem 3 holds for ReLU networks with arbitrary depth.
Inverting LeakyReLU Network: On the other hand, inversion of LeakyReLU layers are significantly easier for the realizable case. Unlike ReLU, LeakyReLU is a bijective map, i.e., each observation corresponds to a unique preimage:
Invertibility for Noisy ReLU Networks
Again we start with a single layer, i.e. we observe . Depending on the distribution over the measurement noise , different norm in the objective should be used, with corresponding error bound analysis. We first look at the case where the entries of are uniformly bounded and the approximation of .
Note that for an error , the true prior that produces the observation falls into the following constraints:
which is also equivalent to the set \{{\boldsymbol{z}}\big{|}\|\phi({\boldsymbol{z}})-{\boldsymbol{x}}\|_{\infty}\leq\epsilon\}. Therefore a natural way to approximate the prior is to use linear programming to solve the above constraints.
If is known, inversion is straightforward from constraints (6). However, suppose we don’t want to use a loose guess, we could start from a small estimation and gradually increase the tolerance until feasibility is achieved. A layer-wise inversion is formally presented in Algorithm 1For practical use, we introduce a factor to gradually increase the error estimation. In our theorem, it assumed we expicitly set to invert the -th layer as the error estimation ..
A key assumption that possibly conveys the error bound from the output to the solution is the following assumption:
with high probability for any , and is a constant. Recall that is the sub-rows of confined to .
With this assumption, we are able to show the following theorem that bounds the recovery error.
We argue that the assumptions required could be satisfied by random weight matrices sampled from i.i.d Gaussian distribution, and present the following corollary.
For LeakyReLU, we could do at least as good as ReLU, since we could simply view all negative coordinates as inactive coordinates of ReLU, and each observation will produce a loose bound. On the other hand, if there are significant number of negative entries, we could also change the linear programming constraints of Algorithm 1 as follows:
with high probability for any .
There is a significant volume of prior work on the RIP-1 condition. For instance, studies in showed that a (scaled) random sparse binary matrix with rows is -RIP-1 with high probability. In our case and could be arbitrarily large, therefore again we only require the expansion factor to be constant. Similar results with different weight matrices are also shown in .
3 Relaxation on the ReLU Configuration Estimation
Our previous methods critically depend on the correct estimation of the ReLU configurations. In both Algorithm 1 and 2, we require the ground truth of all intermediate layer outputs to have many coordinates with large magnitude so that they can be distinguished from noise. An incorrect estimate from an "off" configuration to an "on" condition will possibly cause primal infeasibility when solving the LP. Increasing ameliorates this problem but also increases the recovery error.
With this intuition, a natural workaround is to perform some relaxation to tolerate incorrectly estimated signs of the observations.
Here the ReLU configuration is no longer explicitly reflected in the constraints. Instead, we only include the upper bound for each inner product , which is always valid whether the ReLU is on or off. The previous requirement for the lower bound is now relaxed and hidden in the objective part. When the value of is relatively large, the solver will produce a larger value of to achieve optimality. Since this value is also upper bounded by , the optimal solution would be approaching to if possible. On the other hand, when the value of is close to 0, the objective dependence on is almost negligible.
Meanwhile, in the realizable case when such that , and , it is easy to show that the solution set for (8) is exactly the preimage of . This also trivially holds for Algorithm 1 and 2.
Experiments
We validate our algorithms on synthetic data at various noise levels and verify Theorem 4 and 5 numerically. For our methods, we choose the scaling factor . With gradient descent, we use learning rate of and up to 1,000 iterations or until the gradient norm is no more than .
Model architecture: The architecture we choose in the simulation aligns with our theoretical findings. We choose a two layer network with constant expansion factor : latent dimension , hidden neurons of size and observation dimension . The entries in the weight matrix are independently drawn from .
Recovery with Various Input Neurons: According to the theoretical result, one advantage of our proposals is the much smaller expansion requirement than gradient descent (constant vs factors). Therefore we conduct the experiments to verify this point. We follow the exact setting as ; we fix the hidden layer and output sizes as and and vary the input size to measure the empirical success rate of recovery influenced by the input size.
In Figure 2 we report the empirical success rate of recovery for our proposals and gradient descent. With exact setting as in , a run is considered successful when . We observe that when input width is small, both gradient descent and our methods grant success rate. However, as the input neurons grows, gradient descent drops to complete failure when 60, while our algorithms continue to present 100% success rate until . The performance of gradient descent is slightly worse than reported in since they have conducted number of measurements for each run while we only considered the measurement matrix as identity matrix.
2 Experiments on Generative Model for MNIST Dataset
To verify the practical contribution of our model, we conduct experiments on a real generative network with the MNIST dataset. We set a simple fully-connected architecture with latent dimension , hidden neurons of size and output size . The network has a single channel. We train the network using the original Generative Adversarial Network . We set to be small since the output usually only has around to non-zero pixels.
Similar to the simulation part, we compared our methods with gradient descent . Under this setting, we choose the learning rate to be and number of iterations up to 10,000 (or until gradient norm is below ).
We also compare the distribution of relative recovery error with respect to different input noise levels, as ploted in Figure 1(c)(d). From the figures, we observe that for this real network, our proposals still successfully recover the ground truth with good accuracy most of the time, while gradient descent usually gets stuck in local minimum. This explains why it produces defective image reconstructions as shown in 3.
Finally, we presented some sensing results when we mask part of the observations using PGD with our inverting procedure. As shown in Figure 4, our algorithm always show reliable recovery while gradient descent sometimes fails to output reasonable result. More experiments are presented in the Appendix.
Conclusion
References
Appendix A Methodology Details
In this section we present the detailed steps for our proposed methods.
We formally present the relaxed version based on (8):
We also propose the relaxed LP for LeakyReLU activation, with key step as follows:
Similarly when and , the solution to (A.1) is exactly .
Appendix B Theoretical Analysis
Warm-up: NP-hardness to Invert a Binary Two-Layer Network: We show that 3SAT is reducible to the inversion problem. We first review the MAX-3SAT problem: Given a 3-CNF formula (i.e. a formula in conjunctive normal form where each clause is limited to at most three literals), determine its satisfiability.
Now we design a network with binary input vectors that could be reduced from 3SAT problem.
Now we design a real-valued network that could be reduced from 3SAT problem. Firstly, the network consists of input nodes . Next, the connecting 2 layers map each to . Now, the third connecting layer consists of nodes, where the first nodes indicate each clause: will be connected to nodes among , where the weight is for a positive literal, and for a negative literal. Let , and . The bias term on this third layer is such that the first values are and the last two values are 0. Finally, the last layer is of 2 nodes, first one is the summation of the first nodes of , and the second one is
We will set the output to be . Notice the first two layers make sure each value of is in the range of When the output of , it means all values of must be . Therefore we go back to the previous setting with binary input vectors and simply means that all clauses are satisfied. Therefore a 4 layered ReLU network could be polynomially reduced from 3SAT problem. ∎
Proof of Non-convexity. The following example demonstrate this property is no longer true for a two-layer case:
For , , and observation , the solution set for
Example 1 is very straightforward to show the non-convexity of the preimage. Notice point and are in the solution set, but their convex combination is not a solution point with .
B.2 Proof of Exact Recovery for the Realizable Case
The proof of Theorem 4 highly depends on the exact inversion for a single layer:
With Assumption 2, we are able to show the following theorem that bounds the recovery error.
Given a noisy observation . Let If satisfies Assumption 2 with the integer , and the observation has at least coordinates that is larger than , then Algorithm 1 outputs an that satisfies with high probability .
Denote , and to be the true output. Notice it also satisfies from the error bound assumption. Since has more than entries , the observation satisfies . Notice for a feasible vector with constraints in (6), it satisfies that
since the error is bounded uniformly for each coordinate in . Meanwhile, notice the real satisfies , we have . With Assumption 2, satisfies for an arbitrary whp. Therefore together with (10) and let and get:
Therefore with probability .
For a sub-Gaussian random matrix with height and width , where . Its smallest singular value
satisfies with high probability , where is some absolute constant.
The original paper requires and we presented above with a relaxed condition that .
Here is the ground truth of -th intermediate vector. is the one we observe and is the solution Algorithm 2 produces.
Appendix C More Experimental Results
More Results on LP Relaxation. In Figure 5, we compare the performance with respect to different noise levels over all our proposals, including the results of Algorithm 3 that we omit in the main text. Although we do not see significant improvement of the LP relaxation method over our other proposals, we believe the relaxation over the strict ReLU configurations estimation is of good potential and should be more investigated in the future.
Time comparison. Firstly, we should declare that for the very well-conditioned random weighted networks, gradient descent converges with large stepsize and we don’t observe much supriority over GD in terms of the running time. In the table below we presented the running time for random net with different input dimensions ranging from 10 to 110.
More experiments on the Sensing Problem. Finally we add some more examples for some impainting problem on MNIST with non-identity forward operator .