← All articles

capsule networkshandwritingindic scriptsimage classification

Capsule networks learn handwritten Bangla, Devanagari and Telugu quickly, and make AlexNet a little better

Handwritten character recognition is an old test for neural networks, and the usual tool is the convolutional network. A newer design called the capsule network lets groups of filters work together, which is meant to deal with the relative position of parts better. In this paper we trained capsule networks to read handwritten digits and characters in three Indian scripts, and compared them with two classic networks, LeNet and AlexNet.

What a normal network misses

A convolutional network works with small filters (kernels) that slide across an image. Each filter detects one pattern, such as a curve or a stroke, wherever it appears. This makes the network good at finding features, but the filters do not talk to each other. If two filters detect two parts of a shape, the network reports the same strength whether or not those parts sit in the right places relative to each other.

People are good at judging how the parts of an object are arranged. Capsule networks, proposed by Sabour, Frosst and Hinton, try to build this in.

How a capsule network differs

A capsule is a group of filters that work together and output a small vector instead of a single number. After an ordinary first convolution layer comes the layer of primary capsules. The last layer has one capsule per class, for example one for each digit.

In between sits dynamic routing. Each primary capsule gives its own opinion about what each class capsule should look like. The network then combines those opinions, checks how well each one agrees with the combined answer, and gives more weight to the capsules that agree. It repeats this a few times for every image. The length of each class capsule becomes the score for that class.

Schematic of a capsule network: an input image, a primary capsule layer built from several groups of convolutions, then a reshape into a grid of capsules that connect to one capsule per class, with the symbols used in the paper listed underneath.
The primary capsules (middle) group filters together. They then vote on the class capsules (right) through dynamic routing.Source: Fig. 2 of the paper.

What we tested

We used five datasets from the CMATERdb collection: digits in Bangla, Devanagari and Telugu (10 classes each), Bangla basic characters (50 classes) and Bangla compound characters (199 classes). We split each set into training and test data in a 2:1 ratio.

The capsule network has about 8.2 million parameters (the numbers a network learns) (Table I). LeNet has around 61 thousand and AlexNet around 57 million, so AlexNet is almost seven times larger than the capsule network. Besides the three networks alone, we also averaged the output probabilities of pairs of them and of all three.

What we found

The capsule network beat LeNet on every dataset. The gap was small on the digit sets and large on Bangla basic characters, where LeNet scored 63.0% and the capsule network 90.6%. On Bangla compound characters, the 199-class problem, the scores were 75.4% and 79.3% (Table II).

AlexNet, the larger network, scored higher than the capsule network on every dataset, for example 94.2% against 79.3% on compound characters. Its mean accuracy over the five sets was 96.29%, against 91.65% for the capsule network (Table II). The capsule network did learn faster, though. Its test accuracy has the steepest slope in the first few epochs, which are passes over the training data.

Five line charts of test accuracy against training epochs, one per dataset, with a curve each for the capsule network, LeNet and AlexNet. The capsule network curve rises fastest at the start in every chart.
The green capsule network curve shoots up within a few epochs. LeNet (orange) is slowest, and on Bangla basic characters it is still far behind at the end of the 200 or so epochs plotted.Source: Fig. 3 of the paper.
Averaging AlexNet with the capsule network gave the best mean accuracy, 96.51%, slightly above AlexNet alone at 96.29% (Table II).

The combination helped on all five datasets, for instance 96.2% against 95.9% on Bangla basic characters. Averaging LeNet with AlexNet made AlexNet worse on every dataset. We read this as a sign that the capsule network picks up something AlexNet misses, despite having far fewer parameters (Table II). For Telugu digits the best result, 97.8%, came from combining all three networks. For the other four sets the best result came from AlexNet plus the capsule network. Table III lists earlier published results on the same datasets next to our best combinations, for instance 94.40% for compound characters against 93.12% from an earlier paper.

Results in more detail

Table II holds the full set of numbers: test accuracy for each of the seven models on each of the five datasets, plus the mean over the five datasets with its standard deviation in brackets (a small deviation means the model did about equally well everywhere). The rows with a plus sign are ensembles, where the output probabilities of two or three networks were averaged. We report the model that was best in terms of training accuracy, and the images were resized to the size each network expects: 28×28 pixels for the capsule network, 32×32 for LeNet and 227×227 for AlexNet.

Test accuracy (%) of each network and each ensemble
ArchitectureBengali digitsDevanagari digitsTelugu digitsBengali basic charactersBengali compound charactersMean (std. dev.)
LeNet94.692.195.863.075.484.18 (±14.42)
AlexNet97.6596.397.495.994.296.29 (±1.39)
CapsNet97.3594.896.290.679.391.65 (±7.36)
LeNet+AlexNet97.696.297.395.892.695.9 (±1.99)
LeNet+CapsNet95.459496.288.479.990.79 (±6.81)
AlexNet+CapsNet97.7596.697.696.294.496.51 (±1.35)
All combined97.596.597.896.175.292.62 (±9.76)
Higher accuracy is better. CapsNet is the capsule network. Source: Table II of the paper.

LeNet has the largest spread across datasets, and AlexNet plus the capsule network has the smallest spread and the highest mean. The paper says LeNet fails poorly on the two character datasets, while the capsule network held up much better when there were many classes. Adding the capsule network to LeNet also lifted LeNet's own scores on every dataset, for instance from 63.0% to 88.4% on Bangla basic characters (Table II).

