Method and system for automatic generation of visual algorithms based on multi-modal large models

By automating the generation of visual algorithms from multimodal large models, the problems of manual reliance and insufficient accuracy of AI models in existing technologies have been solved, realizing fully automated algorithm generation and deployment, and improving the efficiency and consistency of industrial vision algorithms.

CN123157263APending Publication Date: 2026-11-24BEIJING FOCUSIGHT TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611352864.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-02
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing technologies in industrial vision algorithm development suffer from problems such as manual coding and reliance on manual algorithm platform construction, resulting in low efficiency and unstable results. Pure AI models also lack accuracy in precision positioning and measurement scenarios and require manual intervention.

Method used

A multimodal large model is used to parse historical algorithm code into structured data of operator codes and parameters. Training samples are constructed by combining images and demand prompts. The multimodal large model is trained to establish the mapping relationship between visual task description and operator sequence, automatically output operator codes and parameters, generate algorithm program files and integrate them into application software.

Benefits of technology

It achieves fully automated generation from natural language requirements to deployable algorithm programs, reduces labor costs, ensures the stability and consistency of algorithm performance, makes full use of the high-precision advantages of traditional operators, and solves the engineering gap problem of existing solutions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123157263A_ABST
    Figure CN123157263A_ABST
Patent Text Reader

Abstract

This invention relates to the field of machine vision algorithm technology, and in particular to a method and system for automatically generating visual algorithms based on a multimodal large model. The method for automatically generating visual algorithms based on a multimodal large model parses historical algorithm code into structured data of operator codes and parameters, constructs training samples using images and natural language requirement prompts, and trains the multimodal large model to establish a mapping relationship between visual task descriptions and operator sequences. During inference, the model automatically outputs operator codes and parameters, and generates program files executable on algorithm platforms such as Halcon using single-operator code generation tools, construction tools, and integration tools. These files are then deployed to general vision platforms or customized software via code injection. This achieves full automation from natural language requirements to deployable visual algorithms, eliminating the need for manual coding and parameter tuning, reducing labor costs, ensuring consistent algorithm performance, and compensating for the insufficient accuracy of pure AI models in localization and measurement scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of machine vision algorithm technology, and in particular to a method and system for automatically generating vision algorithms based on a multimodal large model. Background Technology

[0002] In the industrial manufacturing sector, machine vision technology has been widely applied in product quality inspection, precision measurement, and target positioning. Typical industrial vision algorithms usually consist of a combination of multiple traditional image processing operators, such as image preprocessing, feature extraction, geometric fitting, and template matching, in a specific order. Currently, the development of such algorithms mainly relies on the following three methods: 1. Manual coding development Algorithm engineers write algorithm code from scratch using programming languages ​​such as C++ or basic algorithm libraries such as OpenCV based on sample images, and manually adjust parameters, repeatedly debugging until the algorithm effect meets the requirements. This method has the following shortcomings: (1) It requires algorithm engineers with in-depth professional knowledge, which has a high human resource threshold and cost; (2) The difference in experience and level of different engineers leads to unstable algorithm effect; (3) The development cycle is long and it is difficult to quickly respond to diverse visual detection needs.

[0003] 2. Building an algorithm based on an algorithm platform Using commercial machine vision algorithm platforms such as VM, existing operators are combined into a workflow through drag-and-drop or configuration operations, and then the parameters of each operator are manually debugged. Although this method lowers the programming threshold, it still has obvious defects: (1) Operators still need to have certain algorithm knowledge, and it cannot be fully automated; (2) Operator selection and parameter setting are highly dependent on personal experience, and the construction schemes of different people are very different, resulting in poor consistency of effects; (3) When faced with a large number of parameter combinations, manual debugging is inefficient.

[0004] 3. Based on AI models By collecting a large number of labeled samples to train a deep learning model, the model can be equipped with classification, detection, segmentation and other capabilities to directly complete the corresponding visual tasks. However, this method also has the following drawbacks in industrial vision scenarios: (1) In scenarios that require sub-pixel accuracy, such as matching and positioning and precision measurement, the performance of pure AI models is still difficult to meet industrial requirements, and these scenarios still rely on traditional image processing algorithms; (2) Deep learning models require a large number of labeled samples, and the cost of data collection and labeling is high; (3) Even in classification and detection tasks that AI models are good at, human intervention is still required in model selection, parameter tuning or prompt word design, and human differences also affect the stability of the results.

[0005] Therefore, there is currently a lack of a solution in the technology that can automate the entire process from requirement understanding to algorithm generation to engineering deployment for traditional algorithm scenarios such as matching and positioning, and measurement. Summary of the Invention

