Crop growth period prediction method and device

Through a multi-task learning method, the microscopic characteristics of crops, planting spacing and timing information are used to train the target classification network, which solves the problem of insufficient crop variety traceability and quality control in the existing technology, and improves the accuracy and traceability of crop growth predictions. sex.

CN117789037BActive Publication Date: 2024-09-10INTELLIGENT EQUIPMENT RESEARCH CENTER BEIJING ACADEMY OF AGRICULTURE AND FORESTRY SCIENCES +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410185298.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-19
Publication Date
2024-09-10
Estimated Expiration
2044-02-19

AI Technical Summary

Technical Problem

The existing technology monitors crops in the later stages of growth and lacks traceability and quality control of crop varieties, resulting in low crop safety and traceability, and the prediction model has weak feature representation capabilities, resulting in poor generalization and prediction capabilities of the model. insufficient.

Method used

Using a multi-task learning method based on microscopic features, planting spacing and time series information, through convolutional neural network and self-attention mechanism, features are extracted and fused, and the target classification network is trained to achieve crop category prediction and growth period prediction.

Benefits of technology

It improves the accuracy of crop classification and growth prediction, enables accurate identification of different types of crops in the early seedling stage, and enhances seedling management support for greenhouse agriculture.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117789037B
    Figure CN117789037B
Patent Text Reader

Abstract

The present invention relates to the field of image recognition technology, and provides a method and device for predicting the growth period of crops, the method comprising: obtaining a crop image to be tested, the crop image to be tested including at least one type of crop; inputting the crop image to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result; wherein the crop prediction model is based on the microscopic features of each crop in the sample crop image, the planting spacing between different crops, and the time series information corresponding to the sample crop image as training features, and multi-task training is performed on the target classification network using a multi-task learning loss function as a training function; the multi-task learning loss function is determined based on a cross entropy loss function and a mean square error loss function. The method of the present invention can accurately identify different types of crops in the early stage of the crop seedling stage, improve the accuracy of crop classification and growth prediction, and thus provide strong support for seedling management in greenhouse agriculture.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image recognition, and in particular to a crop growth period prediction method and device. Background Art

[0002] Crop identification and growth monitoring is one of the key technologies for intelligent facility agriculture. It can realize the automatic acquisition and analysis of information such as the type, quantity, growth status, maturity, etc. of crops in the facility, and provide a scientific basis for production management, market forecasting, risk assessment, etc. of facility agriculture. Due to the high planting density of crops in the facility, complex crop appearance, long crop growth cycle, and changeable crop growth environment, crop identification and growth monitoring in the facility are very difficult and complex.

[0003] Among the related technologies, traditional crop identification and growth monitoring methods mainly focus on solving the monitoring of the later stages of crop growth. They lack traceability and quality control of crop varieties, resulting in low crop safety and traceability. Moreover, when existing prediction models use end-to-end implementation from data collection to crop growth parameter prediction, the extracted feature representation capabilities are weak, resulting in insufficient generalization and prediction capabilities of the model. Summary of the invention

[0004] The present invention provides a crop growth period prediction method and device, which are used to solve the problems that the prior art mainly monitors the late stage of crop growth, lacks tracing and quality control of crop varieties, resulting in low safety and traceability of crops, and the feature characterization ability extracted by the existing prediction model is weak, resulting in insufficient generalization and prediction capabilities of the model, thereby improving the accuracy of crop classification and growth prediction.

[0005] The present invention provides a crop growth period prediction method, comprising:

[0006] Acquire a crop image to be tested, wherein the crop image to be tested includes at least one type of crop;

[0007] Inputting the image of the crop to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result;

[0008] Among them, the crop prediction model is based on the microscopic characteristics of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and the target classification network is multi-task trained with a multi-task learning loss function as a training function; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function.

[0009] According to a crop growth period prediction method provided by the present invention, the crop prediction model is obtained through the following steps:

[0010] Acquire a sample crop image, wherein the sample crop image includes at least one type of crop;

[0011] Extracting mask features from the sample crop image and segmenting it to obtain segmented images of different crops, and determining images that can be distinguished into seedling stages according to the statistical analysis amount of each crop in the segmented image;

[0012] Classifying the images that can be distinguished as seedling stages according to a self-attention mechanism to obtain classified images, and extracting microscopic features of each crop, planting spacing between different crops, and timing information from the classified images;

[0013] Performing feature fusion on the microscopic features and the planting spacing to obtain fused features;

[0014] The target classification network is multi-task trained according to the fusion features, and the target classification network is time-series discriminated through the time series information. When the target classification network converges, a crop prediction model is obtained to achieve crop category prediction and growth period prediction.

[0015] According to a crop growth period prediction method provided by the present invention, extracting mask features from the sample crop image and segmenting it to obtain segmented images of different crops includes:

[0016] An instance mask is generated from the pixel level of the sample crop image according to the SOLOv2 network, and the instance mask is optimized according to a mask loss function to obtain the segmented image.

[0017] According to a crop growth period prediction method provided by the present invention, the step of determining the seedling stage image according to the statistical analysis amount of each crop in the segmented image comprises:

[0018] The segmented image is sequentially subjected to morphologically based image erosion, image dilation and noise filtering operations to obtain a filtered image;

[0019] The connected domain labeling algorithm based on depth-first search is used to count the number of each crop and the corresponding area in the filtered image to obtain statistical data;

[0020] Calculating the average height and leaf area index of each crop in the statistical data based on an image color space conversion algorithm, and determining that the segmented image is the seedling-separable image when the average height exceeds a height threshold and the leaf area index exceeds an index threshold;

[0021] The height threshold and the index threshold are determined based on the growth cycle, phenological characteristics, historical data and expert knowledge of each crop in the segmented image.

[0022] According to a crop growth period prediction method provided by the present invention, the classifying the separable seedling stage images according to the self-attention mechanism to obtain the classified images includes:

[0023] According to the image classification model of the visual transformer, global features are extracted from the distinguishable seedling stage images, and the distinguishable seedling stage images are classified according to the global features to obtain leafy vegetable classification images and fruit and vegetable classification images; wherein the image classification model of the visual transformer is constructed based on the self-attention mechanism.

[0024] According to a crop growth period prediction method provided by the present invention, the extracting of microscopic features of each crop, planting spacing between different crops and time sequence information from the classified images respectively comprises:

[0025] The microscopic features are extracted from the classified image based on a first convolutional neural network, the planting distance is extracted from the classified image based on a second convolutional neural network, and the timing information is extracted from the classified image based on a time series prediction network.

[0026] According to a crop growth period prediction method provided by the present invention, after obtaining the crop prediction model, the method further includes:

[0027] The crop prediction model is subjected to model pruning, quantization, and distillation operations in sequence to obtain an optimized crop prediction model.

[0028] The present invention also provides a crop growth period prediction device, comprising:

[0029] An image acquisition module, used for acquiring an image of a crop to be tested, wherein the image of the crop to be tested includes at least one type of crop;

[0030] A prediction module, used for inputting the image of the crop to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result;

[0031] Among them, the crop prediction model is based on the microscopic characteristics of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and the target classification network is multi-task trained with a multi-task learning loss function as a training function; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function.

[0032] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the crop growth period prediction methods described above is implemented.

[0033] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the crop growth period prediction method as described in any one of the above is implemented.

[0034] The crop growth period prediction method and device provided by the present invention use the microscopic characteristics of each crop, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features and a crop prediction model trained with a multi-task learning loss function to predict different tasks on the crop image to be tested, thereby obtaining more accurate crop category recognition results and crop growth period prediction results. Different types of crops can be accurately identified in the early stage of the crop seedling stage, thereby improving the accuracy of crop classification and growth prediction, thereby providing strong support for seedling management of greenhouse agriculture. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0036] Figure 1 This is one of the flow charts of the crop growth period prediction method provided by the present invention;

