Cyclical Learning Rates for Training Neural Networks — part 1/3

Cleaned-text code points [0, 15809). Bibliography omitted here; source.md includes it.

# Cyclical Learning Rates for Training Neural Networks

###### Abstract

It is known that the learning rate is the most important hyper-parameter to tune for training deep neural networks. This paper describes a new method for setting the learning rate, named cyclical learning rates , which practically eliminates the need to experimentally find the best values and schedule for the global learning rates. Instead of monotonically decreasing the learning rate, this method lets the learning rate cyclically vary between reasonable boundary values. Training with cyclical learning rates instead of fixed values achieves improved classification accuracy without a need to tune and often in fewer iterations. This paper also describes a simple way to estimate “reasonable bounds” – linearly increasing the learning rate of the network for a few epochs. In addition, cyclical learning rates are demonstrated on the CIFAR-10 and CIFAR-100 datasets with ResNets, Stochastic Depth networks, and DenseNets, and the ImageNet dataset with the AlexNet and GoogLeNet architectures. These are practical tools for everyone who trains neural networks.

## 1 Introduction

Deep neural networks are the basis of state-of-the-art results for image recognition [ 17 , 23 , 25 ] , object detection [ 7 ] , face recognition [ 26 ] , speech recognition [ 8 ] , machine translation [ 24 ] , image caption generation [ 28 ] , and driverless car technology [ 14 ] . However, training a deep neural network is a difficult global optimization problem.

A deep neural network is typically updated by stochastic gradient descent and the parameters θ \theta (weights) are updated by θ t = θ t − 1 − ϵ t ​ ∂ L ∂ θ \theta^{t}=\theta^{t-1}-\epsilon_{t}\frac{\partial L}{\partial\theta} , where L is a loss function and ϵ t \epsilon_{t} is the learning rate. It is well known that too small a learning rate will make a training algorithm converge slowly while too large a learning rate will make the training algorithm diverge [ 2 ] . Hence, one must experiment with a variety of learning rates and schedules.

Conventional wisdom dictates that the learning rate should be a single value that monotonically decreases during training. This paper demonstrates the surprising phenomenon that a varying learning rate during training is beneficial overall and thus proposes to let the global learning rate vary cyclically within a band of values instead of setting it to a fixed value. In addition, this cyclical learning rate (CLR) method practically eliminates the need to tune the learning rate yet achieve near optimal classification accuracy. Furthermore, unlike adaptive learning rates, the CLR methods require essentially no additional computation.

The potential benefits of CLR can be seen in Figure 1 , which shows the test data classification accuracy of the CIFAR-10 dataset during training 1 1 1 Hyper-parameters and architecture were obtained in April 2015 from caffe.berkeleyvision.org/gathered/examples/cifar10.html . The baseline (blue curve) reaches a final accuracy of 81.4 % 81.4\% after 70,000 70,000 iterations. In contrast, it is possible to fully train the network using the CLR method instead of tuning (red curve) within 25,000 iterations and attain the same accuracy.

The contributions of this paper are: 1. A methodology for setting the global learning rates for training neural networks that eliminates the need to perform numerous experiments to find the best values and schedule with essentially no additional computation.

2. A surprising phenomenon is demonstrated - allowing the learning rate to rise and fall is beneficial overall even though it might temporarily harm the network’s performance.

3. Cyclical learning rates are demonstrated with ResNets, Stochastic Depth networks, and DenseNets on the CIFAR-10 and CIFAR-100 datasets, and on ImageNet with two well-known architectures: AlexNet [ 17 ] and GoogleNet [ 25 ] .

## 2 Related work

The book “Neural Networks: Tricks of the Trade” is a terrific source of practical advice. In particular, Yoshua Bengio [ 2 ] discusses reasonable ranges for learning rates and stresses the importance of tuning the learning rate. A technical report by Breuel [ 3 ] provides guidance on a variety of hyper-parameters. There are also a numerous websites giving practical suggestions for setting the learning rates.

