Agricultural knowledge question answering method and system based on image recognition

Through image recognition technology, combined with multi-task classification algorithms and large language models, it solves the problem that agricultural intelligent question and answer systems cannot use images to obtain professional knowledge, realizes intuitive interpretation from agricultural images to professional knowledge, simplifies the user interaction process and expands Model application scope.

CN118193679BActive Publication Date: 2024-10-11HUBEI TAIYUE SATELLITE TECH DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410399141.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-03
Publication Date
2024-10-11
Estimated Expiration
2044-04-03

AI Technical Summary

Technical Problem

Existing agricultural intelligent question and answer systems cannot directly obtain professional knowledge using agricultural images. It is difficult for users to describe professional issues through text, which makes it more difficult to obtain professional knowledge.

Method used

Using a method based on image recognition, we collect standard questions in the agricultural field, extract word vectors and feature vectors, combine the multi-task classification algorithm to classify agricultural images, calculate the similarity between the image and the standard questions, and select the standard question with the highest similarity as the matches, word vectors for the images are generated and fed into large language models for interpretation.

Benefits of technology

It achieves intuitive and convenient interpretation from agricultural images to professional knowledge, reduces the difficulty of user interaction with artificial intelligence systems, expands the application scope of large language models in the agricultural field, and can accurately process and understand image information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118193679B_ABST
    Figure CN118193679B_ABST
Patent Text Reader

Abstract

The present invention discloses an agricultural knowledge question-answering method and system based on image recognition, which belongs to the field of artificial intelligence technology. The method comprises: collecting standard questions in the agricultural field and establishing a standard question data set; obtaining agricultural images input by users and constructing feature vectors of agricultural images; respectively calculating the comprehensive similarity between the feature vectors of agricultural images and each standard question in the standard question data set, and selecting the standard question with the highest comprehensive similarity as the final matching item; calculating the word vector of the agricultural image according to the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item; inputting the word vector of the agricultural image into a pre-trained large language model, and outputting the result of agricultural knowledge interpretation. The present invention realizes the interpretation and output of professional knowledge based on agricultural images, simplifies the interaction process between users and artificial intelligence systems, and makes the acquisition of agricultural professional knowledge more intuitive and convenient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence technology, and specifically relates to an agricultural knowledge question-answering method and system based on image recognition. Background Art

[0002] In the agricultural field, a large amount of knowledge is mainly recorded in text form, which facilitates the training of large-scale language models for agricultural knowledge. A common practice is to input professional knowledge in the agricultural field into large models to train agricultural intelligent question-answering systems that can provide professional knowledge through text questions.

[0003] However, this method requires users to input specific questions. For ordinary users, it may not be possible to accurately describe professional problems in the agricultural field in text, so the professional knowledge obtained from the agricultural intelligent question-answering system is limited. When users need to understand the status of related crops or agricultural products, due to the limited ability to describe professional questions, they cannot obtain reliable professional knowledge interpretation from the agricultural intelligent question-answering system, which is not conducive to the promotion of agricultural professional knowledge.

[0004] Therefore, a new agricultural knowledge question-answering system is needed to help users interpret professional knowledge conveniently and accurately. Summary of the invention

[0005] In view of this, the present invention proposes an agricultural knowledge question-answering method and system based on image recognition, which is used to solve the problem that the existing agricultural knowledge question-answering system cannot directly obtain professional knowledge using agricultural images.

[0006] In a first aspect, the present invention discloses an agricultural knowledge question-answering method based on image recognition, the method comprising:

[0007] Collect standard questions in the agricultural field, extract word vectors and feature vectors of the standard questions, and establish a standard question dataset based on the word vectors and feature vectors;

[0008] Obtain the agricultural image input by the user, use the multi-task classification algorithm to perform multi-task classification on the agricultural image, sequentially splice the multi-task classification results, and construct the feature vector of the agricultural image;

[0009] Calculate the comprehensive similarity between the feature vector of the agricultural image and each standard question in the standard question dataset, and select the standard question with the highest comprehensive similarity as the final matching item;

[0010] Calculate the word vector of the agricultural image based on the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item;

[0011] The word vectors of agricultural images are input into a pre-trained large language model to output agricultural knowledge interpretation results.

[0012] Based on the above technical solutions, preferably, the types of standard questions in the agricultural field include categories of crops or agricultural products, detection of pest and disease types, types of appearance characteristics, maturity of crops or agricultural products, vegetation density levels, growth status levels, soil types and condition levels, moisture levels, light condition levels, weather types and farmland environment levels.

[0013] Based on the above technical solution, preferably, the word vector and feature vector of the extracted standard question specifically include:

[0014] Use a pre-trained large language model to extract word vectors for standard questions;

[0015] A multi-task classification and recognition algorithm is used to perform multi-task classification on the standard questions, and the multi-task classification results are sequentially spliced ​​to construct the feature vector of the standard questions.

[0016] On the basis of the above technical solution, preferably, the multi-task classification and recognition algorithm adopts a machine learning or deep learning model;

[0017] The multi-task classification results are of the same type as standard problems in the agricultural domain.

[0018] On the basis of the above technical solution, preferably, the calculation formula of the comprehensive similarity is:

[0019]

[0020] Among them, p is the comprehensive similarity, λ i is the weight coefficient of the i-th dimension; s i is the cosine similarity between the agricultural image and the standard problem in the i-th dimension:

[0021]

[0022] A i is the i-th subsequence vector in the eigenvector of the standard problem, B i is the i-th subsequence vector in the feature vector of the agricultural image.

