A method and system for nondestructive detection of fruit quality

By combining the fruit photos and near-infrared spectrum data taken by the camera, using the Transformer encoder for feature fusion, the problem of low accuracy of fruit quality detection in the existing technology is solved, the fruit size and peel color are taken into consideration, and the detection is improved. accuracy and non-destructiveness.

CN117347306BActive Publication Date: 2024-08-30SHENYANG AGRI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311463332.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-06
Publication Date
2024-08-30
Estimated Expiration
2043-11-06

AI Technical Summary

Technical Problem

The accuracy of near-infrared spectroscopy for fruit quality detection in the existing technology is low, and the impact of factors such as fruit size and peel color on near-infrared light absorption rate is not effectively considered.

Method used

Use left-right symmetrical cameras to take photos of fruits and combine them with near-infrared spectrum data from different angles. They are processed through feature fusion and Transformer encoders to fuse fruit images and near-infrared spectrum discrete data to improve detection accuracy.

Benefits of technology

It improves the accuracy of fruit quality testing and can more accurately evaluate the internal quality of the fruit without damaging the fruit, meeting the needs of farmers, fruit producers and consumers for non-destructive testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117347306B
    Figure CN117347306B
Patent Text Reader

Abstract

The present invention provides a method and system for nondestructive detection of fruit quality. Two fruit pictures are obtained by shooting vertically placed fruits with left-right symmetrical cameras, and the pictures are spliced ​​into a fruit image; near-infrared spectrum data obtained after irradiating fruits with near-infrared light sources at different angles are obtained to obtain near-infrared spectrum discrete data; the fruit image and the near-infrared spectrum discrete data are feature fused, and then input into a first encoder to obtain a first encoding result; the normalized vector corresponding to the discrete data corresponding to each near-infrared light source is input into a second encoder as a Token; the classification vector CLS output by the first encoder and the classification vector CLS of the second encoder are used as inputs of an MLP layer, and the output of the MLP layer is used as a result of the fruit quality. The present invention effectively avoids the influence of external factors such as peel color and fruit size in the nondestructive detection of fruit quality using near-infrared spectroscopy, and improves the accuracy of detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence, and in particular to a fruit quality nondestructive detection method and system. Background Art

[0002] As an indispensable part of daily life, fruits have always been loved by people. However, the quality of fruits is related to many factors, such as damage, bruises, sweetness, etc. The appearance of damage and cracks can be identified by human eyes or artificial intelligence, but the measurement of sweetness requires opening the fruit. In traditional testing methods, destructive testing of fruits is a serious problem. Fruit non-destructive testing technology will not cause any damage to the fruit, thus ensuring the integrity and quality of the fruit, which is a huge advantage for farmers and fruit producers, sellers and consumers because they can sell their products at a higher price.

[0003] Common non-destructive testing mainly includes optical testing, electromagnetic testing, ultrasonic testing, etc. Near-infrared spectroscopy (NIRS) is a non-invasive analysis method based on optical principles. It has made significant progress in the field of fruit non-destructive testing. It is an efficient, accurate and non-destructive method for fruit quality assessment. It mainly obtains the composition and tissue information of apples through diffuse reflection or diffuse transmission, extracts and analyzes the obtained spectral information, and thus detects the internal quality of the fruit. However, the size and skin color of fruits of the same variety, even fruits on the same tree, are different, which directly affects the absorption rate of near-infrared light. In the past, these factors were not considered when using near-infrared spectroscopy technology for fruit non-destructive testing. It is very important to integrate these factors into the near-infrared spectrum to improve the accuracy of detection. Summary of the invention

[0004] In order to improve the accuracy of fruit quality detection, the present invention provides a fruit quality non-destructive detection method, the method comprising the following steps:

[0005] The left-right symmetrical camera takes pictures of the vertically placed fruit to obtain two fruit pictures, and the two fruit pictures are spliced ​​into a fruit image; the near-infrared spectrum data obtained after the fruit is irradiated with near-infrared light sources at different angles is obtained, and the near-infrared spectrum data is smoothed to extract the discrete near-infrared spectrum data corresponding to each light source;