Adaptive learning rates : Adaptive learning rates can be considered a competitor to cyclical learning rates because one can rely on local adaptive learning rates in place of global learning rate experimentation but there is a significant computational cost in doing so. CLR does not possess this computational costs so it can be used freely.

A review of the early work on adaptive learning rates can be found in George and Powell [ 6 ] . Duchi, et al . [ 5 ] proposed AdaGrad, which is one of the early adaptive methods that estimates the learning rates from the gradients.

RMSProp is discussed in the slides by Geoffrey Hinton 2 2 2 www.cs.toronto.edu/ tijmen/csc321/slides/lecture_slides_lec6.pdf [ 27 ] . RMSProp is described there as “Divide the learning rate for a weight by a running average of the magnitudes of recent gradients for that weight.” RMSProp is a fundamental adaptive learning rate method that others have built on.

Schaul et al . [ 22 ] discuss an adaptive learning rate based on a diagonal estimation of the Hessian of the gradients. One of the features of their method is that they allow their automatic method to decrease or increase the learning rate. However, their paper seems to limit the idea of increasing learning rate to non-stationary problems. On the other hand, this paper demonstrates that a schedule of increasing the learning rate is more universally valuable.

Zeiler [ 29 ] describes his AdaDelta method, which improves on AdaGrad based on two ideas: limiting the sum of squared gradients over all time to a limited window, and making the parameter update rule consistent with a units evaluation on the relationship between the update and the Hessian.

More recently, several papers have appeared on adaptive learning rates. Gulcehre and Bengio [ 9 ] propose an adaptive learning rate algorithm, called AdaSecant, that utilizes the root mean square statistics and variance of the gradients. Dauphin et al . [ 4 ] show that RMSProp provides a biased estimate and go on to describe another estimator, named ESGD, that is unbiased. Kingma and Lei-Ba [ 16 ] introduce Adam that is designed to combine the advantages from AdaGrad and RMSProp. Bache, et al . [ 1 ] propose exploiting solutions to a multi-armed bandit problem for learning rate selection. A summary and tutorial of adaptive learning rates can be found in a recent paper by Ruder [ 20 ] .

Adaptive learning rates are fundamentally different from CLR policies, and CLR can be combined with adaptive learning rates, as shown in Section 4.1 . In addition, CLR policies are computationally simpler than adaptive learning rates. CLR is likely most similar to the SGDR method [ 18 ] that appeared recently.

## 3 Optimal Learning Rates

### 3.1 Cyclical Learning Rates

The essence of this learning rate policy comes from the observation that increasing the learning rate might have a short term negative effect and yet achieve a longer term beneficial effect. This observation leads to the idea of letting the learning rate vary within a range of values rather than adopting a stepwise fixed or exponentially decreasing value. That is, one sets minimum and maximum boundaries and the learning rate cyclically varies between these bounds. Experiments with numerous functional forms, such as a triangular window (linear), a Welch window (parabolic) and a Hann window (sinusoidal) all produced equivalent results This led to adopting a triangular window (linearly increasing then linearly decreasing), which is illustrated in Figure 2 , because it is the simplest function that incorporates this idea. The rest of this paper refers to this as the t ​ r ​ i ​ a ​ n ​ g ​ u ​ l ​ a ​ r triangular learning rate policy.

An intuitive understanding of why CLR methods work comes from considering the loss function topology. Dauphin et al . [ 4 ] argue that the difficulty in minimizing the loss arises from saddle points rather than poor local minima. Saddle points have small gradients that slow the learning process. However, increasing the learning rate allows more rapid traversal of saddle point plateaus. A more practical reason as to why CLR works is that, by following the methods in Section 3.3 , it is likely the optimum learning rate will be between the bounds and near optimal learning rates will be used throughout training.