[0006] The technical problem this invention aims to solve is to overcome the shortcomings of existing technologies, such as manual coding and algorithm platform development relying on manual labor, low efficiency, and unstable results, as well as the insufficient accuracy of pure AI models in precise positioning and measurement scenarios, which still require manual intervention. This invention provides a method and system for automatically generating visual algorithms based on a multimodal large model. It parses historical algorithm code into structured data of operator codes and parameters, constructs training samples with images and requirement prompts, and trains a multimodal large model to establish a mapping relationship from visual task description to operator sequences. During inference, the multimodal large model automatically outputs operator codes and parameters, generates algorithm program files through a toolset, and integrates them into application software to achieve fully automatic algorithm generation and deployment.

[0007] The technical solution adopted by this invention to solve its technical problem is: an automatic generation method for visual algorithms based on multimodal large models, comprising the following steps: S1. Obtain a training sample set, which includes sample images, requirement prompts associated with the sample images, and algorithm code samples corresponding to the sample images and requirement prompts. S2. The multimodal large model is trained using the training sample set. The multimodal large model takes images and text as input and operator symbols and operator parameters as output. S3. Input the target task image and target task requirement prompts into the trained multimodal large model, and obtain the operator code sequence and corresponding parameters output by the multimodal large model; S4. Based on the operator code sequence and the corresponding parameters, call the toolset for interacting with the algorithm platform to generate an algorithm program file that can be executed on the algorithm platform.

[0008] Furthermore, the sample images in S1 are obtained from the original image set through the following selection process: Input the original image into the historical algorithm corresponding to the algorithm code sample, and obtain the algorithm output result; Based on the algorithm output, the original image is clustered into multiple categories using a clustering algorithm. Select at least one image from each category to obtain an intermediate image set; The matching score between each image in the intermediate image set and the demand prompt is calculated using an image-text matching model; Based on the matching score, a subset of images are selected from the intermediate image set as sample images in the training sample set.

[0009] Furthermore, the clustering algorithm is the K-means algorithm, and the image-text matching model is the CLIP model; When the number of original images exceeds 200, the original images are clustered into 200 categories, and one image is selected from each category to obtain 200 intermediate images; when the number of original images does not exceed 200, all original images are used as the intermediate image set. The intermediate image set was sorted by matching score and divided into 50 score intervals. One image was randomly selected from each score interval to obtain 50 sample images.

[0010] Furthermore, the demand prompts in S1 include: Product information is used to describe the type, material, and structure of the product to be tested; Detection site information, used to describe the site to be detected or located and its visual features; Specific requirements information is used to describe the task type, detection indicators, and accuracy requirements; Furthermore, the algorithm code sample in S1 is constructed in the following way: each line of operator call statement in the algorithm code is parsed into structured data, which includes comment information, operator code and operator input parameters.

[0011] Furthermore, S2 also includes a fine-tuning step after training the multimodal large model: Input the samples from the training sample set into the trained multimodal large model to generate the test algorithm; The output of the test algorithm is compared with the output of the corresponding historical algorithm in the training sample set; Samples with deviations exceeding a preset threshold are selected as fine-tuning samples; Fine-tuning of large multimodal models is performed using fine-tuning samples.

[0012] By comparing the inference output with historical results, difficult sample samples with deviations exceeding the threshold are selected for LoRA fine-tuning, forming a closed-loop optimization process.

[0013] Furthermore, S2 includes a reinforcement learning step after training the multimodal large model: Input the samples from the training sample set into the multimodal large model to generate the first algorithm; The second algorithm is obtained by removing at least one preprocessing operator from the first algorithm; Input the corresponding sample images into the first algorithm and the second algorithm respectively, and compare the deviation of the output results; If the deviation does not exceed the preset accuracy threshold, or if the output of the second algorithm is better than that of the first algorithm, then the second algorithm is used as a positive sample and the first algorithm is used as a negative sample. We use positive and negative samples to perform reinforcement learning optimization on a large multimodal model.

[0014] By removing redundant preprocessing operators to construct positive and negative sample pairs, the DPO algorithm is used to enable the model to learn to generate more concise and efficient algorithms.

[0015] Furthermore, the algorithm platform is Halcon, and the algorithm program file is a .hdev format file.

[0016] Furthermore, the toolset in S4 includes: A single operator code generation tool, used to generate single-line operator code based on a single operator code and its corresponding parameters; A build tool for sequentially assembling multiple single-line operator codes into a complete algorithm program file; Integration tools integrate algorithm program files into target application software via code injection; target application software includes general vision platforms or customer-customized dedicated detection software.

