Skip to content
Projekte

zoli333/Weight-Normalization

Auf GitHub ansehen

Über uns

Complete implementation of Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks article

Systeme und Infrastruktur

So werden diese Zahlen gemessen

Gemessener Sternzuwachs

in 24h
0
in 7 days
0
in 15 days
Verlauf wird gesammelt
in 1 month
Verlauf wird gesammelt

Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.

README.md

Original

Weight Normalization in PyTorch (CIFAR-10)

PyTorch implementation of Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks (Salimans & Kingma, 2016), written after the paper and the official Lasagne code (TimSalimans/weight_norm). The CIFAR-10 experiment of the paper is reproduced with the network of its appendix (3x3 convs, two network-in-network 1x1 layers, global average pooling).

What is implemented

  • w = g * v / ||v||, one (g, v) pair per output filter (WNConv2d); NIN layers and the output layer are 1x1 convs.
  • Data-dependent initialization (sec. 3): g = 1/sigma, b = -mu/sigma from one batch of 500 images.
  • Mean-only batch norm (sec. 4), plus full batch norm and a "normal" parametrization as baselines.
  • Modes: wn_mobn (WN + mean-only BN), wn, bn, none_fixg (Lasagne InitLayer baseline: w = g*v with fixed g), none (w trained directly).
  • ZCA whitening as in the official code (zca.py), exact Lasagne-style Adam (lasagne_adam.py, optional).

Protocol (as in the paper / official train.py): Adam, batch 100, 200 epochs; epochs 1-100 constant lr and beta1 = 0.9, then beta1 = 0.5 and lr decaying linearly; additive Gaussian input noise (sigma = 0.15), dropout 0.5, leaky ReLU 0.1; inputs scaled to [-1, 1], ZCA (reg 1e-5), no augmentation.

Run

The training scripts has been run with 2 seeds each (--seed 1 and --seed 2)

Baseline

Run the baseline model with different configurations if --w-init is not specified then the default initialization of the weights will be N(0,0.05)

python train.py --mode none_fixg --lr 0.0003 --zca --w-init glorot
python train.py --mode none_fixg --lr 0.001  --zca --w-init glorot
python train.py --mode none_fixg --lr 0.001  --zca

Final after Baseline's best

python train.py --mode wn_mobn --lr 0.003 --zca
python train.py --mode wn      --lr 0.003 --zca
python train.py --mode bn      --lr 0.003 --zca
python train.py --mode none_fixg --lr 0.001 --zca --w-init glorot   # baseline
python plot_results.py --runs runs --out figures

Results are written to runs/*.csv. Tests: python test_wn.py, python test_zca.py (the WN layer matches torch.nn.utils.parametrizations.weight_norm in forward and gradients up to float32 rounding; after the init every layer has zero mean / unit variance pre-activations).

Results (ZCA, 2 seeds)

Test accuracy = mean of the last 5 evaluations (epochs 180, 185, ..., 200), then mean over seeds.

mode seed 1 seed 2 mean acc. mean error paper error
WN + mean-only BN 92.20% 92.39% 92.29% 7.71% 7.31%
BN 91.67% 91.75% 91.71% 8.29% 8.05%
WN 91.30% 91.80% 91.55% 8.45% 8.46%
Normal (fixed g, Glorot, lr 1e-3) 91.11% 90.97% 91.04% 8.96% 8.43%

training loss test accuracy training accuracy

Findings

  • WN + mean-only BN is the best in both seeds (+0.5 to +1.4 points over the others). BN and WN cannot be told apart (the sign of their difference flips between seeds); the two seeds of a mode differ by 0.07-0.5 points.
  • ZCA matters most. Without it every mode is 3.5-4 points worse (seed 1: wn_mobn 88.26% -> 92.20%, bn 87.81% -> 91.67%, wn 87.79% -> 91.30%, normal 86.27% -> 90.27%). The official code applies the input noise (sigma = 0.15) to whitened inputs.
  • The baseline needs care. With the Lasagne-style fixed g, Glorot init (what the official no_norm layer keeps) and lr 1e-3 it reaches 91.11% vs 90.27% for N(0, 0.05) init and lr 3e-4 (seed 1; the two changes give 90.98% / 90.86% separately). Its configuration was picked on test accuracy among 4 tried, the other modes got a single lr, so the comparison slightly favours the baseline.
  • Data-dependent init changes the final accuracy only slightly (seed 1, ZCA: wn 91.30% vs 90.85% without, wn_mobn 92.20% vs 92.01%).
  • Adam with the epsilon inside the square root (official code) made no difference (wn_mobn, no ZCA: 88.20% vs 88.26%).

Reproducibility

train.py seeds Python/NumPy/PyTorch, uses separate generators for the data order and the init batch, and enables deterministic cuDNN / use_deterministic_algorithms. Bit-identical results need the same GPU type and PyTorch version. A run takes about 1.7-2 hours on a Kaggle GPU.

Ähnliche Projekte entdecken

Wird geladen…