[0023] Based on the above technical solution, preferably, the weight coefficient λ i The calculation method is:

[0024] Collect multiple sample images related to agriculture, interpret each sample image separately, and generate corresponding text description of the problem;

[0025] Extract the feature vector of the sample image and the feature vector of the corresponding question text description respectively;

[0026] Calculate the comprehensive similarity between the feature vector of the sample image and the feature vector of the corresponding question text description, and set the comprehensive similarity to 1. Use the least squares method to calculate the weight coefficient λ of each dimension i .

[0027] On the basis of the above technical solution, preferably, the formula for calculating the word vector of the agricultural image is:

[0028] U = p × T or U = (1 + 1 / p) × T

[0029] Among them, U is the word vector of the agricultural image, p is the comprehensive similarity between the feature vector of the agricultural image and the final matching item, and T is the word vector of the final matching item.

[0030] In a second aspect, the present invention discloses an agricultural knowledge question-answering system based on image recognition, characterized in that the system comprises:

[0031] Dataset building module: used to collect standard questions in the agricultural field, extract word vectors and feature vectors of the standard questions, and build a standard question dataset based on the word vectors and feature vectors;

[0032] Feature quantity construction module: used to obtain agricultural images input by users, use multi-task classification algorithm to perform multi-task classification on agricultural images, sequentially splice the multi-task classification results, and construct feature vectors of agricultural images;

[0033] Feature matching module: used to calculate the comprehensive similarity between the feature vectors of agricultural images and each standard question in the standard question dataset, and select the standard question with the highest comprehensive similarity as the final matching item;

[0034] Word vector conversion module: used to calculate the word vector of the agricultural image based on the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item;

[0035] Knowledge interpretation module: used to input the word vectors of agricultural images into the pre-trained large language model and output the agricultural knowledge interpretation results.

[0036] In a third aspect of the present invention, an electronic device is disclosed, comprising: at least one processor, at least one memory, a communication interface and a bus;

[0037] Wherein, the processor, memory, and communication interface communicate with each other via the bus;

[0038] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to implement the method according to the first aspect of the present invention.

[0039] According to a fourth aspect of the present invention, a computer-readable storage medium is disclosed, wherein the computer-readable storage medium stores computer instructions, and the computer instructions enable a computer to implement the method described in the first aspect of the present invention.

[0040] Compared with the prior art, the present invention has the following beneficial effects:

[0041] 1) The present invention calculates the similarity between agricultural images and related agricultural problems, identifies the agricultural problems most similar to given agricultural images, fine-tunes the word vectors of agricultural problems, obtains new word vectors representing agricultural images, and inputs the word vectors of agricultural images into a pre-trained large language model, thereby realizing the interpretation and output of professional knowledge of agricultural images; when planting problems are found, users can ask questions to the artificial intelligence system by only taking images of crops or agricultural products to obtain answers with relevant professional knowledge, so that the original large language model can process image input and achieve expected text output, reducing the difficulty of problem text description, simplifying the interaction process between users and artificial intelligence systems, and making it more intuitive and convenient to obtain agricultural professional knowledge.

[0042] 2) The present invention starts from multiple dimensions and angles of agricultural problems, constructs an ordered feature vector with a unified structure, and conveniently describes the characteristics of various fields of agriculture. The multi-task classification algorithm performs multi-task classification on agricultural images and standard problems respectively, and sequentially splices the multi-task classification results to generate corresponding image feature vectors and problem feature vectors, thereby realizing accurate quantitative expression of agricultural images and related agricultural problems, and providing reliable technical support for the conversion between agricultural images and problem text descriptions.

[0043] 3) The present invention calculates the comprehensive similarity between agricultural images and all standard questions respectively, and then selects the standard question with the highest comprehensive similarity as the final matching item. The highest comprehensive similarity is used to adjust the word vector T of the standard question to obtain the word vector U that describes the question expressed by the image, that is, converting the image content into text information that can be understood and processed by the language model, thereby making it possible to use the image to ask questions and obtain the target answers; the present invention effectively bridges the difference between image input and text output, expands the application scope of the original large language model, and enables it to effectively process and understand image information in the agricultural field.

[0044] 4) The present invention collects multiple sample images related to agriculture, interprets them respectively to generate corresponding question text descriptions, calculates the comprehensive similarity between the two, and uses the least squares method to calculate the weight coefficient of each dimension, which effectively measures the importance of different dimensions and can improve the accuracy of comprehensive similarity calculation. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only 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.

[0046] Figure 1 The flowchart of the agricultural knowledge question-answering method based on image recognition of the present invention;

[0047] Figure 2 A flow chart for establishing a standard problem data set for the present invention;

[0048] Figure 3 Flowchart for calculating similarity vector S;

[0049] Figure 4 Flow chart for selecting final matches;

[0050] Figure 5 Flowchart for calculating the comprehensive similarity between the input agricultural image and the standard problem;

[0051] Figure 6 Examples of responses from the agricultural knowledge question-answering system when inputting standard questions;

[0052] Figure 7 for Figure 6 Examples of some word vectors T corresponding to the standard question;

[0053] Figure 8 Example of the answer given by the agricultural knowledge question answering system when the input is an agricultural image;

[0054] Fig. 9 for Figure 8 Examples of partial word vectors U corresponding to agricultural images. DETAILED DESCRIPTION

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

[0056] See also Figure 1 The present invention proposes an agricultural knowledge question-answering method based on image recognition, the method comprising:

[0057] S1. Collect standard questions in the agricultural field, extract word vectors and feature vectors of the standard questions respectively, and establish a standard question dataset based on the word vectors and feature vectors.