[0006] Performing feature fusion on the fruit image and the near-infrared spectrum discrete data, and inputting the fusion result into a first encoder to obtain a first encoding result; the first encoder includes at least two Transformer encoding layers;

[0007] The normalized vector corresponding to the discrete data corresponding to each near-infrared light source is input as a Token into the second encoder; the second encoder includes at least two Transformer encoding layers; the number of Transformer encoding layers of the first encoder and the second encoder is the same and one-to-one corresponding, and the Transformer encoding layer of the first encoder and the corresponding Transformer encoding layer of the second encoder are feature fused;

[0008] The classification vector CLS output by the first encoder and the classification vector CLS output by the second encoder are used as inputs of the MLP layer, and the output of the MLP layer is used as the result of fruit quality.

[0009] Preferably, the feature fusion of the fruit image and the near infrared spectrum discrete data is specifically as follows:

[0010] The discrete data corresponding to each near-infrared light source are formed into a 1×M vector, the vectors corresponding to all near-infrared light sources are spliced ​​into an N×M matrix, and the matrix is ​​bilinearly interpolated to obtain an M×M matrix; the fruit image is upsampled or downsampled and converted into an image of size M×M, and the matrix and the image are feature fused; wherein N represents the number of near-infrared light sources at different angles, and M represents the number of discrete data.

[0011] Preferably, the feature fusion of the matrix and the image is specifically as follows:

[0012] Normalize the matrix to [0, 1] by row, and normalize the three RGB channels of the image to [0, 1] respectively, and use the matrix as the fourth channel of the image;

[0013] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×4 equals M, where K and L are positive integers;

[0014] Expand each patch into a vector of size 1×M as the fusion result.

[0015] Preferably, the feature fusion of the matrix and the image is specifically performed as follows:

[0016] Normalize the matrix to [0, 0.5] by row, and normalize the three RGB channels of the image to [0, 1] respectively, superimpose the matrix on each of the three RGB channels, and then normalize the three RGB channels to [0, 1] respectively;

[0017] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×3 equals M, where K and L are positive integers;

[0018] Expand each patch into a vector of size 1×M as the fusion result.

[0019] Preferably, the Transformer coding layer of the first encoder and the corresponding Transformer coding layer of the second encoder perform feature fusion, specifically:

[0020] The classification vector CLS1 output by the first Transformer encoding layer of the first encoder and the classification vector CLS2 output by the first Transformer encoder of the second encoder are averaged to obtain a new classification vector CLS3 to replace CLS1 and CLS2.

[0021] Preferably, the method further comprises:

[0022] The output of the Pth Transformer encoding layer of the first encoder is converted into a 1×M vector through an MLP layer and combined with the output of the Pth Transformer encoding layer of the second encoder, so that the number of input vectors of the P+1th Transformer encoder corresponding to the second encoder increases by 1.

[0023] In another aspect, the present invention provides a fruit quality non-destructive detection system, the system comprising the following modules:

[0024] The data acquisition module uses a left-right symmetrical camera to take pictures of vertically placed fruits to obtain two fruit pictures, and splices the two fruit pictures into a fruit image; obtains near-infrared spectrum data obtained after the fruit is irradiated with near-infrared light sources at different angles, and after smoothing the near-infrared spectrum data, extracts discrete near-infrared spectrum data corresponding to each light source;

[0025] A first fusion module is used to perform feature fusion on the fruit image and the near infrared spectrum discrete data, and input the fusion result into a first encoder to obtain a first encoding result; the first encoder includes at least two Transformer encoding layers;

[0026] The second fusion module is used to input the normalized vector corresponding to the discrete data corresponding to each near-infrared light source into the second encoder as a Token; the second encoder includes at least two Transformer encoding layers; the number of Transformer encoding layers of the first encoder and the second encoder is the same and one-to-one corresponding, and the Transformer encoding layer of the first encoder and the corresponding Transformer encoding layer of the second encoder perform feature fusion;