[0037] Figure 2 This is the second flow chart of the crop growth period prediction method provided by the present invention;

[0038] Figure 3 This is one of the structural schematic diagrams of the crop growth period prediction device provided by the present invention;

[0039] Figure 4 This is the second structural schematic diagram of the crop growth period prediction device provided by the present invention;

[0040] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0041] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are 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.

[0042] Combine the following Figure 1-Figure 4The present invention describes a method and device for predicting the crop growth period.

[0043] Figure 1 This is one of the flow charts of the crop growth period prediction method provided by the present invention, such as Figure 1 As shown, a schematic diagram of the process of the crop growth period prediction method is provided. The present invention provides a crop growth period prediction method, comprising the following steps:

[0044] Step 110: Acquire an image of a crop to be tested, where the image of the crop to be tested includes at least one type of crop.

[0045] In this step, the crop image to be tested includes the crop images in a designated planting area (such as a greenhouse or breeding shed, etc.) captured by the camera, as well as the image capture time information.

[0046] In this embodiment, monitoring cameras are installed on the top of the greenhouse. The number, position and shooting angle of the cameras are determined according to the size and shape of the greenhouse so that the cameras can cover the entire farming area of ​​the greenhouse. The cameras are calibrated using the intrinsic and extrinsic parameters of the cameras to eliminate image aberrations and distortions. Finally, at fixed time intervals (for example, every day or every week), aerial pictures of the greenhouse are obtained and the current timestamp is recorded.

[0047] In this embodiment, the size and shape of the greenhouse, the scope of the cultivation area and other information can be obtained from BIM (Building Information Modeling); or on-site measurements can be performed using measurement tools.

[0048] In this embodiment, appropriate monitoring cameras are selected, and the number, position and shooting angle of the cameras are determined to obtain images of the crops to be tested; specifically, waterproof, dustproof, fogproof and shockproof cameras are selected according to the environmental conditions of the greenhouse to ensure the clarity and stability of the image. According to the imaging principle and model of the camera, appropriate parameters such as resolution, focal length and field of view are selected to ensure the quality and information content of the image.

[0049] In this embodiment, the camera can be an RGB camera, the resolution of the camera is not less than 1920×1080, i.e. 1080P, which can provide clear image quality, the focal length of the camera is 2.8mm focal length, and the field of view of the camera is not less than 90° field of view; in addition, a camera with a higher resolution can also be selected, for example, a 2K (2560×1440) or 4K (3840×2160) camera can be selected.

[0050] In this embodiment, the storage format of the RGB camera should select a format that can retain the original information of the image while compressing the size of the image. The image format includes JPEG (Joint Photographic Experts Group) or PNG (Portable Network Graphics) format.

[0051] In this embodiment, at least one camera may be installed at the four corners and the center of the greenhouse to ensure that the camera's shooting angle can cover more viewing areas.

[0052] In this embodiment, the camera calibration method is used to obtain the intrinsic parameters and extrinsic parameters of the camera, and eliminate the distortion and aberration of the image. The intrinsic parameters include the principal point, focal length and distortion coefficients of the camera, and the extrinsic parameters include the rotation and translation of the camera; wherein the goal of camera calibration is to solve the following equation:

[0053] x=K[R|t]X

[0054] Where x is the image coordinate, X is the world coordinate, K is the intrinsic parameter matrix, R and t are the extrinsic parameter matrices; solve the above equation by using the world coordinate and the corresponding image coordinate; where the world coordinate can be obtained from the calibration object, using a chessboard or circle grid; use the findChessboardCorners or findCirclesGrid functions in the OpenCV library to detect feature points on the calibration object, and use calibrateCamera or solvePnP to solve the camera parameters.

[0055] In this embodiment, by optimizing the number, position and shooting angle of cameras, the cameras can cover the entire greenhouse cultivation area; specifically, the problem is modeled as a combinatorial optimization problem, given the maximum number of cameras, a set of camera positions are selected from a larger camera position pool to minimize the square error between the expected coverage and the actual coverage, and the nonlinear cost function is converted into a mixed integer linear programming problem. Using the camera lens model, the camera's view is projected onto a 3D voxel map to calculate the coverage score, which makes the optimization problem feasible in a real environment; wherein, tools such as Gurobi or CPLEX can be used to solve the mixed integer linear programming problem.

[0056] In this embodiment, an overhead picture of the greenhouse is obtained at a fixed time interval (every day), and the current timestamp is recorded; a timer or sensor is used to trigger the camera's shooting action, and the function VideoCapture or imwrite in the OpenCV library is used to obtain and save the picture; the picture is named in the format of YYYYMMDDHHMMSS.jpg, where YYYY is the year, MM is the month, DD is the date, HH is the hour, MM is the minute, and SS is the second; the picture's metadata (metadata) timestamp, camera number, camera position, etc. can be written and read using tools such as ExifTool or PyExifTool.

[0057] Step 120: input the crop image to be tested into the crop prediction model to obtain the crop category prediction result and the crop growth period prediction result; wherein the crop prediction model is based on the microscopic characteristics of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and multi-task learning loss function is used as the training function to perform multi-task training on the target classification network; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function.

[0058] In this step, the microscopic characteristics include different growth parts of the crop, such as the branches, leaves and fruits of the plant, etc. The microscopic characteristics include the height, shape, color and smell of different crops.

[0059] In this embodiment, the timing information includes different growth stages of the crop, for example, a timestamp corresponding to a germination stage, a timestamp corresponding to a seedling stage, a timestamp corresponding to a flowering stage, and a timestamp corresponding to a fruiting stage.

[0060] In this embodiment, the multi-task learning loss function can be a weighted sum of loss functions of multiple tasks. For example, the multi-task learning loss function includes a cross entropy loss function and a mean square error loss function, wherein the cross entropy loss function is used as the loss function for common crop identification tasks, and the mean square error loss function is used as the loss function for crop growth and maturity prediction tasks.

[0061] In this embodiment, the target classification network includes a convolutional neural network or a deep convolutional neural network. For example, the target classification network is a CNN (Convolutional Neural Networks).

[0062] In this embodiment, for each picture that can be distinguished into seedling stages, a GoogLeNet network based on the Inception module is used to realize the fusion of multidimensional data and multi-task learning; wherein the multidimensional data includes image color histogram, primary crop classification results, microscopic crop characteristics, macroscopic planting spacing, time series information, etc.; multi-tasks include common crop identification and crop growth and maturity prediction; according to the characteristics of the data set, this embodiment selects appropriate loss functions, optimizers, learning rates and other hyperparameters, as well as appropriate data enhancement, regularization, pre-training and other strategies to train and optimize the CNN network, improve the performance and generalization ability of the model, so as to realize accurate prediction of crop categories and growth periods.

[0063] The crop growth period prediction method provided by the embodiment of the present invention uses the microscopic characteristics of each crop, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features and a crop prediction model trained with a multi-task learning loss function to predict different tasks on the crop image to be tested, thereby obtaining more accurate crop category recognition results and crop growth period prediction results. It can accurately identify different types of crops in the early stage of the crop seedling stage, improve the accuracy of crop classification and growth prediction, and thus provide strong support for seedling management of greenhouse agriculture.

[0064] In some embodiments, a crop prediction model is obtained by the following steps: obtaining a sample crop image, the sample crop image includes at least one type of crop; extracting mask features from the sample crop image and segmenting it to obtain segmented images of different crops, and determining separable seedling images based on the statistical analysis quantity of each crop in the segmented image; classifying the separable seedling images according to the self-attention mechanism to obtain classified images, and extracting the microscopic features of each crop, the planting spacing and timing information between different crops from the classified images; performing feature fusion on the microscopic features and planting spacing to obtain fused features; performing multi-task training on the target classification network according to the fused features, and performing timing discrimination on the target classification network through timing information, and when the target classification network converges, obtaining a crop prediction model to achieve crop category prediction and growth period prediction.

[0065] In this embodiment, the sample crop image includes the crop images of a greenhouse or breeding shed captured by the camera, as well as the image capture time information. The acquisition method and size setting are consistent with the technical means for acquiring the image of the crop to be tested in the above embodiment, and will not be repeated in this embodiment.

[0066] In this embodiment, for each sample crop image, an advanced object segmentation network based on deep learning is used to generate instance masks directly from the pixel level to automatically learn the features of the image to achieve image segmentation and classification, where each instance corresponds to a crop.

[0067] In this embodiment, the advanced object segmentation network based on deep learning includes convolutional neural networks such as SOLOv2 (Segmenting Objects by Locations v2) network.

[0068] In this embodiment, the statistical analysis quantities of each crop include the quantity, category and area of ​​each crop in the sample crop image, and also include statistics such as the height and leaf area index of each crop.

[0069] In this embodiment, after the crops are transplanted into the cultivation area, the transplanting timestamp T is first recorded. 0 , and use image processing algorithms to dynamically analyze the amount of crops in the cultivated area. For each segmented image, the image corrosion and expansion operations based on morphology are used to eliminate noise and interference in the image, and then the connected domain labeling algorithm based on depth-first search is used to count the number and area of ​​crops in the image; then the image color space conversion algorithm is used to calculate the discrimination index of the seedling stage based on the counted number and area of ​​crops: as the average height and leaf area index, and then determine whether the current image is a seedling stage image.

[0070] In this embodiment, for each picture of the distinguishable seedling stage, a network constructed based on the self-attention mechanism is used to classify the distinguishable seedling stage image. For example, a ViT-G / 14 network based on the Transformer structure is used to automatically learn the global features in the distinguishable seedling stage image and realize the classification of the image; a neural network based on the self-attention mechanism is used to classify crops, and the facilities are divided into common leafy vegetables and fruity vegetables.

[0071] In this embodiment, after obtaining the classification image, the microscopic features of the crop are identified, the planting spacing is detected, and the timing information is calculated from the classification images (for example, leafy vegetable classification images and fruit and vegetable classification images). The target classification network is trained by using the features fused according to the microscopic features and the planting spacing. At the same time, multiple timing information of the crop is used as labels to predict the growth period corresponding to different classification results, and the growth period prediction results of different crops are obtained.

[0072] In this embodiment, the target classification network is a GoogLeNet network based on the Inception module. For each picture that can be classified into seedling stages, multi-dimensional data fusion and multi-task learning are realized. The specific steps are as follows:

[0073] (1) Using the input layer of the GoogLeNet network, the pixel values ​​of the image are converted into a matrix X of size N × D, where N is the number of blocks in the image and D is the dimension of each block.

[0074] Specifically, an image of size 224×224 is used and divided into 64 blocks, each of which has a dimension of 64.

[0075] (2) Using the position encoding layer of the GoogLeNet network, a position encoding vector is added to the representation vector of the block to increase the position information; a learnable position encoding vector of size D is used and added to the representation vector of the block to obtain a matrix X' of size N×D.

[0076] (3) Use the Inception module of the GoogLeNet network to fuse the block representation vector with the multi-dimensional data to obtain a new block representation vector.

[0077] Specifically, the present invention uses 9 Inception modules, each module contains 1×1, 3×3, 5×5 convolution layers and 3×3 maximum pooling layers, and 1×1 convolution layers as dimensionality reduction operations; the output of each module is spliced ​​into a new block representation matrix X″.

[0078] (4) Using the multi-task learning layer of the GoogLeNet network, the block representation vectors are mapped to output vectors of multiple tasks, where the output vector of each task contains the number of task categories.

[0079] In this embodiment, the multiple tasks may include the following two tasks, namely common crop identification and crop growth and maturity prediction; for the common crop identification task, a fully connected layer and a Softmax layer are used to map the block representation matrix X″ into a matrix Y of size N×C, where C is the number of common crop categories; for the crop growth and maturity prediction task, a fully connected layer and a linear regression layer are used to map the block representation matrix X″ into a matrix Z of size N×R, where R is the predicted value of crop growth and maturity.

[0080] (5) For each image that can be distinguished into seedling stages, the output of the GoogLeNet network, that is, the output vector of the multi-task, is used to identify common crops and predict crop growth and maturity.

[0081] Specifically, this embodiment uses a voting mechanism to weight the output vector of the image and the area of ​​the block to obtain a scalar that represents the probability that the image belongs to a certain category or a certain prediction value. The following formula represents this process:

[0082]

[0083] Among them, P is the output probability of the picture, O i is the output vector of the ith block, A i is the area of ​​the ith block, and N is the number of blocks.

[0084] In this embodiment, the specific method of training and optimizing the target classification network (CNN network) is as follows:

[0085] (1) For the loss function, the loss function of multi-task learning is adopted, that is, the weighted sum of the loss functions of multiple tasks; specifically, the cross entropy loss function is used as the loss function of the common crop identification task, and the mean square error loss function is used as the loss function of the crop growth maturity prediction task.

[0086] (2) A learnable weight vector is used to balance the contribution of the loss functions of different tasks. This process is expressed as follows:

[0087]

[0088] Among them, L is the loss function of multi-task learning, w j is the weight of the loss function of the jth task, L j is the loss function of the jth task, and M is the number of tasks.

[0089] (3) For the optimizer, the Adam optimizer is used to update the parameters of the CNN network; an initial learning rate of 0.001, a decay factor of 0.9, a momentum factor of 0.99, and an epsilon value of e -8 , and a weight decay factor of 0.0005, the process is expressed as follows:

[0090]

[0091] Among them, θ t is the parameter of the tth iteration, α is the learning rate, is the first-order moment estimate of the t-th iteration, is the second-order moment estimate of the t-th iteration, ∈ is a small constant, and λ is the weight decay factor.

[0092] (4) For the learning rate, an exponential decay strategy is adopted to dynamically adjust the learning rate. In this embodiment, an initial learning rate of 0.001, a decay rate of 0.95, and a decay step of 1000 are adopted. The process is represented by the following formula:

[0093]

[0094] Among them, α t is the learning rate of the tth iteration, α 0 is the initial learning rate, γ is the decay rate, s is the decay step size, is the floor function.

[0095] In this embodiment, a three-stage cascade neural network of "feature-crop-growth period" was constructed according to different data sources and tasks; specifically, the TensorFlow2.6 deep learning framework was used to build the following network models:

[0096] (1) Feature network: This example uses the SOLOv2 network, an advanced object segmentation network based on deep learning, to achieve segmentation and classification of monitoring site images. Each instance corresponds to a crop. The Keras API is used to build and train the SOLOv2 network.