[0017] A system employing the automatic generation method of visual algorithms based on multimodal large models as described above includes: The sample creation module is used to obtain a training sample set, which includes sample images, requirement prompts associated with the sample images, and algorithm code samples corresponding to the sample images and requirement prompts. A multimodal large model takes images and text as input and operator symbols and operator parameters as output. The training module is used to train a large multimodal model using a training sample set; A toolset that interacts with the algorithm platform to generate algorithm program files that can be executed on the algorithm platform based on the operator code sequence and corresponding parameters output by the multimodal large model.

[0018] The beneficial effects of this invention are: This invention achieves end-to-end automated generation from natural language requirements to deployable algorithm programs, without the need for manual coding or parameter tuning, significantly reducing labor costs. Furthermore, it replaces human experience with unified model reasoning, ensuring the stability and consistency of algorithm performance. This invention uses a traditional algorithm platform as the execution carrier, giving full play to the high-precision advantages of traditional operators in scenarios such as matching and positioning and precision measurement, and making up for the lack of precision of pure AI models; through a two-stage image screening strategy that combines clustering and image-text matching, highly representative training samples are automatically selected to improve training efficiency and model generalization ability. This invention achieves code injection deployment of algorithm program files into general vision platforms or customized detection software through integration tools, completing the engineering closed loop from algorithm generation to production line usability, and solving the engineering gap problem of existing solutions stopping at code output. Attached Figure Description

[0019] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0020] Figure 1 This is a flowchart of the method of the present invention.

[0021] Figure 2 This is a schematic diagram of the toolset composition and workflow in the method of the present invention.

[0022] Figure 3 This is a schematic diagram of the forward propagation and iterative inference of the multimodal large model in the method of this invention.

[0023] Figure 4 This is a flowchart of the algorithmic intelligent agent reasoning and deployment in the method of this invention.

[0024] Figure 5 This is a block diagram of the system of the present invention. Detailed Implementation

[0025] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0026] Example 1: like Figure 1 As shown, this embodiment provides an automatic generation method for visual algorithms based on multimodal large models, including the following steps: Step 1: Case Collection In this embodiment, a preferred implementation is to select an algorithm platform for building the algorithm. Halcon is chosen as the platform. Real-world algorithm examples used in actual projects are collected, along with example code provided by the selected platform, including complete algorithm code and corresponding sample images. A richer source of examples will result in a stronger generalization ability of the model trained subsequently.

[0027] Step 2: Sample Preparation Sample creation is the process of transforming historical algorithm cases into training samples that can be used for learning by large multimodal models. Specifically, it includes: (a) Designing operator codes All operators on the algorithm platform are numbered, creating a one-to-one mapping between operators and their codes. In a preferred embodiment, the operators are numbered sequentially according to the order described in the Halcon official documentation. For example, the first operator is numbered 001, the second 002, and so on. After numbering, an operator code mapping table is established, recording the operator name, functional description, and parameter information corresponding to each code.

[0028] It should be noted that in this embodiment, the operator code refers to the digital identifier of the operator, used for the output of the model classification head; while the operator name refers to the text identifier of the operator, used for actual execution in the algorithm platform. A one-to-one correspondence is established between the two through an operator code mapping table. During the model training and inference phases, the operator code is used as the classification target to reduce the difficulty of the classification task; during the code generation phase, the operator code is converted into the operator name through the mapping table and written into the algorithm program file.

[0029] (ii) Code conversion The historical algorithm code is divided into a comment section and the actual code statements. Each line of operator call statements is converted into a structured triple data format: [comment, operator ID, parameter], where the parameter is the input parameter corresponding to the operator, represented by an array. For code statements without comments, the comment section can be empty. The part consisting of comment information and operator ID is called the code sample. Through the above transformation, the program code, which was originally incomprehensible to the model, is transformed into structured text data, laying the foundation for subsequent model training.