[0027] The result output module is used to use the classification vector CLS output by the first encoder and the classification vector CLS of the second encoder as the input of the MLP layer, and use the output of the MLP layer as the result of fruit quality.

[0028] Preferably, the feature fusion of the fruit image and the near infrared spectrum discrete data is specifically as follows:

[0029] The discrete data corresponding to each near-infrared light source are formed into a 1×M vector, the vectors corresponding to all near-infrared light sources are spliced ​​into an N×M matrix, and the matrix is ​​bilinearly interpolated to obtain an M×M matrix; the fruit image is upsampled or downsampled and converted into an image of size M×M, and the matrix and the image are feature fused; wherein N represents the number of near-infrared light sources at different angles, and M represents the number of discrete data.

[0030] Preferably, the feature fusion of the matrix and the image is specifically performed as follows:

[0031] Normalize the matrix to [0, 1] by row, and normalize the three RGB channels of the image to [0, 1] respectively, and use the matrix as the fourth channel of the image;

[0032] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×4 equals M, where K and L are positive integers;

[0033] Expand each patch into a vector of size 1×M as the fusion result.

[0034] Preferably, the feature fusion of the matrix and the image is specifically performed as follows:

[0035] Normalize the matrix to [0, 0.5] by row, and normalize the three RGB channels of the image to [0, 1] respectively, superimpose the matrix on each of the three RGB channels, and then normalize the three RGB channels to [0, 1] respectively;

[0036] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×3 equals M, where K and L are positive integers;

[0037] Expand each patch into a vector of size 1×M as the fusion result.

[0038] Preferably, the Transformer coding layer of the first encoder and the corresponding Transformer coding layer of the second encoder perform feature fusion, specifically:

[0039] The classification vector CLS1 output by the first Transformer encoding layer of the first encoder and the classification vector CLS2 output by the first Transformer encoder of the second encoder are averaged to obtain a new classification vector CLS3 to replace CLS1 and CLS2.

[0040] Preferably, the method further comprises:

[0041] The output of the Pth Transformer encoding layer of the first encoder is converted into a 1×M vector through an MLP layer and combined with the output of the Pth Transformer encoding layer of the second encoder, so that the number of input vectors of the P+1th Transformer encoder corresponding to the second encoder increases by 1.

[0042] Finally, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described above is implemented.

[0043] In view of the low accuracy of fruit quality detection using near-infrared spectroscopy in the prior art, the present invention adopts artificial vision to analyze external factors affecting near-infrared light absorption rate, such as fruit size and peel color, and integrates them into the near-infrared spectrum of the collected fruit, thereby improving the accuracy of detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0045] Figure 1 This is a flow chart of Embodiment 1;

[0046] Figure 2 Schematic diagram for taking photos of fruits;

[0047] Figure 3 is a schematic diagram of a first network structure;

[0048] Figure 4 is a schematic diagram of a second network structure;

[0049] Figure 5 It is a structural diagram of the second embodiment. DETAILED DESCRIPTION

[0050] In this article, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0051] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0052] Embodiment 1

[0053] The present invention provides a method for nondestructive testing of fruit quality. Figure 1 As shown, the method comprises the following steps:

[0054] S1, using a left-right symmetrical camera to take pictures of vertically placed fruits to obtain two pictures of fruits, and splicing the two pictures of fruits into one picture of fruits; obtaining near-infrared spectrum data obtained after irradiating the fruits with near-infrared light sources at different angles, and extracting near-infrared spectrum discrete data corresponding to each light source after smoothing the near-infrared spectrum data;

