A Simple Fix for Convolutional Neural Network via Coordinate Embedding

03/24/2020 ∙ by Liliang Ren, et al. ∙ University of California, San Diego 59

Convolutional Neural Networks (CNN) has been widely applied in the realm of computer vision. However, given the fact that CNN models are translation invariant, they are not aware of the coordinate information of each pixel. Thus the generalization ability of CNN will be limited since the coordinate information is crucial for a model to learn affine transformations which directly operate on the coordinate of each pixel. In this project, we proposed a simple approach to incorporate the coordinate information to the CNN model through coordinate embedding. Our approach does not change the downstream model architecture and can be easily applied to the pre-trained models for the task like object detection. Our experiments on the German Traffic Sign Detection Benchmark show that our approach not only significantly improve the model performance but also have better robustness with respect to the affine transformation.



There are no comments yet.


page 2

page 4

page 5

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Convolutional Neural Networks (CNN) have enjoyed a wide range of applications as the most effective tool in the field of computer vision. In contrast with fully-connected neural networks, CNN exploit the image property of translation invariance for parameter sharing and thus reduce the computational complexity and improve the generalization ability.

For the object recognition task, many one-stage CNN models that directly optimized on bounding box regression and ROI classification (e.g. Single Shot Detector (SSD)[5] and YOLO [6]) have been widely applied to the real world application scenarios. However, since CNN only has translation invariance and is not aware of the coordinates of each of the pixel in the image, its generalization ability will be limited when the affine distortion happens to the objects in the image. This kind of distortion commonly occurs in the object detection tasks when the objects are observed from different perspectives in the real world.

Some detection models have taken advantage of layers to learn simple coordinate transformation, but they have been illustrated the inability with respect to spatial transformation between dense Cartesian representation and a sparse, pixel-based representation [4]. One feasible solution is using extra coordinate channels in convolutional layer, which is called CoordConv layer [4]. However, since this approach needs to change every convolutional layer to the CoordConv layer, it can not be applied to most of the pre-trained models that use vanilla convolutions, which harms the universality of this approach.

Contribution: In this paper, we propose to incorporate the coordinate information through two learnable coordinate embeddings which are normalized and only added to each channel of the initial input image. Thus our approach does not change the downstream model architecture and can be applied to any pre-trained models in the tasks such as object object detection and recognition. Our experiments on a traffic sign detection dataset show that our approach not only significantly improve the model performance but also have better robustness with respect to the affine transformation.

Figure 1: The prediction results of Convolutional Neural Network on the Supervised Coordinate Classification and Regression tasks proposed by Liu et al. [4].
Figure 2: The structure of CoordConv layers (Left) and an object detection architecture with CoordConv (Right) proposed by Liu et al. [4].

2 Related work

CNN models for traffic sign detection. Traffic sign detection is slightly different from common object detection scenarios. For simplicity, the frame of traffic sign is always in fundamental shapes and basic colors, such as red cycle, black rectangle and so forth. Meanwhile, central pictograph represents meaning of traffic signs. But for complexity, bad physical conditions like shadow, deformation and rust in reality are expected to be a major challenge in the detection process. Thus, detectors that excel in recognizing real-time transformation with high detection accuracy are in demand.

Generally, current CNN models for German Traffic Sign Detection Benchmark (GTSDB) [1] are based on the various state-of-the-art object detection models, such as Faster R-CNN, R-FCN, SSD, and YOLO. They first initialize the model parameters pre-trained on the COCO dataset [3], and then fine-tune them on the traffic sign detection datasets with backbone image feature extractors like Resnet V1 101, Inception V2, Inception Resnet V2, and Mobilenet V1. Finally, take key metrics, including mean average precision (mAP) and execution time for a batch size of one, to evaluate and compare outcomes over four categorised traffic sign detection. As selected results shown in Table 1, modules do not balance very well between mAP and running time.

Model mAP Latency
Faster R-CNN Inception Resnet V2 98.77 500 ms
YOLO V2 78.33 21.48 ms
SSD Inception V2 66.10 15.14 ms
Table 1: The mAP and latency measurement on the simplified traffic sign categories as being a) Prohibitory, b) Mandatory, c) Danger, or d) Other, for various kinds of object detection models on the GTSDB test set.

Failing of CNN. A simple classification and regression task conducted by Liu et al. [4] clearly illustrates the defect of CNN towards coordinate transform. As Figure 1 shown, with the goal of highlighting one-hot pixels via learning in Cartesian coordinate space, it turned out CNN performed well over training set in spite of uncertain noises emerging. However, prediction over testing set receive a large fail to generalize highlight pixels. Likewise, the similar outcomes happened in regression task. Thus far, the test argued that CNN had much difficulties dealing with coordinate transform problem.