[0030] As an example, suppose the original Halcon code snippet is as follows: Set the constant of pi PI:=3.1415926 Calculate PI / 2 MeasurePhi := PI / 2 Get image size get_image_size (Image, Width, Height) Calculate the height of the scale MeasureHeight := RoiBottom - RoiTop Calculate the center of the scale CenterRow := (RoiTop + RoiBottom) / 2.0 Set an empty array n_edges := [] col_positions := [] Set ROI region gen_rectangle1 (ROIRect, RoiTop, RoiLeft, RoiBottom, RoiRight) reduce_domain (Image, ROIRect, ImageROI) for loop for i_col := ColStripWidth / 2 + 1 to RoiRight - ColStripWidth / 2-1 byv_step Traversal range StripLeft := max2(i_col - ColStripWidth / 2, 0) StripRight := min2(i_col + ColStripWidth / 2, RoiRight-1) ruler width MeasureWidth := StripRight - StripLeft Get the current ruler object gen_measure_rectangle2 (CenterRow, i_col, MeasurePhi, MeasureHeight / 2.0, MeasureWidth / 2.0, Width, Height, 'nearest_neighbor', MeasureHandle) Use a ruler to measure. measure_pos (ImageROI, MeasureHandle, MeasureSigma, MeasureThreshold,'positive', 'all', RowEdge, ColEdge, Amplitude, Distance) Save measurement results n_edges := [n_edges, |RowEdge|] col_positions := [col_positions, i_col] Close the current ruler close_measure (MeasureHandle) endfor Find all consecutive intervals that satisfy the given conditions, and identify the longest interval. StartIdx := [] EndIdx := [] in_region := 0 Parameter settings: Allowable deviation Delta := 3 v_bia:=0 for i := 0 to |n_edges| - 1 by 1 if (n_edges[i]>= (v_pre - (Delta-v_bia)) and n_edges[i]<=v_pre+(Delta+v_bia)) if (in_region == 0) The starting point of the new section in_region := 1 current_start := i endif else if (in_region == 1) End of interval, record in_region := 0 StartIdx := [StartIdx, current_start] EndIdx := [EndIdx, i - 1] endif endif endfor If the last point is still within the interval, it needs to be added. if (in_region == 1) StartIdx := [StartIdx, current_start] EndIdx := [EndIdx, |n_edges| - 1] endif return () The following structured data was obtained after being summoned:

[0031] (III) Design of Requirement Prompt Keywords For example programs provided by the algorithm platform, since they usually come with detailed descriptions of application scenarios and requirements, these descriptions can be directly used as requirement prompts. For real-world project cases without detailed descriptions, the following structured approach is used to design requirement prompts: (1) Product Information: Describe the product's detailed information, including type, brand, components to which the parts belong, material, shape, etc.; (2) Detection location information: Describe the location to be detected or located and its additional characteristics, such as whether it has specular high reflectivity, high curvature, etc. (3) Specific requirements information: Describe whether the task is classification, detection, segmentation or localization, the name and shape of the defect, the specific requirements for localization, and quantitative indicators (such as detection area ratio, localization accuracy, etc.).

[0032] Below is a complete example of a requirement prompt, corresponding to a visual task involving counting the number of cell layers inside the electrode: [Task] Statistics on the number of cell layers in electrode products

Product Information

[0033] [Location] Objective: To count the number of bright line layers representing battery cells in imaging; Feature: Linear shape with a brightness higher than the background; Note: There may be interference such as bending or folding. [Specific Requirements] 1. Task: Count the number of consecutive bright lines; areas with unclear imaging that cause interruptions need to be reconnected through evaluation. 2. Accuracy: None (This is a statistical measurement task, not a traditional measurement task). 3. Robustness: 4. Speed: Single image processing ≤150ms; 5. Output: A data structure containing the number of layers and intermediate results; 6. Metric: Accuracy rate greater than 95%.

[0034] [Reference Sample] Normal samples: Samples #01, #02, #04 to #06, #08 to #11, #13, #14, #16 to #20; Bending interference: Samples #03, #07, #12; Foldback interference: Sample #15; Following the steps above, each sample consists of three parts: code sample (comment information, operator codes and parameters), image (single or multiple images), and requirement prompts.

[0035] (iv) Image selection When the number of images corresponding to a case is no more than 50, all images are directly used as the images corresponding to the code sample; when the number of images exceeds 50, the following two-stage screening strategy is used to obtain a representative subset of images: Phase 1: When the number of images exceeds 200, all images are input into the corresponding historical algorithm file to obtain the algorithm output for each image. Using this output as a feature, the K-means clustering algorithm is used to cluster all images into 200 categories. One image is randomly selected from each category to obtain 200 intermediate images. If the current number of images does not exceed 200, all images are selected as the intermediate image set. The purpose of this step is to compress the number of images to a controllable range while ensuring image diversity.

[0036] The second stage: Select a model to measure the degree of matching between images and text as a preferred implementation of this embodiment. The model is the Clip model. Input the intermediate image selected in the first stage into the image encoder of the Clip model, and input the requirement prompt words into the text encoder of the Clip model to obtain image feature vectors and text feature vectors respectively. Calculate the cosine similarity between the two as the matching score. This score reflects the semantic relevance between each image and the current visual task requirement.

[0037] Sort the images by matching score from high to low, and divide the intermediate image set into 50 score intervals. Randomly select one image from each interval, and select a total of 50 images as the final sample image set. By using stratified random sampling, we can ensure that the images most relevant to the requirements are selected, while also covering samples with different degrees of relevance, thus avoiding sample homogeneity.