[0055] The size, color, spots, and rot of fruits can all be identified through computer vision. The color or pattern of some fruits is also closely related to the sweetness of the fruit. For example, in general, dark red Fuji apples are sweeter than light red Fuji apples, and even if the Fuji apples are of the same color, the larger ones taste better than the smaller ones. In addition, the absorption of near-infrared is also different. Large Fuji apples absorb more near-infrared due to their larger radius; even if the Fuji apples are of the same size, the different colors of the peel will affect the absorption rate. If the fruit quality is judged only based on the absorption rate, the accuracy is often poor.

[0056] Based on this, the present invention adopts a left-right symmetrical camera to take pictures of fruits. In order to be able to capture the appearance of the entire fruit, the left and right cameras are set to shoot, and the two are symmetrical, so that the appearance of the fruit can be captured as much as possible. Of course, three cameras or four cameras can also be used. Considering data processing and processing efficiency, it is preferred to use left-right symmetrical cameras to take pictures of upright fruits, such as Figure 2 As shown, the so-called upright fruit means that the fruit stalk is on top.

[0057] After shooting, the two images are merged into one image. Specifically, the merging or splicing method may be to combine the two images into the left half and the right half of one image.

[0058] When collecting near-infrared spectra of fruits, the fruits are irradiated by near-infrared light sources at multiple different angles. For example, the fruits are still upright, and multiple near-infrared light sources are set above the middle of the fruits to irradiate in sequence. The spectrum data in the diffuse transmission mode can be obtained by the near-infrared spectrometer. If there are 5 near-infrared light sources, 5 groups of spectrum data will be obtained. After smoothing each group of data, the near-infrared spectrum discrete data corresponding to each light source is obtained. Among them, there are many ways to smooth, such as outlier removal, etc. For each group of data, the absorbance corresponding to several wavelengths can be extracted to obtain the near-infrared spectrum discrete data. In a preferred embodiment, data extraction is performed in a way that an absorbance is obtained at each preset wavelength.

[0059] S2, performing feature fusion on the fruit image and the near infrared spectrum discrete data, and inputting the fusion result into a first encoder to obtain a first encoding result; the first encoder includes at least two Transformer encoding layers;

[0060] The fruit image obtained in step S1 represents the appearance of the fruit. The appearance contains at least two aspects of information: one is the degree of influence on the absorption rate of near-infrared light, and the other is the information containing the quality of the fruit. For example, a red and large apple tastes better than a small and not red apple.

[0061] Soluble solids in fruits, such as soluble sugars and acids, will affect the absorption of near-infrared light by fruits. Near-infrared spectral information is obtained from the inside of fruits. The fruit image and the near-infrared spectral discrete data are fused to fuse the external features and internal features of the fruit. In a specific embodiment, the feature fusion of the fruit image and the near-infrared spectral discrete data is specifically as follows:

[0062] The discrete data corresponding to each near-infrared light source are formed into a 1×M vector, the vectors corresponding to all near-infrared light sources are spliced ​​into an N×M matrix, and the matrix is ​​bilinearly interpolated to obtain an M×M matrix; the fruit image is upsampled or downsampled and converted into an image of size M×M, and the matrix and the image are feature fused; wherein N represents the number of near-infrared light sources at different angles, and M represents the number of discrete data.

[0063] Each near-infrared light source corresponds to a group of near-infrared spectrum data. After smoothing and extracting this group of near-infrared spectrum data, a group of discrete near-infrared spectrum data is obtained, such as the corresponding absorbance a1 at a wavelength of 600nm, the corresponding absorbance a2 at a wavelength of 700, etc. Of course, the degree of absorption can also be expressed by transmittance, etc., which is not specifically limited here. If there are 100 discrete data, then M=100, and each near-infrared light source corresponds to a 1×100 vector. If there are 5 near-infrared light sources, then N=5, and the resulting matrix is ​​5×100, wherein each row of the matrix represents a group of discrete data corresponding to a light source. In order to merge with the fruit image, the scale of the matrix needs to be converted to the same as the image scale. Preferably, bilinear interpolation is performed on the N×M matrix. Of course, bilinear interpolation or other methods can also be used to convert the N×M matrix into an M×M matrix, which is then converted into a 100×100 matrix.