[0058] The present invention collects a series of standard questions related to the agricultural field, calculates the word vectors T and feature vectors W of these standard questions, and combines them into a standard question data set according to the sequence numbers of the standard questions.

[0059] The types of standard questions in the agricultural field involved in the present invention include categories of crops or agricultural products, detection of pest and disease types, types of appearance characteristics, maturity of crops or agricultural products, vegetation density levels, growth status levels, soil types and condition levels, moisture levels, light condition levels, weather types and farmland environment levels.

[0060] In order to accurately quantify and characterize standard issues related to the agricultural field, the present invention creates a multi-dimensional ordered metric space specifically used to comprehensively capture key features in the agricultural field. These dimensions include but are not limited to the categories of crops or agricultural products, pest and disease type detection, appearance feature types, maturity of crops or agricultural products, vegetation density levels, growth status levels, soil types and condition levels, moisture levels, light condition levels, weather types, and farmland environment levels. The number of categories contained in each dimension is not exactly the same. For example, in the dimension of the categories of crops or agricultural products, more than 100 agricultural-related objects including wheat, corn, rice, potatoes, pears, pigs, cattle, sheep, grass carp, etc. can be distinguished; while in the dimension of growth status level, only four categories are distinguished: excellent, good, medium, and poor. The classification of other dimensions is similar, and the categories can be divided according to actual needs. Assuming that the metric space is n-dimensional, the multi-dimensional structure vector is V{v1,v2,…,v i ,…,v n}(i=1~n), where v i It is the length of the space that records the corresponding dimension.

[0061] In order to facilitate calculation, we can perform multi-task classification and recognition on the standard problem, and splice the recognition results in the order of n-dimensional structural vectors, so that the multi-dimensional ordered metric space can be converted into a one-dimensional ordered vector, which can describe the characteristics of various agricultural fields. This one-dimensional ordered vector is called a feature vector, and its total length is

[0062] Figure 2 The flowchart of establishing a standard question data set is shown, and step S1 specifically includes the following steps:

[0063] Step S11, establish a set of standard questions and set the question number: set the initial value of recording a standard question number q to 1, and the total number of standard questions to Q. After completion, proceed to step S12.

[0064] Step S12, select a standard question: select a standard question from the standard question set for processing. If it is the first selection, the first standard question is selected; if it is not the first selection, the next question immediately following the previous standard question is selected. After completion, proceed to step S13.

[0065] Step S13, calculate word vector T: use a large language model designed for the agricultural field to calculate the word vector T for the selected standard question to achieve the vector representation of this question. After completion, proceed to step S14.

[0066] Step S14, calculate the feature vector W: perform multi-task classification on the standard problem through a multi-task classification algorithm, sequentially concatenate the multi-task classification results, and calculate its one-dimensional feature vector W{w1,w2,…,w k ,…,w N}(k=1~N). After completion, proceed to step S15.

[0067] Step S15, generating a data set element object: generating a new object, which has three attributes, namely, sequence number q, T and U. After completion, proceed to step S16.

[0068] Step S16, q=q+1: indicates that the data calculation of this standard question has been completed, q is incremented by 1, and the next standard question needs to be selected, and the above task is repeated. After completion, step S17 is entered.

[0069] Step S17, whether all standard questions have been traversed: Determine whether all standard questions have been processed. If q>Q, go to step S18; otherwise, it means that there are still standard questions that have not been processed, go to step S12 and continue processing.

[0070] Step S18, generating a standard question data set: generating a standard question data set according to the sequence of the new objects generated in step S15.

[0071] After completing step S1, the standard question dataset has been prepared, and we can now start processing images and calculating the corresponding word vectors. This means that we have the basis for converting image content into word vector representations, so that we can further analyze the relationship between images and questions.

[0072] S2. Obtain the agricultural image input by the user, use the multi-task classification algorithm to perform multi-task classification on the agricultural image, sequentially splice the multi-task classification results, and construct a feature vector of the agricultural image.

[0073] After obtaining the agricultural image input by the user, the present invention adopts a multi-task classification algorithm to perform multi-task classification on the agricultural image, and sequentially splices the multi-task classification results to obtain a one-dimensional feature vector M{m1,m2,…,m k ,…,m N}(k=1~N).

[0074] Similar to step S14, the multi-task classification and recognition algorithm uses machine learning or deep learning models such as SVM, decision tree, RNN, LSTM, GRU, BERT, GPT, etc., and the multi-task classification results are the same as the type of standard problems in the agricultural field.

[0075] S3. Calculate the comprehensive similarity between the feature vector of the agricultural image and each standard question in the standard question dataset, and select the standard question with the highest comprehensive similarity as the final matching item.

[0076] Each element of the feature vector W of the standard problem and the feature vector M of the agricultural image has a value between 0 and 1. In order to calculate the similarity between the agricultural image and the standard problem, the cosine similarity is used to construct the similarity vector S{s1,s2,…,s i ,…,s n}(i=1~n), where each element s i The value of is obtained through the cosine similarity algorithm.

[0077] The calculation formula of cosine similarity is as follows:

[0078]

[0079] Among them, A i is a subsequence vector extracted from the W sequence, obtained by splitting the W sequence according to the structure of the metric space. Similarly, B i is extracted from the M sequence in the same way as A i The same as A i Consistent.

[0080] For vector A i , whose elements consist of the corresponding parts in the W sequence, specifically Here t1 = 0, other Similarly, vector B i The elements of M are composed of corresponding parts in the sequence, and the form is similar, B i The elements are

[0081] The similarity vector S reflects the similarity of an agricultural image to a standard problem in multiple key dimensions. These dimensions cover the categories of crops or agricultural products, pest and disease type detection, appearance feature types, maturity of crops or agricultural products, vegetation density level, growth state level, soil type and condition level, moisture level, light condition level, weather type, and farmland environment level. Since this is an n-dimensional vector and each dimension contributes differently to the final similarity, a weighted method is used to combine this information to obtain a comprehensive similarity p. The calculation formula for this value is:

[0082]

[0083] Among them, s i is an element in the similarity vector S, indicating the similarity between the agricultural image and the standard problem in the i-th dimension; i is the weight coefficient of the i-th dimension, reflecting the importance of this dimension in the total similarity.

[0084] In order to determine the weight coefficient λ i , the present invention introduces a series of representative sample images as benchmarks, and calculates the corresponding similarity vectors between these sample images and the benchmark problem. The comprehensive similarity value is set to 1. Based on this, the least squares method is used to calculate the weight coefficients λ on multiple dimensions i .

[0085] Determine the weight coefficient λ i The methods specifically include:

[0086] (1) Collect multiple sample images related to agriculture, interpret each sample image separately, and generate corresponding question text descriptions.

[0087] (2) Extract the feature vector M0 of the sample image and the feature vector W0 of the corresponding question text description respectively.

[0088] (3) Calculate the similarity vector S between the feature vector of the sample image and the feature vector of the corresponding question text description.

[0089] First, the feature vector W0 described by the question text is decomposed into n one-dimensional vectors A according to the structure vector V i (i=1~n), similarly, the feature vector M0 of the sample image is also decomposed into n one-dimensional vectors B i (i=1~n), where the length of each vector is v i Next, use the cosine similarity calculation formula (1) to calculate A i With B i Similarities between i . These similarities iCombine them in sequence to eventually form a similar vector S.

[0090] like Figure 3 As shown, the sub-process of calculating the similarity vector S in step (3) is as follows:

[0091] Sub-step 1) Set initial traversal i=1, t1=0, k=1: During the initialization process, set i as the serial number of the dimension, and its starting value is 1. At the same time, set t1 as an accumulator to summarize the length values ​​of each dimension, and its initial value is set to 0. In addition, k is the serial number of the one-dimensional feature vector, and its initial value is also set to 1. After completion, proceed to sub-step 2).

[0092] Sub-step 2) Set A i and B i Empty: In the process of calculating similarity, the two one-dimensional vectors are initially set to empty. Since the length of each vector is variable, they are set to empty values ​​first so that elements can be dynamically added as needed in subsequent steps. After completion, proceed to sub-step 3).

[0093] Sub-step 3) k <t1+v i +1: Determine whether k satisfies the condition. In the process of decomposing the eigenvectors W0 and M0, the decomposed elements are dynamically classified into the corresponding A by using specific judgment conditions. i and B i If the judgment condition is met, then continue to classify the element into the current A i and B i In, go to sub-step 4); otherwise, if it is not satisfied, this indicates that the current A i and B i The elements of have been collected completely, and we go to sub-step 6), and we can use A i and B i Calculate similarity s i .

[0094] Sub-step 4) Set w k Return to A i , m k Return to B i : Take the corresponding element w from vectors W0 and M0 respectively k and m k , and are assigned to vector A i and B i After completion, proceed to sub-step 5).

[0095] Sub-step 5) k=k+1: Increment the eigenvector number with a step size of 1 to facilitate the judgment and classification of the next element. After completion, proceed to sub-step 3).

[0096] Sub-step 6) Calculate s using the formulai : In A i and B i After the vectors are determined, we can use the corresponding formula (1) to calculate the similarity s between the two vectors in the current dimension: i . After completion, proceed to sub-step 7).

[0097] Sub-step 7) t1 = t1 + v i : After completing the similarity calculation of the current dimension, in order to enter the similarity calculation of the next dimension, it is necessary to update the judgment condition of k so as to correctly perform the analysis and calculation of the next dimension. After completion, proceed to sub-step 8).

[0098] Sub-step 8) i=i+1: In order to calculate the similarity of the next dimension, the value of i needs to be increased, so that the calculation process of the next dimension can be smoothly entered. After completion, proceed to sub-step 9).

[0099] Sub-step 9) i>n+1: compare the size of i and n+1; if i is greater than n+1, it means that the similarity calculation of all dimensions has been completed, and the next step should be to proceed to sub-step 10). On the contrary, if i is not greater than n+1, it means that the similarity calculation of some dimensions has not been completed, so it is necessary to return to sub-step 2) to continue.

[0100] Sub-step 10) Generate similarity vector S: Put all s i Sort and combine in order to generate the similarity vector S corresponding to W0 and M0.

[0101] (4) Calculate the weight coefficient λ i :After calculating the similarity vectors S of all collected sample images and their corresponding questions, for these similarity vector groups, set all comprehensive similarity values ​​p = 1 in the similarity calculation formula. Finally, the least squares method is used to calculate the weight coefficient λ of each dimension i .

[0102] After constructing the feature vector of the agricultural image, the present invention calculates the similarity vector S between the agricultural image and each standard question. Then, the similarity vectors S are used to calculate the corresponding comprehensive similarity p, and a standard question with the highest similarity is selected. Based on this, the corresponding word vector U can be calculated for the agricultural image, thereby completing the process of converting the agricultural image content into a word vector representation.

[0103] Figure 4 The flowchart shown is for screening the final matching items, and step S3 specifically includes the following steps:

[0104] Step S31, set temp=0, No=-1: Initialize two variables: temp is used to record similarity, and since the range of similarity is 0 to 1, its initial value is set to 0; No is used to record the sequence number in the problem data set, and its initial value is set to -1. After completion, enter step S32.

[0105] Step S32, select an element from the question data set: In the question data set, each entry is an object containing serial numbers q, W and T. If it is the first selection, select the entry with serial number 1; if it is not the first selection, select the next entry with the current serial number. After completion, go to step S33.

[0106] Step S33, calculate the similarity vector S: by using the W of the current element and the M obtained in the second step, apply the same algorithm as in the first step to calculate the similarity matrix S. After completion, proceed to step S34.

[0107] Step S34, calculate the comprehensive similarity p: by similarity vector S and weight coefficient λ i , calculate the comprehensive similarity p according to formula (2), and then proceed to step S35.

[0108] Step S35, p>temp: compare the size of p and temp. If yes, it means p is larger, then go to step S36; otherwise, go to step S37.

[0109] Step S36, temp=p, No=q: temp records the data with a relatively large p value; No records the corresponding problem data set number when the p value is large. After completion, proceed to step S37.

[0110] Step S37, determine whether all entries in the question data set have been traversed: that is, determine whether q>Q. If so, it means that the maximum comprehensive similarity p has been found, and its value is saved in the variable temp. At the same time, the corresponding serial number is also saved in the variable No. Then, the standard question corresponding to the serial number of variable No is saved as the final matching item; otherwise, enter step S32 and continue to traverse the next record.

[0111] S4. Calculate the word vector of the agricultural image according to the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item.

[0112] Specifically, obtain the word vector T corresponding to No: according to the value of the variable No in step S37 as the serial number, select the element whose serial number matches No from the question data set, and obtain the word vector T of the element. Calculate the word vector U corresponding to this agricultural image through T and temp.

[0113] The formula for calculating the word vector of agricultural images is:

[0114] U=p×T (3)

[0115] Among them, U is the word vector of the agricultural image, p is the comprehensive similarity between the feature vector of the agricultural image and the final matching item, and T is the word vector of the final matching item.

[0116] In addition, the formula for calculating the word vector of agricultural images can also be:

[0117] U=(1+1 / p)×T (4)

[0118] If U = (1 + 1 / p) × T is used to calculate the word vector of agricultural images, it is necessary to note that the value of the elements in U may exceed the limit set by the word vector. If this happens, the value exceeding the upper limit needs to be replaced with the limit value of the element.

[0119] Through the above steps, the word vector U corresponding to the agricultural image is found.

[0120] S5. Input the word vector of the agricultural image into the pre-trained large language model and output the agricultural knowledge interpretation results.

[0121] The new word vector U is input into the pre-trained large language model. The large language model generates an output based on the input word vector. This output is regarded as the interpretation result of the input agricultural image, thereby realizing the professional knowledge interpretation and output of the image.

[0122] The present invention realizes the conversion from image to agricultural knowledge text output without retraining the entire model. This method not only simplifies the interaction process between users and artificial intelligence systems, but also makes the acquisition of agricultural expertise more intuitive and convenient.

[0123] Based on the above method embodiments, the present invention discloses an agricultural knowledge question-answering system based on image recognition, the system comprising:

[0124] Dataset building module: used to collect standard questions in the agricultural field, extract word vectors and feature vectors of the standard questions, and build a standard question dataset based on the word vectors and feature vectors;

[0125] Feature quantity construction module: used to obtain agricultural images input by users, use multi-task classification algorithm to perform multi-task classification on agricultural images, sequentially splice the multi-task classification results, and construct feature vectors of agricultural images;

[0126] Feature matching module: used to calculate the comprehensive similarity between the feature vectors of agricultural images and each standard question in the standard question dataset, and select the standard question with the highest comprehensive similarity as the final matching item;

[0127] Word vector conversion module: used to calculate the word vector of the agricultural image based on the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item;

[0128] Knowledge interpretation module: used to input the word vectors of agricultural images into the pre-trained large language model and output the agricultural knowledge interpretation results.

[0129] The above system embodiments and method embodiments correspond one to one, and for a brief description of the system embodiments, please refer to the method embodiments.

[0130] The agricultural knowledge question-answering method and agricultural knowledge question-answering system of the present invention are described below with reference to specific examples:

[0131] When processing the input agricultural image, the goal is to calculate the similarity p between the agricultural image and a standard question. This process involves constructing a similarity matrix. To illustrate this process, we only take the calculation of the first two elements s1 and s2 in the similarity matrix as an example. The calculation method of s1 and s2 will be applicable to the calculation of all other similarity elements in the matrix. In this way, the similarity between the image and the question can be systematically analyzed, and finally a comprehensive similarity p can be obtained. The specific processing flow is as follows Figure 5 As shown:

[0132] 1. Input agricultural images

[0133] Generally, agricultural images are taken from mobile terminals and uploaded to the dialog box of the large language model. Since the pixels of this agricultural image are relatively large, it does not meet the image classification standards and needs to be converted.

[0134] 2. Adjust pixels

[0135] The introduced CNN classification algorithm requires the image pixels to be 244*244, so the original agricultural image is reduced in dimension to meet this requirement.

[0136] 3. Grayscale processing

[0137] After the image is reduced in dimension, it needs to be further grayed out to enhance the contrast of the image, making the differences between different areas in the image more obvious, which is helpful for image feature extraction and analysis.

[0138] 4. Normalization