[0097] Specifically, the pre-trained ResNet50 is used as the backbone network, Focal Loss is used as the loss function, RPN is used as the candidate region generator, and Mask R-CNN is used as the instance segmenter; this example also uses multi-scale training and testing, as well as gradient accumulation and other techniques to improve the performance and stability of the model; this example uses the ViT-G / 14 network based on the Transformer structure to realize the classification of overhead images of solar greenhouses, and divides the facilities into common leafy vegetables and fruit vegetables; the TensorFlow Hub API is used to build and train the ViT-G / 14 network; this example uses the pre-trained ViT-G / 14 as a classifier, cross entropy loss function, AdamW optimizer, learning rate decay strategy, and regularization methods such as Dropout and LabelSmoothing; this example uses a ResNet network based on deep learning to realize the recognition of microscopic features of side-shot images, using Keras The API implements the construction and training of the ResNet network; the pre-trained ResNet50 is used as a feature extractor, the fully connected layer and the Softmax layer are used as classifiers, the cross entropy loss function, the SGD optimizer, batch normalization and Dropout techniques are used; the deep learning-based YOLOX network is used to detect the macro features of side-shot images, and the TensorFlow Object Detection API implements the construction and training of the YOLOX network; the pre-trained YOLOX-s is used as the target detector, the YOLO Loss is used as the loss function, the SGD optimizer, the Mosaic data enhancement and the EMA model averaging methods are used.

[0098] (2) Crop network: This example uses a BiLSTM network based on deep learning to calculate the temporal characteristics of crops. The Keras API is used to build and train the BiLSTM network. The bidirectional LSTM layer is used as a temporal modeler, and the fully connected layer and the Sigmoid layer are used as regressors. The mean square error loss function, Adam optimizer, learning rate decay strategy, Dropout and Batch Normalization techniques are used.

[0099] (3) Growth period network: This example uses the GoogLeNet network based on the Inception module to achieve the fusion of multidimensional data and multi-task learning; the multidimensional data includes image color histogram, primary crop classification results, microscopic crop characteristics, macroscopic planting spacing, time series information, etc.; the multi-tasks include common crop identification and crop growth and maturity prediction; this example uses the Keras API to build and train the GoogLeNet network; the pre-trained GoogLeNet is used as a feature fusion, multiple auxiliary classifiers and the main classifier, weighted cross entropy loss function, RMSProp optimizer, batch normalization and Dropout and other techniques.

[0100] (4) The training parameters of this example are set as follows: the byte width is dynamically set to 8 or 4 according to the network size, the momentum factor is set to 0.95, the cosine annealing decay coefficient is 0.005, the initial learning rate is 0.001, and the model training uses the Adam optimizer and cosine annealing to dynamically optimize the learning rate.

[0101] Figure 2 This is the second flow chart of the crop growth period prediction method provided by the present invention. Figure 2 In the embodiment shown, a sample crop image is first collected, and the region of interest of the image is segmented. The crop is monitored according to the segmentation result, the threshold of the seedling stage can be counted, and the transplanting time T corresponding to the segmentation result is calculated. 0 Determine the seedling stage T n ; According to the threshold of seedling stage and seedling stage T n First-level crop classification is performed, and microscopic features (corresponding to crop feature identification), planting spacing (corresponding to planting macroscopic spacing) and time series information are extracted based on the classification results. Second-level crop classification with multidimensional data fusion is performed based on the above features to realize crop type identification and growth parameter monitoring.

[0102] The crop growth period prediction method provided by the embodiment of the present invention constructs a crop prediction model from a three-stage cascade neural network model mode of "feature-crop-growth period". The model breaks the static and isolated traditional visual detection method, introduces the shooting timestamp and integrates the time series information, realizes the fusion of multi-dimensional data, and forms a reliable seedling crop recognition model. It describes specific crops from three levels: time series changes, microscopic characteristics, and macroscopic morphology, making the crop image full and three-dimensional. At the same time, it fully mines the effective information in the crop picture, and improves the accuracy and robustness of the model.

[0103] In some embodiments, extracting mask features from sample crop images and segmenting them to obtain segmented images of different crops includes: generating instance masks at the pixel level of the sample crop images according to a SOLOv2 network, and optimizing the instance masks according to a mask loss function to obtain segmented images.

[0104] In this embodiment, for each sample crop image, the SOLOv2 network is used to automatically learn the features of the image by directly generating an instance mask from the pixel level without pre-defining the region of interest ROI, so as to achieve image segmentation and classification. Specifically, an overhead image, i.e., a sample crop image, is obtained from a greenhouse, and the current timestamp is recorded. For each overhead image, the SOLOv2 network is used to achieve image segmentation and classification. The structure of the SOLOv2 network includes:

[0105] SOLOv2(I)==FPN(Backbone(I))=={F 2 ,F 3 ,F 4 ,F 5 ,F 6};

[0106] Where I is the input image, F is the output feature pyramid, and F i is the feature map of the i-th level, Backbone is the backbone network, and FPN is the feature pyramid network.

[0107] In this embodiment, the SOLOv2 network consists of the following parts:

[0108] (1) The backbone network of the fully convolutional network (FCN) is used to extract multi-scale feature maps, or features of different levels, from the input image. The present invention uses ResNet-50 as the backbone network, and outputs 5 levels of features, namely P2, P3, P4, P5, and P6, according to the resolution of the input image, with resolutions of 1 / 4, 1 / 8, 1 / 16, 1 / 32, and 1 / 64, respectively; the output of the backbone network can be expressed as:

[0109] {P 2 ,P 3 ,P 4 ,P 5 ,P 6}=Backbone(I)

[0110] (2) Feature Pyramid Network (FPN), which is used to fuse features at different levels and enhance the expressiveness of features. The SOLOv2 network uses the BiFPN structure to achieve adaptive feature fusion through the self-attention mechanism and weighted feature fusion. The structure of BiFPN is expressed as follows:

[0111]

[0112] (3) Category branch: used to predict the category probability of each pixel.

[0113] Specifically, the category branch consists of 5 parallel convolutional layers, each convolutional layer corresponds to a level of features, and the number of output channels is C, where C is the number of crop categories; the output of the category branch is 5 category probability maps, whose sizes are H / 4×W / 4×C, H / 8×W / 8×C, H / 16×W / 16×C, H / 32×W / 32×C, H / 64×W / 64×C, where H and W are the height and width of the input image. The category probability maps output by each category branch are expressed as follows:

[0114]

[0115] in, is the category probability map of the i-th level, and CategoryBranch is the category branch.

[0116] (4) The loss function of the category branch is Focal Loss, which is used to solve the problem of category imbalance. Focal Loss is defined as:

[0117]

[0118] Where N is the total number of pixels, C is the number of crop categories, and y i,c is the true label of the cth category of the ith pixel, p i,c is the predicted probability of the cth category of the ith pixel, and γ is a tuning parameter used to reduce the weight of easy-to-classify samples.

[0119] (5) Mask branch: used to predict the mask probability of each pixel.

[0120] Specifically, the mask branch consists of 5 parallel convolutional layers, each of which corresponds to a level of features, and its output channels are S×S, where S is the size of the mask. The output of the mask branch is 5 mask probability maps, whose sizes are H / 4×W / 4×S×S, H / 8×W / 8×S×S, H / 16×W / 16×S×S, H / 32×W / 32×S×S, and H / 64×W / 64×S×S. The output of the mask branch can be expressed as:

[0121]

[0122] in, is the mask probability map of the i-th level, MaskBranch is the mask branch; the loss function of the mask branch is Dice Loss, which is used to measure the similarity between the predicted mask and the true mask; the loss function of the mask branch is expressed as:

[0123]

[0124] Where N is the total number of pixels, m i is the true mask of the i-th pixel, p i is the predicted mask of the i-th pixel.

[0125] In this implementation, the training process of the SOLOv2 network is as follows:

[0126] First, the input image is scaled to a fixed size of 800×800, and then randomly cropped, horizontally flipped, color jittered, etc. are used for data augmentation. Secondly, the input image and the corresponding ground truth are sent to the SOLOv2 network, the outputs of the category branch and the mask branch are calculated and compared with the ground truth, the loss function is calculated, and the stochastic gradient descent (SGD) optimizer is used to update the network parameters and minimize the loss function.