[0064] Similarly, the scale of the fruit image is converted to 100×100, which is conducive to the fusion of the near infrared spectrum data and the fruit image. In a more specific embodiment, the matrix and the image are subjected to feature fusion, specifically:

[0065] Normalize the matrix to [0, 1] by row, and normalize the three RGB channels of the image to [0, 1] respectively, and use the matrix as the fourth channel of the image;

[0066] The image has three channels, RGB, with a minimum value of 0 and a maximum value of 255. The discrete data of the near-infrared spectrum is usually less than 1 or less than 2 (this is related to the specific unit representing the degree of absorption of the near-infrared spectrum). This requires normalization. In this embodiment, each channel and matrix of the image is normalized to [0,1], and then the normalized matrix is ​​used as the fourth channel of the image.

[0067] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×4 equals M, where K and L are positive integers;

[0068] Expand each patch into a vector of size 1×M as the fusion result.

[0069] The image is then divided into multiple blocks (patches), which are embedded and added to the embedding of the patch position before being input into the first encoder. The embedding of the patch is preferably obtained by expanding each patch. If M = 100, then K×L×4 = 100, that is, K×L = 25, then K = L = 5, where 4 is because the image has four channels.

[0070] The first encoder preferably uses an encoder of the ViT model. The first encoder includes at least two Transformer encoding layers. The Transformer encoding layer is also called Transformer Layer, Transformer Block, TransformerEncoder Layer, and Transformer Encoder Block. In the Transformer, the encoder Encoder is composed of multiple identical layers stacked together, wherein the identical layers are called Transformer encoding layers. The Transformer encoding layer includes two sublayers. The first sublayer is a multi-head attention mechanism layer, and the second sublayer is a fully connected layer. Each sublayer has a residual connection, and the output of each sublayer is: z l' =MSA(LN(z l-1 ))+z l-1 、z l =MLP(LN(z' l ))+z' l ; Among them, z l-1 is the output of the previous Transformer encoding layer.

[0071] In another optional embodiment, the feature fusion of the matrix and the image is specifically:

[0072] Normalize the matrix to [0, 0.5] by row, and normalize the three RGB channels of the image to [0, 1] respectively, superimpose the matrix on each of the three RGB channels, and then normalize the three RGB channels to [0, 1] respectively;

[0073] After normalizing the matrix to [0,0.5] by row, add it to each of the three normalized RGB channels, and then normalize each channel again.

[0074] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×3 equals M, where K and L are positive integers;

[0075] Expand each patch into a vector of size 1×M as the fusion result.

[0076] If M=108, then K×L×3=108, that is, K×L=36, then K=L=6, where 3 is because the image has 3 channels.

[0077] S3, inputting the normalized vector corresponding to the discrete data corresponding to each near-infrared light source into the second encoder as a Token; the second encoder includes at least two Transformer encoding layers; the first encoder and the second encoder have the same number of Transformer encoding layers and correspond one to one, and the Transformer encoding layer of the first encoder and the corresponding Transformer encoding layer of the second encoder perform feature fusion;

[0078] Each near-infrared light source corresponds to a 1×M vector. If M=100 and there are 5 near-infrared light sources, 5 1×100 vectors will be obtained. Each vector is used as a Token and then input into the second encoder. The second encoder preferably uses the BERT model.

[0079] In another embodiment, the first encoder and the second encoder have the same structure. Figure 3 , preferably using the ViT model, but the difference is that when performing embedding, the first encoder also needs to add the position embedding, while the second encoder does not need to, such as Figure 3 and Figure 4 As shown, how to perform embedding specifically belongs to the prior art and will not be described here. When setting the number of Transformer coding layers of the first encoder and the second encoder, the two are set to be the same, for example, both use 3 Transformer coding layers, such as Figure 3 In order to better fuse the features, the Transformer encoding layer of the first encoder and the corresponding Transformer encoding layer of the second encoder are subjected to feature fusion, specifically:

[0080] The classification vector CLS1 output by the first Transformer coding layer of the first encoder and the classification vector CLS2 output by the first Transformer coding layer of the second encoder are averaged to obtain a new classification vector CLS3 to replace CLS1 and CLS2, and then serve as the input of the second Transformer coding layer of the first and second encoders. The replacement here means replacing CLS1 in the output of the first Transformer coding layer of the first encoder and CLS2 in the output of the first Transformer coding layer of the second encoder, while keeping the other parts unchanged, and then inputting them into the corresponding second Transformer coding layer.

[0081] The first token in the first encoder and the second encoder is CLS, also known as class token, classification vector token, classification vector CLS. In further fusion, the classification vector CLS1 output by the first Transformer encoding layer of the first encoder and the classification vector CLS2 output by the first Transformer encoder of the second encoder are averaged to obtain a new classification vector CLS3, and then CLS3 is used to replace CLS1 and CLS2. The first Transformer encoder refers to the first Transformer encoder counted from input to output.

[0082] In another embodiment, the method further comprises:

[0083] The output of the Pth Transformer encoding layer of the first encoder is converted into a 1×M vector through an MLP layer and combined with the output of the Pth Transformer encoding layer of the second encoder, as shown in Figure 4 As shown, the number of input vectors of the P+1th Transformer encoder corresponding to the second encoder increases by 1.

[0084] The combination refers to converting the output of the Pth Transformer coding layer of the first encoder into a 1×M vector through an MLP layer and appending it to the output of the Pth Transformer coding layer of the second encoder. For example, the original Pth Transformer coding layer corresponds to 5 Tokens, that is, 5 1×M vectors, which become 6 1×M vectors after combination and serve as the input of the P+1th Transformer coding layer.

[0085] S4, taking the classification vector CLS output by the first encoder and the classification vector CLS output by the second encoder as the input of the MLP layer, and taking the output of the MLP layer as the result of fruit quality.

[0086] The classification vector CLS output by the first encoder is a 1×M vector, and the classification vector CLS output by the second encoder is also a 1×M vector. The two are fused into a 1×2M vector as the input of the MLP (Multi-Layer Perception). The output of the MLP layer corresponds to the highest probability, which is the quality of the fruit finally determined. The quality of the fruit is divided into multiple grades. In an exemplary embodiment, three grades are included, namely: good, good, and poor. Of course, it can also be divided into more detailed grades. The present invention does not make specific limitations on this. In addition, the fruits in the present invention include but are not limited to apples, pears, kiwis, pitaya, strawberries, carambolas, etc.

[0087] Embodiment 2

[0088] The present invention provides a fruit quality nondestructive detection system, such as Figure 5 As shown, the system includes the following modules:

[0089] The data acquisition module uses a left-right symmetrical camera to take pictures of vertically placed fruits to obtain two fruit pictures, and splices the two fruit pictures into a fruit image; obtains near-infrared spectrum data obtained after the fruit is irradiated with near-infrared light sources at different angles, and after smoothing the near-infrared spectrum data, extracts discrete near-infrared spectrum data corresponding to each light source;

[0090] A first fusion module is used to perform feature fusion on the fruit image and the near infrared spectrum discrete data, and input the fusion result into a first encoder to obtain a first encoding result; the first encoder includes at least two Transformer encoding layers;

[0091] The second fusion module is used to input the normalized vector corresponding to the discrete data corresponding to each near-infrared light source into the second encoder as a Token; the second encoder includes at least two Transformer encoding layers; the number of Transformer encoding layers of the first encoder and the second encoder is the same and one-to-one corresponding, and the Transformer encoding layer of the first encoder and the corresponding Transformer encoding layer of the second encoder perform feature fusion;