One solution that has been proposed is to replace the convolutional layer with the CoordConv layer [4]. As shown in Figure 2, two more input coordinate channels are give to convolution layer, ensuring CNN to learn complete coordinate information. In practical operation, and coordinates layers are simply filled with row numbers or coulum numbers. Since extra channels are added to the original features, this approach introduces new kernel parameters in the following convolutional layers. The right part of Figure 2 shows that these extra channels should be added throughout the model, and thus this approach can not be applied to the pretrained CNN models that use the traditional convolutional layers.

3 Coordinate Embedding - A Simple Fix

Figure 3: The structure of the Coordinate Embedding layer.

As shown in Figure 3, we construct the Coordinate Embedding (CoordEmb) using two trainable matrices to embed the x coordinate and y coordinate information of the input image respectively, where is the height of the input image, is the image width and represents the number of the image channels. Since the original input image is normalized to be in the range , we also require the initial value of the x-dim embedding and y-dim embedding be normalized in the range . The final output of the coordinate embedding layer, , is normalized to maintain the data range of the original image,

The coordinate information is introduced through an initialization of the x-dim and y-dim embeddings with their normalized x and y coordinates separately, as depicted in Figure 4.

Our approach only introduced new parameters at the very beginning of the original CNN model with the number of the 2/3 size of the input image. Thus it can be applied to any downstream CNN models for any two dimensional computer vision tasks, and our approach can be simply extended to the three dimensional tasks by adding a new z-dimensional embedding matrix. The downside of our approach is that the model parameters will then be proportional to size of the input image and the translation invariance is harmed by introducing the positional information. However, considering the fact that human eyes have a fixed number of receptors on the retina, the scale of the vision signals into human retina are actually fixed sized images and those receptors may have different activation bias due to their positions on the human retina, and this kind of activation bias is what actually modeled by our coordinate embedding matrix. This kind of positional activation bias of the retina receptors is important and can be exemplified with the fact that human is more sensible to the moving objects near the edges of the Field of View (FoV) than the moving objects that happens in the center of FoV, which helps the ancient human beings to be more easily alerted for the incoming dangers and survive.

As for the harm of the translation invariance possessed by the vanilla CNN, we believe that any kinds of invariance should be learned as model parameters through the interaction between the model and the environment. Given the fact that affine invariance is not favorable in all conditions of vision cognition (e.g. a common visual illusion image that can be viewed as duck in one rotation angle and also viewed as a rabbit in the other angle), we in turn hypothesize that the invariance property should be as the learned model parameters that can be applied locally on the input image but not as the structure priors through the design of the model architecture that applies globally to the whole input image.

Figure 4: The initialization for the x-dim embedding and the y-dim embedding

4 Experimentation

The sections below describe the dataset setup and the specific architecture of the downstream CNN model.

4.1 Datasets

We evaluate Coordinate embedding CNN using German Traffic Sign Detection Benchmark (GTSDB) [2], which has been highly accepted and typically used for studies in traffic sign detection field. This dataset contains 900 full images including 1206 traffic signs from 43 categories. 600 images with 846 traffic signs are arranged for training purpose and the rest 300 images with 360 traffic signs for testing consideration. Arcos (2018) et al. [1] categorised traffic sign as being a) Prohibitory, b) Mandatory, c) Danger, or d) Other, and detailed sign labels were discarded in their analysis. Note that the initiative wins in mAP as well as execution time, but four categories is less instructive in practical application like an autonomous driving or driving assistance system. Thus in our experiments, we use the full 43 categories for both model training and evaluation.

Figure 5: A sample image from GTSDB

4.2 Single Shot Detector (SSD)

In this project, the official Tensorflow implementation

111https://github.com/tensorflow/models/blob/master/research/object_detection/models/ssd_inception_v2_feature_extractor.py of the Single Shot Detector with Inception V2 backbone (SSD Inception V2)[5] is applied as the downstream CNN model. Specifically, for a given input image with ground truth labels, SSD will do the following:

Firstly, transfer the image through a series of convolutional layers, producing several sets of feature maps at different scales.

Secondly, for each location in each of these feature maps, use a 3x3 convolutional filter to evaluate a small set of default bounding boxes.

Thirdly, for each box, simultaneously predict: a) the bounding box offset, and b) the class probabilities

Lastly, during training, match the ground truth box with these predicted boxes based on Jaccard index. The best predicted box will be labeled a “positive,” along with all other boxes that have an Jaccard index with the truth


Our downstream CNN model is initialized with the parameters pre-trained on the COCO dataset, and the whole model including the CoordEmb layer is fine-tuned on the GTSDB dataset with the RMSprop optimizer using a learning rate of 0.004 for 155k training steps with a batch size of 24.

5 Results

Figure 6: The mAP scores on the test set of GTSDB with respect to the training steps for the vanilla SSD Inception V2 (in dark blue) model and the CoordEmb+SSD Inception V2 model (in light blue).