[0038] The principle behind the two-stage image selection strategy is as follows: the first stage ensures the diversity coverage of images in the algorithm output space through clustering, and the second stage ensures the semantic relevance of images to task requirements through image-text matching. The combination of the two makes the final 50 selected images both representative and targeted.

[0039] Step 3: Toolset Setup Toolsets act as a bridge between large multimodal models and algorithm platforms, converting the operator symbols and parameters output by the model into program files that can be actually executed on the algorithm platform. For example... Figure 2 As shown, the toolset includes single operator code generation tools, build tools, and integration tools.

[0040] (a) Single operator code generation tool The function of the single operator code generation tool is to receive a single operator code and its corresponding parameters, write the single line of code corresponding to the operator into the format file of the algorithm platform, and generate corresponding code comments.

[0041] In a preferred embodiment of this invention, the input parameters of the single operator code generation tool follow the following JSON Schema format: { "type": "object", "properties":{ "operator_name":{"type":"string","description":"Halcon operator name"}, "params":{"type":"object","description":"A dictionary of parameters, where the key is the parameter name and the value is the parameter value"}, "description":{"type":"string","description":"code comment"} }, "required":["operator_name","params"] } When in use, the operator obtains the corresponding operator name through its code index, and then generates code lines that conform to the syntax of the algorithm platform. The tool internally maintains a complete mapping relationship between operator codes and operator names, parameter types, and parameter constraints.

[0042] (ii) Build tools It receives multiple operator codes and their corresponding parameters, calls the single operator code generation tool in the order of invocation to generate the code lines of each operator, assembles them into a complete algorithm program file in sequence, and adds program header comments.

[0043] In a preferred embodiment of this invention, the input parameters of the build tool follow the following JSON Schema format: { "type":"object", "properties":{ "operators":{ "type":"array", "items":{ "type":"object", "properties":{ "name":{"type": "string"}, "params":{"type": "object"}, "description":{"type": "string"} } } }, "program_name":{"type": "string"}, "comments":{"type":"array","items":{"type":"string"}} } } When using it, the operator list is traversed, and the single operator code generation tool is called in sequence to generate the code for each operator. The code is then assembled in order, and a program header comment is added. The program header comment includes the program name, generation timestamp, and global comment information. Finally, the complete algorithm platform program string is output.

[0044] As an example, based on the operator sequence output by the aforementioned electrode cell layer count task, the Halcon program generated by the construction tool is as follows: hdev Alignment of the edges of the black plastic block on the battery top cover Generation time: 2026-08-10 14:30:00 Set the constant of pi PI:=3.1415926 Calculate PI / 2 MeasurePhi := PI / 2 Get image size get_image_size (Image, Width, Height) Calculate the height of the scale MeasureHeight := RoiBottom - RoiTop Calculate the center of the scale CenterRow := (RoiTop + RoiBottom) / 2.0 Set an empty array n_edges := [] col_positions := [] Set ROI region gen_rectangle1 (ROIRect, RoiTop, RoiLeft, RoiBottom, RoiRight) reduce_domain (Image, ROIRect, ImageROI) for loop for i_col := ColStripWidth / 2 + 1 to RoiRight - ColStripWidth / 2-1 byv_step Traversal range StripLeft := max2(i_col - ColStripWidth / 2, 0) StripRight := min2(i_col + ColStripWidth / 2, RoiRight-1) ruler width MeasureWidth := StripRight - StripLeft Get the current ruler object gen_measure_rectangle2 (CenterRow, i_col, MeasurePhi, MeasureHeight / 2.0, MeasureWidth / 2.0, Width, Height, 'nearest_neighbor', MeasureHandle) Use a ruler to measure. measure_pos (ImageROI, MeasureHandle, MeasureSigma, MeasureThreshold,'positive', 'all', RowEdge, ColEdge, Amplitude, Distance) Save measurement results n_edges := [n_edges, |RowEdge|] col_positions := [col_positions, i_col] Close the current ruler close_measure (MeasureHandle) endfor Find all consecutive intervals that satisfy the given conditions, and identify the longest interval. StartIdx := [] EndIdx := [] in_region := 0 Parameter settings: Allowable deviation Delta := 3 v_bia:=0 for i := 0 to |n_edges| - 1 by 1 if (n_edges[i]>= (v_pre - (Delta-v_bia)) and n_edges[i]<=v_pre+(Delta+v_bia)) if (in_region == 0) The starting point of the new section in_region := 1 current_start := i endif else if (in_region == 1) End of interval, record in_region := 0 StartIdx := [StartIdx, current_start] EndIdx := [EndIdx, i - 1] endif endif endfor If the last point is still within the interval, it needs to be added. if (in_region == 1) StartIdx := [StartIdx, current_start] EndIdx := [EndIdx, |n_edges| - 1] endif return () (III) Integration Tools The complete algorithm program file output by the building tool is integrated into the target application software, enabling the target application software to perform the current vision task. The integration tool works by injecting code, that is, configuring the storage path of the generated algorithm program file into the target application software's configuration file or loading logic, or encapsulating the algorithm program file as a functional module that the target application software can call. The target application software includes, but is not limited to, general vision platforms (such as general machine vision software platforms from various vendors) and customer-customized special detection software. The above three tools interact with the multimodal large model through a preset communication protocol. As a preferred embodiment, the communication protocol used is the MCP protocol, which provides a standardized interaction interface between the large language model and external tools.