[0139] When processing grayscale images, the value of each pixel is generally between 0 and 255. In order to enhance the performance and stability of the classification algorithm, it is often necessary to normalize these pixel values ​​to a smaller range, usually between 0 and 1. Such processing can not only optimize the algorithm's computational efficiency, but also help improve its accuracy.

[0140] 5. Image multi-task classification and recognition

[0141] When processing the input agricultural image data, the present invention adopts a multi-task classification strategy for image recognition. Here, two core dimensions are given as examples: agricultural category classification and pest and disease detection. In view of the diversity of agricultural categories, it is further subdivided into two subcategories: plant classification and animal classification. Specifically, plant classification covers 65 different species, while animal classification includes 39 species. Similarly, pest and disease detection is also divided into two subtasks: plant pests and diseases and animal pests and diseases. Plant pests and diseases cover 82 different situations, while animal pests and diseases include 39 species. Under this multi-task recognition framework, all classification results are given in the form of probability that the image belongs to a specific category.

[0142] 6. Feature vector M of agricultural image

[0143] In this scenario, two different classification algorithms, an agricultural plant classification algorithm and an agricultural animal classification algorithm, were used to classify the same input agricultural image and obtained two different results.

[0144] First, by applying the agricultural plant classification algorithm, a one-dimensional probability vector with a length of 65 is obtained. The probability value of rapeseed in the 15th element is 0.9540, which is a very high value, indicating that the model is very confident in classifying the agricultural image as rapeseed. At the same time, the radish classification corresponding to the 14th element and the mustard classification corresponding to the 16th element also have relatively high probability values, indicating that the model believes that the agricultural image may also be radish or mustard.

[0145] Next, the agricultural animal classification algorithm was used to classify the same agricultural image. The results showed that the probability value of each element given by this algorithm was relatively low, which means that the model is not very confident that the agricultural image is classified as a certain animal.

[0146] The result vectors obtained by these two algorithms are concatenated to form a new vector B1. This vector B1 combines the judgments of the plant and animal classification algorithms to provide a comprehensive classification probability distribution.

[0147] Similarly, when using the plant pest classification algorithm, a result vector of length 82 was generated. In this vector, the 26th element stands out with a probability value of 0.8432, indicating the presence of clubroot in the image, while the probability values ​​of other elements are generally low. Then, through the animal pest classification algorithm, a vector containing 39 elements was obtained. Finally, the two classification result vectors were spliced ​​to form a new vector B2.

[0148] By combining the results of all relevant classification algorithms, a comprehensive feature vector M is constructed, which comprehensively reflects the multi-faceted characteristics of the input image. Specifically, each different classification algorithm - whether for agricultural plants, animal classification, or for plant and animal pests and diseases - will produce a specific classification result vector B i Then, these B i The vectors are spliced ​​together in the order of the established feature structure to form a vector M that fully describes the image features. In this way, the vector M contains the information obtained from each classification algorithm, providing a detailed data basis for further analysis and application.

[0149] 7. Eigenvector W of the standard problem

[0150] In this example, the text classification algorithm tackled a standard question that is most closely related to agricultural images: "In conditions of fertile soil, high density of planting, and high humidity, rapeseed is prone to clubroot. What is the cause and treatment for it?"

[0151] For this standard question, the text classification algorithm identified rapeseed with the highest probability of 0.91634, while the probabilities for radish and mustard were relatively low. This result shows that the agricultural products mentioned in the text are mainly rapeseed, which is closely related to the text content. This classification result is marked as A1.

[0152] When classifying pests and diseases for this standard problem, clubroot has the highest probability. This indicates that, according to the standard problem, this problem describes clubroot. The vector corresponding to this classification result is A2.

[0153] By classifying all texts into A i By sequentially combining them, a complete text feature vector W is obtained. This process not only accurately extracts key information (i.e. rapeseed and clubroot) from the standard, but also provides a rich data basis for further analysis by constructing the feature vector W and comparing and correlating it with other data (such as image data) to obtain more comprehensive analysis results.

[0154] 8. Similarity vector S

