A method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN
Through the improved 3D-SwinT-CNN model, combined with 3D Swin Transformer and 3D-CNN, the uncertainty and computational complexity problems in detecting the fermentation degree of black tea are solved, the fermentation degree of black tea is quickly and accurately determined, and the processing of black tea is improved. Stability of quality and consistency of flavor.
Patent Information
- Application Number
- CN202410942969.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-07-15
AI Technical Summary
In the existing technology, the detection of black tea fermentation degree is uncertain and relies on manual review. Data preprocessing is complex and traditional 3D-CNN cannot capture global features. The Transformer model requires a large amount of calculation and is not suitable for hyperspectral image analysis.
The improved 3D-SwinT-CNN model is used, combined with 3D Swin Transformer and 3D-CNN, to reduce computational complexity and capture the space of three-dimensional hyperspectral images by extending the moving window self-attention mechanism and multi-scale spectral-spatial joint feature extraction module. -Spectral combined features to achieve end-to-end identification of the fermentation degree of black tea.
It achieves rapid and accurate identification of the fermentation degree of black tea, reduces model complexity and calculation amount, improves the stability and flavor consistency of black tea processing quality, and promotes the digitalization and intelligence of black tea processing.
Smart Images

Figure CN118533834B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of food engineering, and in particular relates to a method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN. Background Art
[0002] The traditional processing technology of black tea includes withering, rolling, fermentation and drying. Fermentation is the key process for the formation of the characteristic flavor of black tea. The degree of fermentation will directly determine the quality of the finished black tea. In this process, black tea mainly achieves its characteristic flavor through enzymatic oxidation with polyphenol compounds as the main body. Under the appropriate fermentation temperature and humidity environment, the substances contained in the tea undergo a series of complex chemical reactions such as violent oxidation polymerization and condensation to form substances such as theaflavins, thearubigins and theabrownins. In addition, the surface color of black tea will undergo the following changes: light green-cyan-yellow-red-copper red-reddish brown, and the smell of black tea will gradually change from grassy to aromatic, thus finally forming a unique color, aroma, taste and quality. Therefore, accurate judgment of the degree of fermentation of black tea is crucial.
[0003] At present, in the on-site black tea processing and production, the detection and evaluation of the fermentation state of black tea mainly rely on the observation of the black tea on-site and their personal experience by tea experts. This method has uncertainty and is easily affected by human subjective factors, resulting in light or excessive fermentation, which directly affects the quality stability and flavor consistency of black tea. Hyperspectral imaging (HSI) technology has the advantages of being fast and non-destructive. In recent years, it has been widely studied in the task of distinguishing the fermentation degree of black tea. Existing literature extracts average spectral data and image feature information, and combines machine learning algorithms to carry out research on distinguishing the fermentation degree of black tea. However, this method has a complex data preprocessing process, and the extraction of spectral and image features depends on expert experience. Compared with traditional machine learning, deep learning models have achieved better performance in end-to-end hyperspectral image classification and regression analysis; among them, convolutional neural network (CNN) is one of the mainstream algorithms with powerful feature learning capabilities. Three-dimensional CNN (3D-CNN) has been applied to hyperspectral image analysis. It can directly extract local signal changes in space and spectrum from the original hyperspectral image, extract local spectral-spatial joint features end-to-end, and classify based on the extracted features. However, 3D-CNN focuses on local information, cannot capture global feature information, and has difficulty capturing sequence properties, especially medium- and long-term spectral dependencies. In contrast, the Transformer model captures long-range spectral-spatial features through an attention mechanism to achieve the construction of a global information model. However, the original Transformer model uses a global attention mechanism for all pixels in the image to calculate the relationship between a certain pixel in the image and all elements. The computational complexity is high and increases with the increase of image size. In order to reduce the computational complexity of the model, some scholars proposed a moving window (Swin) Transformer model, which significantly reduces the computational complexity of the self-attention mechanism by introducing a shift window mechanism. However, this method has not yet been extended to the analysis and modeling of three-dimensional data blocks of hyperspectral images, and has not been studied in the discrimination of the degree of fermentation of black tea.
[0004] In summary, the problems existing in the prior art are:
[0005] (1) There is uncertainty in the evaluation of the fermentation degree of black tea by tea-making experts, which is easily affected by subjective factors, resulting in light or excessive fermentation, which directly affects the quality stability and flavor consistency of black tea.
[0006] (2) Based on one-dimensional average spectral data and image feature information, the traditional machine learning algorithm was combined to carry out research on the discrimination of the fermentation degree of black tea. However, the data preprocessing process of this method is complicated, and the extraction of spectral and image features depends on expert experience.
[0007] (3) Traditional 3D-CNN can extract local spectral-spatial features end-to-end, but cannot focus on global features. The Transformer model has a large amount of computation and is not suitable for the analysis of high-dimensional data blocks of hyperspectral images.
[0008] Therefore, in the task of discriminating the fermentation degree of black tea, it is urgent to explore a new algorithm to fully exploit the spatial-spectral characteristics of three-dimensional hyperspectral images, reduce the model complexity and computational complexity, process black tea hyperspectral images end-to-end, and realize rapid discrimination of the fermentation degree of black tea. Summary of the invention
[0009] The object of the present invention is to provide a method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN to solve the above-mentioned technical problems.
[0010] In order to solve the above technical problems, the present invention provides a method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN. The Swin Transformer model is improved to a 3D Swin Transformer that can extract three-dimensional image features, and an improved 3D-SwinT-CNN is constructed in combination with 3D-CNN, which can fully exploit the three-dimensional space-spectral features of HSI and realize the effective distinction of the fermentation degree of black tea, specifically comprising the following steps:
[0011] A method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN comprises the following steps:
[0012] S1: Fermented black tea hyperspectral image acquisition and preprocessing: Build a hyperspectral imaging system, set the spectral band range and spatial resolution, collect hyperspectral images of fermented black tea leaves at different fermentation degrees, correct the original hyperspectral images, and perform image preprocessing;
[0013] S2: Design of 3D Swin Transformer module: Extend the moving window self-attention mechanism in the Swin Transformer model to 3D hyperspectral image processing to capture the key spatial-spectral joint features and global features of 3D hyperspectral images;
[0014] S3: Design of 3D-SwinT-CNN model: including three modules, one of which is the 3D SwinTransformer module described in S2, and the other two modules are 3D multi-scale spectral-spatial joint feature extraction module and classifier module;
[0015] S4: Algorithm model performance comparison: The data set was divided, and the 3D-SwinT-CNN model described in S3 was constructed and compared with the benchmark 3D-CNN. At the same time, an ablation experiment was performed on the 3D-SwinT-CNN to verify the effectiveness of the proposed 3D-SwinT-CNN combined with HSI in discriminating the fermentation degree of black tea.
[0016] Further, the hyperspectral imaging system described in S1 is a visible-near infrared hyperspectral imaging system, including a spectral camera, a lens, a light source and an image acquisition platform;
[0017] The spectral band range is 470-900nm, with a total of 140 bands;
[0018] The spatial resolution was adjusted according to the leaf sample size.
[0019] Furthermore, the specific operation of collecting hyperspectral images of fermented black tea leaves at different fermentation degrees in S1 is to extend the fermentation time so that the black tea samples cover the over-fermentation stage; set multiple time points within multiple hours, and collect a batch of fermentation samples at each time point; define the end of rolling as fermentation time 0, and collect hyperspectral images of black tea samples at multiple time points during the fermentation process; divide the samples at multiple different fermentation time sequences into four categories according to the fermentation degree: initial fermentation, insufficient fermentation, moderate fermentation, and over-fermentation;
[0020] Furthermore, the original hyperspectral image correction described in S1 is a black and white correction to reduce the influence of illumination and camera dark current on the acquisition of different sample spectra. The specific calculation formula is as follows (1):
[0021]
[0022] in R 0 and R are the hyperspectral images before and after correction, W and D They are whiteboard reference image and dark current reference image respectively;
[0023] Furthermore, the image preprocessing in S1 includes background removal and image segmentation, in the following manner: the near-infrared band with the largest difference in spectral reflectance between leaves and background is used as the threshold band for background removal; image segmentation is then performed, and then an image containing only fermented black tea leaves is cut out; the segmented three-dimensional hyperspectral image is used to establish a three-dimensional black tea fermentation degree discrimination model.
[0024] Furthermore, the moving window self-attention mechanism in the Swin Transformer model is extended to three-dimensional hyperspectral image processing as described in S2, which means that the Swin Transformer extends the moving window to a 3D structure to capture the long-range spatial-spectral features of HSI to form a 3D Swin Transformer module; the 3D Swin Transformer module performs the following steps: the input size of HSI is 1×140×64×64; first, 3D Patch Partition splits the input HSI into 64 patches of size 35×16×16; secondly, Linear Embedding projects each patch to a dimension of 64×8960 and marks the location information of each patch; finally, these patches are sent to the 3D Swin Transformer to generate a feature map of size 16×35×32×32; the components of the 3D Swin Transformer module include a multi-layer perceptron MLP, a layer normalization LN, a residual connection, and a 3D window-based multi-head self-attention mechanism 3D W-MSA and 3D SW-MSA based on 3D shift window multi-head self-attention mechanism; the calculation process of 3D Swin Transformer is expressed by the following formula:
[0025]
[0026]
[0027]
[0028]
[0029] in and Represents blocks l Output features of the 3D W-MSA module and the 3D SW-MSA module; and Representation Block l of Output features of the module;
[0030] The multi-head self-attention mechanism MSA can capture the complex relationship between HSI. MSA is the splicing of multiple single self-attention modules; for single self-attention, a learnable weight matrix is used , and Linearly map patches to queries Q , key K and numerical values Vmatrix, as shown in formula (6); for MSA, the results of each attention head are concatenated together to obtain the final representation of multi-head attention, expressed by formula (7); where h is the number of heads, W is the parameter matrix;
[0031]
[0032]
[0033] in, S is a single self-attention, Q , K , V are query, key, and value matrix respectively, d Yes Query Q / Key K Dimension.
[0034] Furthermore, the 3D Swin Transformer model described in S2 integrates the spectral domain into W-MSA to form a 3D W-MSA, which takes into account window division and movement and establishes a 3D moving window mechanism. The 3D moving window mechanism is as follows: first, the entire 3D data is divided into smaller windows; these windows are usually cubic in shape, containing a small part of the original 3D data, and the self-attention mechanism is calculated within the window; the window of the latter layer moves a distance of half the window size in height, width and spectral dimensions.
[0035] Furthermore, the 3D multi-scale spectral-spatial joint feature extraction module described in S3 introduces dilated convolution in 3D-CNN, concatenates the results of standard convolution and dilated convolution, and convolution kernels with different receptive fields extract spectral-spatial features of different scales from feature maps. The output feature maps generated by different convolutions are batch normalized and then concatenated along the channel dimension.
[0036] Furthermore, the classifier module described in S3 refers to a 3D-SwinT-CNN model classifier consisting of three serially connected convolutional layers followed by a fully connected layer, each convolutional layer is followed by a batch normalization layer, the size of all convolution kernels in the convolutional layer is set to 3×3×3, and the padding is set to 1×1×1; the input features are passed through the classifier to distinguish different fermentation degrees, and finally the classification of the black tea hyperspectral image is realized.
[0037] Furthermore, the performance comparison of the algorithm model described in S4 includes: dividing the data set, constructing the 3D-SwinT-CNN model described in S3, and comparing it with the benchmark 3D-CNN, and performing an ablation experiment on the 3D-SwinT-CNN to verify the effectiveness of the proposed 3D-SwinT-CNN combined with HSI in discriminating the fermentation degree of black tea.
[0038] The black tea fermentation degree discrimination method based on 3D-SwinT-CNN of the present invention has the following advantages:
[0039] (1) In view of the problems that manual evaluation of the fermentation degree of black tea is highly subjective and cannot be quantified, the present invention proposes a method for using HSI to identify the fermentation degree of black tea. The improved 3D-SwinT-CNN is used to capture the key spatial-spectral joint features and global features of three-dimensional hyperspectral images to achieve the identification of the fermentation degree of black tea.
[0040] (2) Compared with traditional deep learning algorithms, the 3D-SwinT-CNN algorithm proposed in the present invention has a smaller amount of computational effort in extracting three-dimensional features, better model performance, and more significant effects. It can realize end-to-end processing of black tea hyperspectral images, contribute to the digitization and intelligence of the black tea fermentation process, and improve the processing quality of black tea. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a workflow diagram of a method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN of the present invention;
[0042] Figure 2 It is the average spectrum curve diagram of the hyperspectral image of black tea at different fermentation times of the present invention;
[0043] Figure 3a 3D Swin Transformer module structure diagram of the present invention;
[0044] Figure 3b It is a flow chart of the calculation of the components of the 3D Swin Transformer module of the present invention;
[0045] Figure 4 The window division and shifting mechanism of the 3D Swin Transformer module of the present invention;
[0046] Figure 5a 3D standard convolution structure diagram of the 3D multi-scale spectral-spatial joint feature extraction module of the present invention;
[0047] Figure 5b Expanding the 3D convolution structure diagram for the 3D multi-scale spectral-spatial joint feature extraction module of the present invention;
[0048] Figure 5c This is a structural diagram of the 3D multi-scale spectral-spatial joint feature extraction module of the present invention;
[0049] Figure 6 It is a structural diagram of the classifier module of the present invention;
[0050] Figure 7 Schematic diagram of the 3D-SwinT-CNN network structure of the present invention;
[0051] Figure 8a The C2D confusion matrix diagram of the classification result of the benchmark 3D-CNN of the present invention;
[0052] Figure 8b 3D-DenseNet confusion matrix diagram of the classification result of the benchmark 3D-CNN of the present invention;
[0053] Figure 8c 3D-ResNet18 confusion matrix diagram of the classification result of the benchmark 3D-CNN of the present invention;
[0054] Figure 8d 3D-SqueezeNet confusion matrix diagram of the classification result of the benchmark 3D-CNN of the present invention;
[0055] Figure 9a The confusion matrix diagram of the model proposed for the classification results of the 3D-SwinT-CNN ablation experiment of the present invention;
[0056] Figure 9b The confusion matrix diagram of the classification results of the 3D-SwinT-CNN ablation experiment of the present invention when Model-3DSwinT-1 is removed;
[0057] Fig.9c The confusion matrix diagram of the classification results of the 3D-SwinT-CNN ablation experiment of the present invention when Model-3DSwinT-2 is removed;
[0058] Figure 9d The confusion matrix diagram is a diagram of the classification results of the 3D-SwinT-CNN ablation experiment of the present invention when Model-3DSwinT-3 is removed. DETAILED DESCRIPTION
[0059] In order to better understand the purpose, structure and function of the present invention, a method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN of the present invention is further described in detail below in conjunction with the accompanying drawings.
[0060] like Figure 1 As shown, a method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN of the present invention specifically comprises the following steps:
[0061] S1: Hyperspectral image acquisition and preprocessing of fermented black tea: Build a hyperspectral imaging system, set the spectral band range and spatial resolution, collect hyperspectral images of fermented black tea leaves at different fermentation degrees, correct the original hyperspectral images, and perform preprocessing such as image background removal and image segmentation;
[0062] The hyperspectral imaging system described in S1 is a visible-near-infrared hyperspectral imaging system, including a SNAPSCAN VNIR spectral camera (IMEC, Leuven, Belgium), a 35 mm lens, a 150 W annular tungsten halogen light source, and an image acquisition platform;
[0063] The spectral band range is 470-900nm, with a total of 140 bands;
[0064] The spatial resolution was adjusted according to the leaf sample size;
[0065] The hyperspectral images of fermented black tea leaves at different fermentation degrees were collected. The specific operation was to extend the fermentation time to 8 hours so that the black tea samples covered the over-fermentation stage; set 25 time points within 0-8 hours, and collect a batch of fermentation samples at each time point; the end of rolling was defined as fermentation time 0, and black tea samples were collected at the following time points during the fermentation process (0, 0.5, 1, 1.5, 2, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25,5.5, 5.75, 6, 6.25, 6.5, 7, 7.5, 8) h of hyperspectral images; 25 samples at different fermentation time sequences were divided into four categories according to the fermentation degree (fermentation initial, insufficient fermentation, moderate fermentation and over-fermentation), 0-0.5h was defined as fermentation initial, 1-2.75h was defined as insufficient fermentation, 3-4.75h was defined as moderate fermentation, and 5-8h was defined as over-fermentation;
[0066] The original hyperspectral image is corrected to black and white correction to reduce the influence of illumination and camera dark current on the acquisition of different sample spectra. The specific calculation formula is as follows (1):
[0067]
[0068] in R 0 and R are the hyperspectral images before and after correction, W and D They are whiteboard reference image and dark current reference image respectively; Figure 2The average spectra of black tea at different fermentation degrees are shown. The reflectance of the average spectra of the samples shows obvious differences, especially in the range of 780-1000 nm, which may be attributed to the stretching and vibration of the third and fourth overtones of the CH group. Although the difference in spectral reflectance in the visible light range is not obvious, some small absorption peaks still show dynamic changes with fermentation time, which may be related to the change in sample color.
[0069] The image background removal and image segmentation methods are as follows: the near-infrared band with the largest difference in spectral reflectance between leaves and background is used as the threshold band for background removal, and the threshold is set to 0.15; then the image is segmented into images of size 140×64×64, and then the image containing only fermented black tea leaves is selected; the segmented three-dimensional hyperspectral image is used to establish a three-dimensional black tea fermentation degree discrimination model.
[0070] S2: Design of 3D Swin Transformer module: Extend the moving window self-attention mechanism in the Swin Transformer model to 3D hyperspectral image processing to capture the key spatial-spectral joint features and global features of 3D hyperspectral images;
[0071] The moving window self-attention mechanism in the Swin Transformer model is extended to 3D hyperspectral image processing. The Swin Transformer was originally built to process 2D RGB images. In order to process 3D hyperspectral images, the moving window is extended to a 3D structure to capture the long-range spatial-spectral features of HSI. The structure of the 3D Swin Transformer module is shown in Figure 3a As shown in the figure, the input size of HSI is 1×140×64×64. First, 3D PatchPartition splits the input HSI into 64 patches of size 35×16×16. Second, Linear Embedding projects each patch to a dimension of 64×8960 and marks the location information of each patch. Finally, these patches are fed into 3D Swin Transformer to generate feature maps of size 16×35×32×32. Figure 3b As shown, the components of the 3D SwinTransformer module include multi-layer perceptron MLP, layer normalization LN, residual connection, multi-head self-attention 3D W-MSA mechanism based on 3D window and multi-head self-attention 3D SW-MSA mechanism based on 3D shift window; the calculation process of 3D SwinTransformer is expressed by the following formula:
[0072] ,
[0073] ,
[0074] ,
[0075] ,
[0076] in and Represents blocks l Output features of the 3D W-MSA module and the 3D SW-MSA module; and Representation Block l of Output features of the module;
[0077] The multi-head self-attention MSA mechanism can capture the complex relationship between HSI. MSA is the splicing of multiple single self-attention modules. For single self-attention, a learnable weight matrix is used. , and Linearly map patches to queries Q , key K and numerical values V matrix, as shown in formula (6); for MSA, the results of each attention head are concatenated together to obtain the final representation of multi-head attention, expressed by formula (7); where h is the number of heads, W is the parameter matrix;
[0078] ,
[0079] ,
[0080] in, S is a single self-attention, Q , K , V are query, key, and value matrix respectively, d Yes Query Q / Key K Dimensions;
[0081] Compared with the traditional 2D Swin Transformer, the improvement of 3D Swin Transformer is that the spectral domain is integrated into W-MSA to form a 3D W-MSA, which takes into account the window division and movement and establishes a 3D moving window mechanism. Figure 4As shown in the figure, the specific steps are as follows: first, the entire 3D data is divided into smaller windows; these windows are usually cube-shaped and contain a small part of the original 3D data, and the self-attention mechanism is calculated within the window; the window of the latter layer is moved by half the window size in height, width and spectral dimensions. This shifting strategy allows the network to cover and integrate different regional information and promote the flow of information between adjacent windows; through this staggered window layout, the model is able to capture a wider range of spectral-spatial features, not just features within the local window; this helps to understand long-distance dependencies in the data; this shifting window mechanism expands the receptive field, but because it still limits each self-attention calculation to a smaller window, it maintains computational efficiency.
[0082] S3: Design of 3D-SwinT-CNN model: including three modules, one of which is the 3D SwinTransformer module described in S2, and the other two modules are 3D multi-scale spectral-spatial joint feature extraction module and classifier module;
[0083] The 3D multi-scale spectral-spatial joint feature extraction module refers to the fact that 3D standard convolution often focuses on the local feature information of hyperspectral images, which makes the network unable to capture a wider range of spatial and spectral information; while the dilated convolution with a larger receptive field can capture a wider range of feature information without increasing the complexity of the model; the proposed 3D-SwinT-CNNnetwork introduces dilated convolution into 3D-CNN, splices the results of standard convolution and dilated convolution, and convolution kernels with different receptive fields can extract spectral-spatial features of different scales from the feature map. The output feature maps generated by different convolutions are spliced along the channel dimension after batch normalization; the 3D multi-scale spectral-spatial joint feature extraction module is as follows Figure 5a-5cAs shown in the figure; specifically, a hyperspectral image data cube with a size of 1×140×64×64 is used as input. It first passes through a convolution with a kernel size of 1×1×1 to increase the number of channels, followed by batch normalization (BN) layer and ReLU (Rectified Linear Unite, ReLU) layer calculation to achieve feature normalization and increase the nonlinearity of the network respectively; then, the features pass through a standard 3D convolution kernel with a size of 3×3×3, the step size is set to (4, 2, 2), and the padding is set to (0, 1, 1) to extract local spectral-spatial features, and then the batch normalization layer is calculated again, and the size of the output feature is 32×35×32×32 (channel×band×spatial height×spatial width); at the same time, the hyperspectral image is input in parallel to a 3×3×3 dilated convolution layer with a dilation factor d=2, the step size is set to (4, 2, 2), and the padding is set to (1, 2, 2) The purpose of dilated convolution is to increase the receptive field of the network to capture a wider range of spectral-spatial information. The feature output size of the dilated convolution is 32×35×32×32, and then batch normalization is performed. Finally, the feature maps of the standard 3D convolution and the dilated 3D convolution are connected along the channel dimension to integrate feature information of different scales. The output size of the 3D multi-scale spectral-spatial joint feature extraction module is 64×35×32×32.
[0084] The classifier module refers to the 3D-SwinT-CNN model classifier, which consists of three concatenated convolutional layers followed by a fully connected layer. Its purpose is to further extract high-level features and perform classification. Its structure is as follows Figure 6 As shown in the figure; in deep learning, each convolution layer learns different features of the input data, and as the network depth increases, subsequent layers extract more complex features from the features learned by the previous layer; the series connection of multiple convolution layers can help the model learn the hierarchical representation of data; each convolution layer is followed by a batch normalization layer to accelerate the training process; the size of all convolution kernels in the convolution layer is set to 3×3×3, and the padding is set to 1×1×1; the input features are judged by the classifier to determine the different fermentation degrees, and finally the classification of the hyperspectral image of black tea is realized.
[0085] At this point, the three components of the 3D-SwinT-CNN black tea fermentation degree discrimination model have been listed to form a complete 3D-SwinT-CNN. Its complete structure is as follows: Figure 7As shown in the figure; the input of the network is a 1×140×64×64 hyperspectral image. The input hyperspectral image is spliced together with the feature map obtained by the multi-scale spectral-spatial joint feature extraction module and the feature map obtained by the 3DSwin Transformer module, and then input into the classifier module for feature extraction, and finally input into the fully connected layer to realize the classification of different fermentation degrees.
[0086] S4: Algorithm model performance comparison: The data set was divided, and the 3D-SwinT-CNN black tea fermentation degree discrimination model described in S3 was constructed and compared with the benchmark 3D-CNN. At the same time, an ablation experiment was performed on the 3D-SwinT-CNN to verify the effectiveness of the proposed 3D-SwinT-CNN combined with HSI in discriminating the fermentation degree of black tea.
[0087] The images are divided into training set, validation set and test set by randomly dividing the sample data set into training set, validation set and test set according to 6:2:2;
[0088] Benchmark 3D-CNN refers to a total of four benchmark 3D-CNN models designed for end-to-end processing of hyperspectral images, namely C3D, 3D-ResNet18, 3D-DenseNet, and 3D-SqueezeNet; the network input size is 1×140×64×64, and the output feature map size is 4×1×1×1, which respectively represent the probability of the image being classified as four fermentation degrees; the hyperparameters of all networks are as follows: the number of cycles is set to 100, the random seed is fixed to 42, the batch size is set to 8, the learning rate is set to 0.0001, the optimizer is Stochastic Gradient Descent (SGD), and the loss function is the cross-entropy loss function (CrossEntropyLoss);
[0089] The algorithm model performance comparison uses four different evaluation indicators, namely accuracy, precision, recall, and F1 score, to compare the 3D-SwinT-CNN model with four benchmark 3D-CNN models; Table 1 shows the classification performance of the four benchmark 3D-CNN models on the test set. Figures 8a-8d The corresponding confusion matrix is shown in Table 2. Compared with other models, DenseNet has a high classification accuracy, which may be attributed to the fact that each layer in DenseNet directly accesses the feature maps of all previous layers. This feature allows the network to reuse features, thereby reducing the necessity of learning redundant features and achieving performance improvement. Table 2 shows the discrimination results of the test set based on the improved 3D-SwinT-CNN model. Figures 9a-9dIts corresponding confusion matrix; 3D-SwinT-CNN exhibits 98.13% accuracy, 99.00% precision, 98.30% recall, and 98.65% F1 score. Compared with the baseline 3D-CNN, the 3D-SwinT-CNN model performs better; experimental results show that 3D-SwinT-CNN can achieve classification of different fermentation degrees by extracting high-level spatial-spectral features; in order to further prove the effectiveness of the proposed model, an ablation experiment was conducted on it; the classification accuracy of the model decreased after the convolution module (Model-3DSwinT-1), dilated convolution module (Model-3DSwinT-2) and 3D-SwinTBlock module (Model-3DSwinT-3) were removed respectively; especially when 3D-SwinTBlock was removed, the classification performance of the model decreased significantly, with the accuracy decreased by 3.44% and the F1 score decreased by 3.31%; after removing the convolution module and dilated convolution module, the performance of the proposed model decreased, but the classification accuracy was above 96%; the results show that 3D-SwinT The module can effectively extract high-level spatial-spectral joint features, proving its effectiveness in capturing sequence features in black tea hyperspectral imaging; the multi-scale convolutional neural network constructed by the parallel combination of ordinary convolution and dilated convolution can expand the network's receptive field and help extract multi-level features for classification;
[0090] Table 1 Classification results of the benchmark 3D-CNN test set
[0091]
[0092] Table 2 Classification results of 3D-SwinT-CNN test set
[0093]
[0094] In summary, the technical effect of the present invention is remarkable, and it has a good technical contribution to guiding the production and processing of black tea. It has broad application prospects in the field of black tea fermentation research and considerable economic benefits.
[0095] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN, characterized in that: The following steps are involved: S1: Fermented black tea hyperspectral image acquisition and preprocessing: Build a hyperspectral imaging system, set the spectral band range and spatial resolution, collect hyperspectral images of fermented black tea leaves at different fermentation degrees, correct the original hyperspectral images, and perform image preprocessing; S2: Design of 3D Swin Transformer module: Extend the moving window self-attention mechanism in the Swin Transformer model to 3D hyperspectral image processing to capture the key spatial-spectral joint features and global features of 3D hyperspectral images; The extension of the moving window self-attention mechanism in the Swin Transformer model to three-dimensional hyperspectral image processing means that the Swin Transformer extends the moving window to a 3D structure to capture the long-range spatial-spectral characteristics of hyperspectral imaging HSI to form a 3D Swin Transformer module; the 3D Swin Transformer module performs the following steps: the input size of HSI is 1×140×64×64; first, 3D Patch Partition splits the input HSI into 64 patches of size 35×16×16; secondly, Linear Embedding projects each patch to a dimension of 64×8960 and marks the location information of each patch; finally, these patches are sent to the 3D Swin Transformer to generate a feature map of size 16×35×32×32; the components of the 3D Swin Transformer module include a multi-layer perceptron MLP, layer normalization LN, residual connection, and a 3D window-based multi-head self-attention mechanism 3D W-MSA and 3D SW-MSA based on 3D shift window multi-head self-attention mechanism; the calculation process of 3D Swin Transformer is expressed by the following formula: , , , , in and Represents blocks l Output features of the 3D W-MSA module and the 3D SW-MSA module; , and Representation Block l of Output features of the module; The multi-head self-attention mechanism MSA can capture the complex relationship between HSI. MSA is the splicing of multiple single self-attention modules; for single self-attention, a learnable weight matrix is used , and Linearly map patches to queries Q , key K and numerical values V Matrix, as shown in formula (6); For MSA, the results of each attention head are concatenated together to obtain the final representation of multi-head attention, expressed by formula (7); in h is the number of heads, W is the parameter matrix; , , in, SA is a single self-attention, Q , K , V are query, key, and value matrix respectively, d K Yes Query Q or key K Dimensions; The 3D Swin Transformer model integrates the spectral domain into the window-based multi-head attention mechanism W-MSA, thereby forming a 3D window-based multi-head self-attention mechanism 3D W-MSA, which takes into account window division and movement and establishes a 3D moving window mechanism. The 3D moving window mechanism is as follows: first, the entire 3D data is divided into smaller windows; these windows are usually cube-shaped and contain a small part of the original 3D data, and the self-attention mechanism calculation is performed within the window; the window of the latter layer is moved by half the window size in height, width and spectral dimensions; S3: Design of 3D-SwinT-CNN model: including three modules, one of which is the 3D Swin Transformer module described in S2, and the other two modules are 3D multi-scale spectral-spatial joint feature extraction module and classifier module; The 3D multi-scale spectral-spatial joint feature extraction module introduces dilated convolution in the 3D convolutional neural network 3D-CNN, splices the results of standard convolution and dilated convolution, and convolution kernels with different receptive fields extract spectral-spatial features of different scales from the feature map. The output feature maps generated by different convolutions are batch normalized and then spliced along the channel dimension. The classifier module refers to a 3D-SwinT-CNN model classifier consisting of three concatenated convolutional layers followed by a fully connected layer, each convolutional layer is followed by a batch normalization layer, the size of all convolution kernels in the convolutional layer is set to 3×3×3, and the padding is set to 1×1×1; the input features are passed through the classifier to distinguish different fermentation degrees, and finally the classification of the black tea hyperspectral image is realized; S4: Algorithm model performance comparison: The data set was divided, and the 3D-SwinT-CNN model described in S3 was constructed and compared with the benchmark 3D-CNN. At the same time, an ablation experiment was performed on the 3D-SwinT-CNN to verify the effectiveness of the proposed 3D-SwinT-CNN combined with hyperspectral imaging HSI in discriminating the fermentation degree of black tea.
2. The method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN according to claim 1, characterized in that: The hyperspectral imaging system described in S1 is a visible-near infrared hyperspectral imaging system, including a spectral camera, a lens, a light source, and an image acquisition platform; The spectral band range is 470-900nm, with a total of 140 bands; The spatial resolution was adjusted according to the leaf sample size.
3. The method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN according to claim 1, characterized in that: The specific operation of collecting hyperspectral images of fermented black tea leaves at different fermentation degrees in S1 is to extend the fermentation time so that the black tea samples cover the over-fermentation stage; set multiple time points within multiple hours, and collect a batch of fermentation samples at each time point; the end of rolling is defined as fermentation time 0, and hyperspectral images of black tea samples are collected at multiple time points during the fermentation process; The samples at different fermentation time sequences were divided into four categories according to the degree of fermentation: initial fermentation, insufficient fermentation, moderate fermentation and excessive fermentation.
4. The method for distinguishing the fermentation degree of black tea based on 3D-SwinT-CNN according to claim 1, characterized in that: The image preprocessing in S1 includes background removal and image segmentation, which is as follows: the near-infrared band with the largest difference in spectral reflectance between leaves and background is used as the threshold band for background removal; image segmentation is then performed, and then the image containing only fermented black tea leaves is cut out; the segmented three-dimensional hyperspectral image is used to establish a three-dimensional black tea fermentation degree discrimination model.
Citation Information
Cited By
Tea fermentation parameter regulation method and system based on time sequence sensing
CN122861236A