The red curve in Figure 1 shows the result of the t ​ r ​ i ​ a ​ n ​ g ​ u ​ l ​ a ​ r triangular policy on CIFAR-10. The settings used to create the red curve were a minimum learning rate of 0.001 0.001 (as in the original parameter file) and a maximum of 0.006 0.006 . Also, the cycle length (i.e., the number of iterations until the learning rate returns to the initial value) is set to 4,000 4,000 iterations (i.e., s ​ t ​ e ​ p ​ s ​ i ​ z ​ e = 2000 stepsize=2000 ) and Figure 1 shows that the accuracy peaks at the end of each cycle.

Implementation of the code for a new learning rate policy is straightforward. An example of the code added to Torch 7 in the experiments shown in Section 4.1.2 is the following few lines: ⬇

where o ​ p ​ t . L ​ R opt.LR is the specified lower (i.e., base) learning rate, e ​ p ​ o ​ c ​ h ​ C ​ o ​ u ​ n ​ t ​ e ​ r epochCounter is the number of epochs of training, and l ​ r lr is the computed learning rate. This policy is named t ​ r ​ i ​ a ​ n ​ g ​ u ​ l ​ a ​ r triangular and is as described above, with two new input parameters defined: s ​ t ​ e ​ p ​ s ​ i ​ z ​ e stepsize (half the period or cycle length) and m ​ a ​ x ​ _ ​ l ​ r max\_lr (the maximum learning rate boundary). This code varies the learning rate linearly between the minimum ( b ​ a ​ s ​ e ​ _ ​ l ​ r base\_lr ) and the maximum ( m ​ a ​ x ​ _ ​ l ​ r max\_lr ).

In addition to the triangular policy, the following CLR policies are discussed in this paper: 1. t ​ r ​ i ​ a ​ n ​ g ​ u ​ l ​ a ​ r ​ 2 triangular2 ; the same as the t ​ r ​ i ​ a ​ n ​ g ​ u ​ l ​ a ​ r triangular policy except the learning rate difference is cut in half at the end of each cycle. This means the learning rate difference drops after each cycle.

2. e ​ x ​ p ​ _ ​ r ​ a ​ n ​ g ​ e exp\_range ; the learning rate varies between the minimum and maximum boundaries and each boundary value declines by an exponential factor of g ​ a ​ m ​ m ​ a i ​ t ​ e ​ r ​ a ​ t ​ i ​ o ​ n gamma^{iteration} .

### 3.2 How can one estimate a good value for the cycle length?

The length of a cycle and the input parameter s ​ t ​ e ​ p ​ s ​ i ​ z ​ e stepsize can be easily computed from the number of iterations in an epoch. An epoch is calculated by dividing the number of training images by the b ​ a ​ t ​ c ​ h ​ s ​ i ​ z ​ e batchsize used. For example, CIFAR-10 has 50,000 50,000 training images and the b ​ a ​ t ​ c ​ h ​ s ​ i ​ z ​ e batchsize is 100 100 so an epoch = 50,000 / 100 = 500 =50,000/100=500 iterations. The final accuracy results are actually quite robust to cycle length but experiments show that it often is good to set s ​ t ​ e ​ p ​ s ​ i ​ z ​ e stepsize equal to 2 − 10 2-10 times the number of iterations in an epoch. For example, setting s ​ t ​ e ​ p ​ s ​ i ​ z ​ e = 8 ∗ e ​ p ​ o ​ c ​ h stepsize=8*epoch with the CIFAR-10 training run (as shown in Figure 1 ) only gives slightly better results than setting s ​ t ​ e ​ p ​ s ​ i ​ z ​ e = 2 ∗ e ​ p ​ o ​ c ​ h stepsize=2*epoch .

Furthermore, there is a certain elegance to the rhythm of these cycles and it simplifies the decision of when to drop learning rates and when to stop the current training run. Experiments show that replacing each step of a constant learning rate with at least 3 cycles trains the network weights most of the way and running for 4 or more cycles will achieve even better performance. Also, it is best to stop training at the end of a cycle, which is when the learning rate is at the minimum value and the accuracy peaks.