[0045] Taking the aforementioned task of counting the number of battery cell layers as an example, the integration tool writes the path of the hdev program file output by the construction tool into the configuration file of the target visual inspection software. The target software automatically loads this program file upon startup, counts the number of battery cell layers for each input image frame, and returns a data structure containing the statistical results. For general-purpose vision platforms, the integration tool registers the algorithm program as a custom functional module of that platform; for customer-customized specialized inspection software, the integration tool encapsulates the algorithm program as a dynamic calling interface for that software.

[0046] In this embodiment, the toolset and the multimodal large model communicate using the MCP protocol. However, those skilled in the art will understand that the communication method between the toolset and the large model is not limited to the MCP protocol; RESTful API, gRPC, or other standardized communication protocols suitable for interaction between large models and external tools can also be used. This embodiment uses the Halcon platform as an example for illustration, but those skilled in the art will understand that the method of this invention is also applicable to other industrial machine vision algorithm platforms, such as OpenCV, VisionPro, and VM.

[0047] Step 4: Model Training and Optimization like Figure 3 As shown, the multimodal large model takes images and text as input and outputs operator code classification results and parameter text.

[0048] (a) Model selection A multimodal large model is selected, capable of simultaneously inputting images and text, and outputting classification and text results. As a preferred embodiment, the ViT model is chosen as the backbone network. The number of categories in the classification head is set to the total number of categories for the operator codes, allowing the classification head to predict which operator should be used in the current step, and the text head to output the parameters corresponding to that operator. Specifically, for numerical or text-based parameters, the text head directly outputs their values; for image or region-based parameters, the text head outputs text describing the image or region reading path.

[0049] In this embodiment, the image encoder adopts a ViT-B / 16 structure, dividing the input image into 16×16 pixel patches, which are then encoded into image feature vectors through multiple Transformer layers. The text encoder uses a Transformer encoder to encode the request prompts into text feature vectors. The image feature vectors and text feature vectors are fused through a cross-modal attention fusion layer, and the fused features are input into the classification head and text head, respectively. The classification head is a fully connected layer, with an output dimension equal to the total number of categories for each operator code, and uses a Softmax activation function to output the probability distribution of each operator code. The text head is a Transformer-based decoder that generates parameter strings for each token in an autoregressive manner.

[0050] The forward propagation process of the network is as follows: visual features are extracted from images through the backbone network, and semantic features are extracted from text through the text encoder. The two types of features are fused across modalities within the model. The fused features are then fed into the classification head and the text head, respectively. The classification head outputs the probability distribution of the operator codes, and the text head generates the parameter text sequence. During training, the model needs to learn the structured mapping from the visual-language joint representation to the operator sequence.

[0051] (ii) Input modification During inference, the multimodal large model iteratively constructs a complete sequence of operators. Specifically, the requirement prompt is used as part of the initial text input. After the model outputs an operator code and its corresponding parameters each time, the output is appended to the end of the existing text sequence as part of the text input for the next iteration. This process is repeated until the model outputs an end marker or reaches the preset maximum number of iterations. Initially, the list of selected operators is empty. As iteration progresses, the model can infer and generate subsequent operators based on the context of the generated operator sequence. A task end marker is preset in the requirement prompt; the iteration terminates when the operator code output by the model matches this marker.

[0052] (III) Full-scale training All the prepared training samples were used for large-scale full training. The training method adopted the conventional multimodal large model supervised training method, that is, taking the sample images and demand prompts as inputs and the operator codes and parameters in the code samples as output targets, and updating the model parameters by minimizing the difference between the predicted output and the true output.

