Disclosure of Invention
The embodiment of the invention provides a specification identification method, device, terminal equipment and readable storage medium for bottled drinks, which can improve the accuracy of identifying different specifications of the same type of bottled drinks.
An embodiment of the invention provides a specification identification method for bottled drinks, which comprises the following steps:
Acquiring an image of the bottled drink to be identified, and obtaining the image to be identified;
Inputting the image to be identified into a preset specification identification model so that the specification identification model identifies the ratio of the bottle cap to the bottle body of the bottled drink to be identified, and determining the specification of the bottled drink to be identified according to the ratio of the bottle cap to the bottle body.
Further, the specification identification model identifies the ratio of the bottle cap to the bottle body of the bottled drink to be identified, and determines the specification of the bottled drink to be identified according to the ratio of the bottle cap to the bottle body, specifically:
The specification identification model extracts the bottle cap size and the bottle body size of the bottled drink to be identified, and then the ratio of the bottle cap to the bottle body of the bottled drink to be identified is determined according to the bottle cap size and the bottle body size of the bottled drink to be identified;
And comparing the ratio of the bottle cap to the bottle body of the bottled drink to be identified with the ratio of the bottle cap to the bottle body corresponding to each specification of the similar drink, and determining the specification of the bottled drink to be identified.
Further, the method for constructing the specification recognition model comprises the following steps:
collecting images to be trained of a plurality of bottled drinks with different specifications; wherein, the bottled drink corresponding to each image to be trained is the same as the type of the bottled drink to be identified;
Labeling the bottle cap size and the bottle body size of the bottled drink in each image to be trained, taking the labeled image to be trained as input, and taking the bottle cap size predicted value and the bottle body size predicted value corresponding to each image to be trained as output to construct a regression network;
Constructing a classifier according to the ratio of bottle caps to bottle bodies corresponding to the bottled beverages of different specifications;
and constructing the specification identification model according to the regression network and the classifier.
Optionally, the bottle cap is in a bottle cap width, and the bottle body is in a bottle body width.
Optionally, the bottle cap is in a bottle cap height, and the bottle body is in a bottle body height.
On the basis of the method item embodiment, the invention correspondingly provides the device item embodiment
Another embodiment of the present invention provides a specification identifying device for bottled drink, including: an image acquisition module and a specification identification module;
the image acquisition module is used for acquiring an image of the bottled drink to be identified and obtaining the image to be identified;
The specification identification module is used for inputting the image to be identified into a preset specification identification model so that the specification identification model identifies the ratio of the bottle cap to the bottle body of the bottled drink to be identified, and determines the specification of the bottled drink to be identified according to the ratio of the bottle cap to the bottle body.
Further, the system also comprises a model building module; the model construction module is used for collecting images to be trained of a plurality of bottled drinks with different specifications; wherein, the bottled drink corresponding to each image to be trained is the same as the type of the bottled drink to be identified;
Labeling the bottle cap size and the bottle body size of the bottled drink in each image to be trained, taking the labeled image to be trained as input, and taking the bottle cap size predicted value and the bottle body size predicted value corresponding to each image to be trained as output to construct a regression network;
Constructing a classifier according to the ratio of bottle caps to bottle bodies corresponding to the bottled beverages of different specifications;
and constructing the specification identification model according to the regression network and the classifier.
On the basis of the method item embodiment of the invention, a terminal equipment item embodiment is correspondingly provided;
Another embodiment of the present invention provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, where the processor implements the method for identifying specifications of a bottled beverage according to any one of the embodiments of the method when the processor executes the computer program.
On the basis of the method item embodiment, a readable storage medium item embodiment is correspondingly provided;
In another embodiment of the present invention, a readable storage medium is provided, where the readable storage medium includes a stored computer program, and when the computer program is executed, the apparatus where the readable storage medium is located is controlled to execute the method for identifying the specification of the bottled drink according to any one of the method embodiments of the present invention.
The embodiment of the invention has the following beneficial effects:
The embodiment of the invention provides a specification identification method, device, terminal equipment and readable storage medium for bottled drinks, wherein the method comprises the steps of firstly acquiring an image of bottled drinks to be identified, inputting the image into a preset specification identification model, and identifying the specification of the bottled drinks to be identified by the preset specification identification model; in the identification process, the specification identification model carries out specification identification according to the ratio of the bottle cap and the bottle body of the bottled drink to be identified, compared with the prior art, for example, the specification identification is carried out according to the integral size of the commodity, for example, the integral height, because the ratio of the bottle cap and the bottle body belongs to the relative size relationship, generally, the integral size of the commodity in the image is greatly changed due to the influence of factors such as shooting distance, angle and the like, but the relative size relationship is not easy to change, for example, the ratio of the bottle cap to the bottle body is the ratio of the bottle cap to the bottle body, therefore, the ratio relationship between the bottle cap and the bottle body of the bottled drink is selected, and compared with the traditional method for distinguishing and identifying by the integral ratio, the specification identification standard is higher in accuracy and better in robustness.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
As shown in fig. 1, a method for identifying specifications of bottled beverages according to an embodiment of the present invention includes:
And S101, acquiring an image of the bottled drink to be identified, and obtaining the image to be identified.
Step S102, inputting the image to be identified into a preset specification identification model so that the specification identification model identifies the ratio of the bottle cap to the bottle body of the bottled drink to be identified, and determining the specification of the bottled drink to be identified according to the ratio of the bottle cap to the bottle body.
For step S101, the bottled drink to be identified may be photographed by various photographing tools, so as to obtain the image to be identified.
In step S102, first, the construction of the specification recognition model is described:
in a preferred embodiment, the method for constructing the specification recognition model includes:
Collecting images to be trained of a plurality of bottled drinks with different specifications; wherein, the bottled drink corresponding to each image to be trained is the same as the type of the bottled drink to be identified; labeling the bottle cap size and the bottle body size of the bottled drink in each image to be trained, taking the labeled image to be trained as input, and taking the bottle cap size predicted value and the bottle body size predicted value corresponding to each image to be trained as output to construct a regression network; constructing a classifier according to the ratio of bottle caps to bottle bodies corresponding to the bottled beverages of different specifications; and constructing the specification identification model according to the regression network and the classifier.
More detailed examples are as follows:
Firstly, obtaining images of various specifications which are the same as the types of bottled drinks to be identified, and taking the images as images to be trained; for example, assuming that the bottled drink to be identified is type a cola, firstly, images of the type a cola with different specifications need to be acquired as images to be trained, and the number of images of each specification is preferably kept consistent, for example, 10 300ml of type a cola images, 10 500ml of type a cola images, 10 1.25L of type a cola images and 10 2L of type a cola images can be acquired; the sizes of a bottle cap and a bottle body of the beverage in each image are marked immediately, and a label of each image is obtained; meanwhile, calculating the ratio of the bottle cap to the bottle body of the beverage with each specification, wherein each specification has a unique corresponding ratio; in the present invention, the width of the bottle cap and the width of the bottle body may be selected as the sizes of the bottle cap and the bottle body of the present invention, and the height of the bottle cap and the height of the bottle body (the height of the bottle body does not include the portion covered by the bottle cap) may be selected as the sizes of the bottle cap and the bottle body of the present invention;
Step B, carrying out data enhancement and normalization processing on the marked image;
inputting the image dataset processed in the step B into ResNet network, returning to obtain corresponding bottle cap width and bottle body size, wherein the corresponding label is the label processed in the step A, specifically, removing the full connection layer of ResNet network, and replacing with the structure shown in figure 3; the activating function of the last layer adopts Relu activating functions; the loss function of the bottle cap size and the bottle body size in the training process adopts a mean square error function, and the loss function of loss1 is obtained by adding the mean square error function and the loss function of loss1 in the regression training process, wherein loss1 is used as the loss function;
loss1=lu+Ld,Lu is a loss function corresponding to the bottle cap size, and Ld is a loss function corresponding to the bottle body size.
Where i denotes the i-th sample, n denotes the total number of samples, yi denotes the cap size label value of the i-th sample,A predicted value representing the size of the ith sample vial cap; yj represents the body size label value of the i-th sample,/>A predicted value representing the body size of the ith sample;
step D, dividing two outputs (a bottle cap size predicted value and a bottle body size predicted value) of the regression network in the step C, wherein a small bias item (such as 1 e-5) is added to a numerator and a denominator during calculation, and the strategy is to avoid the situation that the numerator is zero or the denominator is zero and cannot be divided; outputting the final predicted proportion, and constructing a classifier according to the real proportions of the beverage bottle caps and the bottle bodies with different specifications; and the loss function of loss2 is proposed to help network convergence, and the formula is as follows:
Where i represents the i-th sample, n represents the total number of samples, P represents the predicted ratio of the i-th sample (i.e., the ratio of the cap size predicted value to the body size predicted value), and D represents the true ratio of the i-th sample (i.e., the actual ratio of the cap to the body of the corresponding specification).
E, constructing a specification identification network according to the regression network and the classifier in the step; the total loss function of the network is l=lu+Ld+Ls; and stopping training to obtain the specification recognition model when the iteration of the specification recognition network reaches the preset times. When the classifier classifies, the real proportional difference between the predicted proportion and each specification is calculated, and the specification with the smallest difference is used as the final classification result.
In a preferred embodiment, the specific identification process of the bottled drink to be identified in the preset specification identification model is as follows:
The specification identification model extracts the bottle cap size and the bottle body size of the bottled drink to be identified, and then the ratio of the bottle cap to the bottle body of the bottled drink to be identified is determined according to the bottle cap size and the bottle body size of the bottled drink to be identified;
And comparing the ratio of the bottle cap to the bottle body of the bottled drink to be identified with the ratio of the bottle cap to the bottle body corresponding to each specification of the similar drink, and determining the specification of the bottled drink to be identified.
In the specific recognition process, if the bottle cap width and the bottle body width are selected as the bottle cap size and the bottle body size in the process of training the model, the bottle cap size and the bottle body size of the bottled drink to be recognized extracted at the position are the bottle cap width and the bottle body width of the bottled drink to be recognized; if the bottle cap height and the bottle body height are selected as the bottle cap size and the bottle body size in the training of the model, the bottle cap size and the bottle body size of the bottled drink to be identified extracted at the position are the bottle cap height and the bottle body height of the bottled drink to be identified; determining the ratio of the bottle cap to the bottle body of the bottled drink to be identified, namely the predicted ratio of the bottled drink to be identified, by calculating the ratio of the two sizes; and finally, calculating the actual ratio difference value between the predicted ratio of the bottled drink to be identified and each specification, and taking the specification with the smallest difference value as the final specification of the bottled drink to be identified.
On the basis of the embodiment of the invention, the invention correspondingly provides an embodiment of the device item, as shown in fig. 2;
Another embodiment of the present invention provides a specification identifying device for bottled drink, including: an image acquisition module and a specification identification module;
the image acquisition module is used for acquiring an image of the bottled drink to be identified and obtaining the image to be identified;
The specification identification module is used for inputting the image to be identified into a preset specification identification model so that the specification identification model identifies the ratio of the bottle cap to the bottle body of the bottled drink to be identified, and determines the specification of the bottled drink to be identified according to the ratio of the bottle cap to the bottle body.
Further, the system also comprises a model building module; the model construction module is used for collecting images to be trained of a plurality of bottled drinks with different specifications; wherein, the bottled drink corresponding to each image to be trained is the same as the type of the bottled drink to be identified;
Labeling the bottle cap size and the bottle body size of the bottled drink in each image to be trained, taking the labeled image to be trained as input, and taking the bottle cap size predicted value and the bottle body size predicted value corresponding to each image to be trained as output to construct a regression network;
Constructing a classifier according to the ratio of bottle caps to bottle bodies corresponding to the bottled beverages of different specifications;
and constructing the specification identification model according to the regression network and the classifier.
The embodiment of the device disclosed by the invention corresponds to the embodiment of the method disclosed by the invention, and the specification identification method of the bottled drink disclosed by any one of the embodiments of the invention can be realized.
On the basis of the embodiment of the invention item, the invention correspondingly provides the embodiment of the terminal equipment item;
Another embodiment of the present invention provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, where the processor implements the method for identifying specifications of a bottled beverage according to any one of the embodiments of the method when the processor executes the computer program.
On the basis of the embodiment of the invention, the invention correspondingly provides a readable storage medium embodiment;
In another embodiment of the present invention, a readable storage medium is provided, where the readable storage medium includes a stored computer program, and when the computer program is executed, the apparatus where the readable storage medium is located is controlled to execute the method for identifying the specification of the bottled drink according to any one of the method embodiments of the present invention.
The computer program may be divided into one or more modules, which are stored in the memory and executed by the processor to accomplish the present invention, for example. The one or more modules may be a series of computer program instruction segments capable of performing specific functions for describing the execution of the computer program in the terminal device.
The terminal equipment can be computing equipment such as a desktop computer, a notebook computer, a palm computer, a cloud server and the like. The terminal device may include, but is not limited to, a processor, a memory.
The Processor may be a central processing unit (Central Processing Unit, CPU), other general purpose Processor, digital signal Processor (DIGITAL SIGNAL Processor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), off-the-shelf Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. The general purpose processor may be a microprocessor or the processor may be any conventional processor or the like, which is a control center of the terminal device, and which connects various parts of the entire terminal device using various interfaces and lines.
The memory may be used to store the computer program and/or module, and the processor may implement various functions of the terminal device by running or executing the computer program and/or module stored in the memory and invoking data stored in the memory. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program (such as a sound playing function, an image playing function, etc.) required for at least one function, and the like; the storage data area may store data (such as audio data, phonebook, etc.) created according to the use of the handset, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as a hard disk, memory, plug-in hard disk, smart memory card (SMART MEDIA CARD, SMC), secure Digital (SD) card, flash memory card (FLASH CARD), at least one disk storage device, flash memory device, or other volatile solid-state storage device.
Wherein the terminal device integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium, i.e. the above-mentioned readable storage medium. Based on such understanding, the present invention may implement all or part of the flow of the method of the above embodiment, or may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, and when the computer program is executed by a processor, the computer program may implement the steps of each of the method embodiments described above. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth.
It should be noted that the above-described apparatus embodiments are merely illustrative, and the units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, in the drawings of the embodiment of the device provided by the invention, the connection relation between the modules represents that the modules have communication connection, and can be specifically implemented as one or more communication buses or signal lines. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
While the foregoing is directed to the preferred embodiments of the present invention, it will be appreciated by those skilled in the art that changes and modifications may be made without departing from the principles of the invention, such changes and modifications are also intended to be within the scope of the invention.