[0127] In this embodiment, the hyperparameters used in the training process of the SOLOv2 network are as follows: the initial learning rate is 0.01, the momentum is 0.9, the weight decay is 0.0001, the batch size is 16, the number of training epochs is 36, and the learning rate decay policy is cosine annealing.

[0128] The crop growth period prediction method provided by the embodiment of the present invention generates instance masks from the pixel level of the sample crop image through the SOLOv2 network, and optimizes the instance masks according to the mask loss function to obtain a segmented image, which greatly reduces the workload and cost of data annotation and improves the efficiency and quality of data utilization.

[0129] In some embodiments, determining a seedling-separable image based on the statistical analysis of each crop in the segmented image includes: sequentially performing morphologically-based image erosion, image dilation, and noise filtering operations on the segmented image to obtain a filtered image; using a depth-first search connected domain labeling algorithm to count the number of each crop and the corresponding area in the filtered image to obtain statistical data; calculating the average height and leaf area index of each crop in the statistical data based on an image color space conversion algorithm, and determining that the segmented image is a seedling-separable image when the average height exceeds a height threshold and the leaf area index exceeds an index threshold; wherein the height threshold and the index threshold are determined based on the growth cycle, phenological characteristics, historical data, and expert knowledge of each crop in the segmented image.

[0130] In this embodiment, after the crops are transplanted into the cultivation area, the transplanting timestamp T is first recorded. 0 , and use image processing algorithms to dynamically analyze the amount of crops in the cultivated area; for each segmented image, use morphological image corrosion and expansion operations to eliminate noise and interference in the image, and then use the connected domain labeling algorithm based on depth-first search to count the number and area of ​​crops in the image. The specific steps are as follows:

[0131] (1) For each segmented image, the output of the SOLOv2 network, namely the category probability map and the mask probability map, is used to generate a binary instance mask map.

[0132] (2) For each pixel, if its category probability is greater than a threshold and its mask probability is greater than a threshold, it is marked as 1, otherwise it is marked as 0, and a binary instance mask map M of size H×W is obtained, where H and W are the height and width of the input image.

[0133] (3) For each binary instance mask image, use morphologically based image erosion and dilation operations to eliminate noise and interference in the image.

[0134] Specifically, the image erosion operation compares each pixel in the image with a structuring element. If one pixel in the area covered by the structuring element is 0, the original pixel is set to 0, otherwise it remains unchanged; the image erosion operation can eliminate small white areas in the image, that is, isolated noise points; the image dilation operation compares each pixel in the image with a structuring element. If one pixel in the area covered by the structuring element is 1, the original pixel is set to 1, otherwise it remains unchanged; the image dilation operation can fill small black areas in the image, that is, tiny cracks or holes.

[0135] In this embodiment, the function erode or dilate in the OpenCV library is used to implement image erosion and dilation operations. This embodiment uses a rectangular structure element of size 3×3, first performs an image erosion operation, and then performs an image dilation operation, so that a denoised instance mask image M′ can be obtained. The specific calculation process is expressed as the following formula:

[0136] M′=dilate(erode(M,K),K);

[0137] Among them, M is the binarized instance mask map, M′ is the denoised instance mask map, K is the structure element, erode and dilate are image erosion and dilation operations.

[0138]

[0139] (4) For each denoised instance mask image, a connected domain labeling algorithm based on depth-first search is used to count the number and area of ​​crops in the image. The connected domain labeling algorithm is an algorithm that assigns a label to each pixel in an image so that pixels with the same label belong to the same connected domain, that is, adjacent areas with the same pixel value.

[0140] Specifically, the connected component function in the OpenCV library is used to implement the connected domain labeling algorithm. The four-neighborhood is used as the neighboring relationship of pixels, that is, only the neighboring pixels in the four directions of the top, bottom, left and right of the pixel are considered. The depth-first search (DFS) method is used to traverse each pixel starting from the upper left corner of the image. If an unlabeled pixel with a value of 1 is found, it is used as the starting point of a new connected domain, and a new label is assigned. The DFS method is used to mark the pixels with adjacent pixel values ​​of 1 with the same label. At the same time, the number of pixels in the connected domain, that is, the area of ​​the crop, is recorded. A label map L of size H×W and a list N of the number and area of ​​crops can be obtained; the specific calculation process is expressed as follows:

[0141] L,N=connectedComponents(M′);

[0142] Among them, M′ is the denoised instance mask map, L is the label map, N is the list of crop numbers and areas, and connectedComponents is the connected domain labeling algorithm.

[0143] N=(n 1 ,a 1 ),(n 2 ,a 2 ),…,(n k ,a k );

[0144] Among them, n i is the label of the i-th connected domain, a i is the number of pixels in the ith connected domain, and k is the total number of connected domains.

[0145] In this embodiment, for each segmented image, the image color space conversion algorithm is used to design the cvtColor function to realize the conversion of the image color space, and the HSV, RGB, and CMYK color histograms of each instance are calculated respectively; then the image histogram analysis algorithm is used to design the calcHist function to calculate the image color histogram; finally, according to the growth cycle and phenological characteristics of the crops, combined with historical data and expert knowledge, the threshold of the seedling stage, the average height of the crops, and the leaf area index are determined; when the amount of crops reaches the threshold of the seedling stage, the image is recorded as the seedling stage, and the timestamp T is saved. n .

[0146] In this embodiment, for each binary instance mask image, an image color space conversion algorithm is used, and a cvtColor function is designed to implement image color space conversion, and the HSV, RGB, and CMYK color histograms of each instance are calculated respectively.

[0147] It should be noted that the image color space conversion algorithm is a process of converting one color representation method into another color representation method. This embodiment uses the function cvtColor in the OpenCV library to achieve the conversion of the image color space; it is used to represent the conversion of the image color space:

[0148] I HSV =cvtColor(M,COLOR_BGR2HSV)

[0149] I RGB =cvtColor(M,COLOR_BGR2RGB)

[0150] ICMYK =cvtColor(M,COLOR_BGR2CMYK)

[0151] Where M is the binary instance mask map, I HSV , I RGB and I CMYK is the converted image, cvtColor is the image color space conversion function, COLOR_BGR2HSV, COLOR_BGR2RGB and COLOR_BGR2CMYK are the conversion flags.

[0152] In this embodiment, for each converted image, the image histogram analysis algorithm is used to design a calcHist function to calculate the image color histogram; wherein the image histogram represents a graph of the relationship between pixel intensity (on the x-axis) and the number of pixels (on the y-axis) in the image, the x-axis contains all available gray levels, and the y-axis represents the number of pixels with a specific gray value; the image color histogram is calculated by designing the calcHist function, and the following formula is specifically used to represent the calculation of the image color histogram:

[0153] H HSV =calcHist(I HSV ,[0,1,2],M,[180,256,256],[0,180,0,256,0,256])

[0154] H RGB =calcHist(I RGB ,[0,1,2],M,[256,256,256],[0,256,0,256,0,256])

[0155] H CMYK =calcHist(I CMYK ,[0,1,2,3],M,[256,256,256,256],[0,256,0,256,0,256,0,256])

[0156] Among them, I HSV , I RGB and I CMYK is the transformed image, H HSV , H RGB and H CMYK is the image color histogram, calcHist is the image histogram analysis function, [0,1,2] and [0,1,2,3] are the indices of the color channels, M is the binary instance mask map, [180,256,256],

[0157] [256,256,256] and [256,256,256,256] are the sizes of the histogram, [0,180,0,256,0,256], [0,256,0,256,0,256] and [0,256,0,256,0,256,0,256] are the ranges of the histogram.

[0158] In this embodiment, the threshold for seedling stage classification, the average height of crops, leaf area index, etc. are determined based on the growth cycle and phenological characteristics of crops, combined with historical data and expert knowledge. When the amount of crops reaches the threshold for seedling stage classification, the image is recorded as seedling stage classification, and the timestamp T is saved. n , the seedling stage image can be judged by the following formula:

[0159] (1) Calculate the average height of crops:

[0160]

[0161] Among them, H avg is the average height of the crop, H i is the height of the i-th crop, and N is the number of crops.

[0162] (2) Calculate the leaf area index of crops:

[0163]

[0164] Among them, L avg is the leaf area index of the crop, L i is the leaf area index of the ith crop.

[0165] In this embodiment, it is determined whether the threshold of the seedling stage is reached, assuming that θ H and θ L is the threshold value of the height and leaf area index of the seedling stage for judgment; for example, H corresponding to the current crop image avg ≥θ H , and L avg ≥θ L , it is determined that the current crop image is a stageable image.

[0166] The crop growth period prediction method provided by the embodiment of the present invention sequentially performs morphological image erosion, image dilation, noise filtering and depth-first search connected domain labeling algorithm on the segmented image, and then counts the number of each crop and the corresponding area in the filtered image to obtain accurate statistical data, thereby improving the accuracy and efficiency of seedling stage image recognition.

[0167] In some implementations, classifying the separable seedling images according to the self-attention mechanism to obtain classified images includes: extracting global features from the separable seedling images according to the image classification model of the visual transformer, and classifying the separable seedling images according to the global features to obtain leafy vegetable classification images and fruit and vegetable classification images; wherein the image classification model of the visual transformer is constructed based on the self-attention mechanism.

[0168] In this embodiment, the image classification model of the visual transformer includes a ViT-G / 14 network of the Transformer structure. The specific steps of automatically learning the global features of the image and realizing the classification of the image through the network are as follows:

[0169] (1) For each image that can be divided into seedling stages, use the input layer of the ViT-G / 14 network to convert the pixel values ​​of the image into a matrix X of size N×D, where N is the number of blocks in the image and D is the dimension of each block; this embodiment uses a convolution kernel of size 16×16 to divide the image into 196 blocks, and the dimension of each block is 768. The following formula represents this process:

[0170] X = conv(I,W,S);

[0171] Among them, I is the pixel value matrix of the image, W is the weight matrix of the convolution kernel, S is the step size of the convolution kernel, and conv is the convolution operation.

[0172] (2) For each block, a position encoding vector is added to the block representation vector using the position encoding layer of the ViT-G / 14 network to increase the position information; this embodiment uses a learnable position encoding vector of size D, adds it to the block representation vector, and obtains a matrix X′ of size N×D. The following formula represents this process:

[0173] X′=X+P;

[0174] Among them, X is the block representation matrix, P is the position encoding matrix, and X′ is the block representation matrix after adding position information.

[0175] (3) For each block, the multi-head self-attention layer of the ViT-G / 14 network is used to calculate the correlation between the block and other blocks, and obtain a new block representation vector. The present invention uses 12 self-attention heads, each with a dimension of 64, and divides the block representation matrix X′ into 12 sub-matrices, each with a size of N×64; for each sub-matrix, the self-attention output is calculated to obtain a sub-matrix with a size of N×64. Finally, the 12 sub-matrices are concatenated to obtain a matrix X″ with a size of N×D. The specific representation is:

[0176] X″=concat(head 1 ,head 2 ,…,head 12 );

[0177] Among them, head i is the output of the i-th self-attention head, and concat is the concatenation operation.

[0178] (4) For each block, the feedforward layer of the ViT-G / 14 network is used to perform a nonlinear transformation on the block representation vector and obtain a new block representation vector. This embodiment uses two fully connected layers and a ReLU activation function to transform the block representation matrix X″ into a matrix X″′ of size N×D. The specific representation is:

[0179] X″′=ReLU(W 2 X″+b 2 )W 1 +b 1 ;

[0180] Where X″ is the output of the multi-head self-attention layer, W 1 , W 2 , b 1 , b 2 is a learnable parameter and ReLU is the activation function.

[0181] (5) For each block, the residual connection layer of the ViT-G / 14 network is used to add the block representation vector to the output of the feedforward layer, and layer normalization is performed to obtain a new block representation vector. This embodiment uses a layer normalization vector of size D, multiplies it with the block representation matrix X″′, and obtains a matrix X″′ of size N×D. The specific representation is:

[0182] X″″=LayerNorm(X′+X″′);

[0183] Among them, X′ is the output of the position encoding layer, X″′ is the output of the feedforward layer, and LayerNorm is the layer normalization operation; repeat the above steps to obtain a matrix X″″′ of size N×D, which is the output of the encoder of the ViT-G / 14 network. The specific representation is:

[0184] X″″′=Encoder(X,P,W,S,W 1 ,W 2 ,b 1 ,b 2 );

[0185] Among them, X is the block representation matrix, P is the position encoding matrix, W is the weight matrix of the convolution kernel, S is the step size of the convolution kernel, and W1 ,W 2 ,b 1 ,b 2 is a learnable parameter, and Encoder is the encoder of the ViT-G / 14 network.

[0186] (6) Using the classification layer of the ViT-G / 14 network, the block representation vector is mapped to a vector of size C, where C is the number of crop categories. This embodiment uses a fully connected layer and a Softmax function to map the block representation matrix X″″′ to a matrix Y of size N×C. The specific representation is:

[0187] Y = Softmax(X″″′W 3 +b 3 );

[0188] Where X″″′ is the output of the encoder, W 3 , b 3 is a learnable parameter and Softmax is the Softmax function.

[0189] (7) For each image that can be classified into seedling stages, the output of the ViT-G / 14 network, that is, the predicted label of the block, is used to determine whether the image belongs to leafy vegetables or fruity vegetables. This embodiment adopts a voting mechanism to weight the predicted label of the image and the area of ​​the block to obtain a scalar indicating the probability that the image belongs to leafy vegetables or fruity vegetables. The specific expression is:

[0190]

[0191] Among them, P is the predicted probability of the image, Z i is the predicted label of the i-th block, A i is the area of ​​the ith block, and N is the number of blocks.

[0192] (8) The prediction probability of the ViT-G / 14 network is used to determine the primary crop classification of the image. In this embodiment, a threshold τ′ is used to compare the prediction probability of the image with the threshold to obtain a scalar indicating whether the image belongs to leafy vegetables or fruity vegetables. The specific representation is as follows:

[0193]

[0194] Where C is the first-level crop classification of the image, P is the predicted probability of the image, and τ′ is the threshold.

[0195] The crop growth period prediction method provided by the embodiment of the present invention extracts global features from separable seedling stage images through the image classification model of the visual transformer, and combines them with the geometric information in the segmented image to form a richer and more complete crop feature representation, thereby improving the accuracy and robustness of crop classification.

[0196] In some embodiments, extracting the microscopic features of each crop, the planting spacing between different crops, and the timing information from the classified images respectively includes: extracting the microscopic features from the classified images based on a first convolutional neural network, extracting the planting spacing from the classified images based on a second convolutional neural network; and extracting timing information from the classified images based on a time series prediction network.

[0197] In this embodiment, the first convolutional neural network includes ResNet (residual network), the second convolutional neural network includes a YOLOX network, and the time series prediction network includes a BiLSTM (Bi-directional Long Short-Term Memory) network.

[0198] In this embodiment, for each classified image that can be divided into seedling stage images, microscopic crop features are identified from leafy vegetables and fruit and vegetable crops, macroscopic planting spacing is detected, and time series information is calculated. The specific steps are as follows:

[0199] (1) For leafy vegetables, a ResNet network based on deep learning is used to recognize the microscopic features of the crops. This embodiment uses a ResNet-50 network pre-trained on the ImageNet dataset as a feature extractor, inputs an image into the network, obtains a feature vector of size 2048, and uses a fully connected layer and a Softmax layer to map the feature vector to a vector of size C, where C is the number of categories of microscopic features. The recognition process of microscopic features is expressed by the following formula:

[0200] F=Softmax(ResNet-50(I)W+b);

[0201] Among them, I is the pixel value matrix of the image, ResNet-50 is the feature extractor, W, b are learnable parameters, Softmax is the Softmax function, and F is the classification vector of micro features.

[0202] (2) For fruit and vegetable crops, the YOLOX network based on deep learning is used to automatically learn the features of the image to detect the macroscopic features of the crop, such as the planting spacing, number of rows and columns, etc. This embodiment uses a YOLOX-S network pre-trained on the COCO dataset as the target detector, inputs the image into the network, and obtains a matrix of size N×5, where N is the number of detected targets and 5 is the location and category information of the target; the detection process of the planting spacing is expressed by the following formula:

[0203] D = YOLOX-S (I);

[0204] Where I is the pixel value matrix of the image, YOLOX-S is the object detector, and D is the detection matrix of macro features.

[0205] (3) For each picture that can be distinguished into seedling stages, a BiLSTM network based on deep learning is used to realize the maturity calculation of the temporal features of the crop. This embodiment uses a bidirectional long short-term memory network (BiLSTM) to model the image sequence and learn the temporal relationship between images. This embodiment uses a sliding window of size T to divide the image sequence into multiple subsequences, each subsequence contains T pictures, and each subsequence is input into the BiLSTM network to obtain a matrix of size T×H, where H is the dimension of the hidden state. A fully connected layer and a linear regression layer are used to map the temporal feature matrix to a vector of size R, where R is the number of temporal features. The extraction process of temporal information is expressed by the following formula:

[0206] S=Linear(BiLSTM(I 1 ,I 2 ,…,I T )W 4 +b 4 );

[0207] Among them, I 1 ,I 2 ,…,I T is a subsequence of the image sequence, BiLSTM is a temporal modeler, W, b 4 is a learnable parameter, Linear is a linear regression layer, and S is the regression vector of time series features.

[0208] The crop growth period prediction method provided by the embodiment of the present invention extracts microscopic features from the classified image through a first convolutional neural network, and extracts the planting spacing from the classified image through a second convolutional neural network, thereby improving the target positioning and recognition effect, while also reducing the calculation amount and memory occupancy of the model, improving the speed and performance of the model, and extracting time series information from the classified image through a time series prediction network, thereby realizing the regression calculation of the maturity period of the crop, and improving the accuracy and stability of crop growth prediction. The present invention adopts multiple deep learning networks, which not only overcomes the shortcomings and deficiencies of a single model, but also combines the rapid response of image classification and the accurate positioning of target detection to form an organic whole of a multi-dimensional deep learning network.

[0209] In some embodiments, after obtaining the crop prediction model, the method further includes: sequentially performing model pruning, quantization, and distillation operations on the crop prediction model to obtain an optimized crop prediction model.

[0210] In this embodiment, for each picture that can be distinguished into seedling stages, model compression and acceleration technologies such as model pruning, quantization, and distillation are used to reduce the complexity and running time of the model and improve the efficiency and portability of the model. The specific steps are as follows:

[0211] (1) For model pruning, this embodiment adopts a sensitivity-based pruning method to delete unimportant parameters in the model and reduce the size and amount of calculation of the model. The present invention uses the following formula to calculate the sensitivity of each parameter in the model, that is, the degree of influence of the parameter on the model performance.

[0212]

[0213] Among them, S i represents the sensitivity of the i-th parameter, L(θ) represents the loss function value of the model under the original parameter θ, L(θ-Δ i ) means that the model subtracts a small change Δ from the i-th parameter i The loss function value after .

[0214] (2) For model quantization, this embodiment adopts a method based on uniform quantization to represent the parameters in the model with fewer bits, thereby reducing the storage space and memory usage of the model. This embodiment adopts the following formula to calculate the quantized value of each parameter in the model, that is, the approximate value of the parameter after quantization. The quantization process is represented by the following formula:

[0215]

[0216] Among them, Q i represents the quantized value of the i-th parameter, θ irepresents the original value of the i-th parameter, min(θ) and max(θ) represent the minimum and maximum values ​​of the parameter, b represents the number of quantized bits, and round represents the rounding function. The present invention uses a bit number b=8 to quantize the parameters in the model into 8-bit unsigned integers, i.e., integers between 0 and 255.

[0217] (3) For model distillation, this embodiment adopts a method based on knowledge distillation to transfer the knowledge in the model to a smaller model to improve the generalization ability and reasoning speed of the model. This embodiment uses the following formula to calculate the distillation loss function of the model, that is, the difference between the model and a larger teacher model:

[0218] L distill =αL hard +(1-α)T 2 L soft ;

[0219] Among them, L distill represents the distillation loss function of the model, α represents the weight of the loss function, and L hard represents the hard label loss function of the model, that is, the difference between the model and the true label, L soft represents the soft label loss function of the model, that is, the difference between the model and the teacher model, and T represents the temperature parameter, which is used to smooth the probability distribution of soft labels.

[0220] In this embodiment, a weight α=0.5, a temperature parameter T=2, and a GoogLeNet network trained on the ImageNet dataset are used as a teacher model to perform knowledge distillation.

[0221] The crop growth period prediction method provided by the embodiment of the present invention obtains an optimized crop prediction model by successively performing model pruning, quantization, and distillation operations on the crop prediction model, thereby reducing the complexity and running time of the model, improving the efficiency and portability of the model, and enabling it to adapt to different hardware platforms and scenario requirements.

[0222] Figure 3 This is one of the structural schematic diagrams of the crop growth period prediction device provided by the present invention. Figure 3In the embodiment shown, a crop growth period prediction device includes a facility greenhouse monitoring camera, an image acquisition module, a primary crop classification module, a secondary crop classification module and a model building module; wherein the facility greenhouse monitoring camera includes image parameters and device parameters, the image parameters include resolution, timestamp, clarity, color deviation, storage format and image size; the device parameters include battery voltage, location information, device number, time, protocol number and storage size; the image acquisition module is specifically used to: detect whether the input image is complete, if it is incomplete (abnormal and blurred, etc.), take another shot, if the image is complete, perform foreground segmentation to determine the planting area, and record the transplanting timestamp T of each input image 0 , the planting area and transplanting timestamp T 0 The first-level crop classification module is specifically used for: calling the planting area and the corresponding time series information from the database, determining the color space histogram through the planting area to determine whether the crop indicators (height and leaf area index) in the image have reached the threshold for distinguishable seedling stage, if reached, determining the distinguishable seedling stage image, and updating the time series information of the distinguishable seedling stage image, and inputting the value ViT self-attention network for subsequent classification; the second-level crop classification module is specifically used for: classifying the distinguishable seedling stage images, determining the fruit and vegetable classification images and the leafy vegetable classification images, extracting micro features from the leafy vegetable classification images, extracting the planting spacing from the fruit and vegetable classification images, and realizing the maturity period calculation of the crop timing features according to the time series information; then fusing the micro features and the planting spacing data, and inputting them into the CNN classifier for training, and using the time series information to classify The results are used for time series discrimination, and the growth period prediction model is trained in sequence; the model building module is specifically used for: manually labeling the images through the LabelImg tool. In order to increase the diversity and balance of the data, this example performs 8 types of data enhancement preprocessing on a small number of labels, including color balance, brightness adjustment, grayscale balance enhancement, left and right mirroring, color enhancement, image segmentation, lateral deformation, and longitudinal deformation. By using ordinary RGB images as input, there is no need to use special sensors or equipment, which reduces the difficulty and cost of data collection, while also ensuring the quality and consistency of the data, and avoiding data distortion and loss due to equipment differences and failures; in addition, according to different visual tasks, this example randomly selects 60% of the data as a training set, 20% of the data as a validation set, and 20% of the data as a test set.