[0053] (iv) Fine-tuning After large-scale full training, the training samples are re-inputted into the agent to generate a test algorithm. The test results of the generated algorithm are compared with the test results of the original algorithm on the samples, and the deviation is calculated. Samples with a deviation exceeding a preset threshold are selected as fine-tuning samples. In a preferred embodiment of this example, the preset threshold is 12%, that is, when the deviation between the generated algorithm result and the original algorithm result exceeds 12%, the sample is selected as a fine-tuning sample. The LoRA method is used to efficiently fine-tune the model parameters using the selected fine-tuning samples. The LoRA method achieves model adaptation to specific difficult examples with a smaller number of trainable parameters by adding a low-rank decomposition matrix next to the original weight matrix.

[0054] The fully trained model performs well on most regular samples, but performs poorly on some specific samples (such as samples with abnormal lighting or unique defect morphologies). By identifying these specific samples and performing targeted fine-tuning, the model can gradually cover more edge cases and improve its overall robustness.

[0055] (V) Strengthen learning optimization Training samples are input into the current multimodal large model to generate an algorithm. One or more preprocessing operators are randomly removed from the generation algorithm. These preprocessing operators include, but are not limited to, Gaussian filtering, image sharpening, mean filtering, and median filtering. The corresponding images are then input into both the algorithm before and after removing the preprocessing operators, and the output deviations are compared. If the deviation does not exceed a preset accuracy threshold, or if the output of the algorithm after removing the preprocessing operators is better than the original algorithm, it indicates that the removed preprocessing operators are redundant for this task. The simplified algorithm after removal is then used as a positive sample (preference), and the original algorithm before removal is used as a negative sample. In a preferred embodiment of this invention, the preset accuracy threshold is 0.5%.

[0056] The DPO algorithm utilizes pre-constructed positive and negative sample pairs for reinforcement learning optimization. The DPO algorithm directly optimizes the model's strategy, gradually increasing the probability of generating positive samples and gradually decreasing the probability of generating negative samples. This allows the model to gradually learn to automatically simplify the algorithm, remove redundant operators, and generate more efficient and concise algorithm solutions.

[0057] Step 5: Put into use like Figure 4As shown, after sample creation, toolset building, model training and optimization, the intelligent agent is ready for deployment. The specific inference and deployment process is as follows: The user inputs the target task image and target task requirement prompts into the trained algorithm agent, i.e., the trained multimodal large model. After receiving the image and text input, the multimodal large model, through forward propagation and iterative inference, sequentially outputs a complete sequence of operator codes and corresponding parameters in the text output section. This output is the algorithm design scheme generated for the current task.

[0058] Subsequently, the agent invokes a single-operator code generation tool to generate corresponding operator code line by line based on the output operator code sequence and parameters, according to the algorithm platform. The agent then invokes a construction tool to assemble the generated operator codes sequentially into a complete algorithm program file and adds header comments. Finally, the agent invokes an integration tool to integrate the algorithm program file into the target application software using code injection, enabling the software to execute the current vision algorithm task. This completes the entire application process of the algorithmic agent.

[0059] Example 2: like Figure 5 As shown, this embodiment provides an automatic visual algorithm generation system based on a multimodal large model, including a sample creation module, a multimodal large model, a training module, and a toolset. The sample creation module is used to acquire a training sample set, which includes sample images, requirement prompts associated with the sample images, and algorithm code samples corresponding to the sample images and requirement prompts. Specifically, the sample creation module performs the following functions: establishing an operator code mapping table for the algorithm platform; parsing each line of operator call statements in historical algorithm code into structured data, including annotation information, operator codes, and operator input parameters; constructing requirement prompts according to a three-part structure of product information, detection location information, and specific requirement information; and selecting representative sample images from the original image set using clustering algorithms and image-text matching models.

[0060] The multimodal large model takes images and text as input and operator symbols and operator parameters as output. As a preferred embodiment of this example, the multimodal large model uses ViT as the backbone network, the number of categories in the classification head is set to the total number of categories in the operator symbols, and the text head is used to output the operator parameters.

[0061] The training module is used to train a large multimodal model using the training sample set. Specifically, the training module performs full supervised training, LoRA fine-tuning based on hard example selection, and DPO reinforcement learning optimization based on positive and negative sample pairs.

[0062] The toolset interacts with the algorithm platform to generate executable algorithm program files based on the operator code sequence and corresponding parameters output by the multimodal large model. Specifically, the toolset includes a single operator code generation tool for generating single-line operator code based on a single operator code and corresponding parameters; a building tool for assembling multiple single-line operator codes sequentially into a complete algorithm program file; and an integration tool for integrating the algorithm program file into target application software via code injection. The target application software includes a general vision platform or customer-customized dedicated detection software.

[0063] The toolset interacts with the multimodal large model through a preset communication protocol. As a preferred embodiment, the communication protocol used is the MCP protocol.

