CN116883720A - Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network - Google Patents

Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network Download PDF

Info

Publication number
CN116883720A
CN116883720A CN202310711018.1A CN202310711018A CN116883720A CN 116883720 A CN116883720 A CN 116883720A CN 202310711018 A CN202310711018 A CN 202310711018A CN 116883720 A CN116883720 A CN 116883720A
Authority
CN
China
Prior art keywords
layer
module
attention
data
spatial
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310711018.1A
Other languages
Chinese (zh)
Inventor
张洪艳
李卓鸿
邹佳琦
胡磊
刘泽鹏
宋阳
贺威
杨光义
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan University WHU
Original Assignee
Wuhan University WHU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan University WHU filed Critical Wuhan University WHU
Priority to CN202310711018.1A priority Critical patent/CN116883720A/en
Publication of CN116883720A publication Critical patent/CN116883720A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/764Arrangements for image or video recognition or understanding using pattern recognition or machine learning using classification, e.g. of video objects
    • GPHYSICS
    • G01MEASURING; TESTING
    • G01NINVESTIGATING OR ANALYSING MATERIALS BY DETERMINING THEIR CHEMICAL OR PHYSICAL PROPERTIES
    • G01N21/00Investigating or analysing materials by the use of optical means, i.e. using sub-millimetre waves, infrared, visible or ultraviolet light
    • G01N21/17Systems in which incident light is modified in accordance with the properties of the material investigated
    • G01N21/25Colour; Spectral properties, i.e. comparison of effect of material on the light at two or more different wavelengths or wavelength bands
    • G01N21/27Colour; Spectral properties, i.e. comparison of effect of material on the light at two or more different wavelengths or wavelength bands using photo-electric detection ; circuits for computing concentration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0464Convolutional networks [CNN, ConvNet]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/084Backpropagation, e.g. using gradient descent
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/77Processing image or video features in feature spaces; using data integration or data reduction, e.g. principal component analysis [PCA] or independent component analysis [ICA] or self-organising maps [SOM]; Blind source separation
    • G06V10/774Generating sets of training patterns; Bootstrap methods, e.g. bagging or boosting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/77Processing image or video features in feature spaces; using data integration or data reduction, e.g. principal component analysis [PCA] or independent component analysis [ICA] or self-organising maps [SOM]; Blind source separation
    • G06V10/80Fusion, i.e. combining data from various sources at the sensor level, preprocessing level, feature extraction level or classification level
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02ATECHNOLOGIES FOR ADAPTATION TO CLIMATE CHANGE
    • Y02A40/00Adaptation technologies in agriculture, forestry, livestock or agroalimentary production
    • Y02A40/10Adaptation technologies in agriculture, forestry, livestock or agroalimentary production in agriculture

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Computing Systems (AREA)
  • Evolutionary Computation (AREA)
  • Software Systems (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Medical Informatics (AREA)
  • Multimedia (AREA)
  • Databases & Information Systems (AREA)
  • Mathematical Physics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Molecular Biology (AREA)
  • Biophysics (AREA)
  • Biomedical Technology (AREA)
  • Spectroscopy & Molecular Physics (AREA)
  • Chemical & Material Sciences (AREA)
  • Analytical Chemistry (AREA)
  • Biochemistry (AREA)
  • Immunology (AREA)
  • Pathology (AREA)
  • Investigating Or Analysing Materials By Optical Means (AREA)

Abstract

The invention discloses a fruit and vegetable pesticide residue detection method and a system based on a spatial spectrum attention network, which are characterized in that hyperspectral images of fruits and vegetables are firstly collected and data preprocessing is carried out; then inputting the preprocessed hyperspectral image into a spatial spectrum attention network for pesticide residue detection; the invention can automatically detect pesticide residues in food, has the advantages of high detection efficiency, high accuracy, simple operation and the like, and provides an effective means for food safety supervision.

Description

Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network
Technical Field
The invention belongs to the technical field of food safety detection, relates to a fruit and vegetable pesticide residue detection method and system, and particularly relates to a fruit and vegetable pesticide residue detection method and system based on a spatial spectrum attention network.
Background
The pesticide residue detection methods mainly include a spectroscopic method (document 1), an enzyme inhibition method (document 2), and a chromatographic method (document 3). However, these methods still have many problems such as high cost, long time, inefficiency, and the like (document 4). For this reason, the hyperspectral technique is a technique which is attracting attention, can obtain continuous spectrum data of high resolution, and can realize detection of pesticide residues by reflecting internal physicochemical properties of a target. The hyperspectral technology is used for detecting pesticide residues, so that the method has the characteristics of convenience and high efficiency, and can not damage targets (documents 5 to 9). However, the conventional hyperspectral pesticide residue detection method needs manual design features, cannot extract complex nonlinear space-spectrum features of hyperspectral images, and has defects in detection precision.
D.Liu,Y.Han,L.Zhu,W.Chen,Y.Zhou,J.Chen,and Z.Dou,“Quantitative detection of isofenphos-methyl in corns using surface-enhanced Raman spectroscopy(SERS)with chemometric methods,”Food Analytical Methods,vol.10,no.5,pp.1202-1208,2017.
HOU X, SHEN G. Wheat bran esterase inhibition method for detection of elimination of false positives in spicy vegetables [ J ]. Food and Fermentation Industries,47 (4): 247-252.
Xu Bing, sun Chengpeng, ge Xiangwu, et al, gas chromatography-tandem mass spectrometry to determine the matrix effect of 61 pesticides in 30 fruits and vegetables and its overcoming mode [ J ]. Food safety quality detection report, 2021,12 (15): 6068-6076.
Li Bo, song Shanshan, xia Jianfeng, etc. modern food safety detection techniques are used in the detection of agricultural product residues [ J ]. Food research and development 2020, (14): 127-132.
Wang Miaozhi, jiang Gongjun, sun Hongyang. Application of hyperspectral imaging technique in detection of pesticide residue on fruits and vegetables [ J ]. Agricultural modernization research, 2019, (4): 23-25.
Wang,Q.,Wang,X.,Zeng,W.,&Wang,C.(2019).Hyperspectral imaging technology in food quality and safety detection:a review.Critical reviews in food science and nutrition,59(2),253-271.
Li,P.,Cao,K.,Zhang,L.,&He,Y.(2020).A review of hyperspectral imaging technology in food safety and quality detection.Journal of Food Protection,83(4),718-735.
Chen,Y.,Huang,Y.,&Wang,J.(2020).Pesticide residue detection based on hyperspectral technology:research progress and perspective.Journal of integrative agriculture,19(5),1000-1014.
Bao,Y.,Li,Y.,Zhang,C.,&Zhou,J.(2020).Non-destructive detection of pesticide residues in agricultural products based on hyperspectral imaging technology:a review.Food Analytical Methods,13(5),1012-1030.
Disclosure of Invention
The invention provides a fruit and vegetable pesticide residue detection method and system based on a spatial spectrum attention network, which aims to solve the problems of low detection precision, high cost, long time, low efficiency and the like of the detection method in the prior art.
The technical scheme adopted by the method is as follows: a fruit and vegetable pesticide residue detection method based on a spatial spectrum attention network comprises the following steps:
step 1: collecting hyperspectral images of fruits and vegetables, and carrying out data pretreatment;
step 2: inputting the pretreated hyperspectral image into a spatial spectrum attention network for pesticide residue detection;
the spatial spectrum attention network comprises an encoder module, a decoder module, a spatial attention module, a spectral attention module and a classifier module;
the encoder module comprises four convolution layers which are arranged in series, wherein residual blocks are added behind the first layer, the second layer and the third layer of convolution layers, and a normalization layer and an activation layer are added behind each convolution layer in sequence;
the decoder module comprises four convolution layers which are arranged in series, wherein the characteristic fusion blocks are added after the first layer, the second layer and the third layer of convolution layers, and the output characteristics from the first layer, the second layer and the third layer of convolution layers of the encoder and the decoder are added respectively; adding a normalization layer and an activation layer after each convolution layer in sequence;
the spatial attention module and the spectral attention module are arranged between the encoder module and the decoder module in parallel;
the classifier module is arranged behind the decoder module and comprises a full connection layer and a softmax activation function, and is used for converting the feature map into one-dimensional vectors and mapping the one-dimensional vectors to category label distribution.
Preferably, in step 1, the preprocessing includes denoising and spectrum normalization; firstly, the original spectrum data is subjected to smoothing filtering, high-frequency noise points are removed, the signal to noise ratio is improved, and the original data sequence is smoothed. And then carrying out normalization processing on the hyperspectral data, and eliminating the difference between different spectral data.
Preferably, in step 2, the encoder module includes four convolution layers arranged in series, where each layer is a convolution layer with a convolution kernel size of 3, and the step size is 1;
the decoder module comprises four convolution layers which are arranged in series, wherein each layer is a convolution layer with the convolution kernel size of 3, and the step length is 1;
the spatial attention module, for each pixel, the spatial attention module takes its feature vector f ij Respectively with three weight matrixes W capable of learning v Multiplying to obtain query vector q ij Key vector k ij Sum vector v ij The method comprises the steps of carrying out a first treatment on the surface of the The attention weight is then obtained through the dot product operation and softmax operation between each pixel query vector and the key vectorA matrix A; finally, multiplying the attention weight matrix A by the value matrix V of all pixels by the spatial attention module to obtain a final output characteristic diagram
The spectrum attention module firstly carries out global average pooling operation on an input feature map X and compresses the feature map of each channel into a scalar; for each channel, the spectral attention module introduces two learnable weight matrices W s And W is e The method comprises the steps of carrying out a first treatment on the surface of the The spectral attention module compresses the scalar z for each channel i Respectively with W s And W is e Multiplying to obtain a scaling factor s i And an offset e i The method comprises the steps of carrying out a first treatment on the surface of the The spectrum attention module uses the characteristic diagram X of each channel i Respectively multiplied by a scaling factor s i Then add the offset e i Obtain a weighted feature map Y i The method comprises the steps of carrying out a first treatment on the surface of the Finally, the spectral attention module will weigh all the weighted feature maps Y i And splicing to obtain an output characteristic diagram Y.
Preferably, in step 2, the spatial spectrum attention network is a trained spatial spectrum attention network; the training process comprises the following substeps:
step S1: preparing a fruit and vegetable sample, and collecting hyperspectral data of the fruit and vegetable sample;
step S2: preprocessing the collected hyperspectral image data;
step S3: preparing a pesticide concentration detection data set;
step S4: the pretreated hyperspectral data are input into a spatial spectrum attention network for training, spectral characteristics and spatial characteristics related to pesticide residues are extracted, and model parameters are continuously optimized through a back propagation algorithm, so that the pesticide residues can be accurately identified.
Preferably, in the step S1, a plurality of fruits and vegetables are collected and washed to be dried, so that no pesticide remains on the surfaces of the fruits and vegetables, and then the pesticide diluted by adding water is uniformly sprayed on the surfaces of the fruits and vegetables; hyperspectral data were acquired using an imaging spectrometer.
Preferably, in step S2, the preprocessing includes denoising and spectrum normalization; firstly, the original spectrum data is subjected to smoothing filtering, high-frequency noise points are removed, the signal to noise ratio is improved, and the original data sequence is smoothed. And then carrying out normalization processing on the hyperspectral data, and eliminating the difference between different spectral data.
Preferably, in step S3, the pesticide concentration detection data set is prepared, the hyperspectral data is labeled first, pesticide concentration labels in different sample data are obtained, and then the labeled data set is divided into a training set and a testing set.
Preferably, in step S4, a cross entropy loss function is used in the training process, and the training is performed until the network converges, i.e. the training loss curve remains stable and does not drop. And taking the pesticide concentration grade with the highest prediction probability as a final detection result.
The system of the invention adopts the technical proposal that: fruit and vegetable pesticide residue detection system based on empty spectrum attention network includes:
one or more processors;
and the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to realize the fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network.
The invention can automatically detect pesticide residues in fruits and vegetables, has the advantages of high detection efficiency, high accuracy, simple operation and the like, and provides an effective means for fruit and vegetable safety supervision.
Drawings
The following examples, as well as specific embodiments, are used to further illustrate the technical solutions herein. In addition, in the course of describing the technical solutions, some drawings are also used. Other figures and the intent of the present invention can be derived from these figures without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method according to an embodiment of the present invention;
FIG. 2 is a block diagram of a spatial spectrum attention network according to an embodiment of the present invention;
fig. 3 is a block diagram of a spatial spectrum attention network training process according to an embodiment of the present invention.
Detailed Description
In order to facilitate the understanding and practice of the invention, those of ordinary skill in the art will now make further details with reference to the drawings and examples, it being understood that the examples described herein are for the purpose of illustration and explanation only and are not intended to limit the invention thereto.
Referring to fig. 1, the method for detecting pesticide residues in fruits and vegetables based on a spatial spectrum attention network provided by the invention comprises the following steps:
step 1: collecting hyperspectral images of fruits and vegetables, and carrying out data pretreatment;
in one embodiment, the preprocessing includes denoising and spectral normalization; firstly, the original spectrum data is subjected to smoothing filtering, high-frequency noise points are removed, the signal to noise ratio is improved, and the original data sequence is smoothed. And then carrying out normalization processing on the hyperspectral data, and eliminating the difference between different spectral data.
Step 2: inputting the pretreated hyperspectral image into a spatial spectrum attention network for pesticide residue detection;
referring to fig. 2, the spatial attention network of the present embodiment includes an encoder module, a decoder module, a spatial attention module, a spectral attention module, and a classifier module;
the encoder module of this embodiment includes four convolution layers arranged in series, wherein each layer is a convolution layer with a convolution kernel size of 3, and the step size is 1; residual blocks are added after the first layer, the second layer and the third layer of convolution layers, and a normalization layer and an activation layer are added after each convolution layer in sequence;
the decoder module of the embodiment comprises four convolution layers which are arranged in series, wherein each layer is a convolution layer with a convolution kernel size of 3, and the step length is 1; adding feature fusion blocks after the first layer, the second layer and the third layer of convolution layers, and respectively adding output features from the first, the second and the third convolution layers of the encoder and the decoder; adding a normalization layer and an activation layer after each convolution layer in sequence;
the implementation isThe spatial attention module of the example, for each pixel, the spatial attention module takes its feature vector f ij Respectively with three weight matrixes W capable of learning v Multiplying to obtain query vector q ij Key vector k ij Sum vector v ij . The attention weight matrix a is then obtained through a dot product operation and a softmax operation between each pixel query vector and the key vector. Finally, multiplying the attention weight matrix A by the value matrix V of all pixels by the spatial attention module to obtain a final output characteristic diagram
The spectral attention module of this embodiment first performs a global averaging pooling operation on an input profile X, compressing the profile for each channel into a scalar. For each channel, the spectral attention module introduces two learnable weight matrices W s And W is e For calculating a scaling factor and an offset, respectively. Specifically, the spectral attention module compresses the scalar z for each channel i Respectively with W s And W is e Multiplying to obtain a scaling factor s i And an offset e i . Scaling factor s i For weighting the feature map of each channel, with an offset e i For adjusting the weighting result. In particular, the spectral attention module maps the features of each channel X i Respectively multiplied by a scaling factor s i Then add the offset e i Obtain a weighted feature map Y i . Finally, the spectral attention module will weigh all the weighted feature maps Y i Splicing to obtain an output characteristic diagram Y;
the classifier module of this embodiment includes a full connection layer and softmax activation function for converting the feature map into one-dimensional vectors, which are then mapped to the class label distribution.
Please refer to fig. 3, the spatial spectrum attention network of the present embodiment is a trained spatial spectrum attention network; the training process comprises the following substeps:
step S1: and preparing a fruit and vegetable sample, and collecting hyperspectral data of the fruit and vegetable sample.
In one embodiment, the fruit and vegetable sample is illustrated by way of example with respect to chinese cabbage, and is applicable to other vegetables, fruits, meats, seafood, and the like. Four typical cabbage pesticides commonly used in the market are selected to be diluted and sprayed on the surfaces of cabbages by adding water, wherein the pesticides comprise abamectin, imidacloprid, acetamiprid and carbendazim. The hyperspectral data are acquired by a MateStec LS portable hyperspectral imager, which is gaze shooting developed based on a line scanning type pixel coating hyperspectral photosensitive element, and a scanning type hyperspectral imaging system is built in. The wave band is 470-900nm, and the weight is only 0.8kg.
The specific spectrum acquisition process of the portable hyperspectral spectrometer is as follows:
(1) Starting a power supply of the spectrometer and preheating for 15 minutes;
(2) Establishing a connection between an imaging spectrometer and a computer;
(3) Setting spectrum measurement parameters;
(4) Calibrating the instrument by using a reference standard or a standard sample;
(4) Clicking a start button to collect spectrum data;
(5) And exporting the acquired data, and carrying out subsequent analysis and processing.
Step S2: preprocessing the collected hyperspectral image data.
In one embodiment, hyperspectral data is first imported into Matlab, and different noise removal methods are selected according to specific data conditions and problems. If the noise is relatively significant, a filter is selected for denoising. If the noise is complex, a wavelet transform is selected for denoising. The wavelet transformation can decompose the original hyperspectral data sequence into different frequency bands, and then noise removal is performed according to the characteristics of the frequency bands. After noise removal, the smoothed raw hyperspectral data sequence is subjected to a min-max normalization, and the data is mapped into the range of 0-1, i.e. each data point is subtracted by a minimum value and divided by the difference between the maximum value and the minimum value. The normalization can unify the data of different wave bands into a range, so that subsequent data processing and analysis are convenient.
Step S3: and (5) preparing a hyperspectral pesticide concentration detection data set.
In one embodiment, pesticide concentrations of different sample hyperspectral data are labeled and combined into one dataset. Each data comprises sample hyperspectral data and a residual pesticide concentration label corresponding to the sample, and the whole data set is divided into a training set and a testing set according to the ratio of 80%/20%.
Step S4: the pretreated hyperspectral data are input into a spatial spectrum attention network for training, spectral characteristics and spatial characteristics related to pesticide residues are extracted, and model parameters are continuously optimized through a back propagation algorithm, so that the pesticide residues can be accurately identified. After model training is completed, the accuracy and generalization performance of the model is assessed by verification of the test set.
In one embodiment, the spatial spectrum attention network structure is composed of an input layer, a convolution layer 1, a pooling layer 1, a convolution layer 2, a pooling layer 2, a full connection layer and an output layer. The convolutional layer is added with a Batchnormal operation function and a ReLU activation function, and the data in each layer of neural network is standardized, so that training of the neural network is accelerated, and the problems of gradient disappearance, gradient explosion and the like are avoided. The nonlinear characteristic of the neural network is increased, and the prediction accuracy of the model can be improved while training is accelerated. And inputting the preprocessed hyperspectral data into a spatial spectrum attention network model for training, and continuously extracting spectral features and spatial features through a plurality of convolution layers and pooling layers. During training, model parameters are typically continually adjusted using a back-propagation algorithm (Backpropagation Algorithm) so that the model's loss function is as small as possible. After model training is completed, the accuracy and generalization performance of the model can be evaluated through verification of the test set. After the model has enough accuracy and robustness, the model can be used for detecting an unknown sample and judging whether the pesticide concentration in the model meets the standard requirement.
The spatial spectrum attention network of the embodiment comprises an encoder module, a decoder module, a spatial attention module, a spectral attention module and a classifier module;
the encoder module of this embodiment includes four convolution layers arranged in series, wherein each layer is a convolution layer with a convolution kernel size of 3, and the step size is 1; residual blocks are added after the first layer, the second layer and the third layer of convolution layers, and a normalization layer and an activation layer are added after each convolution layer in sequence;
the decoder module of the embodiment comprises four convolution layers which are arranged in series, wherein each layer is a convolution layer with a convolution kernel size of 3, and the step length is 1; adding feature fusion blocks after the first layer, the second layer and the third layer of convolution layers, and respectively adding output features from the first, the second and the third convolution layers of the encoder and the decoder; adding a normalization layer and an activation layer after each convolution layer in sequence;
the spatial attention module of the present embodiment, for each pixel, the spatial attention module uses its feature vector f ij Respectively with three weight matrixes W capable of learning v Multiplying to obtain query vector q ij Key vector k ij Sum vector v ij . The attention weight matrix a is then obtained through a dot product operation and a softmax operation between each pixel query vector and the key vector. Finally, multiplying the attention weight matrix A by the value matrix V of all pixels by the spatial attention module to obtain a final output characteristic diagram
The spectral attention module of this embodiment first performs a global averaging pooling operation on an input profile X, compressing the profile for each channel into a scalar. For each channel, the spectral attention module introduces two learnable weight matrices W s And W is e For calculating a scaling factor and an offset, respectively. Specifically, the spectral attention module compresses the scalar z for each channel i Respectively with W s And W is e Multiplying to obtain a scaling factor s i And an offset e i . Scaling factor s i For weighting the feature map of each channel, with an offset e i For adjusting the weighting result. In particular, the spectral attention module will eachCharacteristic diagram X of channel i Respectively multiplied by a scaling factor s i Then add the offset e i Obtain a weighted feature map Y i . Finally, the spectral attention module will weigh all the weighted feature maps Y i Splicing to obtain an output characteristic diagram Y;
the classifier module of this embodiment includes a full connection layer and softmax activation function for converting the feature map into one-dimensional vectors, which are then mapped to the class label distribution.
The nonlinear activation function is introduced in the embodiment, so that the deep neural network can learn nonlinear characteristics and can greatly enhance the network expression capability. Common activation functions include Sigmoid function, softmax function, tanh function, reLU function, leak-ReLU function, and the like, wherein the ReLU nonlinear activation function has a simple form, can effectively avoid the problem of gradient disappearance, and accelerates model convergence, and the specific form is as follows:
and in the training process, a cross entropy loss function is adopted, and the training is performed until the network converges, namely, the training loss curve keeps stable and does not drop any more. And taking the pesticide concentration grade with the highest prediction probability as a final detection result.
In one embodiment, when new sample data is input into a trained model for pesticide residue detection, the data needs to be pre-processed to adapt to the model. Common preprocessing operations include normalization, scaling, cropping, and the like. And then, sending the preprocessed data into a model for forward calculation to obtain a detection result. And further analyzing the obtained detection result to determine whether the pesticide residue exceeds the standard, thereby providing guarantee for food safety.
The invention can automatically detect pesticide residues in food, has the advantages of high detection efficiency, high accuracy, simple operation and the like, and provides an effective means for food safety supervision.
It should be understood that the foregoing description of the preferred embodiments is not intended to limit the scope of the invention, but rather to limit the scope of the claims, and that those skilled in the art can make substitutions or modifications without departing from the scope of the invention as set forth in the appended claims.

Claims (9)

1. The fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network is characterized by comprising the following steps of:
step 1: collecting hyperspectral images of fruits and vegetables, and carrying out data pretreatment;
step 2: inputting the pretreated hyperspectral image into a spatial spectrum attention network for pesticide residue detection;
the spatial spectrum attention network comprises an encoder module, a decoder module, a spatial attention module, a spectral attention module and a classifier module;
the encoder module comprises four convolution layers which are arranged in series, wherein residual blocks are added behind the first layer, the second layer and the third layer of convolution layers, and a normalization layer and an activation layer are added behind each convolution layer in sequence;
the decoder module comprises four convolution layers which are arranged in series, wherein the characteristic fusion blocks are added after the first layer, the second layer and the third layer of convolution layers, and the output characteristics from the first layer, the second layer and the third layer of convolution layers of the encoder and the decoder are added respectively; adding a normalization layer and an activation layer after each convolution layer in sequence;
the spatial attention module and the spectral attention module are arranged between the encoder module and the decoder module in parallel;
the classifier module is arranged behind the decoder module and comprises a full connection layer and a softmax activation function, and is used for converting the feature map into one-dimensional vectors and mapping the one-dimensional vectors to category label distribution.
2. The fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network as set forth in claim 1, wherein the method is characterized in that: in the step 1, the preprocessing comprises denoising and spectrum normalization; firstly, the original spectrum data is subjected to smoothing filtering, high-frequency noise points are removed, the signal to noise ratio is improved, and the original data sequence is smoothed. And then carrying out normalization processing on the hyperspectral data, and eliminating the difference between different spectral data.
3. The fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network as set forth in claim 1, wherein the method is characterized in that: in step 2, the encoder module includes four convolution layers arranged in series, wherein each layer is a convolution layer with a convolution kernel size of 3, and the step length is 1;
the decoder module comprises four convolution layers which are arranged in series, wherein each layer is a convolution layer with the convolution kernel size of 3, and the step length is 1;
the spatial attention module, for each pixel, the spatial attention module takes its feature vector f ij Respectively with three weight matrixes W capable of learning v Multiplying to obtain query vector q ij Key vector k ij Sum vector v ij The method comprises the steps of carrying out a first treatment on the surface of the Then obtaining an attention weight matrix A through dot product operation and softmax operation between each pixel query vector and the key vector; finally, multiplying the attention weight matrix A by the value matrix V of all pixels by the spatial attention module to obtain a final output characteristic diagram
The spectrum attention module firstly carries out global average pooling operation on an input feature map X and compresses the feature map of each channel into a scalar; for each channel, the spectral attention module introduces two learnable weight matrices W s And W is e The method comprises the steps of carrying out a first treatment on the surface of the The spectral attention module compresses the scalar z for each channel i Respectively with W s And W is e Multiplying to obtain a scaling factor s i And an offset e i The method comprises the steps of carrying out a first treatment on the surface of the The spectrum attention module uses the characteristic diagram X of each channel i Respectively multiplied by a scaling factor s i Then add the offset e i Obtain a weighted feature map Y i The method comprises the steps of carrying out a first treatment on the surface of the Finally, the spectral attention module will weigh all the weighted feature maps Y i And splicing to obtain an output characteristic diagram Y.
4. A fruit and vegetable pesticide residue detection method based on a spatial spectrum attention network according to any one of claims 1 to 3, wherein: in step 2, the spatial spectrum attention network is a trained spatial spectrum attention network; the training process comprises the following substeps:
step S1: preparing a fruit and vegetable sample, and collecting hyperspectral data of the fruit and vegetable sample;
step S2: preprocessing the collected hyperspectral image data;
step S3: preparing a pesticide concentration detection data set;
step S4: the pretreated hyperspectral data are input into a spatial spectrum attention network for training, spectral characteristics and spatial characteristics related to pesticide residues are extracted, and model parameters are continuously optimized through a back propagation algorithm, so that the pesticide residues can be accurately identified.
5. The fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network as set forth in claim 4, wherein the method is characterized in that: in the step S1, a plurality of fruits and vegetables are collected and cleaned, so that no pesticide remains on the surfaces of the fruits and vegetables, and then the pesticide diluted by water is uniformly sprayed on the surfaces of the fruits and vegetables; hyperspectral data were acquired using an imaging spectrometer.
6. The fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network as set forth in claim 4, wherein the method is characterized in that: in step S2, the preprocessing includes denoising and spectrum normalization; firstly, the original spectrum data is subjected to smoothing filtering, high-frequency noise points are removed, the signal to noise ratio is improved, and the original data sequence is smoothed. And then carrying out normalization processing on the hyperspectral data, and eliminating the difference between different spectral data.
7. The fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network as set forth in claim 4, wherein the method is characterized in that: and step S3, making a pesticide concentration detection data set, firstly labeling the hyperspectral data to obtain pesticide concentration labels in different sample data, and then dividing the labeled data set into a training set and a testing set.
8. The fruit and vegetable pesticide residue detection method based on the spatial spectrum attention network as set forth in claim 4, wherein the method is characterized in that: in the step S4, a cross entropy loss function is adopted in the training process, and the training is performed until the network converges, namely, the training loss curve keeps stable and does not drop any more; and taking the pesticide concentration grade with the highest prediction probability as a final detection result.
9. Fruit and vegetable pesticide residue detection system based on empty spectrum attention network, characterized by comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the method for detecting pesticide residues in fruits and vegetables based on a spatial spectrum attention network as claimed in any one of claims 1 to 8.
CN202310711018.1A 2023-06-14 2023-06-14 Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network Pending CN116883720A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310711018.1A CN116883720A (en) 2023-06-14 2023-06-14 Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310711018.1A CN116883720A (en) 2023-06-14 2023-06-14 Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network

Publications (1)

Publication Number Publication Date
CN116883720A true CN116883720A (en) 2023-10-13

Family

ID=88267146

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310711018.1A Pending CN116883720A (en) 2023-06-14 2023-06-14 Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network

Country Status (1)

Country Link
CN (1) CN116883720A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117805024A (en) * 2024-02-29 2024-04-02 四川农业大学 Crisp pear saccharin degree detection method and device, cloud equipment and computer device

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117805024A (en) * 2024-02-29 2024-04-02 四川农业大学 Crisp pear saccharin degree detection method and device, cloud equipment and computer device
CN117805024B (en) * 2024-02-29 2024-05-14 四川农业大学 Crisp pear saccharin degree detection method and device, cloud equipment and computer device

Similar Documents

Publication Publication Date Title
WO2020073737A1 (en) Quantitative spectroscopic data analysis and processing method based on deep learning
Wu et al. Advanced applications of hyperspectral imaging technology for food quality and safety analysis and assessment: A review—Part I: Fundamentals
Zhang et al. Noise reduction in the spectral domain of hyperspectral images using denoising autoencoder methods
CN113222836B (en) Hyperspectral and multispectral remote sensing information fusion method and system
Deng et al. Moisture content prediction in tealeaf with near infrared hyperspectral imaging
CN104408705A (en) Anomaly detection method of hyperspectral image
Gowen et al. Time series hyperspectral chemical imaging data: challenges, solutions and applications
CN116883720A (en) Fruit and vegetable pesticide residue detection method and system based on spatial spectrum attention network
Jie et al. Research on Citrus grandis granulation determination based on hyperspectral imaging through deep learning
CN113008805A (en) Radix angelicae decoction piece quality prediction method based on hyperspectral imaging depth analysis
Vimalajeewa et al. Learning in the compressed data domain: Application to milk quality prediction
Zhang et al. Denoising vegetation spectra by combining mathematical-morphology and wavelet-transform-based filters
Qi et al. Rapid and non-destructive determination of soluble solid content of crown pear by visible/near-infrared spectroscopy with deep learning regression
Liu et al. An improved method for predicting soluble solids content in apples by heterogeneous transfer learning and near-infrared spectroscopy
Zhou et al. Research on hyperspectral regression method of soluble solids in green plum based on one-dimensional deep convolution network
CN115575404B (en) Fruit appearance quality detection method based on ratio multispectral image
CN116312860A (en) Agricultural product soluble solid matter prediction method based on supervised transfer learning
CN116203001A (en) Aflatoxin B1 nondestructive testing method and device
Hu et al. Research on rice seed fullness detection method based on terahertz imaging technology and feature extraction method
CN114972075A (en) Hyperspectral image denoising method based on residual learning and mixed domain attention
Hu et al. Application of Vis-NIR hyperspectral imaging in agricultural products detection
Zhou et al. Germination prediction of sugar beet seeds based on HSI and SVM-RBF
Zhang et al. The Handling Approach of Near-Infrared Spectroscopy for Apple Quality Prediction Based on Digital Signal Processing
CN116978487A (en) Pesticide residue type identification method and system based on space-spectrum converter model
Xu et al. Nondestructive detection of yellow peach quality parameters based on 3D-CNN and hyperspectral images

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination