一种基于深度学习的图像识别技术在计量仪表读取方向的新算法。
背景技术:
1、随着智能制造和图像识别技术的不断发展,对于仪器仪表状态的实时监测变得越来越重要。用电几乎已经实现了数字化,智能电表、网上缴费已经普及。但用水、用气还没跟上,这主要是因为水表、气表比电表更难更换,又要入户、又要动管道,还不能影响居民的正常生活和商业用户的正常营业。而用水、用气作为各类企业用能管理中的重要内容之一,实现数字化转型需要投入大量的资金,并且时常作为传统大型市政系统的附属部分一同改造,无法得到有效的重视。
技术实现思路
1、本发明提供了一种基于深度学习的图像识别技术在计量仪表读取方向的新算法,深度学习的图像识别技术原理及构建步骤如下:
2、(1)数据预处理
3、在进行图像识别之前,需要先对数据进行预处理。首先,我们需要从现场采集的仪表图像中提取roi(感兴趣区域)。其次,对采集到的图像进行裁剪、缩放等操作以便于后续处理。
4、(2)特征提取
5、在这个步骤中,我们需要使用卷积神经网络(cnn)来提取图像特征。cnn 是一种深度学习模型,通常用于图像处理和语音识别等领域,可以自动从图像中提取特征,它的核心思想是通过卷积层、池化层和全连接层来提取特征,并使用反向传播算法进行训练和优化。通过对大量训练样本进行学习,网络可以自动识别出影响结果的特征。
6、具体而言,要建立一个cnn模型,我们首先需要确定网络结构。常见的cnn模型包括lenet、alexnet、vgg、googlenet和resnet等。根据具体应用场景和数据集的大小,可以选择不同的网络结构来完成任务。例如,在此次申请的专利中采用了resnet50网络结构进行特征提取。相比于其他模型,resnet50更深,因此能够提取更丰富的特征。另外,resnet50还引入了残差块(residual block),使得网络更加容易训练。在每个残差块中,输入的数据会被复制到多个分支,并在每个分支上进行不同的操作,最后再将这些分支的结果合并起来。这种设计方式可以避免梯度消失的问题,并且能够更好地保留特征信息。
7、(3)分类器
8、一旦确定了网络结构,就需要利用大量的训练样本来进行参数优化。具体来说,我们将训练数据输入到网络中,并计算损失函数。然后使用反向传播算法来更新网络参数,以使得损失函数的值更小。通过不断地迭代训练过程,最终得到一个能够较好地完成特定任务的模型,从而实现了高效准确的仪表读取方向识别和分类。
9、在特征提取之后,我们需要一个分类器来将特征映射到具体的标签。本专利使用支持向量机(svm)作为分类器。svm 是一种二分类模型,可以将数据集划分成两个部分,并找到一个最优超平面来区分这两个部分。通过训练 svm 模型,我们可以得到对于不同类别的特征向量进行分类的方法。
10、(4)自适应调整
11、在实际应用中,环境和数据的变化会影响图像识别的准确性。为了提高算法的鲁棒性,我们需要对算法进行自适应调整。具体来说,我们可以通过以下方式进行调整:
12、1)、数据增强:增加训练数据集的多样性,包括旋转、翻转等操作,从而提高模型的泛化能力。
13、2)、在线学习:利用在线学习技术,不断地将新采集的数据加入到训练集中,从而使模型能够不断地适应新的数据。
14、3)、迁移学习:将已经训练好的模型迁移到新的领域,从而节省训练时间,并且可以利用原模型的知识加快新模型的训练速度。
15、5. 创建resnet50网络结构模型来解决一般商业一级计量水表表盘数据图像识别问题的python代码如下:
16、import tensorflow as tf
17、from tensorflow.keras import layers, models
18、def resnet50(input_shape=(224, 224, 3), classes=2):
19、 """
20、 implementation of the resnet50 architecture for imageclassification
21、 :param input_shape: shape of the images of the dataset
22、 :param classes: number of output classes
23、 :return: a model() instance in keras
24、 """
25、 # define the input as a tensor with shape input_shape
26、 x_input = tf.keras.input(input_shape)
27、 # zero-padding
28、 x = layers.zeropadding2d((3, 3))(x_input)
29、 # stage 1
30、 x = layers.conv2d(64, (7, 7), strides=(2, 2))(x) # 卷积层
31、 x = layers.batchnormalization()(x) # bn层
32、 x = layers.activation('relu')(x) # 激活函数
33、 x = layers.maxpooling2d((3, 3), strides=(2, 2))(x) # 最大池化层
34、 # stage 2
35、 x = conv_block(x, f=3, filters=[64, 64, 256], stage=2, block='a', s=1)
36、 x = identity_block(x, f=3, filters=[64, 64, 256], stage=2, block='b')
37、 x = identity_block(x, f=3, filters=[64, 64, 256], stage=2, block='c')
38、 # stage 3
39、 x = conv_block(x, f=3, filters=[128, 128, 512], stage=3, block='a',s=2)
40、 x = identity_block(x, f=3, filters=[128, 128, 512], stage=3, block='b')
41、 x = identity_block(x, f=3, filters=[128, 128, 512], stage=3, block='c')
42、 x = identity_block(x, f=3, filters=[128, 128, 512], stage=3, block='d')
43、 # stage 4
44、 x = conv_block(x, f=3, filters=[256, 256, 1024], stage=4, block='a', s=2)
45、 x = identity_block(x, f=3, filters=[256, 256, 1024], stage=4, block='b')
46、 x = identity_block(x, f=3, filters=[256, 256, 1024], stage=4, block='c')
47、 x = identity_block(x, f=3, filters=[256, 256, 1024], stage=4, block='d')
48、 x = identity_block(x, f=3, filters=[256, 256, 1024], stage=4, block='e')
49、 x = identity_block(x, f=3, filters=[256, 256, 1024], stage=4, block='f')
50、 # stage 5
51、 x = conv_block(x, f=3, filters=[512, 512, 2048], stage=5, block='a', s=2)
52、 x = identity_block(x, f=3, filters=[512, 512, 2048], stage=5, block='b')
53、 x = identity_block(x, f=3, filters=[512, 512, 2048], stage=5, block='c')
54、 # average pooling
55、 x = layers.globalaveragepooling2d()(x)
56、 # output layer
57、 x = layers.dense(classes, activation='softmax')(x)
58、 # create model
59、 model = models.model(inputs=x_input, outputs=x, name='resnet50')
60、 return model
61、def conv_block(x, f, filters, stage, block, s=2):
62、 """
63、 implementation of the convolutional block as defined in figure 4
64、 :param x: input tensor of shape (m, n_h_prev, n_w_prev, n_c_prev)
65、 :param f: integer, specifying the shape of the middle conv's windowfor the main path
66、 :param filters: python list of integers, defining the number offilters in the conv layers of the main path
67、 :param stage: integer, used to name the layers, depending on theirposition in the network
68、 :param block: string/character, used to name the layers, dependingon their position in the network
69、 :param s: integer, specifying the stride to be used
70、 :return: output of the convolutional block, tensor of shape (n)