图像中目标物体识别方法、冰箱内食品识别方法及系统Target object recognition method in image, food identification method and system in refrigerator
技术领域Technical field
本发明涉及图像识别技术领域,尤其涉及图像中目标物体识别方法、冰箱内食品识别方法及系统。The present invention relates to the field of image recognition technologies, and in particular, to a target object recognition method in an image, a food identification method and system in a refrigerator.
背景技术Background technique
现有的图像处理技术中,采集图像和采集图像不能保证图像的一致性,这种差异导致学习的信息智能反映数据的部分特征,因而在测试数据上的表现不理想,图像识别的识别率较低。In the existing image processing technology, the image acquisition and the acquisition of the image cannot guarantee the consistency of the image. This difference causes the information of the learning to intelligently reflect some characteristics of the data, so the performance on the test data is not satisfactory, and the recognition rate of the image recognition is better. low.
尤其是在冰箱内图像识别技术领域,冰箱的种类繁多,如果各冰箱分别进行拍摄,进行图像识别,会因为图片质量的差异影响识别率。不同型号的冰箱拍摄出来的图像不一致,冰箱内部摆放在不同位置的食品拍摄的图像也会有差异。图像的差异表现在亮度和色彩上。由于训练和采用的图像不同,这种差异导致学习的信息只能反映数据的部分特征,因而在测试数据上的表现不理想,图像识别的识别率不高。Especially in the field of image recognition technology in refrigerators, there are many types of refrigerators. If each refrigerator is photographed separately and image recognition is performed, the recognition rate will be affected by the difference in picture quality. The images taken by different models of refrigerators are inconsistent, and the images taken by foods placed in different positions inside the refrigerator may also differ. The difference in images is expressed in brightness and color. Due to the different training and adopted images, this difference leads to the learning information only reflecting part of the characteristics of the data, so the performance on the test data is not ideal, and the recognition rate of image recognition is not high.
发明内容Summary of the invention
本发明所要解决的技术问题是针对现有技术的不足,提供一种图像中目标物体识别方法、冰箱内食品识别方法及系统。The technical problem to be solved by the present invention is to provide a target object recognition method in an image, a food identification method and system in a refrigerator, in view of the deficiencies of the prior art.
本发明解决上述技术问题的技术方案如下:一种图像中目标物体识别方法,包括如下步骤:The technical solution of the present invention to solve the above technical problem is as follows: a method for identifying a target object in an image, comprising the following steps:
获取训练图像,利用训练图像建立图像识别模型;Obtaining a training image, and establishing an image recognition model using the training image;
获取测试图像,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别;Obtaining a test image, matching the test image with the image recognition model, and realizing recognition of the target object in the test image;
其中,获取的训练图像和获取的测试图像进行归一化处理,将训练图像
和测试图像映射到统一的空间;和/或建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布。Wherein, the acquired training image and the acquired test image are normalized, and the training image is to be
And the test image is mapped to a unified space; and/or a regularization process is performed when the image recognition model is established, so that the image recognition model expresses the full sample distribution.
为实现上述发明目的,本发明还提供一种冰箱内食品识别方法,包括采集冰箱内的图像数据作为训练图像和测试图像,根据上述技术方案所述的图像中目标物体识别方法获得待识别图像数据中食品的属性信息。In order to achieve the above object, the present invention also provides a food identification method in a refrigerator, comprising collecting image data in a refrigerator as a training image and a test image, and obtaining image data to be identified according to the target object recognition method in the image according to the above technical solution. The property information of the food.
为实现上述发明目的,本发明还提供一种图像中目标物体识别系统,包括:To achieve the above object, the present invention also provides an object recognition system in an image, comprising:
训练模块,用于在获取训练图像,利用训练图像建立图像识别模型;a training module, configured to acquire a training image, and use the training image to establish an image recognition model;
测试模块,用于获取测试图像,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别;a test module for acquiring a test image, matching the test image with the image recognition model, and realizing recognition of the target object in the test image;
归一化模块,用于对获取的训练图像和获取的测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间;a normalization module, configured to normalize the acquired training image and the acquired test image, and map the training image and the test image to a unified space;
正则化模块,用于在建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布。A regularization module is used to perform regularization processing when the image recognition model is established, so that the image recognition model expresses a full sample distribution.
为实现上述发明目的,本发明还提供一种冰箱内食品识别系统,,包括安装在冰箱内部的图像采集装置和服务器,所述图像采集装置采集冰箱内的图像数据上传至服务器,所述服务器采用上述技术方案所述的图像中目标物体识别系统获得待识别图像数据中食品的属性信息。In order to achieve the above object, the present invention further provides a food identification system in a refrigerator, comprising: an image collection device and a server installed inside the refrigerator, wherein the image collection device collects image data in the refrigerator and uploads the image to a server, wherein the server adopts The target object recognition system in the image described in the above technical solution obtains attribute information of the food in the image data to be identified.
本发明的有益效果是:本发明通过训练图像和测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间,使得训练样本和测试样本同分布,用训练数据得到的图像识别模型在测试数据上可以取得较好的测试效果;通过在建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布,忽略只对训练样本进行描述的成分,使图像识别模型表达全样本分布,减小参数空间;通过上述处理使图像识别模型在测试数据上的表现尽可能的接近训练数据上的表现,实现图像识别的一致性,提高图像识别精度。
The invention has the beneficial effects that the invention normalizes the training image and the test image, maps the training image and the test image to a unified space, and makes the training sample and the test sample share the same, and the image recognition model obtained by using the training data Good test results can be obtained on the test data; by regularizing the image recognition model, the image recognition model expresses the full sample distribution, ignoring the components that only describe the training samples, and making the image recognition model express the full sample. Distribution, reduce the parameter space; through the above processing, the performance of the image recognition model on the test data is as close as possible to the performance on the training data, achieving consistency of image recognition and improving image recognition accuracy.
附图说明DRAWINGS
图1为本发明实施例提供的图像中目标物体识别方法流程图;1 is a flowchart of a method for identifying a target object in an image according to an embodiment of the present invention;
图2为本发明实施例提供的图像中目标物体识别方法流程图;2 is a flowchart of a method for identifying a target object in an image according to an embodiment of the present invention;
图3为本发明实施例提供的图像中目标物体识别方法流程图;FIG. 3 is a flowchart of a method for identifying a target object in an image according to an embodiment of the present invention;
图4为本发明实施例提供的图像中目标物体识别系统框图;4 is a block diagram of a target object recognition system in an image according to an embodiment of the present invention;
图5为本发明实施例提供的图像中目标物体识别方法框图;FIG. 5 is a block diagram of a method for identifying a target object in an image according to an embodiment of the present invention;
图6为本发明实施例提供的图像中目标物体识别方法框图;FIG. 6 is a block diagram of a method for identifying a target object in an image according to an embodiment of the present invention;
图7为本发明实施例提供的冰箱内食品识别系统框图。FIG. 7 is a block diagram of a food identification system in a refrigerator according to an embodiment of the present invention.
具体实施方式detailed description
以下结合附图对本发明的原理和特征进行描述,所举实例只用于解释本发明,并非用于限定本发明的范围。The principles and features of the present invention are described in the following with reference to the accompanying drawings.
如图1所示,本发明实施例提供一种图像中目标物体识别方法,包括如下步骤:As shown in FIG. 1 , an embodiment of the present invention provides a method for identifying a target object in an image, including the following steps:
S110,训练阶段获取训练图像,对训练图像进行归一化处理,利用训练图像建立图像识别模型;S110: acquiring a training image in a training phase, normalizing the training image, and establishing an image recognition model by using the training image;
S120,测试阶段获取测试图像,对测试图像进行归一化处理,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别;S120: obtaining a test image in a test phase, normalizing the test image, matching the test image with the image recognition model, and realizing recognition of the target object in the test image;
训练阶段获取的训练图像和测试阶段获取的测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间。The training image acquired during the training phase and the test image acquired during the test phase are normalized, and the training image and the test image are mapped to a unified space.
上述实施例中,通过训练图像和测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间,使得训练样本和测试样本同分布,用训练数据得到的图像识别模型在测试数据上可以取得较好的测试效果;通过在训练阶段建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布
,忽略只对训练样本进行描述的成分,使图像识别模型表达全样本分布,减小参数空间;通过上述处理使模型在测试数据上的表现尽可能的接近训练数据上的表现。In the above embodiment, the training image and the test image are normalized, and the training image and the test image are mapped to a unified space, so that the training sample and the test sample are distributed in the same manner, and the image recognition model obtained by using the training data is on the test data. Good test results can be obtained; regularization processing is performed when the image recognition model is established during the training phase, so that the image recognition model expresses the full sample distribution.
Ignore the components that only describe the training samples, so that the image recognition model expresses the full sample distribution and reduces the parameter space; through the above processing, the performance of the model on the test data is as close as possible to the performance on the training data.
可选地,作为本发明一个实施例,训练阶段获取训练图像和测试阶段获取测试图像具有相同的拍摄环境。Optionally, as an embodiment of the present invention, the training phase acquiring the training image and the testing phase acquiring the test image have the same shooting environment.
在该实施例中,保证训练阶段获取的图像和测试阶段获取的图像具体相同的拍摄环境,从硬件上保证训练图像和测试图像的一致性。In this embodiment, it is ensured that the image acquired in the training phase and the image acquired in the test phase have the same shooting environment, and the consistency of the training image and the test image is ensured from the hardware.
可选地,作为本发明的一个实施例,测试阶段利用训练图像建立图像识别模型的步骤具体包括:Optionally, as an embodiment of the present invention, the step of establishing an image recognition model by using the training image in the testing phase specifically includes:
a,获取预定数量的包含目标物体的图像数据;a, obtaining a predetermined number of image data including the target object;
b,对所述图像数据中目标物体的属性参数进行标定,并将经标定处理的图像数据作为训练图像;b, calibrating the attribute parameter of the target object in the image data, and using the calibrated image data as a training image;
c,设定图像识别模型、初始模型参数及损失函数,通过计算损失函数的期望获得风险函数;c, setting an image recognition model, an initial model parameter, and a loss function, and obtaining a risk function by calculating a desired loss function;
d,利用风险函数和训练数据更新图像识别模型,使所述图像识别模型满足所述损失函数的要求,得到所述目标物体对应的图像识别模型。d. Updating the image recognition model by using the risk function and the training data, so that the image recognition model satisfies the requirement of the loss function, and obtain an image recognition model corresponding to the target object.
具体地,所述目标物体的属性参数包括标定图像数据中目标物体的位置及种类。Specifically, the attribute parameter of the target object includes the position and type of the target object in the calibration image data.
具体地,在该实施例中,所述图像识别模型标识输出与输入的映射关系,所述损失函数表示实际输出和模型输出之间的差异;所述风险函数为损失函数的期望。Specifically, in this embodiment, the image recognition model identifies a mapping relationship between the output and the input, the loss function representing the difference between the actual output and the model output; the risk function is the expectation of the loss function.
具体地,在该实施例中,对所述图像数据中目标物体的属性参数进行标定可以采用了点标注法:通过食品左上角的坐标(x,y),宽度w和h标定食品在图片中的位置信息。同时给出该食材的种类信息。无论如何标注,只要能确定图片中关注物体的位置和种类即可。
Specifically, in this embodiment, the attribute parameter of the target object in the image data may be calibrated by using a point labeling method: the food is in the picture by the coordinates (x, y), width w and h of the upper left corner of the food. Location information. At the same time, the type information of the food material is given. No matter how you mark it, you can determine the position and type of the object of interest in the picture.
本发明实施例中,所述图像识别模型为,In the embodiment of the present invention, the image recognition model is
其中,x为图像数据,为模型输出,θ为模型参数;Where x is image data, For model output, θ is the model parameter;
所述损失函数为,The loss function is
L=(y,f(x,θ))L=(y,f(x,θ))
损失函数L表示实际的输出和模型输出之间的差异,y为实际输出;f(x,θ)为图像识别模型;The loss function L represents the difference between the actual output and the model output, y is the actual output; f(x, θ) is the image recognition model;
所述风险函数为,The risk function is
其中,R(θ)为风险函数,N代表训练图像的总数,i代表第i个训练图像。Where R(θ) is a risk function, N represents the total number of training images, and i represents the i-th training image.
图像识别包括训练阶段和测试阶段。Image recognition includes a training phase and a testing phase.
训练阶段,包括1、通过拍摄、标记得到训练数据;2、设定决策函数(模型)确立输入和输出的映射关系;3、设定评价函数衡量决策函数的好坏;4、通过学习算法和训练数据更新决策函数,使决策函数满足评价函数的要求。其中,风险函数时损失函数的期望,通过学习算法(如反向传播)使风险函数最小。The training phase includes: 1. obtaining training data by shooting and marking; 2. setting a decision function (model) to establish a mapping relationship between input and output; 3. setting an evaluation function to measure the quality of the decision function; 4. learning the algorithm and The training data updates the decision function so that the decision function satisfies the requirements of the evaluation function. Among them, the risk function loses the expectation of the function, and the risk function is minimized by a learning algorithm such as backpropagation.
具体来说,对于获得的图像数据(x),标定目标物体位置和种类(y),作为训练数据。设定图像识别模型和初始参数,表达了输出和输入的关系,用决策函数f(.)表示,对于已经标定好的参数x,输出为θ为模型参数。定义损失函数L=(y,f(x,θ)),表示实际的输出和模型输出之间的差异。然后在所有样本上评价决策函数的风险风险函数是在已知样本(x,y)上计算得来,被称为经验风险。训练问题就转化为求解θ*,使得经验风险最小θ*=argminR(θ)。Specifically, for the obtained image data (x), the target object position and kind (y) are calibrated as training data. Set the image recognition model and initial parameters, express the relationship between output and input, expressed by the decision function f(.), for the parameter x that has been calibrated, the output is θ is the model parameter. Define the loss function L = (y, f (x, θ)), which represents the difference between the actual output and the model output. Then evaluate the risk of the decision function on all samples The risk function is calculated on a known sample (x, y) and is called empirical risk. The training problem is transformed into solving θ * such that the empirical risk is minimal θ * = argminR(θ).
测试阶段,具体来说,包括:1.对目标物体进行拍照,得到测试样本,
即输入参数x;2通过预先训练好的图像识别模型,得到输出结果,识别结果为目标物体的位置和种类。The test phase, specifically, includes: 1. taking a picture of the target object, obtaining a test sample, that is, inputting the parameter x; 2 obtaining the output result through the pre-trained image recognition model The recognition result is the position and type of the target object.
本发明实施例中,风险函数在已知样本(x,y)上计算得到,被称为经验风险,训练问题就转化为求解θ*,使得经验风险最小θ*=argminR(θ)。In the embodiment of the present invention, the risk function is calculated on the known sample (x, y), which is called empirical risk, and the training problem is transformed into solving θ * , so that the empirical risk is minimum θ * = argminR (θ).
本发明实施例中,所述风险函数为经验风险,所述经验风险为根据所有训练数据计算损失函数的期望获得的;通过计算获得使图像识别模型的经验风险最小的模型参数作为图像识别模型的最终模型参数,得到所述目标物体对应的图像识别模型。In the embodiment of the present invention, the risk function is an empirical risk, and the empirical risk is obtained by calculating a desired loss function according to all training data; and obtaining a model parameter that minimizes the empirical risk of the image recognition model as an image recognition model by calculation The final model parameter obtains an image recognition model corresponding to the target object.
需要说明的是,本发明实施例中可以采用多种算法训练模型参数,本发明实施例中仅介绍了上述实现方法,其他实现方法也在本发明保护范围之内,此处不再一一列举。It should be noted that, in the embodiment of the present invention, a plurality of algorithms may be used to train the model parameters. In the embodiment of the present invention, only the foregoing implementation method is introduced, and other implementation methods are also within the protection scope of the present invention. .
通过机器学习算法进行图像识别模型训练,但是这种做法通常会存在训练过拟合以及其导致的泛化性错误。具体来说,就是模型参数θ*根据训练样本(x,y)确定,而训练样本通常不能很好的反应全部的真实分布,经验风险最小的准则训练出的模型在训练样本上表现良好,但是却不能适应训练集之外的测试数据。因此,本发明实施例通过归一化和正则化的处理方式解决上述技术问题。Image recognition model training is performed by machine learning algorithms, but this practice usually has training overfitting and the resulting generalization errors. Specifically, the model parameter θ * is determined according to the training sample (x, y), and the training sample usually does not respond well to the true distribution. The model with the least risk criterion is good for the training sample, but But can not adapt to the test data outside the training set. Therefore, the embodiment of the present invention solves the above technical problem by a normalization and regularization processing manner.
归一化技术,通过变换的方法将训练样本和测试样本映射到统一的空间。The normalization technique maps training samples and test samples to a unified space by transforming methods.
正则化技术,通过对经验风险进行约束,减少参数空间,避免过拟合。Regularization techniques reduce the parameter space and avoid overfitting by constraining empirical risks.
可选地,作为本发明一个实施例,归一化处理具体包括:对图像尺寸进行归一化处理,对图像数据特征矢量进行归一化处理和对图像数据进行搬移和缩放处理中的至少一种。Optionally, as an embodiment of the present invention, the normalization process specifically includes: performing normalization processing on the image size, performing normalization processing on the image data feature vector, and performing at least one of moving and scaling the image data. Kind.
在该实施例中,通过上述多种归一化方式,或者对图像尺寸进行归一化,或者对图像数据特征矢量进行归一化,或者对图像数据进行搬移和缩放处
理,或者将上述技术手段任意组合使用,实现对图像数据的归一化处理,保证训练数据与测试数据的一致性,提高图像识别模型的识别精度。In this embodiment, the image size is normalized by the above various normalization methods, or the image data feature vector is normalized, or the image data is moved and scaled.
Or, the above technical means can be used in any combination to achieve normalization of image data, ensure the consistency of training data and test data, and improve the recognition accuracy of the image recognition model.
可选地,作为本发明一个实施例,所述图像尺寸归一化处理包括:在获取图像数据过程中,采集超过目标区域的图像,将感兴趣区域保留在图像中间位置,根据已知的感兴趣区域的大小,修正图像尺寸,去除冗余区域,保留感兴趣区域的全部内容,使所有图像数据具有相同尺寸;Optionally, as an embodiment of the present invention, the image size normalization process includes: collecting an image exceeding a target area in the process of acquiring image data, and retaining the region of interest in an intermediate position of the image, according to a known sense The size of the area of interest, correcting the image size, removing the redundant area, and retaining the entire content of the area of interest, so that all image data have the same size;
所述图像数据特征矢量归一化处理包括:利用训练数据的均值和协方差进行归一化处理;The image data feature vector normalization process includes: performing normalization processing using mean values and covariances of the training data;
具体的,所述归一化处理的公式如下,Specifically, the formula of the normalization process is as follows.
其中x(k)是一组训练数据的特征矢量,E[x(k)]是所有训练数据的均值,Var[x(k)]是所有训练数据的方差的无偏估计,是归一化后的特征矢量;Where x (k) is the eigenvector of a set of training data, E[x (k) ] is the mean of all training data, and Var[x (k) ] is an unbiased estimate of the variance of all training data, Is a normalized feature vector;
所述图像数据进行搬移和缩放处理包括:根据缩放因子对图像数据进行缩放处理,通过平移常量对图像数据进行搬移处理;The moving and scaling processing of the image data includes: scaling the image data according to a scaling factor, and moving the image data by a translation constant;
具体地,所述搬移和缩放处理公式如下,Specifically, the moving and scaling processing formula is as follows.
其中,是经搬移和缩放处理的输出,λ是缩放因子,对样本的缩放,对每个样本点乘以同样的系数,β是对每个样本点加上同样的系数。among them, Is the output of the shift and scale process, λ is the scaling factor, the scaling of the sample, multiplying each sample point by the same coefficient, and β is the same factor for each sample point.
如图2所示,本发明实施例提供一种图像中目标物体识别方法,包括如下步骤:As shown in FIG. 2, an embodiment of the present invention provides a method for identifying a target object in an image, including the following steps:
S210,训练阶段获取训练图像,利用训练图像建立图像识别模型,建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布;S210: acquiring training images in the training phase, establishing an image recognition model by using the training images, and performing regularization processing when establishing the image recognition model, so that the image recognition model expresses the full sample distribution;
S220,测试阶段获取测试图像,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别。
S220: The test image is acquired in the test phase, and the test image is matched with the image recognition model to realize the recognition of the target object in the test image.
具体地,所述正则化处理包括将经验风险转换为结构风险,具体为在经验风险上加上正则化项获得结构风险,通过计算获得使图像识别模型的结构风险最小的模型参数作为图像识别模型的最终模型参数,得到所述目标物体对应的图像识别模型。Specifically, the regularization process includes converting an empirical risk into a structural risk, specifically adding a regularization term to the structural risk to obtain a structural risk, and obtaining a model parameter that minimizes the structural risk of the image recognition model as an image recognition model. The final model parameter obtains an image recognition model corresponding to the target object.
上述实施例中,通过在训练阶段建立图像识别模型时进行正则化处理,保留可以描述全样本的成分,忽略只对训练样本进行描述的成分,使图像识别模型表达全样本分布,减小参数空间。通过上述处理使模型在测试数据上的表现尽可能的接近训练数据上的表现。In the above embodiment, the regularization process is performed when the image recognition model is established in the training phase, the components that can describe the full sample are retained, the components that describe only the training samples are ignored, and the image recognition model expresses the full sample distribution and reduces the parameter space. . Through the above processing, the performance of the model on the test data is as close as possible to the performance on the training data.
可选地,作为本发明一个实施例,正则化处理过程中将经验风险转换为结构风险,所述结构风险为:Optionally, as an embodiment of the present invention, the empirical risk is converted into a structural risk during the regularization process, and the structural risk is:
θ*=arg minR(θ)+λ|θ| (3)θ * =arg minR(θ)+λ|θ| (3)
或者,θ*=arg minR(θ)+λ(θ)2 (4)Or, θ * = arg minR(θ) + λ(θ) 2 (4)
其中公式(3)是L1正则化,λ|θ|为正则化项,|θ|是L1范数;公式(4)是L2正则化,λ(θ)2为正则化项,(θ)2是L2范数,λ是一个常量。Where equation (3) is L1 regularization, λ|θ| is a regularization term, |θ| is the L1 norm; equation (4) is L2 regularization, λ(θ) 2 is a regularization term, (θ) 2 Is the L2 norm and λ is a constant.
数据经过归一化之后,可以在一定程度上弥补训练和测试样本分布不同带来的泛化问题。但是归一化实用的均值和方差均用训练样本估计,无法表达全样本分布。如果模型描述的过于精细,过拟合现象还是存在。After the data is normalized, it can compensate for the generalization problem caused by the different distribution of training and test samples to some extent. However, the normalized mean and variance are estimated using training samples and cannot express the full sample distribution. If the model is described as too fine, the overfitting phenomenon still exists.
正则化的思想是减少参数空间,也就是在训练过程中保留可以描述全样本的成分,忽略只是对训练样本进行描述的成分。其做法是修改风险函数,将经验风险转化为结构风险。The idea of regularization is to reduce the parameter space, that is, to preserve the components of the full sample during the training process, ignoring the components that are only describing the training samples. The approach is to modify the risk function to translate empirical risk into structural risk.
θ*=arg minR(θ)+λ|θ| (3)θ * =arg minR(θ)+λ|θ| (3)
或者,θ*=arg minR(θ)+λ(θ)2 (4)Or, θ * = arg minR(θ) + λ(θ) 2 (4)
其中(3)是L1正则化,|θ|是L1范数,(4)是L2正则化,(θ)2是L2范数。本发明实施例通过加入λ|θ|,不相关的输入(噪声)因为得不到权重被抑制。加入λ(θ)2,能够减小每个特征向量的权重,使参数具有稀疏性。
Where (3) is L1 regularization, |θ| is the L1 norm, (4) is L2 regularization, and (θ) 2 is the L2 norm. In the embodiment of the present invention, by adding λ|θ|, the uncorrelated input (noise) is suppressed because the weight is not obtained. Adding λ(θ) 2 can reduce the weight of each feature vector and make the parameters sparse.
可选地,作为本发明一个实施例,训练阶段获取训练图像和测试阶段获取测试图像具有相同的拍摄环境。Optionally, as an embodiment of the present invention, the training phase acquiring the training image and the testing phase acquiring the test image have the same shooting environment.
在该实施例中,保证训练阶段获取的图像和测试阶段获取的图像具体相同的拍摄环境,从硬件上保证训练图像和测试图像的一致性。In this embodiment, it is ensured that the image acquired in the training phase and the image acquired in the test phase have the same shooting environment, and the consistency of the training image and the test image is ensured from the hardware.
如图3所示,本发明实施例提供一种图像中目标物体识别方法,包括如下步骤:As shown in FIG. 3, an embodiment of the present invention provides a method for identifying a target object in an image, including the following steps:
S310,训练阶段获取训练图像,对训练图像进行归一化处理,利用训练图像建立图像识别模型,建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布;S310: acquiring training images in the training phase, normalizing the training images, establishing an image recognition model by using the training images, and performing regularization processing when establishing the image recognition model, so that the image recognition model expresses the whole sample distribution;
S320,测试阶段获取测试图像,对测试图像进行归一化处理,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别;S320, obtaining a test image in a test phase, normalizing the test image, matching the test image with the image recognition model, and realizing recognition of the target object in the test image;
训练阶段获取的训练图像和测试阶段获取的测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间。The training image acquired during the training phase and the test image acquired during the test phase are normalized, and the training image and the test image are mapped to a unified space.
上述实施例中,通过训练图像和测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间,使得训练样本和测试样本同分布,用训练数据得到的图像识别模型在测试数据上可以取得较好的测试效果;通过在训练阶段建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布,忽略只对训练样本进行描述的成分,使图像识别模型表达全样本分布,减小参数空间;通过上述处理使图像识别模型在测试数据上的表现尽可能的接近训练数据上的表现。In the above embodiment, the training image and the test image are normalized, and the training image and the test image are mapped to a unified space, so that the training sample and the test sample are distributed in the same manner, and the image recognition model obtained by using the training data is on the test data. Good test results can be obtained; the regularization process is performed when the image recognition model is established in the training phase, so that the image recognition model expresses the full sample distribution, ignoring the components that only describe the training samples, and the image recognition model expresses the full sample distribution. The parameter space is reduced; the performance of the image recognition model on the test data is made as close as possible to the performance on the training data by the above processing.
可选地,作为本发明一个实施例,训练阶段获取训练图像和测试阶段获取测试图像具有相同的拍摄环境。Optionally, as an embodiment of the present invention, the training phase acquiring the training image and the testing phase acquiring the test image have the same shooting environment.
在该实施例中,保证训练阶段获取的图像和测试阶段获取的图像具体相同的拍摄环境,从硬件上保证训练图像和测试图像的一致性。
In this embodiment, it is ensured that the image acquired in the training phase and the image acquired in the test phase have the same shooting environment, and the consistency of the training image and the test image is ensured from the hardware.
上文结合图1至图3,对本发明实施例提供的一种图像中目标物体识别方法进行了详细的描述,下面结合图4至图6对本发明实施例提供的一种像中目标物体识别系统进行详细描述。A method for identifying a target object in an image according to an embodiment of the present invention is described in detail above with reference to FIG. 1 to FIG. 3, and an image object recognition system in an image according to an embodiment of the present invention is described below with reference to FIG. 4 to FIG. Carry out a detailed description.
如图4所示,本发明实施例提供的一种图像中目标物体识别系统,包括As shown in FIG. 4, an image object recognition system in an image provided by an embodiment of the present invention includes
训练模块,用于在训练阶段获取训练图像,利用训练图像建立图像识别模型;a training module, configured to acquire a training image in a training phase, and use the training image to establish an image recognition model;
测试模块,用于测试阶段获取测试图像,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别;a test module for obtaining a test image in a test phase, matching the test image with the image recognition model, and realizing recognition of the target object in the test image;
归一化模块,用于对训练阶段获取的训练图像和测试阶段获取的测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间a normalization module for normalizing the training image acquired during the training phase and the test image obtained during the testing phase, and mapping the training image and the test image to a unified space
如图5所示,本发明实施例提供的一种图像中目标物体识别系统,包括As shown in FIG. 5, an image object recognition system in an image provided by an embodiment of the present invention includes
训练模块,用于在训练阶段获取训练图像,利用训练图像建立图像识别模型;a training module, configured to acquire a training image in a training phase, and use the training image to establish an image recognition model;
测试模块,用于测试阶段获取测试图像,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别;a test module for obtaining a test image in a test phase, matching the test image with the image recognition model, and realizing recognition of the target object in the test image;
正则化模块,用于在训练阶段建立图像识别模型时进行正则化处理,使图像识别模型表达全样本分布。The regularization module is used to perform regularization processing when the image recognition model is established in the training phase, so that the image recognition model expresses the full sample distribution.
如图6所示,本发明实施例提供的一种图像中目标物体识别系统,包括As shown in FIG. 6, an image object recognition system in an image provided by an embodiment of the present invention includes
训练模块,用于在训练阶段获取训练图像,利用训练图像建立图像识别模型;a training module, configured to acquire a training image in a training phase, and use the training image to establish an image recognition model;
测试模块,用于测试阶段获取测试图像,将测试图像与图像识别模型匹配,实现测试图像中目标物体的识别;a test module for obtaining a test image in a test phase, matching the test image with the image recognition model, and realizing recognition of the target object in the test image;
归一化模块,用于对训练阶段获取的训练图像和测试阶段获取的测试图像进行归一化处理,将训练图像和测试图像映射到统一的空间;a normalization module for normalizing the training image acquired during the training phase and the test image obtained during the testing phase, and mapping the training image and the test image to a unified space;
正则化模块,用于在训练阶段建立图像识别模型时进行正则化处理,使
图像识别模型表达全样本分布。Regularization module for regularization processing when establishing an image recognition model during the training phase
The image recognition model expresses a full sample distribution.
应理解,在该实施例中,识别系统可对应于根据本发明实施例的识别方法的执行主体,并且识别系统中的各个模块的上述和其它操作和/或功能分别为了实现图1至图3中的各个方法的相应流程,为了简洁,在此不再赘述。It should be understood that in this embodiment, the identification system may correspond to an execution body of the identification method according to an embodiment of the present invention, and the above-described and other operations and/or functions of the respective modules in the identification system are respectively implemented in order to implement FIGS. 1 to 3 The corresponding processes of each method in the following are not repeated here for brevity.
本发明实施例提供一种冰箱内食品识别方法,包括采集冰箱内的图像数据作为训练图像和测试图像,根据上述实施例所述的图像中目标物体识别方法获得待识别图像数据中食品的属性信息。An embodiment of the present invention provides a food identification method in a refrigerator, which includes collecting image data in a refrigerator as a training image and a test image, and obtaining target attribute information of the food in the image data to be identified according to the target object recognition method in the image according to the above embodiment. .
需要说明的是,在该实施例中,为了使冰箱内食品图片识别取得良好的效果,测试阶段的图片和学习阶段的图片质量相近是前提条件。为了实现图像质量一致性的目的,本发明在首先需要硬件上保证相似的条件,保证所拍照片的质量尽可能一致,在软件上通过归一化、正则化的方法使模型在测试数据上的表现尽可能的接近训练数据上的表现,提高冰箱内食品识别的精度。It should be noted that in this embodiment, in order to obtain a good effect of the food picture recognition in the refrigerator, the pictures in the test stage and the picture quality in the learning stage are similar. In order to achieve image quality consistency, the present invention firstly requires similar conditions on the hardware to ensure that the quality of the photographs taken is as uniform as possible, and the model is tested on the test data by normalization and regularization. Performance as close as possible to the performance of the training data, improve the accuracy of food identification in the refrigerator.
具体地,训练和测试过程相对独立,整个训练过程是在服务器端离线进行。首先需要拍摄每种食品的图片,拍摄的图片需要尽可能多的包含不同情景,如背景,光照,大小,前景遮挡等;确保训练阶段获取训练图像和测试阶段获取测试图像具有相同的拍摄环境,拍摄好的食品图片先标定其在图片中的位置以及其种类。最后对于每种食品,都有大量标定好的图片数据,通过机器学习的算法为分别每种食品建立对应的模型。Specifically, the training and testing process is relatively independent, and the entire training process is performed offline on the server side. First, you need to take a picture of each food. The pictures you take need to include as many different scenes as possible, such as background, lighting, size, foreground occlusion, etc.; to ensure that the training image is acquired during the training phase and the test image is taken to have the same shooting environment. Take a good picture of the food and first mark its position in the picture and its type. Finally, for each type of food, there is a large amount of calibrated image data, and a corresponding model is established for each food by a machine learning algorithm.
识别过程的目的是为了通过图像识别的手段判断出冰箱内的食物种类。首先通过冰箱内的摄像头拍摄冰箱内食物图片,之后将图片上穿至识别的服务器,在服务器端和已经建立的模型进行匹配,得到图片中食物的位置和种类的信息。The purpose of the recognition process is to determine the type of food in the refrigerator by means of image recognition. First, the food picture in the refrigerator is photographed by the camera in the refrigerator, and then the picture is passed to the identified server, and the model is matched with the established model on the server side to obtain the information of the position and type of the food in the picture.
可选地,作为本发明一个实施例,训练阶段利用训练图像获得图像识别
模型在服务器端离线进行,测试阶段识别测试图像中食品的属性信息还包括在检测到冰箱门关门信号时,开启冰箱内的照明设备,并将照明设备的光强调节至统一的光强;和/或在拍摄前对摄像头进行除雾处理;在经过上述处理后,使拍摄条件稳定预设时间再进行拍摄获取图像数据。Optionally, as an embodiment of the present invention, the training stage uses the training image to obtain image recognition.
The model is performed offline on the server side, and the identification of the attribute information of the food in the test image during the test phase further includes turning on the lighting device in the refrigerator when the door closing signal of the refrigerator door is detected, and adjusting the light intensity of the lighting device to a uniform light intensity; / or defogging the camera before shooting; after the above processing, the shooting conditions are stabilized for a preset time and then captured to obtain image data.
上述实施例中,为了保证测试图片的一致性,首先从硬件以及拍照流程上进行了相应的处理。In the above embodiment, in order to ensure the consistency of the test picture, the corresponding processing is first performed from the hardware and the photographing process.
硬件上,在每个摄像头的位置同时安装了照明灯,保证摄像头配合冰箱内其他的照明设备进行协同工作,其次为每个摄像头增加了防尘放雾措施防止摄像头被污染,所述防尘防雾措施可以通过加装防尘防雾罩实现,最后采用相同像素的感光设备保证拍摄的图片含有相同的信息量。On the hardware, the illumination light is installed at the position of each camera at the same time to ensure that the camera cooperates with other lighting devices in the refrigerator, and secondly, dustproof and fogging measures are added to each camera to prevent the camera from being contaminated. The fog measure can be achieved by adding a dust-proof anti-fog cover. Finally, the same pixel of the photographic device is used to ensure that the captured picture contains the same amount of information.
拍照流程上,每次用户关冰箱门的时候会产生关门信号,此时冰箱内的食物可能发生变化,选择此时进行冰箱内的拍摄。为了保证冰箱内的食物光照条件一致,拍摄前先打开冰箱内的照明设备,通过调节占空比将摄像头附带的灯光调节至统一的光强,冰箱内原有的照明设备尽可能调节至近似的光强。除此之外,为了避免摄像头本身因为冰箱内外的温差造成结露等情况,通过加热等方式进行防雾处理。这部分处理完成后需要将拍摄条件稳定一段时间,保证拍摄处理上可能造成的延时(软件逻辑控制控制拍摄的延时,快门速度等)不会造成影响,以及防止用户短时间内多次开关冰箱门(此时不进行拍照)。During the photo taking process, each time the user closes the refrigerator door, a door closing signal will be generated. At this time, the food in the refrigerator may change, and the shooting in the refrigerator is selected at this time. In order to ensure the food lighting conditions in the refrigerator are the same, open the lighting equipment in the refrigerator before shooting, adjust the light attached to the camera to adjust the uniform light intensity by adjusting the duty ratio, and adjust the original lighting equipment in the refrigerator to the approximate light as much as possible. Strong. In addition, in order to prevent condensation of the camera itself due to the temperature difference between the inside and outside of the refrigerator, the anti-fog treatment is performed by heating or the like. After this part of the processing is completed, it is necessary to stabilize the shooting conditions for a certain period of time, to ensure that the delay caused by the shooting process (software logic control to control the shooting delay, shutter speed, etc.) will not affect, and prevent the user from switching multiple times in a short time. Refrigerator door (no photo taken at this time).
本发明实施例提供一种冰箱内食品识别系统,包括安装在冰箱内部的图像采集装置和服务器,所述图像采集装置采集冰箱内的图像数据上传至服务器,所述服务器采用上述实施例所述的图像中目标物体识别系统获得待识别图像数据中食品的属性信息。An embodiment of the present invention provides a food identification system in a refrigerator, comprising an image collecting device and a server installed in the refrigerator, wherein the image collecting device collects image data in the refrigerator and uploads the image data to the server, wherein the server adopts the foregoing embodiment. The target object recognition system in the image obtains attribute information of the food in the image data to be identified.
需要说的是,所述冰箱内食品识别系统,从硬件和/或软件上保证训练数据和测试数据的一致性,使图像识别模型在测试数据上的表现尽可能的接
近训练数据上的表现,提高冰箱内食品识别的精度。It should be noted that the food identification system in the refrigerator guarantees the consistency of the training data and the test data from hardware and/or software, so that the image recognition model performs as much as possible on the test data.
The performance on the near training data improves the accuracy of food identification in the refrigerator.
可选地,作为本发明一个实施例,如图7所示,一种冰箱内食品识别系统还包括在冰箱内每个摄像头的位置安装的照明设备、冰箱门检测装置和控制装置,冰箱门检测装置在检测到冰箱门关门信号时,将关门信号发送给控制装置,控制装置根据关门信号控制开启冰箱内的照明设备,并将照明设备的光强调节至统一的光强。Optionally, as an embodiment of the present invention, as shown in FIG. 7, a food identification system in a refrigerator further includes a lighting device, a refrigerator door detecting device and a control device installed at a position of each camera in the refrigerator, and the refrigerator door detecting When detecting the door closing signal of the refrigerator door, the device sends a door closing signal to the control device, and the control device controls to turn on the lighting device in the refrigerator according to the door closing signal, and adjusts the light intensity of the lighting device to a uniform light intensity.
需要说明的是,在该实施例中,通过在拍照前将照明设备的光强调节至统一的光强,保证冰箱内的食物光照条件一致,从拍摄环境确保图像的一致性。It should be noted that, in this embodiment, by adjusting the light intensity of the illumination device to a uniform light intensity before photographing, it is ensured that the food illumination conditions in the refrigerator are consistent, and the image consistency is ensured from the photographing environment.
可选第,作为本发明一个实施例,还包括在冰箱内每个摄像头的位置安装的加热装置,用于在摄像头进行拍摄前为摄像头进行除雾处理,所述控制模块还用于控制拍摄条件稳定预设时间再进行拍摄获取图像数据。Optionally, as an embodiment of the present invention, a heating device installed at a position of each camera in the refrigerator is configured to perform a defogging process for the camera before the camera performs the shooting, and the control module is further configured to control the shooting condition. Stabilize the preset time and then shoot to obtain image data.
需要说明的是,在该实施例中,为每个摄像头增加了防尘放雾装置以及加热装置,防止摄像头被污染,采用相同像素的感光设备保证拍摄的图片含有相同的信息量。为了避免摄像头本身因为冰箱内外的温差造成结露等情况,通过加热等方式进行防雾处理。将拍摄条件稳定一段时间,保证拍摄处理上可能造成的延时不会造成影响,以及防止用户短时间内多次开关冰箱门。It should be noted that, in this embodiment, a dust-proof and fog-removing device and a heating device are added to each camera to prevent the camera from being contaminated, and the photosensitive device using the same pixel ensures that the captured image contains the same amount of information. In order to prevent the camera itself from causing condensation or the like due to temperature difference between the inside and outside of the refrigerator, the anti-fog treatment is performed by heating or the like. Stabilize the shooting conditions for a period of time, to ensure that the delay caused by the shooting process will not be affected, and to prevent the user from switching the refrigerator door multiple times in a short time.
本文中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。The term "and/or" in this context is merely an association describing the associated object, indicating that there may be three relationships, for example, A and / or B, which may indicate that A exists separately, and both A and B exist, respectively. B these three situations. In addition, the character "/" in this article generally indicates that the contextual object is an "or" relationship.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一
般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the various examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both, for clarity of hardware and software. Interchangeability, in accordance with function one in the above description
The composition and steps of the examples are generally described. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the solution. A person skilled in the art can use different methods for implementing the described functions for each particular application, but such implementation should not be considered to be beyond the scope of the present invention.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the system, the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。In the several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the device embodiments described above are merely illustrative. For example, the division of cells is only a logical function division. In actual implementation, there may be another division manner. For example, multiple units or components may be combined or integrated. Go to another system, or some features can be ignored or not executed.
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本发明实施例方案的目的。The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present invention.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,
服务器,或者网络设备等)执行本发明各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。An integrated unit, if implemented in the form of a software functional unit and sold or used as a standalone product, can be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention contributes in essence or to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium. Including a number of instructions to make a computer device (which can be a personal computer,
The server, or network device, etc.) performs all or part of the steps of the various embodiments of the present invention. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .
在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本发明的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。In the description of the present specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" and the like means a specific feature described in connection with the embodiment or example. A structure, material or feature is included in at least one embodiment or example of the invention. In the present specification, the schematic representation of the above terms is not necessarily directed to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in a suitable manner in any one or more embodiments or examples. In addition, various embodiments or examples described in the specification, as well as features of various embodiments or examples, may be combined and combined.
以上所述仅为本发明的较佳实施例,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
The above are only the preferred embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalents, improvements, etc., which are within the spirit and scope of the present invention, should be included in the protection of the present invention. Within the scope.