Table III puts our best combination for each dataset next to earlier results that other groups published for the same datasets. I list every comparison the paper gives. In each of the five cases, our figure is the higher number in the table.

Our best combination compared with earlier published results
DatasetOur approachAccuracy (%)Other approachAccuracy (%)
Bangla digitsAlexNet + CapsNet97.75Basu et al. [6]96.67
Bangla digitsAlexNet + CapsNet97.75Roy et al. [7]95.08
Bangla digitsAlexNet + CapsNet97.75Roy et al. [8]97.45
Devanagari digitsAlexNet + CapsNet96.60Das et al. [9]90.44
Devanagari digitsAlexNet + CapsNet96.60Roy et al. [8]96.50
Telugu digitsAlexNet + CapsNet + LeNet97.80Sarkhel et al. [10]97.50
Telugu digitsAlexNet + CapsNet + LeNet97.80Roy et al. [8]87.20
Bangla basic charactersAlexNet + CapsNet96.20Sarkhel et al. [10]86.53
Bangla basic charactersAlexNet + CapsNet96.20Bhattacharya et al. [11]92.15
Bangla compound charactersAlexNet + CapsNet94.40Roy et al. [12]90.33
Bangla compound charactersAlexNet + CapsNet94.40Pal et al. [13]93.12
Bangla compound charactersAlexNet + CapsNet94.40Sarkhel et al. [14]86.64
Bracketed numbers are the paper's reference numbers. Higher accuracy is better. Source: Table III of the paper.

The size of the capsule network is listed layer by layer in Table I. It has a first convolution layer, the primary capsule layer, the digit capsule layer that holds one capsule per class, and a three-layer decoder that tries to rebuild the input image. The decoder is there to stop overfitting, which means memorising the training set. Its error is scaled down by a factor of 0.0005 so that it does not dominate the main loss. Most of the 8,227,088 parameters sit in the primary capsule layer, and only around 11 thousand are set at run time by dynamic routing.

Layers of the capsule network for a single-channel input and ten classes
LayerKernel sizeStrideInput channelsOutput channelsWeights + biasesRouting weights
Convolution91125620,992NA
Primary Caps92256325,308,6720
Digit CapsNANA1,152101,474,56011,520
Decoder FCNANA16051282,432NA
Decoder FCNANA5121,024525,312NA
Decoder FCNANA1,024784803,600NA
Total number of parameters8,227,088
A selection of the columns of Table I (padding and capsule dimensions are left out). Source: Table I of the paper.

The price of routing is time. For every image the routing weights are tuned again, as many times as there are routing iterations, and each pass computes one coupling coefficient for every pair of a primary capsule and a class. That makes each training step slow. Even so, the capsule network learned faster than LeNet and AlexNet when we plot accuracy against epochs (Fig. 3). All models were trained with the Adam optimiser at an initial learning rate of 0.001, on an Nvidia Quadro P5000 graphics card.

Discussion

We conclude that capsule networks are much better than LeNet on these handwriting datasets and that they cope well with a large number of classes. They also learn faster. We take the results to show that the capsule network picks up information that even AlexNet, with about seven times more parameters, does not capture. That is why adding it to AlexNet helped on all five datasets, while adding LeNet to AlexNet always hurt. The best score came from AlexNet plus the capsule network on four datasets, and from all three networks on Telugu digits.

The limits show in the numbers and in our own text. On its own, the capsule network never reached AlexNet's accuracy, and the gap is widest on the 199-class compound characters, 79.3% against 94.2% (Table II). Combining all three networks did not help there either, at 75.2%. The routing is also slow, because it must be repeated for each sample, and the design allows routing in one layer only.

We see a use for capsule networks in two places: learning with far fewer parameters, and as a booster for larger networks. The slow routing and the single routing layer open up many avenues for research, and that is why we saw this work as a starting point.

Sources

The figures and tables listed here are taken from the paper cited at the top of this page; the numbers quoted in the text come from it too.

  • Figures: Fig. 2, Fig. 3
  • Tables: Table I: layer-by-layer specification and parameter count of the capsule network; Table II: test accuracy of each network and each combination on the five datasets; Table III: our best results next to earlier published results on the same datasets

Acknowledgements

This work was partially supported by the project order no. SB/S3/EECE/054/2016, dated 25/11/2016, sponsored by SERB (Government of India), and carried out at the Centre for Microprocessor Application for Training Education and Research, CSE Department, Jadavpur University.

Cite the paper

B Mandal, S Dubey, Swarnendu Ghosh, R Sarkhel, N Das (2018). Handwritten Indic character recognition using capsule networks. 2018 IEEE Applied Signal Processing Conference (ASPCON), pp. 304–308 · IEEE.

BibTeX
@inproceedings{mandal2018handwritten,
  author    = {Mandal, B and Dubey, S and Ghosh, Swarnendu and Sarkhel, R and Das, N},
  title     = {Handwritten Indic character recognition using capsule networks},
  booktitle = {2018 IEEE Applied Signal Processing Conference (ASPCON)},
  pages     = {304--308},
  publisher = {IEEE},
  year      = {2018},
  doi       = {10.1109/aspcon.2018.8748550}
}