[0155] In this example, the cosine calculation formula (1) is used to calculate s1 = 0.9111 and s2 = 0.9341. These scores are obtained by comparing the text feature vector W (composed of each A i ) and the image feature vector M (composed of each B i Specifically, s1 and s2 correspond to the similarity scores of different feature dimensions (such as agricultural product classification and pest and disease classification).

[0156] Then through A i and B i Calculate s respectively i , by taking these similarity scores s i By combining them, we can construct a similarity vector S. Based on the similarity vector S, we use formula (2) to calculate the comprehensive similarity p = 0.8543 with each standard question.

[0157] In this example, the maximum value of the comprehensive similarity p = 0.8543. This comprehensive similarity p is a comprehensive score that reflects the overall similarity between the input agricultural image and the standard question text, and evaluates the similarity between the image content and the text description from a quantitative perspective. After obtaining the feature vector of the standard question by calculating the comprehensive similarity p, the transformation of the agricultural image to the word vector can be realized.

[0158] The following is an example of an application scenario.

[0159] In a mobile APP application scenario, start entering a standard question, and the agricultural knowledge question-answering system will answer as follows: Figure 6 As shown, Figure 7 for Figure 6 The partial word vector T corresponding to the standard question. Then the user uploads the agricultural image, calculates the comprehensive similarity p = 0.8543, and then the agricultural knowledge question-answering system continues to answer, such as Figure 8 Shown is the response corresponding to the input agricultural image. Fig. 9 for Figure 8 The partial word vector U corresponding to the agricultural image. Compared with the word vector in the background, the word vector U of the agricultural image is U = p*T.

[0160] In this mobile APP application scenario, the results of text and image input are compared for verification. It is divided into the following steps:

[0161] 1. Enter the standard question: The standard question for this example in the APP is shown in Figure 6.

[0162] 2. Answers from the agricultural knowledge question-answering system: The agricultural knowledge question-answering system calculates the word vectors for standard questions and provides standard answers. The input word vector of the agricultural knowledge question-answering system is a word vector with a length of 768 dimensions, such as Figure 7 Shown are some examples of word vectors.

[0163] 3. Upload an agricultural image: Then upload an agricultural image. This agricultural image is the appearance of rapeseed clubroot disease, as shown in Figure 8.

[0164] 4. Similarity between agricultural images and standard questions: The feature vector of agricultural images is calculated through the image multi-task recognition and classification algorithm, and the similarity p is calculated with each standard question. In this example, the comprehensive similarity between the agricultural image and the standard question input in the first step is p = 0.8543, and this value is the largest. At this time, the standard question is fine-tuned and a new word vector U = p*T is calculated, such as Fig. 9 as shown in .

[0165] 5. The agricultural knowledge question-answering system answers based on the new word vector: At this time, the word vector input by the large language model is U, and the answer of the large language model is as follows Figure 8 shown.

[0166] In short: users can input agricultural images and obtain word vectors for the questions corresponding to the agricultural images, which can provide more comprehensive and accurate agricultural knowledge without retraining large language models.

[0167] The present invention also discloses an electronic device, comprising: at least one processor, at least one memory, a communication interface and a bus; wherein the processor, memory, and communication interface communicate with each other through the bus; the memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to implement the aforementioned method of the present invention.

[0168] The present invention also discloses a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, wherein the computer instructions enable the computer to implement all or part of the steps of the method described in the embodiment of the present invention. The storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk, and other media that can store program codes.

[0169] The system embodiment described above is merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be distributed to multiple network units. A person skilled in the art may select some or all of the modules according to actual needs to achieve the purpose of the solution of this embodiment without creative effort.

[0170] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. An agricultural knowledge question-answering method based on image recognition, characterized in that: The method comprises: Collect standard questions in the agricultural field, extract word vectors and feature vectors of the standard questions, and establish a standard question dataset based on the word vectors and feature vectors; Obtain the agricultural image input by the user, use the multi-task classification algorithm to perform multi-task classification on the agricultural image, sequentially splice the multi-task classification results, and construct the feature vector of the agricultural image; Calculate the comprehensive similarity between the feature vector of the agricultural image and each standard question in the standard question dataset, and select the standard question with the highest comprehensive similarity as the final matching item; calculate the word vector of the agricultural image according to the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item; Input the word vectors of agricultural images into a pre-trained large language model to output agricultural knowledge interpretation results; The step of respectively calculating the comprehensive similarity between the feature vector of the agricultural image and each standard question in the standard question dataset specifically includes: Assume that each element value of the feature vector W of the standard problem and the feature vector M of the agricultural image is between 0 and 1, and use cosine similarity to construct a similarity vector S={s1,s2,…,s i ,…,s n }, i=1,2,…,n, n is the total number of dimensions, where each element s i The value of is calculated by cosine similarity; The calculation formula of cosine similarity is as follows: ; Among them, A i is a subsequence vector extracted from the feature vector W of the standard problem, B i is a subsequence vector extracted from the feature vector M of the agricultural image, B i Length and A i Consistency; s i For agricultural images and standard issues i Cosine similarity in dimensions; The comprehensive similarity between the feature vector of the agricultural image and each standard question in the standard question dataset is calculated. The calculation formula of the comprehensive similarity is: ; in, p is the comprehensive similarity, λ i For the i The weight coefficient of each dimension; Determine the weight coefficient λ i The methods specifically include: (1) Collect multiple sample images related to agriculture, interpret each sample image separately, and generate corresponding question text descriptions; (2) Extract the feature vector M0 of the sample image and the feature vector W0 of the corresponding question text description respectively; (3) Calculate the similarity vector S between the feature vector of the sample image and the feature vector of the corresponding question text description: Decompose the feature vector W0 described by the question text into n one-dimensional vectors A according to the structure vector V i , decompose the feature vector M0 of the sample image into n one-dimensional vectors B i , where each vector has length v i , using the cosine similarity calculation formula, calculate A i With B i Similarities between i ; The similarity s i Combine in sequence to form a similar vector S; The sub-process of calculating the similarity vector S in step (3) is as follows: Sub-step 1) Set the initial traversal index i=1, t1=0, k=1: During the initialization process, set i as the serial number of the dimension, with a starting value of 1; set t1 as an accumulator used to summarize the length values ​​of each dimension, with an initial value of 0; k is the serial number of the one-dimensional vector, with an initial value of 1; after completion, proceed to sub-step 2); Sub-step 2) Set A i and B i Empty: In the process of calculating the similarity, the two one-dimensional vectors A are initially i and B i Set to empty; after completion, proceed to sub-step 3); Sub-step 3) Determine whether k satisfies the judgment condition k <t1+v i +1: In the process of decomposing the feature vectors W0 and M0, the decomposed elements are dynamically classified into the corresponding A by using the judgment conditions. i and B i In the vector; if the judgment condition is met, continue to classify the element into the current A i and B i If the condition is not satisfied, proceed to sub-step 6); Sub-step 4) Set w k Return to A i , m k Return to B i : Take the corresponding element w from vectors W0 and M0 respectively k and m k , and are assigned to vector A i and B i After completion, proceed to sub-step 5); Sub-step 5) k=k+1: increment the eigenvector number with a step size of 1, and then proceed to sub-step 3); Sub-step 6) Calculate s using the formula i : In A i and B i After the vector is determined, the corresponding cosine similarity calculation formula is used to calculate the similarity s between the two vectors in the current dimension i ; After completion, proceed to sub-step 7); Sub-step 7) t1=t1+v i : Update the judgment condition of k to perform analysis and calculation of the next dimension; after completion, proceed to sub-step 8); Sub-step 8) i=i+1: increase the value of i by a step of 1 to enter the calculation process of the next dimension; after completion, proceed to sub-step 9); Sub-step 9) Determine whether i>n+1: compare i and n+1; if i is greater than n+1, proceed to sub-step 10); otherwise, return to sub-step 2) and continue execution; Sub-step 10) Generate similarity vector S: Put all s i Sort and combine in order to generate the similarity vector S corresponding to W0 and M0; (4) Calculate the weight coefficient λ i :Calculate the comprehensive similarity between the feature vector of the sample image and the feature vector of the corresponding question text description, set all comprehensive similarity values ​​p=1 in the comprehensive similarity calculation formula, and use the least squares method to calculate the weight coefficient λ of each dimension i ; The steps of respectively calculating the comprehensive similarities between the feature vectors of the agricultural image and each standard question in the standard question data set and selecting the standard question with the highest comprehensive similarity as the final matching item specifically include the following steps: Step S31, set temp=0, No=-1: Initialize two variables temp and No, where temp is used to record similarity and its initial value is set to 0; No is used to record the sequence number in the question data set and its initial value is set to -1; after completion, proceed to step S32; Step S32, select an element from the standard question data set: in the standard question data set, each entry is an object containing a sequence number q, a feature vector W of the standard question, and a word vector T of the standard question; if it is the first selection, select the entry with sequence number 1; if it is not the first selection, select the next entry with the current sequence number; after completion, enter step S33; Step S33, calculating the similarity vector S: based on the feature vector W of the current element and the feature vector M of the obtained agricultural image, calculating the similarity matrix S; after completion, proceeding to step S34; Step S34, calculate the comprehensive similarity p: by similarity vector S and weight coefficient λ i , calculate the comprehensive similarity p using the calculation formula of the comprehensive similarity, and after completion, proceed to step S35; Step S35, p>temp: compare the size of p and temp, if yes, go to step S36; otherwise, go to step S37; Step S36, temp=p, No=q: temp records the data with a relatively large p value, and No records the corresponding sequence number when the p value is relatively large; after completion, go to step S37; Step S37, determine whether all entries in the standard question data set have been traversed: that is, determine whether q>Q is satisfied, Q is the total number of standard questions, if yes, the corresponding p value is saved in the variable temp, and the corresponding sequence number is also saved in the variable No, and the standard question corresponding to the sequence number saved in the variable No is taken as the final matching item; otherwise, go to step S32 and continue to traverse the next record; The step of calculating the word vector of the agricultural image according to the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item specifically includes: Assume that the serial number of the final matching item is No, select the element whose serial number matches No from the question data set, and obtain the word vector T of the corresponding element; The word vector U corresponding to the agricultural image is calculated by T and temp. The formula for calculating the word vector of the agricultural image is: U = p × T; or U = (1 + 1 / p) × T; Among them, U is the word vector of the agricultural image, p is the comprehensive similarity between the feature vector of the agricultural image and the final matching item, and T is the word vector of the final matching item.

