r/MachineLearning • u/aseembits93 • Sep 11 '19
Discussion [D] Batch Normalization is a Cause of Adversarial Vulnerability
Abstract - Batch normalization (batch norm) is often used in an attempt to stabilize and accelerate training in deep neural networks. In many cases it indeed decreases the number of parameter updates required to achieve low training error. However, it also reduces robustness to small adversarial input perturbations and noise by double-digit percentages, as we show on five standard data-sets. Furthermore, substituting weight decay for batch norm is sufficient to nullify the relationship between adversarial vulnerability and the input dimension. Our work is consistent with a mean-field analysis that found that batch norm causes exploding gradients.
Page - https://arxiv.org/abs/1905.02161
PDF - https://arxiv.org/pdf/1905.02161.pdf
Has anyone read the paper and experienced robustness issues with deployment of Batchnorm models in the real world?
46
Sep 11 '19
God bless you for not linking directly to the PDF.
2
u/Vallvaka Sep 11 '19
Clueless guy here-- why?
5
3
Sep 12 '19
Because I hate it when I look on google scholar for a paper on my phone and it links arxiv papers directly to the pdf, and since I'm on the phone, it downloads it automatically, and I don't want shitty articles on my phone.
2
u/DionysusLin Sep 12 '19
I hate it when the pdf just automatically download to my phone
Fine with laptop though.
10
u/mcstarioni Sep 11 '19 edited Sep 11 '19
Haven't fully read yet, are there any highlights on how this is related to non-robust features from the recent Distill.pub publication? Probably BatchNorm somehow smoothes robust activations since examples differ from each other. But also highlights some dataset-related non-robust features, because they are present on each training example as an artifacts of dataset production. Weight decay might have resolved this because smaller amount of weights is needed to learn low-frequency robust feature, than high-frequency non-robust feature. However this is all my speculations, without proofs. Also it's strange to use BN before activation, I've thought that this is a resolved issue.
7
u/AngusGalloway Sep 11 '19 edited Sep 11 '19
The work you mention appeared on arxiv at the same time as ours, so I haven't had time to formally place the role of BatchNorm (BN) in this context.
I think it's quite likely that for the standard vision datasets BN increases use of non-robust features, e.g., texture. This isn't ideal evidence, but BagNets---considered to operate exclusively on local textures---that make extensive use of BN were decimated to near zero accuracy by similar levels of noise considered in this work. It would be interesting if BagNets fail to train with Fixup, which would be a success in terms of identifying BN as helping learn the texture.
I did have a chance to briefly discuss the two works with the first author of the bugs paper, and our consensus was that the results are somewhat orthogonal. You can devise a dataset that contains only robust features and BN still leads to vulnerability (except in special cases) via tilting the decision boundary along task-irrelevant dimensions a la https://arxiv.org/abs/1608.07690. We're working on including this in a future update.
Regarding BN before or after activation, we wanted to be as consistent as possible with the prescribed usage in the original paper. I believe the difference between the two configurations was negligible from a robustness perspective.
1
u/thatguydr Sep 11 '19
This is a great reply. I didn't know the BagNet accuracy was decimated by noise - thanks!
Also, very importantly, if your entire paper is on BN and you didn't perform any experiments using BN after the nonlinearity... people are going to say you've omitted something large. Lots of people run it that way, so demonstrating that this reduction in robustness happens in that mode seems apropos for an appendix at minimum (I'd put it in the body as another result).
4
u/jinpanZe Sep 11 '19
Batchnorm causes gradient explosion at init, as the authors here cite: https://arxiv.org/abs/1902.08129
2
Sep 11 '19
Pardon my ignorance, but I still don't fully understand what batch norm is actually doing to the network model when training.
6
Sep 11 '19
if you apply batch norm to a layer output, it looks at all the output activations of each neuron of that layer for each sample from the batch, and calculates standard deviation and mean of all these samples, and substracts the mean from each activation, and divides each result by the standard deviation.
This normalizes the output of the layer so that the next layer that "looks" at the output of the batch normalized layer doesn't have to deal with differing magnitudes of input vectors between different samples, and also eliminates bias shifts. this means that the next layer can learn with values that are less different from each other, in a sense.
basically it puts each sample from a batch into the relative perspective of all the samples from the batch, so that they all share a common perspective, which makes it easier for the network to recognize patterns in the samples.
1
u/sam_does_things Sep 11 '19
Arxiv-vanity link for those on mobile: https://www.arxiv-vanity.com/papers/1905.02161/
1
Sep 11 '19
I prefer SELU activation as it performs the normalisation by itself
1
u/DeepBlender Sep 12 '19
That would be amazing. Unfortunately, this is not accurate. You can't take an arbitrary architecture and use selu instead of batch normalization.
1
Sep 12 '19
Well I do so could you please explain more why you cant?
1
u/DeepBlender Sep 12 '19
The self normalizing paper doesn't use it for convolutions. I still tried to experiment with them, but it didn't work. I am happy to be proven wrong though!
1
Sep 12 '19
The SELU works just fine with convolutions. As a matter of fact they work just beautifully with convolutions. Their properties are amazing.
1
u/DeepBlender Sep 12 '19
Can you share some references to GitHub repositories where selu is used successfully? Do you know papers besides the initial one?
What's shown in the self normalizing paper is brilliant indeed, but I always struggled to get it to work in general. And as far as I can see, I am not the only person with that issue. It is worth nothing that it is beautiful and that the properties are amazing if I don't get it to work.
1
Sep 12 '19
I am sorry but I only have my own code and if you are looking for a Quick fix to your problem I am not the guy to help you but I assure you it works just fine with convolutions.
You are welcome to discuss your problem on linked in in my group for deep genetic learning and evolution where we also discuss the mechanisms of an actual neural network
1
Sep 12 '19
I can of course show you my examples but you might not be able to use that code as its in C++
1
u/DeepBlender Sep 12 '19
I would be very interested in that! Translating code or comparing code like that is a lot easier!
1
Sep 12 '19
I can start with something very simple just to show you it works. A simple convolution example for the MNIST dataset would perhaps suit you ?
2
u/mcstarioni Sep 12 '19 edited Sep 12 '19
You can just tell the init rule for convolutions, since the activation coefficient is the same. For MLP init is normal with mean = 0, std = sqrt(1/input_features). For convnets its probably with std=sqrt(1/(kernel_X*kernel_Y * in_channels))?
→ More replies (0)1
u/DeepBlender Sep 12 '19
A simple example should be sufficient as the concept as such should be easily scalable to deeper architectures and more involved datasets.
→ More replies (0)
-4
u/xternalz Sep 11 '19
I personally find that GN can circumvent this.
9
2
Sep 11 '19
Any study which confirms this?
4
u/xternalz Sep 11 '19 edited Sep 24 '19
Not exactly a focused study, but we have a small observation (Table 3) in our recent paper https://arxiv.org/abs/1909.06804 that a MLP trained with BN gives very "wild" outputs for unseen inputs, while GN does not.
1
Sep 11 '19
I tried GN instead of BN for a simple image classification problem (VGG style conv net, 20000 images, 23 classes) and iirc it didn’t converge. Not sure why
2
u/ppwwyyxx Sep 11 '19
GN on VGG for ImageNet, original code for the paper: https://github.com/tensorpack/tensorpack/tree/master/examples/ImageNetModels
1
1
-3
u/penalvad00 Sep 11 '19
Does this means " Dont Use BN in Production, prefer do invest Money and Have a DNN Robust in Long Term "?
8
u/iidealized Sep 11 '19
Nobody actually cares about this sort of vulnerability in DNN production. If you're worried an adversary may be making pixel-level modifications to your images, you have far bigger system-level problems to worry about than how your DNN was trained...
2
-2
-2
-2
0
Sep 11 '19
[deleted]
2
u/qwertz_guy Sep 12 '19
but its been empirically observed that dropouts offer better results than any other regularized method
can you provide a source for where this has been shown for ConvNets?
2
u/crouching_dragon_420 Sep 12 '19
BatchNorm and Dropout don't work well together. Dropout causes variance shifts of the the layer output into BatchNorm between training and testing phase which will mess up the moving mean and average that BatchNorm learns in the training phase, resulting in similar or lower accuracy during testing when Dropout is not used.
1
u/facundoq Sep 11 '19
Why the downvotes? I think he's suggesting to see if adding dropout (or other regularization technique) to BN can be useful in getting back some generalization. Since dropout is really cheap in computational costs we may be able to get the best of both worlds.
1
u/bbu3 Sep 12 '19
I did not vote, but I guess it may be because, BN is not only a method for "regularization to ensure stability of the model". BN has a regularizing effect, but it is also about controlling your activations during trainng. Ultimately what BN does is (apart from the regularization and robustness to overfitting too quickly/stronly) also a lot about being able to quickly (and effectively) train your models. I don't think dropout has this effect (whereas it does have a great regularizing effect).
That said, I think the same can be said about the comparison to WD, but that has been addresses by the author, already (see https://www.reddit.com/r/MachineLearning/comments/d2m5zr/d_batch_normalization_is_a_cause_of_adversarial/ezwh9cf?utm_source=share&utm_medium=web2x ). That's also why I think your comment is valid. It could need more explanation though, because the assumption "BN & Dropout are two ways to do the same thing" is pretty inaccurate.
26
u/[deleted] Sep 11 '19
This goes away when BN is replaced with WD. But do the benefits of BN remain? I imagine not right? Else why would people ever use BN. As such it seems like an odd comparison to make.