[0092] The result output module is used to use the classification vector CLS output by the first encoder and the classification vector CLS of the second encoder as the input of the MLP layer, and use the output of the MLP layer as the result of fruit quality.

[0093] Preferably, the feature fusion of the fruit image and the near infrared spectrum discrete data is specifically as follows:

[0094] The discrete data corresponding to each near-infrared light source are formed into a 1×M vector, the vectors corresponding to all near-infrared light sources are spliced ​​into an N×M matrix, and the matrix is ​​bilinearly interpolated to obtain an M×M matrix; the fruit image is upsampled or downsampled and converted into an image of size M×M, and the matrix and the image are feature fused; wherein N represents the number of near-infrared light sources at different angles, and M represents the number of discrete data.

[0095] Preferably, the feature fusion of the matrix and the image is specifically performed as follows:

[0096] Normalize the matrix to [0, 1] by row, and normalize the three RGB channels of the image to [0, 1] respectively, and use the matrix as the fourth channel of the image;

[0097] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×4 equals M, where K and L are positive integers;

[0098] Expand each patch into a vector of size 1×M as the fusion result.

[0099] Preferably, the feature fusion of the matrix and the image is specifically performed as follows:

[0100] Normalize the matrix to [0, 0.5] by row, and normalize the three RGB channels of the image to [0, 1] respectively, superimpose the matrix on each of the three RGB channels, and then normalize the three RGB channels to [0, 1] respectively;

[0101] The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×3 equals M, where K and L are positive integers;

[0102] Expand each patch into a vector of size 1×M as the fusion result.

[0103] Preferably, the Transformer coding layer of the first encoder and the corresponding Transformer coding layer of the second encoder perform feature fusion, specifically:

[0104] The classification vector CLS1 output by the first Transformer encoding layer of the first encoder and the classification vector CLS2 output by the first Transformer encoder of the second encoder are averaged to obtain a new classification vector CLS3 to replace CLS1 and CLS2.

[0105] Preferably, the method further comprises:

[0106] The output of the Pth Transformer encoding layer of the first encoder is converted into a 1×M vector through an MLP layer and combined with the output of the Pth Transformer encoding layer of the second encoder, so that the number of input vectors of the P+1th Transformer encoder corresponding to the second encoder increases by 1.

[0107] Embodiment 3

[0108] The present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a computer, the method described in the first embodiment is implemented.

[0109] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by combining hardware and software. Based on such an understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a computer product, and the present invention can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for nondestructive testing of fruit quality, characterized in that: The method comprises the following steps: The left-right symmetrical camera takes pictures of the vertically placed fruit to obtain two fruit pictures, and the two fruit pictures are spliced ​​into a fruit image; the near-infrared spectrum data obtained after the fruit is irradiated with near-infrared light sources at different angles is obtained, and the near-infrared spectrum data is smoothed to extract the discrete near-infrared spectrum data corresponding to each light source; Performing feature fusion on the fruit image and the near-infrared spectrum discrete data, and inputting the fusion result into a first encoder to obtain a first encoding result; the first encoder includes at least two Transformer encoding layers; The normalized vector corresponding to the discrete data corresponding to each near-infrared light source is input as a Token into the second encoder; the second encoder includes at least two Transformer encoding layers; the number of Transformer encoding layers of the first encoder and the second encoder is the same and one-to-one corresponding, and the Transformer encoding layer of the first encoder and the corresponding Transformer encoding layer of the second encoder are feature fused; The classification vector CLS output by the first encoder and the classification vector CLS of the second encoder are used as inputs of the MLP layer, and the output of the MLP layer is used as the result of fruit quality; The feature fusion of the fruit image and the near infrared spectrum discrete data is specifically as follows: The discrete data corresponding to each near-infrared light source is formed into a 1×M vector, the vectors corresponding to all near-infrared light sources are spliced ​​into an N×M matrix, and the matrix is ​​bilinearly interpolated to obtain an M×M matrix; the fruit image is upsampled or downsampled and converted into an image of size M×M, and the matrix and the image are feature fused; wherein N represents the number of near-infrared light sources at different angles, and M represents the number of discrete data; The Transformer coding layer of the first encoder and the corresponding Transformer coding layer of the second encoder perform feature fusion, specifically: The classification vector CLS1 output by the first Transformer encoding layer of the first encoder and the classification vector CLS2 output by the first Transformer encoder of the second encoder are averaged to obtain a new classification vector CLS3 to replace CLS1 and CLS2.