2. The agricultural knowledge question-answering method based on image recognition according to claim 1, characterized in that: The types of standard questions in the agricultural field include types of crops or agricultural products, detection of pest and disease types, types of appearance characteristics, maturity of crops or agricultural products, vegetation density levels, growth status levels, soil types and condition levels, moisture levels, light condition levels, weather types, and farmland environment levels.

3. The agricultural knowledge question-answering method based on image recognition according to claim 2 is characterized in that: The word vector and feature vector of the extraction standard question specifically include: Use a pre-trained large language model to extract word vectors for standard questions; A multi-task classification and recognition algorithm is used to perform multi-task classification on the standard questions, and the multi-task classification results are sequentially spliced ​​to construct the feature vector of the standard questions.

4. The agricultural knowledge question-answering method based on image recognition according to claim 2, characterized in that: The multi-task classification and recognition algorithm adopts a machine learning or deep learning model; The multi-task classification results are of the same type as standard problems in the agricultural domain.

5. An agricultural knowledge question-answering system based on image recognition using the method according to any one of claims 1 to 4, characterized in that: The system comprises: Dataset building module: used to collect standard questions in the agricultural field, extract word vectors and feature vectors of the standard questions, and build a standard question dataset based on the word vectors and feature vectors; Feature quantity construction module: used to obtain agricultural images input by users, use multi-task classification algorithm to perform multi-task classification on agricultural images, sequentially splice the multi-task classification results, and construct feature vectors of agricultural images; Feature matching module: used to calculate the comprehensive similarity between the feature vectors of agricultural images and each standard question in the standard question dataset, and select the standard question with the highest comprehensive similarity as the final matching item; Word vector conversion module: used to calculate the word vector of the agricultural image based on the similarity between the feature vector of the agricultural image and the final matching item and the word vector of the final matching item; Knowledge interpretation module: used to input the word vectors of agricultural images into the pre-trained large language model and output the agricultural knowledge interpretation results.

6. An electronic device, characterized in that: include: at least one processor, at least one memory, a communication interface, and a bus; Wherein, the processor, memory, and communication interface communicate with each other via the bus; The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to implement the method according to any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions enable a computer to implement the method according to any one of claims 1 to 4.