### 3.3 How can one estimate reasonable minimum and maximum boundary values?

There is a simple way to estimate reasonable minimum and maximum boundary values with one training run of the network for a few epochs. It is a “LR range test”; run your model for several epochs while letting the learning rate increase linearly between low and high LR values. This test is enormously valuable whenever you are facing a new architecture or dataset.

The t ​ r ​ i ​ a ​ n ​ g ​ u ​ l ​ a ​ r triangular learning rate policy provides a simple mechanism to do this. For example, in Caffe, set b ​ a ​ s ​ e ​ _ ​ l ​ r base\_lr to the minimum value and set m ​ a ​ x ​ _ ​ l ​ r max\_lr to the maximum value. Set both the s ​ t ​ e ​ p ​ s ​ i ​ z ​ e stepsize and m ​ a ​ x ​ _ ​ i ​ t ​ e ​ r max\_iter to the same number of iterations. In this case, the learning rate will increase linearly from the minimum value to the maximum value during this short run. Next, plot the accuracy versus learning rate. Note the learning rate value when the accuracy starts to increase and when the accuracy slows, becomes ragged, or starts to fall. These two learning rates are good choices for bounds; that is, set b ​ a ​ s ​ e ​ _ ​ l ​ r base\_lr to the first value and set m ​ a ​ x ​ _ ​ l ​ r max\_lr to the latter value. Alternatively, one can use the rule of thumb that the optimum learning rate is usually within a factor of two of the largest one that converges [ 2 ] and set b ​ a ​ s ​ e ​ _ ​ l ​ r base\_lr to 1 3 \frac{1}{3} or 1 4 \frac{1}{4} of m ​ a ​ x ​ _ ​ l ​ r max\_lr .

Figure 3 shows an example of making this type of run with the CIFAR-10 dataset, using the architecture and hyper-parameters provided by Caffe. One can see from Figure 3 that the model starts converging right away, so it is reasonable to set b ​ a ​ s ​ e ​ _ ​ l ​ r = 0.001 base\_lr=0.001 . Furthermore, above a learning rate of 0.006 0.006 the accuracy rise gets rough and eventually begins to drop so it is reasonable to set m ​ a ​ x ​ _ ​ l ​ r = 0.006 max\_lr=0.006 .

Whenever one is starting with a new architecture or dataset, a single LR range test provides both a good LR value and a good range. Then one should compare runs with a fixed LR versus CLR with this range. Whichever wins can be used with confidence for the rest of one’s experiments.

## 4 Experiments

The purpose of this section is to demonstrate the effectiveness of the CLR methods on some standard datasets and with a range of architectures. In the subsections below, CLR policies are used for training with the CIFAR-10, CIFAR-100, and ImageNet datasets. These three datasets and a variety of architectures demonstrate the versatility of CLR.

### 4.1 CIFAR-10 and CIFAR-100

#### 4.1.1 Caffe’s CIFAR-10 architecture

The CIFAR-10 architecture and hyper-parameter settings on the Caffe website are fairly standard and were used here as a baseline. As discussed in Section 3.2 , an epoch is equal to 500 500 iterations and a good setting for s ​ t ​ e ​ p ​ s ​ i ​ z ​ e stepsize is 2,000 2,000 . Section 3.3 discussed how to estimate reasonable minimum and maximum boundary values for the learning rate from Figure 3 . All that is needed to optimally train the network is to set b ​ a ​ s ​ e ​ _ ​ l ​ r = 0.001 base\_lr=0.001 and m ​ a ​ x ​ _ ​ l ​ r = 0.006 max\_lr=0.006 . This is all that is needed to optimally train the network. For the t ​ r ​ i ​ a ​ n ​ g ​ u ​ l ​ a ​ r ​ 2 triangular2 policy run shown in Figure 1 , the s ​ t ​ e ​ p ​ s ​ i ​ z ​ e stepsize and learning rate bounds are shown in Table 2 .