Figure 6 shows the mAP scores on the test set of GTSDB with respect to the training steps for the vanilla SSD Inception V2 (in dark blue) model and the SSD Inception V2 model with CoordEmb layer added at the very beginning stage of the input image (in light blue). We can observe that the model with our proposed CoordEmb consistently outperforms the vanilla model regarding to the metric of mAP throughout the training steps. The final converged mAP of the baseline model is 0.2041, while it is 0.2288 for the model with the CoordEmb, which means that our approach can bring a significant 2.47% absolute mAP performance boost compared with the vanilla SSD Inception V2 model.

From Figure 6, we can also see that our model is especially good at detecting the small and medium sized objects, while have a similar performance on the large sized objects compared with the vanilla model. This is because the small traffic signs often exists at the sides of the road that is far in distance and thus is often near the edges of the image. Our coordinate embeddings can capture this kind of relation between the positions and the objects and boosts the sensitivity of the model detections with respect to the small traffic signs.

(a) SSD Inceptino V2
(b) CoordEmb+SSD Inception V2
Figure 7: GTSDB sample detection results
(a) SSD Inception V2
(b) CoordEmb+SSD Inception V2
(c) SSD Inception V2
(d) CoordEmb+SSD Inception V2
Figure 8: The object detection results for the affine distorted images

6 Qualitative Analysis

To consider the comprehensive performance of proposed model in real world detection scenarios, we qualitatively compare the model performance on both the images from the test set of GTSDB and the images with the affine distortion.

Label Original CNN CoordEmb CNN
No entry 99% 99%
Keep right 99% 99%
Speed limit 70 (left) 96% 99%
Speed limit 70 (right) 94% 99%
Table 2: the Confidence score of the model

Figure 7 and Table 2 reveal that CoordEmb model has equal share with vanilla model in regard of traffic signs large size, i.e., No entry, Keep right, but holds much more confidence with respect to small and marginal traffic signs, such as two speed limit at the far end, increasing accuracy in magnitude of 3% and 5% respectively. Besides, proposed model is significantly superior when slight coordinate transformations happen on detected object. Figure 8 shows two special cases in detection, where traffic signs are not well-placed from the perspective of detector, our model is still robust with acceptable reliability of 55% and 93%. In contrast, vanilla model has assigned them to unrecognizable cases. The outcomes remarkably corroborate the model’s capability of sensitive detection in reality.

7 Conclusion and future work

In this paper, we proposed a novel Coordinate Embedding (CoordEmb) approach that introducing the positional information to CNN models with the following advantages: (1) it adds minimal extra computations and parameters to the original model. (2) it can be applied to the existing pretrained CNN models without model architecture modification. (3) the model with CoordEmb significantly beats the vanilla CNN model on the traffic sign detection task. (4) it enables the model with CoordEmb to be more robustness with respect to the affine distortion compared with the vanilla CNN model.

Our future work is to test our CoordEmb approach on a larger scale of dataset like COCO[3] to see if it can boost the performance of the state-of-the-art models, and to compare the CoordEmb model trained from scratch with the CoordConv approach to see if our approach can give better results apart from the fine-tuning paradigm.


  • [1] A. Arcos-Garcia, J. A. Alvarez-Garcia, and L. M. Soria-Morillo (2018) Evaluation of deep neural networks for traffic sign detection systems. Neurocomputing 316, pp. 332–344. Cited by: §2, §4.1.
  • [2] S. Houben, J. Stallkamp, J. Salmen, M. Schlipsing, and C. Igel (2013) Detection of traffic signs in real-world images: the german traffic sign detection benchmark. In The 2013 international joint conference on neural networks (IJCNN), pp. 1–8. Cited by: §4.1.
  • [3] T. Lin, M. Maire, S. Belongie, J. Hays, P. Perona, D. Ramanan, P. Dollár, and C. L. Zitnick (2014) Microsoft coco: common objects in context. In European conference on computer vision, pp. 740–755. Cited by: §2, §7.
  • [4] R. Liu, J. Lehman, P. Molino, F. P. Such, E. Frank, A. Sergeev, and J. Yosinski (2018) An intriguing failing of convolutional neural networks and the coordconv solution. In Advances in Neural Information Processing Systems, pp. 9605–9616. Cited by: Figure 1, Figure 2, §1, §2, §2.
  • [5] W. Liu, D. Anguelov, D. Erhan, C. Szegedy, S. Reed, C. Fu, and A. C. Berg (2016) Ssd: single shot multibox detector. In European conference on computer vision, pp. 21–37. Cited by: §1, §4.2.
  • [6] J. Redmon and A. Farhadi (2017) YOLO9000: better, faster, stronger. In

    Proceedings of the IEEE conference on computer vision and pattern recognition

    pp. 7263–7271. Cited by: §1.