This repository is the official implementation of Convolutional Normalization: Improving Robustness and Training for Deep Neural Networks.
We introduce a simple and efficient “convolutional normalization” method thatcan fully exploit the convolutional structure in theFourier domain and serve as a simple plug-and-play module to be conveniently incorporated intoany ConvNets. We show that convolutional normalization can reduce the layerwise spectral norm of the weight matrices and hence improve the Lipschitzness of the network, leading to easier training and improved robustness for deep ConvNets. Applied to classification under noise corruptions and generative adversarial network (GAN), we show that convolutional normalization improves the robustness of common ConvNets such as ResNet and the performance of GAN.
These graphs show the comparison between BatchNorm and ConvNorm on activations of k=1,...,C channels. BatchNorm subtracts and multiplies the activations of each channel by computed scalars: mean µ and variance σ, before a per-channel affine transform parameterized by learned parameters β and γ; ConvNorm performs per-channel convolution with precomputed kernel v to normalize the spectrum of the weight matrix for the convolution layer, following with a channel-wise convolution with learned kernel r as the affine transform..- python 3.9.0
- torch 1.6.0
- torchvision 0.7.0
- sklearn 0.23.2
- comet_ml 3.2.11
- numpy 1.19.2
- matplotlib 3.3.2
The versions of the dependencies listed are not strict, some earlier versions of the dependencies should also work.
We use config files to control the parameters of training and validation. An example of standard training config could be found in config_cifar10_standard.json and an example of robustly training could be found in config_robust_train.json. We will mention the important parameters for each set up below.
In order to use our proposed Convolutional Normalization (ConvNorm), you can simply replace your convolutional layer and normalization layer by this module. In the module, the parameter affine controls whether to use the affine transform of our method, and the parameter bn controls whether to use BatchNorm after ConvNorm.
- Please download the data before running the code, add path to the downloaded data to
data_loader.args.data_dirin the corresponding config file.
Change arch.args.conv_layer_type for different methods and set arch.args.norm_layer_type accordingly. For example, to run standard convolution with BatchNorm, set arch.args.conv_layer_type to be "conv" and arch.args.norm_layer_type to be "bn"; to run our our method, set arch.args.conv_layer_type to be "prec_conv" and arch.args.norm_layer_type to be "no" (since we include the BatchNorm in the implementation of our method) in the config file.
- Code for standard training with ConvNorm is in the following file:
train.py. For reproducing our label noise experiments, settrainer.symto True and denote the desired label noise percentage by changingtrainer.percent. For reproducing the data scarcity experiments, changetrainer.subset_percentto the desired subset percentage. - Code for rubust training of CIFAR10 is in the following file:
train_robust.py. A corresponding config file isconfig_robust_train.json. Note that in the config,trainer.adv_repeatsmeans the times for repeating training for each minibatch;trainer.fgsm_stepdenotes the step amount of one FGSM iteration;trainer.adv_clip_epsis the$l_{inf}$ norm bound of the perturbation;pgd_attack.Kis the total steps for PGD attack;pgd_attack.stepis the attack amount of one PGD step;trainer.OCNNdenotes whether to use OCNN method or not (different than other methods which should be set inarchsince OCNN is a regularization method enforced directly to the loss) andtrainer.lamb_ocnnis the correpsonding penalty constraint constant of OCNN.
Example usage:
$ python train.py -c config_cifar10_standard.json
$ python train_robust.py -c config_robust_train.jsonvalidate_pgd.py and fgsm.py are the validation codes for measuing the performances of the robustly trained models, they should be used with the config file config_robust_train.json as well.
Example usage:
$ python validate_pgd.py -c config_robust_train.json -s <model checkpoint directory> --seed <random seed>
$ python fgsm.py -c config_robust_train.json -s <model checkpoint directory> --seed <random seed>check_result.ipynb contains some example usage of the validation codes and the corresponding results from our experiments.
For technical details and full experimental results, please check our paper.
@article{liu2021convolutional,
title={Convolutional Normalization: Improving Deep Convolutional Network Robustness and Training},
author={Sheng Liu and Xiao Li and Yuexiang Zhai and Chong You and Zhihui Zhu and Carlos Fernandez-Granda and Qing Qu},
journal={Advances in Neural Information Processing Systems},
volume={34},
year={2021}
}
Please contact [email protected] or [email protected] if you have any question on the codes.
