L EARNING I MPLICITLY R ECURRENT CNN S T HROUGH P ARAMETER S HARING
Anonymous authors
Paper under double-blind review
A BSTRACT
We introduce a parameter sharing scheme, in which different layers of a convolutional neural network (CNN) are deﬁned by a learned linear combination of parameter tensors from a global bank of templates.
Restricting the number of templates yields a ﬂexible hybridization of traditional CNNs and recurrent networks.
Compared to traditional CNNs, we demonstrate substantial parameter savings on standard image classiﬁcation tasks, while maintaining accuracy.
Our simple parameter sharing scheme, though deﬁned via soft weights, in practice yields trained networks with near strict recurrent structure; with negligible side effects, they convert into networks with actual recurrent loops.
Training these networks thus implicitly involves discovery of suitable recurrent architectures.
As a consequence, our hybrid networks are not only more parameter efﬁcient, but also learn some tasks faster.
Speciﬁcally, on synthetic tasks which are algorithmic in nature, our hybrid networks both train faster and extrapolate better on test examples outside the span of the training set.
I NTRODUCTION
The architectural details of convolutional neural networks (CNNs) have undergone rapid exploration and improvement via both human hand-design (Simonyan & Zisserman, 2015; Szegedy et al., 2015;
He et al., 2016; Huang et al., 2016; Zhu et al., 2018) and automated search methods (Zoph & Le, 2017; Liu et al., 2018).
Yet, this vast array of work limits itself to a circuit-like view of neural networks.
Here, a CNN is regarded as a ﬁxed-depth feed-forward circuit, with a distinct parameter governing each internal connection.
These circuits are often trained to perform tasks which, in a prior era, might have been (less accurately) accomplished by running a traditional computer program coded by humans.
Programs, and even traditional hardware circuits, have more reusable internal structure, including subroutines or modules, loops, and associated control ﬂow mechanisms.
We bring one aspect of such modularity into CNNs, by making it possible to learn a set of parameters that is reused across multiple layers at different depths.
As the pattern of reuse is itself learned, our scheme effectively permits learning the length (iteration count) and content of multiple loops deﬁning the resulting CNN.
We view this approach as a ﬁrst step towards learning neural networks with internal organization reminiscent of computer programs.
Though we focus solely on loop-like structure, leaving subroutines and dynamic control ﬂow to future work, this simple change sufﬁces to yield substantial quantitative and qualitative beneﬁts over the standard baseline CNN models.
While recurrent neural networks (RNNs) possess loop-like structure by deﬁnition, their loop structure is ﬁxed a priori, rather than learned as part of training.
This can actually be a disadvantage in the event that the length of the loop is mismatched to the target task.
Our parameter sharing scheme for CNNs permits a mix of loops and feed-forward layers to emerge.
For example, trained with our scheme, a 50-layer CNN might learn a 2-layer loop that executes 5 times between layers 10 and 20, a 3-layer loop that runs 4 times from layers 30 to 42, while leaving the remaining layers to assume independent parameter sets.
Our approach generalizes both CNNs and RNNs, creating a hybrid.
Figure 1 diagrams the parameter sharing scheme facilitating this hybridization.
Inspired by dictionary learning, different network layers share, via weighted combination, global parameter templates.
This re-parameterization is fully differentiable, allowing learning of sharing weights and template parameters.
Section 3 elaborates, and also introduces tools for analyzing learned loop structure.
[Figure]
[Figure]
W (1) Section 4 demonstrates advantages of our hybrid CNNs across multiple experimental settings.
Taking a modern CNN design as a baseline, and re-parameterizing it according to our scheme improves:
• Parameter efﬁciency.
Here, we experiment with the standard task of image classiﬁcation using modern residual networks (He et al., 2016; Zagoruyko & Komodakis
This task is a good proxy for general usefulness in computer vision, as high-performance classiﬁcation architectures often serve as a backbone for many other vision tasks, such as semantic segmentation (Chen et al., 2016; Zhao et al., Our parameter sharing scheme drastically reduces the number
of unique parameters required to achieve a given
accuracy on CIFAR (Krizhevsky, 2009) or ImageNet (Russakovsky et al., 2015) classiﬁcation tasks.
Re-parameterizing a standard residual network with our scheme cuts parameters, without triggering any drop in accuracy
This suggests that standard CNNs may be overparameterized in part because, by design (and unlike RNNs), they lack capacity to learn reusable internal operations.
• Extrapolation and generalization.
Here, we explore whether our hybrid networks expand the class of tasks that one can expect to train neural networks to accomplish.
This line of inquiry, focusing on synthetic tasks, shares motivations with work on Neural Turing Machines (Graves et al., 2014).
Speciﬁcally, we would like neural networks to be capable of learning to perform tasks for which there are concise traditional solution algorithms.
Graves et al.
(2014) uses sorting as an example task.
As we examine an extension of CNNs, our tasks take the form of queries about planar graphs encoded as image input.
On these tasks, we observe improvements to both generalization ability and learning speed for our hybrid CNNs, in comparison to standard CNNs or RNNs.
Our parameter sharing scheme, by virtue of providing an architectural bias towards networks with loops, appears to assist in learning to emulate traditional algorithms.
An additional side effect, seen in practice in many of our experiments, is that two different learned layers often snap to the same parameter values.
That is, layers i and j , learn coefﬁcient vectors α ( i ) and α ( j ) (see Figure 1) that converge to be the same (up to scaling).
This is a form of architecture discovery, as it permits representation of the CNN as a loopy wiring diagram between repeated layers.
Section 4.3 presents example results.
Though different from existing neural architecture search techniques, this might open a complementary research direction, in which some aspects of architecture are selected as a byproduct of the standard stochastic gradient descent training procedure.
Before delving into the details of our method, Section 2 provides additional context in terms of prior work on recurrent models, parameter reduction techniques, and program emulation.
Sections 3 anddescribe our hybrid shared-parameter CNN, experimental setup, and results.
Section 5 concludes with commentary on our results and possible future research pathways.
R ELATED W ORK
Recurrent variants of CNNs are used extensively for visual tasks.
Recently, Zamir et al.
(2017) propose utilizing a convolutional LSTM (Shi et al., 2015) as a generic feedback architecture.
RNN and CNN combinations have been used for scene labeling (Pinheiro & Collobert, 2014), image captioning with attention (Xu et al., 2015), and understanding video (Donahue et al., 2015), among others.
These works combine CNNs and RNNs at a coarse scale, and in a ﬁxed hand-crafted manner.
In contrast, we learn the recurrence structure itself, blending it into the inner workings of a CNN.
More closely related to our approach is the idea of hyperneworks (Ha et al., 2016), in which one part of a neural network is parameterized by another neural network.
Our shared template-based reparameterization could be viewed as one simple choice of hypernetwork implementation.
Perhaps surprisingly, this class of ideas has not been well explored for the purpose of reducing the size of neural networks.
Rather, prior work has achieved parameter reduction through explicit representation bottlenecks (Iandola et al., 2016), sparsifying connection structure (Prabhu et al., 2017; Huang et al., 2018; Zhu et al., 2018), and pruning trained networks (Han et al., 2016).
Orthogonal to the question of efﬁciency, there is substantial interest in extending neural networks to tackle new kinds of tasks, including emulation of computer programs.
Some approach this problem using additional supervision in the form of execution traces (Reed & de Freitas, 2016; Cai et al., 2017), while other focus on development of network architectures that can learn from input-output pairs alone (Graves et al., 2014; 2016; Zaremba et al., 2016;
Trask et al., 2018).
Our experiments on synthetic tasks fall into the latter camp.
At the level of architectural strategy, Trask et al.
(2018) beneﬁt from changing the form of activation function to bias the network towards correctly extrapolating common mathematical formulae.
We build in a different implicit bias, towards learning iterative procedures within a CNN, and obtain a boost on correctly emulating programs.
S OFT P ARAMETER S HARING
In convolutional neural networks (CNNs) and variants such as residual CNNs (ResNets) (He et al., 2016) and DenseNets (Huang et al., 2016), each convolutional layer i contains a set of parameters
W ( i ) , with no explicit relation between parameter sets of different layers.
Conversely, a strict structure is imposed to layers of recurrent neural networks (RNNs), where, in standard models (Hochreiter & Schmidhuber, 1997), a single parameter set W is shared among all time steps.
This leads to a program-like computational ﬂow, where RNNs can be seen as loops with ﬁxed length and content.
While some RNN variants (Graves et al., 2013; Koutn ´ ık et al., 2014; Yang et al., 2018) are less strict on the length or content of loops, these are still typically ﬁxed beforehand.
As an alternative to learning hard parameter sharing schemes – which correspond to the strict structure present in RNNs – our method consists of learning soft sharing schemes through a relaxation of this structure.
We accomplish this by expressing each layer’s parameters W ( i ) as a linear combination of parameter templates T (1) , . . .
, T ( k ) , each with the same dimensionality as W ( i ) :
[Equation]
where k is the number of parameter templates (chosen freely as a hyperparameter) and α ( i ) , a kdimensional vector, is the coefﬁcients of layer i .
Figure 1 (left and middle) illustrate the difference between networks trained with and without our method.
This relaxation allows for coefﬁcients and parameter templates to be (jointly) optimized with gradient-based methods, yielding negligible extra computational cost, with a single constraint that only layers with same parameter sizes can share templates.
Note that constraining coefﬁcients α ( i ) to be one-hot vectors leads to hard sharing schemes, at the cost of non-differentiability.
Having k as a free parameter decouples the number of parameters in network from its depth.
Typically, L convolutional layers with constant channel and kernel sizes C, K have O ( LC 2 K 2 ) total parameters.
Our soft sharing scheme changes the total number of parameters to O ( kL + kC 2 K 2 ) =
O ( kC 2 K 2 ) .
Sections 4.1 and 4.2 show that we can decrease the parameter count of standard models without signiﬁcantly impacting accuracy, or simply attain higher accuracy with k = L .
[Figure]
In the next two subsections we discuss two consequences of the linearity of Equation (1).
First, it enables alternative interpretations of our method.
Second and a major advantage, as is the case in many linear relaxations of integer problems, we are able to extract hard sharing schemes in practice, and consequently detect implicit self-loops in a CNN trained with our method
3. I NTERPRETATION
For layers i that are linear in W ( i ) ( e g. matrix multiplication, convolution), we can view our method as learning template layers which are shared among a network.
More speciﬁcally, for a convolutional layer
U ( i ) ( X ) =
W ( i ) ∗ X , and considering Equation (1):
[Equation]
where T ( j ) ∗ X , the result of a convolution with ﬁlter sets T ( j ) , can be seen as the output of a template layer with individual parameters T ( j ) .
Such layers can be seen as global feature extractors, and coefﬁcients α ( i ) determine which features are relevant for the i ’th computation of a network.
This is illustrated in Figure 1 (right diagram).
This view gives a clear connection between coefﬁcients α and the network’s structure.
Having, α ( i ) =
α ( i +2) yields W ( i ) = (cid:80) kj =1 α ( i ) j T ( j ) = (cid:80) kj =1 α ( i +2)
j
T ( j ) = W ( i +2) , hence layers i
and i + 2 are functionally equivalent.
Such a network can be folded to generate an equivalent model with two layers and a self-loop, an explicitly recurrent network.
While this is also possible for networks without parameter sharing, a learned alignment of C 2 K 2 parameters is required (unlikely in practice), instead of aligning only k ≤ L parameters.
3. I MPLICIT R ECURRENCES
To identify which layers in a network perform approximately the same operation, we can simply check whether their coefﬁcients are similar.
We can condense this information for all pairs of layers i, j in a similarity matrix S , where S i,j = s ( α ( i ) , α ( j ) ) for some similarity measure s .
For networks with normalization layers, the network’s output is invariant to weight rescaling.
In this setting, a natural measure is s ( α ( i ) , α ( j ) )
=
|(cid:104)
α ( i ) , α ( j ) (cid:105)| (cid:107) α
( i ) (cid:107)(cid:107) α
( j ) (cid:107) (absolute of cosine similarity), since it pos- [Table] outperforms [Table]
[Table]
[Table] [Table] [Table] [Table]
sess this same property.
1 We call S the layer similarity matrix (LSM), and we show experimentally in Section 4.3 how it can be used to extract implicit recurrences from trained CNNs.
While structure might emerge naturally, having a bias towards more structured (recurrent) models might be desirable.
In this case, we can add a recurrence regularizer to the training objective, pushing parameters to values which result in more structure.
For example, we can add the negative of sum of elements of the LSM:
L R =
L − λ R (cid:80) i,j S i,j , where L is the original objective.
The larger λ R is, the closer the elements of S will be to 1 .
At an extreme case, this regularizer will push all elements in S to 1 , resulting in a network with a single layer and a self-loop.
E XPERIMENTS
We begin by training variants of standard models with soft parameter sharing, observing that it can offer parameter savings with little impact to performance, or increase performance at the same parameter count.
Section 4.3 demonstrates conversion of a trained model into explicitly recurrent form.
We then examine synthetic tasks (Section 4.4), where parameter sharing improves generalization.
Appendix B contains details on the initialization for the coefﬁcients α .
4. C LASSIFICATION ON CIFAR
The CIFAR-10 and CIFAR-100 datasets (Krizhevsky, 2009) are composed of 60 , 000 colored 32 ×images, labeled among 10 and 100 classes respectively, and split into 50 , 000 and 10 , 000 for training and testing.
We pre-process the training set with channel-wise normalization, and use horizontal ﬂips and random crops for data augmentation, following He et al.
Using Wide ResNets (WRN) (Zagoruyko & Komodakis, 2016) as a base model, we train networks with the proposed soft parameter sharing method.
Since convolution layers have different number of channels and kernel sizes throughout the network, we create 3 layer groups and only share templates among layers in the same group.
More speciﬁcally, WRNs for CIFAR consist of 3 stages whose inputs and outputs mostly have a constant number of channels ( C , 2 C and 4 C , for some C ).
Each stage contains L − 4layers for a network with depth L , hence we group layers in the same stage together, except for the ﬁrst two, a residual block whose input has a different number of channels.
Thus, all layers except for the ﬁrst 2 in each stage perform parameter sharing (illustrated in left diagram of Figure 4).
Having k templates per group means that L − 4 3 − 2 convolution layers share k parameter templates.
We denote by SWRN-
L - w - k a WRN with L layers, widen factor w and k parameter templates per group (trained with our method).
Setting k
=
L − 4 3 − 2 means we have [Figure] one parameter template per layer, and hence no parameter reduction.
We denote SWRN-
L - w (thus omitting k ) as a model in this setting
[Figure]
Following Zagoruyko & Komodakis (2016), we train each model for 200 epochs with SGD and
Nesterov momentum of 0 .
9 and a batch size of 128 .
The learning rate is initially set to 0 .
1 and decays by a factor of 5 at epochs 60, 120 and 160.
We also apply weight decay of 5 × 10 − 4 on all parameters except for the coefﬁcients α .
Table 1 presents results.
Networks trained with our method yielded superior performance in the setting with no parameter reduction: SWRN 28-10 presents 6 .
5% and 2 .
5% lower relative test errors on C-10 and C-100, compared to the base WRN 28-10 model.
With fewer templates than layers, SWRN 28-10-1 (all 6 layers of each group perform the same operation), performs virtually the same as the base WRN 28-10 network, while having 13 of its parameters.
On CIFAR-10, parameter reduction ( k = 2 ) is beneﬁcial to test performance: the best performance is achieved by SWRN 28-18-2 ( 3.43% test error ), outperforming the ResNeXt-29 16x64 model (Xie et al., 2016), while having fewer parameters (55M against 68M) and no bottleneck layers.
Figure 3 shows that our parameter sharing scheme uniformly improves accuracy-parameter efﬁciency; compare the WRN model family (solid red) to our SWRN models (dotted red).
4. C LASSIFICATION ON I MAGE N ET
We use the ILSVRC 2012 dataset (Russakovsky et al., 2015) as a stronger test of our method.
It is composed of 1 , 2 M training and 50 , 000 validation images, drawn from 1000 classes.
We follow Gross & Wilber (2016), as in Zagoruyko & Komodakis (2016);
Huang et al.
; Xie et al.
(2016), and report Top-1 and Top-5 errors on the validation set using single 224 × 224 crops.
For this experiment, we use a WRN 50-2 as base model, and train it with soft sharing and no parameter reduction.
Having bottleneck blocks, this model presents less uniform number of channels of layer inputs and outputs.
To apply our method, we group convolutions in 12 groups: for each of thestages in a WRN 50-2, we create 3 groups, one for each type of layer in a bottleneck unit ( C → B ,
B → B and B → C channel mappings, for bottleneck B ).
Without any change in hyperparameters, the network trained with our method outperforms the base model and also deeper models such as
[Table]
Conv W (1)
Conv W (2)
Conv α (3)
Conv α (4)
Conv α (5)
Conv α (6)
Conv α (7)
Conv α (8)
Templates T (1) T (2)
T (3) T (4)
Stage
Stage Stage
Conv W (2)
Conv W (3)
Conv W (4) 3x
Conv W (1)
Conv W (2)
Conv W (3)
Conv W (4)
Conv W (1)
Conv W (5)
Conv W (6) 2x
Folded Stage Folded Stage
DenseNets (though using more parameters), and performs close to ResNet-200, a model with four times the number of layers and a similar parameter count.
See Table 3.
4. L EARNING I MPLICIT R ECURRENCES
Results on CIFAR suggest that training networks with few parameter templates k in our soft sharing scheme results in performance comparable to the base models, which have signiﬁcantly more parameters.
The lower k is, the larger we should expect the layer similarities to be: in the extreme case where k = 1 , all layers in a sharing scheme have similarity 1 , and can be folded into a single layer with a self-loop (Figure 2).
For the case k > 1 , there is no trivial way to fold the network, as layer similarities depend on the learned coefﬁcients.
We can inspect the model’s layer similarity matrix (LSM) and see if it presents implicit recurrences: a form of recurrence in the rows/columns of the LSM.
Surprisingly, we observe that rich structures emerge in networks trained with soft parameter sharing.
Figure 4 shows the perstage LSM for CIFAR-trained SWRN 28-10-4.
Here, the six layers of its stage-2 block can be folded into a loop of two layers, leading to an error increase of only 0 .
Also see Appendix A.
4. E VALUATION ON N ATURALLY R ECURRENT T ASKS
While the propensity of our parameter sharing scheme to encourage learning of recurrent networks is a useful parameter reduction tool, we would also like to leverage it for qualitative advantage over standard CNNs.
On tasks for which a natural recurrent algorithm exists, does training CNNs with soft parameter sharing lead to better extrapolation?
To answer this question, we set up a synthetic algorithmic task: computing shortest paths.
Examples are 32 × 32 grids containing two query points and randomly placed obstacles (placed with probability 0 . 1 ).
The objective is to indicate which points in the grid belong to a shortest path between the query points.
250 epoch 0.
F 1 S c
o r e
CNNSCNNSCNN, R =0.
We use curriculum learning for training, allowing us to observe how well each model adapts to more difﬁcult examples as training phases progress.
Moreover, for this task curriculum learning causes faster learning and superior performance for all trained models.
Training consists of 5 curriculum phases, each one containing 5000 examples.
The maximum allowed distance between the two query points increases at each phase, thus increasing difﬁculty.
In the ﬁrst phase, each query point is within a 5 × 5 grid around the other query point, and the grid size increases by 2 on each side at each phase, yielding a ﬁnal grid size of 21 × 21 at phase 5.
We train a CNN, a CNN with soft parameter sharing and one template per layer (SCNN), and an
SCNN with recurrence regularizer λ R = 0 .
Each model trains for 50 epochs per phase with
Adam (Kingma & Ba, 2014) and a ﬁxed learning rate of 0 .
As classes are heavily unbalanced and the balance itself changes during phases, we compare F 1 scores instead of classiﬁcation error.
Each model starts with a 1 × 1 convolution, mapping the 2 input channels to 32 output channels.
Next, there are 20 channel-preserving 3 × 3 convolutions, followed by a ﬁnal 1 × 1 convolution that maps 32 channels to 1.
Each of the 20 3 × 3 convolutions is followed by batch normalization (Ioffe & Szegedy, 2015), a ReLU non-linearity (Nair & Hinton, 2010) and has a 1-skip connection.
Figure 5 shows one example from our generated dataset and the training curves for the 3 trained models: the SCNN not only outperforms the CNN, but adapts better to harder examples at new curriculum phases.
The SCNN is also advantaged over a more RNN-like model: with the recurrence regularizer λ R = 0 . 01 , all entries in the LSM quickly converge 1 , as in a RNN. This leads to faster learning during the ﬁrst phase, but presents issues in adapting to difﬁculty changes in latter phases.
C ONCLUSION
In this work, we took a step toward more modular and interpretable CNNs by extracting recurrences from feed-forward models where parameters are shared among layers.
Experimentally, parameter sharing yields models with lower error on CIFAR and ImageNet, and can be used for parameter reduction by training in a regime with fewer parameter templates than layers.
Moreover, we observed that parameter sharing often leads to different layers being functionally equivalent after training, enabling us to collapse them into recurrent blocks.
Results on an algorithmic task suggest that our shared parameter structure beneﬁcially biases extrapolation.
We gain a more ﬂexible form of behavior typically attributed to RNNs, as our networks adapt better to out-of-domain examples.
As the only requirement for our method is for a network to have groups of layers with matching parameter sizes, it can be applied to a plethora of CNN model families, making it a general technique with negligible computational cost.
We hope to raise questions regarding the rigid deﬁnitions of
CNNs and RNNs, and increase interest in models that fall between these deﬁnitions.
Finally, we point out that adapting our method for models with non-uniform layer parameter sizes (Huang et al., 2016; Zhu et al., 2018) might be of particular future interest.
Appendix A A DDITIONAL R ESULTS FOR I MPLICIT R ECURRENCES
Section 4.3 presented an example of implicit recurrences and folding of a SWRN 28-10-4 trained on CIFAR-10, where, for example, the last 6 layers in the second stage of the network fold intolayers with a self-loop
Here we present an additional example, where non-trivial recurrences (unlike the one in Figure 4) emerge naturally, resulting in a model that is rich in structure.
See Figure
[Figure]
B I NITIALIZATION OF C OEFFICIENTS
During our initial experiments, we explored different initializations for the coefﬁcients α of each layer, and observed that using an orthogonal initialization (Saxe et al., 2013) resulted in superior performance compared to uniform or normal initialization schemes.
Denote A as the L × k matrix ( L is the number of layers sharing parameters and k the number of templates) with each i ’th row containing the coefﬁcient of the i ’th layer α ( i ) .
We initialize it such that
A T A
=
I , leading to ∀ i , (cid:104) α
( i ) , α ( i ) (cid:105)
= 1 and ∀
i (cid:54) =
j , (cid:104)
α
( i ) , α ( j ) (cid:105) = 0 .
While our choice for this was mostly empirical, we believe that there is likely a connection with the motivation for using orthogonal initialization for RNNs.
Moreover, we discovered that other initialization options for A work similarly to the orthogonal one.
More speciﬁcally, either initializing A with the identity matrix when L = k (which naturally leads to A T A
= I )
or enforcing some sparsity (initialize A with a uniform or normal distribution and randomly setting half of its entries to zero) performed similarly to the orthogonal initialization in a consistent manner.
We believe the sparse initialization to be the simplest one, as each coefﬁcient α can be initialized independenty.
Finally, note that having A T A
= I results in the Layer Similarity Matrix also being the identity at initialization (check that S i,j = |(cid:104)
α
( i ) , α ( j ) (cid:105)| (cid:107) α
( i ) (cid:107)(cid:107) α
( j ) (cid:107) =
| ( A T A ) i,j | (cid:107) α
( i ) (cid:107)(cid:107) α
( j ) (cid:107) , so if ( A T A )
i,j = 1 , then S i,j = 1 , and the same holds for 0 .
Surprisingly, even though the orthogonal initialization leads to a LSM that has no structure in the beginning of training, the rich patterns that we observe still emerge naturally after optimization.