使用深度学习对交通标志进行分类

Traffic-sign recognition (TSR) technology- a technology by which a vehicle is able to recognize the traffic signs that are placed on the road e.g. “ Turn right ahead”, “Speed limit”, or “Stop” etc.- can be implemented using CNNs. This is important because a prompt response to real-time traffic events can prevent road accidents.This article will explain all the steps taken to design a Deep Learning model to do that.

可以实施交通标志识别 (TSR)技术-一种车辆能够识别道路上交通标志的技术,例如“向右转”,“限速”或“停车”等。使用CNN。 这很重要,因为对实时交通事件做出SwiftReact可以预防道路交通事故。本文将解释设计深度学习模型以实现此目的的所有步骤。

1.导入库和数据集 (1. Importing Libraries and Dataset)

Key python libraries will be imported.

关键的python库将被导入。

Image for post

The dataset used is a German Traffic Sign Dataset. We will use around 34,800 images for training dataset, 12630 images for test dataset and 4410 images for validation dataset.

使用的数据集是德国交通标志数据集 。 我们将使用约34,800张图像作为训练数据集,使用12630张图像作为测试数据集,并使用4410张图像作为验证数据集。

Image for post

2.显示数据集 (2. Displaying the Dataset)

You can display the dataset using the following code:

您可以使用以下代码显示数据集:

Image for post
Image for post

3.图像标准化 (3. Normalization of Images)

Data is shuffled to prevent the neural network from learning the order of images. RGB pixels are averaged by dividing by 3. Then, RGB images must be transformed to Grayscale before performing Normalization.

对数据进行混洗以防止神经网络学习图像的顺序。 RGB像素除以3求平均值。然后,在执行归一化之前,必须将RGB图像转换为灰度。

Image for post
Image for post

The gray scale and normalized images can then be visualized.

然后可以显示灰度和标准化图像。

Image for post
Image for post

4.建立CNN模型 (4. Building a CNN Model)

Convolutions are applied to extract features from the images. As input, a CNN takes tensors of shape (image_height, image_width, color_channels), here color_channels will be 1 since we have converted colored images to gray-scale ones.

应用卷积从图像中提取特征。 作为输入,CNN采用张量形状(image_height,image_width,color_channels),在这里color_channels将为1,因为我们已将彩色图像转换为灰度图像。

The code below defines the convolution base using a common pattern: a stack of Conv2D and MaxPooling2D layers.

下面的代码使用一种常见的模式定义了卷积基础: Conv2DMaxPooling2D图层的堆栈。

ReLU is used in the hidden layers as it can make the training speed of deep neural networks faster as compared to traditional activation functions. If the input is positive, the derivative of ReLu is 1 which is a constant, thus deep neural networks do not need to take extra time for computation of error terms during training phase.

ReLU用于隐藏层中,因为与传统的激活函数相比,它可以使深度神经网络的训练速度更快。 如果输入为正,则ReLu的导数为1,这是一个常数,因此深度神经网络在训练阶段不需要花费额外的时间来计算误差项。

Average pooling involves calculating the average for each patch of the feature map. This means that each square of the feature map is down sampled to the average value in the square. Dropout is used to reduce over-fitting.

平均池化涉及为特征图的每个面片计算平均值。 这意味着将特征图的每个正方形下采样到该正方形中的平均值。 压差用于减少过度拟合。

Image for post

Output tensor from the convolutional base (of shape (10,10, 16)) is fed into Conv2D layer, which outputs a tensor (of shape (5,5,16)) which is flattened first-as Dense layers take vectors as input (which are 1D)- and then fed into Dense layers to perform classification.

来自卷积基数(形状(10,10,16))的输出张量被馈送到Conv2D层,后者输出一个张量(形状(5,5,16))的张量,该张量首先被展平-因为密集层将向量作为输入(一维)-然后馈入密集层以执行分类。

Image for post

The datset has 43 output classes, so you use a final Dense layer with 43 outputs and a softmax activation, which assigns decimal probabilities to each class in a multi-class problem. These decimal probabilities must add up to 1.0.

该数据集具有43个输出类,因此您使用具有43个输出和softmax激活的最终Dense层,该层为多类问题中的每个类分配十进制概率。 这些十进制概率之和必须为1.0。

5.训练深度CNN模型 (5. Training the Deep CNN Model)

Adam optimizer is used since its uses performs the best on average, while compiling the CNN.compile, along with loss= sparse-categrical_crossentropy . since our classes are mutually exclusive, meaning each sample belongs exactly to one class.

之所以使用Adam优化器,是因为它的使用平均表现最佳,同时可以编译CNN.compile以及loss = sparse-categrical_crossentropy 。 由于我们的类是互斥的,这意味着每个样本完全属于一个类。

Image for post

6.评估绩效 (6. Evaluating Performance)

CNN.evaluate is used to assess the performance of a CNN, here we can see around 80% test accuracy.

CNN.evaluate用于评估CNN的性能,在这里我们可以看到大约80%的测试准确性。

Image for post

Training and Validation Loss:

培训和验证损失:

Image for post

Training and Validation Accuracy:

培训和验证准确性:

Image for post

Plotting a Confusion Matrix

绘制混淆矩阵

Here, a Confusion Matrix is used to evaluate the quality of the output of a classifier on a dataset. In this plot, the diagonal elements represent the number of points for which the predicted label is equal to the true label, while off-diagonal elements are those that are mislabeled by the classifier. The higher the diagonal values of the confusion matrix the better, indicating many correct predictions. True labels are along the y-axis while predicted labels are on the x axis.

在这里,混淆矩阵用于评估数据集上分类器输出的质量。 在该图中,对角线元素表示预测标签等于真实标签的点数,而对角线元素则是分类器未正确标记的元素。 混淆矩阵的对角线值越高,表示对数越多越好。 真实标签沿y轴,而预测标签沿x轴。

Image for post
Image for post

Displaying the Output Images with Classes:

显示带有类的输出图像:

Image for post

The above output shows that, if an image of traffic signs is input, then it can be classified accurately.

以上输出显示,如果输入了交通标志图像,则可以对其进行准确分类。

Citation J. Stallkamp, M. Schlipsing, J. Salmen, and C. Igel. The German Traffic Sign Recognition Benchmark: A multi-class classification competition. In Proceedings of the IEEE International Joint Conference on Neural Networks, pages 1453–1460. 2011. Coursera Project Network

引用J. Stallkamp,M。Schlipsing,J。Salmen和C. Igel。 德国交通标志识别基准测试:多类别分类比赛。 在IEEE国际神经网络联合会议录中,第1453–1460页。 2011. Coursera项目网络

翻译自: https://medium.com/swlh/classification-of-traffic-signs-using-deep-learning-d6c79e95db5f

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值