2. The method according to claim 1, characterized in that The feature fusion of the matrix and the image is specifically as follows: Normalize the matrix to [0, 1] by row, and normalize the three RGB channels of the image to [0, 1] respectively, and use the matrix as the fourth channel of the image; The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×4 equals M, where K and L are positive integers; Expand each patch into a vector of size 1×M as the fusion result.

3. The method according to claim 1, characterized in that The feature fusion of the matrix and the image is specifically as follows: Normalize the matrix to [0, 0.5] by row, and normalize the three RGB channels of the image to [0, 1] respectively, superimpose the matrix on each of the three RGB channels, and then normalize the three RGB channels to [0, 1] respectively; The multidimensional matrix corresponding to the image is divided into a plurality of patches, each of which has a size of K×L and satisfies K×L×3 equals M, where K and L are positive integers; Expand each patch into a vector of size 1×M as the fusion result.

4. The method according to claim 1, characterized in that The method further comprises: The output of the Pth Transformer encoding layer of the first encoder is converted into a 1×M vector through an MLP layer and combined with the output of the Pth Transformer encoding layer of the second encoder, so that the number of input vectors of the P+1th Transformer encoder corresponding to the second encoder increases by 1.

5. A fruit quality nondestructive testing system, characterized in that: The system includes the following modules: The data acquisition module uses a left-right symmetrical camera to take pictures of vertically placed fruits to obtain two fruit pictures, and splices the two fruit pictures into a fruit image; obtains near-infrared spectrum data obtained after the fruit is irradiated with near-infrared light sources at different angles, and after smoothing the near-infrared spectrum data, extracts discrete near-infrared spectrum data corresponding to each light source; A first fusion module is used to perform feature fusion on the fruit image and the near infrared spectrum discrete data, and input the fusion result into a first encoder to obtain a first encoding result; the first encoder includes at least two Transformer encoding layers; The second fusion module is used to input the normalized vector corresponding to the discrete data corresponding to each near-infrared light source into the second encoder as a Token; the second encoder includes at least two Transformer encoding layers; the number of Transformer encoding layers of the first encoder and the second encoder is the same and one-to-one corresponding, and the Transformer encoding layer of the first encoder and the corresponding Transformer encoding layer of the second encoder perform feature fusion; A result output module is used to use the classification vector CLS output by the first encoder and the classification vector CLS of the second encoder as inputs of the MLP layer, and use the output of the MLP layer as a result of fruit quality; The feature fusion of the fruit image and the near infrared spectrum discrete data is specifically as follows: The discrete data corresponding to each near-infrared light source is formed into a 1×M vector, the vectors corresponding to all near-infrared light sources are spliced ​​into an N×M matrix, and the matrix is ​​bilinearly interpolated to obtain an M×M matrix; the fruit image is upsampled or downsampled and converted into an image of size M×M, and the matrix and the image are feature fused; Wherein N represents the number of near-infrared light sources at different angles, and M represents the number of discrete data; The Transformer coding layer of the first encoder and the corresponding Transformer coding layer of the second encoder perform feature fusion, specifically: The classification vector CLS1 output by the first Transformer encoding layer of the first encoder and the classification vector CLS2 output by the first Transformer encoder of the second encoder are averaged to obtain a new classification vector CLS3 to replace CLS1 and CLS2.

6. A computer-readable storage medium, wherein a computer program is stored on the storage medium, and when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Image defogging method and device fused with near-infrared Transform structure

    CN116703752A