[0064] The output of the sample creation module is connected to the training input of the multimodal large model. The training module and the multimodal large model are bidirectionally connected. The inference output of the multimodal large model is connected to the input of the toolset. The output of the toolset is connected to the deployment interface of the target application software.

[0065] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.

Claims

1. A multi-modal large model-based visual algorithm automatic generation method, characterized in that, Includes the following steps: S1. Obtain a training sample set, which includes sample images, requirement prompts associated with the sample images, and algorithm code samples corresponding to the sample images and requirement prompts. S2. The multimodal large model is trained using the training sample set. The multimodal large model takes images and text as input and operator symbols and operator parameters as output. S3. Input the target task image and target task requirement prompts into the trained multimodal large model, and obtain the operator code sequence and corresponding parameters output by the multimodal large model; S4. Based on the operator code sequence and the corresponding parameters, call the toolset for interacting with the algorithm platform to generate an algorithm program file that can be executed on the algorithm platform.

2. The method of claim 1, wherein the method is characterized in that: The sample images in S1 were obtained from the original image set through the following method: Input the original image into the historical algorithm corresponding to the algorithm code sample, and obtain the algorithm output result; Based on the algorithm output, the original image is clustered into multiple categories using a clustering algorithm. Select at least one image from each category to obtain an intermediate image set; The matching score between each image in the intermediate image set and the demand prompt is calculated using an image-text matching model; Based on the matching score, a subset of images are selected from the intermediate image set as sample images in the training sample set.

3. The method of claim 2, wherein the method further comprises: The clustering algorithm is the K-means algorithm, and the image-text matching model is the CLIP model. When the number of original images exceeds 200, the original images are clustered into 200 categories, and one image is selected from each category to obtain 200 intermediate images; When the number of original images does not exceed 200, all original images are used as the intermediate image set; The intermediate image set was sorted by matching score and divided into 50 score intervals. One image was randomly selected from each score interval to obtain 50 sample images.

4. The method of claim 1, wherein the method further comprises: The requirement prompts in S1 include: Product information is used to describe the type, material, and structure of the product to be tested; Detection site information, used to describe the site to be detected or located and its visual features; Specific requirements information describes the task type, detection indicators, and accuracy requirements.

5. The method of claim 1, wherein the method further comprises: The algorithm code sample in S1 is constructed in the following way: each line of operator call statement in the algorithm code is parsed into structured data, which includes comment information, operator code and operator input parameters.

6. The method for automatically generating visual algorithms based on multimodal large models according to claim 1, characterized in that: S2 also includes a fine-tuning step after training the multimodal large model: Input the samples from the training sample set into the trained multimodal large model to generate the test algorithm; The output of the test algorithm is compared with the output of the corresponding historical algorithm in the training sample set; Samples with deviations exceeding a preset threshold are selected as fine-tuning samples; Fine-tuning of large multimodal models is performed using fine-tuning samples.

7. The method for automatically generating visual algorithms based on multimodal large models according to claim 1, characterized in that: S2 also includes a reinforcement learning step after training the multimodal large model: Input the samples from the training sample set into the multimodal large model to generate the first algorithm; The second algorithm is obtained by removing at least one preprocessing operator from the first algorithm; Input the corresponding sample images into the first algorithm and the second algorithm respectively, and compare the deviation of the output results; If the deviation does not exceed the preset accuracy threshold, or if the output of the second algorithm is better than that of the first algorithm, then the second algorithm is used as a positive sample and the first algorithm is used as a negative sample. We use positive and negative samples to perform reinforcement learning optimization on a large multimodal model.

8. The method for automatically generating visual algorithms based on multimodal large models according to claim 1, characterized in that: The algorithm platform is Halcon, and the algorithm program file is a .hdev format file.

9. The method for automatically generating visual algorithms based on multimodal large models according to claim 8, characterized in that: The toolset in S4 includes: A single operator code generation tool, used to generate single-line operator code based on a single operator code and its corresponding parameters; A build tool for sequentially assembling multiple single-line operator codes into a complete algorithm program file; Integration tools integrate algorithm program files into target application software via code injection; target application software includes general vision platforms or customer-customized dedicated detection software.

10. A system employing the automatic generation method of visual algorithms based on multimodal large models as described in any one of claims 1 to 9, characterized in that, include: The sample creation module is used to obtain a training sample set, which includes sample images, requirement prompts associated with the sample images, and algorithm code samples corresponding to the sample images and requirement prompts. A multimodal large model takes images and text as input and operator symbols and operator parameters as output. The training module is used to train a large multimodal model using a training sample set; A toolset that interacts with the algorithm platform to generate algorithm program files that can be executed on the algorithm platform based on the operator code sequence and corresponding parameters output by the multimodal large model.