[0223] The crop growth period prediction device provided by the present invention is described below. The crop growth period prediction device described below and the crop growth period prediction method described above can be referred to each other.

[0224] Figure 4 This is the second structural schematic diagram of the crop growth period prediction device provided by the present invention. Figure 4As shown, the crop growth period prediction device includes: an image acquisition module 410 and a prediction module 420.

[0225] An image acquisition module 410 is used to acquire an image of a crop to be tested, where the image of the crop to be tested includes at least one type of crop;

[0226] The prediction module 420 is used to input the image of the crop to be tested into the crop prediction model to obtain the crop category prediction result and the crop growth period prediction result;

[0227] Among them, the crop prediction model is based on the microscopic characteristics of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and the target classification network is multi-task trained with the multi-task learning loss function as the training function; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function.

[0228] The crop growth period prediction device provided by the embodiment of the present invention uses the microscopic characteristics of each crop, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features and a crop prediction model trained with a multi-task learning loss function to predict different tasks on the crop image to be tested, thereby obtaining more accurate crop category recognition results and crop growth period prediction results. It can accurately identify different types of crops in the early stage of the crop seedling stage, improve the accuracy of crop classification and growth prediction, and thus provide strong support for seedling management of greenhouse agriculture.

[0229] Figure 5 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute the crop growth period prediction method, which includes: obtaining a crop image to be tested, wherein the crop image to be tested includes at least one type of crop; inputting the crop image to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result; wherein the crop prediction model is based on the microscopic features of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and the target classification network is multi-task trained using a multi-task learning loss function as a training function; the multi-task learning loss function is determined based on a cross entropy loss function and a mean square error loss function.

[0230] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0231] On the other hand, the present invention also provides a computer program product, which includes a computer program, and the computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the crop growth period prediction method provided by the above-mentioned methods, and the method includes: obtaining a crop image to be tested, and the crop image to be tested includes at least one type of crop; inputting the crop image to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result; wherein the crop prediction model is based on the microscopic characteristics of each crop in the sample crop image, the planting spacing between different crops, and the time series information corresponding to the sample crop image as training features, and multi-task training is performed on the target classification network using the multi-task learning loss function as the training function; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function.

[0232] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the crop growth period prediction method provided by the above-mentioned methods, the method comprising: obtaining an image of a crop to be tested, the image of the crop to be tested including at least one type of crop; inputting the image of the crop to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result; wherein the crop prediction model is based on the microscopic characteristics of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and multi-task training is performed on the target classification network using a multi-task learning loss function as a training function; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function.

[0233] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0234] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0235] 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 predicting crop growth period, characterized in that: include: Acquire a crop image to be tested, wherein the crop image to be tested includes at least one type of crop; Inputting the image of the crop to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result; The crop prediction model is obtained by multi-task training of the target classification network based on the microscopic features of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and the multi-task learning loss function as the training function; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function; the crop prediction model is obtained by the following steps: Acquire a sample crop image, wherein the sample crop image includes at least one type of crop; Extracting mask features from the sample crop image and segmenting it to obtain segmented images of different crops, and determining images that can be distinguished into seedling stages according to the statistical analysis amount of each crop in the segmented image; Classifying the images that can be distinguished as seedling stages according to a self-attention mechanism to obtain classified images, and extracting microscopic features of each crop, planting spacing between different crops, and timing information from the classified images; Performing feature fusion on the microscopic features and the planting spacing to obtain fused features; The target classification network is multi-task trained according to the fusion features, and the target classification network is time-series discriminated through the time series information. When the target classification network converges, a crop prediction model is obtained to achieve crop category prediction and growth period prediction.

2. The crop growth period prediction method according to claim 1, characterized in that: Extracting mask features from the sample crop image and segmenting the image to obtain segmented images of different crops includes: An instance mask is generated from the pixel level of the sample crop image according to the SOLOv2 network, and the instance mask is optimized according to a mask loss function to obtain the segmented image.

3. The crop growth period prediction method according to claim 1, characterized in that: The step of determining the seedling stage image according to the statistical analysis amount of each crop in the segmented image comprises: The segmented image is sequentially subjected to morphologically based image erosion, image dilation and noise filtering operations to obtain a filtered image; The connected domain labeling algorithm based on depth-first search is used to count the number of each crop and the corresponding area in the filtered image to obtain statistical data; Calculating the average height and leaf area index of each crop in the statistical data based on an image color space conversion algorithm, and determining that the segmented image is the seedling-separable image when the average height exceeds a height threshold and the leaf area index exceeds an index threshold; The height threshold and the index threshold are determined based on the growth cycle, phenological characteristics, historical data and expert knowledge of each crop in the segmented image.

4. The crop growth period prediction method according to claim 1, characterized in that: The classifying the separable seedling stage images according to the self-attention mechanism to obtain the classified images includes: According to the image classification model of the visual transformer, global features are extracted from the distinguishable seedling stage images, and the distinguishable seedling stage images are classified according to the global features to obtain leafy vegetable classification images and fruit and vegetable classification images; wherein the image classification model of the visual transformer is constructed based on the self-attention mechanism.

5. The crop growth period prediction method according to claim 1, characterized in that: The extracting of the microscopic features of each crop, the planting spacing between different crops and the time sequence information from the classified images includes: The microscopic features are extracted from the classified image based on a first convolutional neural network, the planting distance is extracted from the classified image based on a second convolutional neural network, and the timing information is extracted from the classified image based on a time series prediction network.

6. The crop growth period prediction method according to claim 1, characterized in that: After obtaining the crop prediction model, the method further includes: The crop prediction model is subjected to model pruning, quantization, and distillation operations in sequence to obtain an optimized crop prediction model.

7. A crop growth period prediction device, characterized in that: include: An image acquisition module, used for acquiring an image of a crop to be tested, wherein the image of the crop to be tested includes at least one type of crop; A prediction module, used for inputting the image of the crop to be tested into a crop prediction model to obtain a crop category prediction result and a crop growth period prediction result; The crop prediction model is obtained by performing multi-task training on the target classification network based on the microscopic features of each crop in the sample crop image, the planting spacing between different crops and the time series information corresponding to the sample crop image as training features, and using the multi-task learning loss function as the training function; the multi-task learning loss function is determined based on the cross entropy loss function and the mean square error loss function; The crop prediction model is obtained through the following steps: Acquire a sample crop image, wherein the sample crop image includes at least one type of crop; Extracting mask features from the sample crop image and segmenting it to obtain segmented images of different crops, and determining images that can be distinguished into seedling stages according to the statistical analysis amount of each crop in the segmented image; Classifying the images that can be distinguished as seedling stages according to a self-attention mechanism to obtain classified images, and extracting microscopic features of each crop, planting spacing between different crops, and timing information from the classified images; Performing feature fusion on the microscopic features and the planting spacing to obtain fused features; The target classification network is multi-task trained according to the fusion features, and the target classification network is time-series discriminated through the time series information. When the target classification network converges, a crop prediction model is obtained to achieve crop category prediction and growth period prediction.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the crop growth period prediction method according to any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the crop growth period prediction method according to any one of claims 1 to 6 is implemented.