Model algorithm selection method, apparatus, device, and medium
By narrowing down the range of candidate algorithms through algorithmic prediction models and selecting the algorithm with the shortest execution time as the final algorithm based on the attribute parameters of the target image, the problem of excessively long execution time of neural network models is solved, and efficient algorithm selection is achieved.
Patent Information
- Application Number
- CN202210894795.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-27
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-07-27
AI Technical Summary
In existing technologies, neural network models need to run all candidate algorithms to determine the final algorithm when processing images, which results in excessive time consumption.
The search range of candidate algorithms is narrowed by using an algorithm prediction model. Candidate algorithms are predicted based on the attribute parameters of the target image, and the algorithm with the shortest execution time is selected as the final algorithm.
This significantly reduces the time required to determine the final algorithm for the model, avoiding the time consumption caused by iterating through all algorithms.
Smart Images

Figure CN115439709B_ABST
Abstract
Description
Technical Field
[0001] This disclosure generally relates to the field of artificial intelligence technology, specifically to the field of deep learning technology, and in particular to a method, apparatus, device, and medium for selecting model algorithms. Background Technology
[0002] A neural network model can receive an input and perform operations on that input using different algorithms (e.g., convolution and matrix multiplication), resulting in the same output. For example, if an image of a specific size is input into the model, the model can select the algorithm with the shortest runtime from all candidate algorithms as the final algorithm for the input image.
[0003] However, when an image is input into the model, the model will run all algorithms as candidate algorithms. For a single image, running one algorithm is already very time-consuming. If all algorithms are run, although a final algorithm will eventually be derived, a significant amount of time will be spent running all algorithms before the final algorithm is obtained. Summary of the Invention
[0004] Therefore, it is necessary to provide a method, apparatus, device, and medium for selecting model algorithms to address the above-mentioned technical problems. By using the method of this application, the range of candidate algorithms for the target image can be narrowed down through algorithm prediction models, thereby greatly reducing the time required to determine the final algorithm of the model.
[0005] Firstly, a method for selecting a model algorithm is provided, the method comprising:
[0006] The attribute parameters of the target image are input into the algorithm prediction model to obtain one or more candidate algorithms output by the algorithm prediction model. The algorithm prediction model is trained based on at least one set of historical attribute parameters and at least one set of target algorithms corresponding to the attribute parameters. The target algorithm is the algorithm used when making image prediction based on historical attribute parameters and the image prediction model. Based on one or more candidate algorithms, the final algorithm used to predict the target image based on the image prediction model is determined.
[0007] Secondly, a model algorithm selection device is provided, the device comprising:
[0008] The prediction unit is used to input the attribute parameters of the target image into the algorithm prediction model and obtain one or more candidate algorithms output by the algorithm prediction model. The algorithm prediction model is trained based on at least one set of historical attribute parameters and at least one set of target algorithms corresponding to the attribute parameters. The target algorithm is the algorithm used when performing image prediction based on historical attribute parameters and the image prediction model. The determination unit is used to determine the final algorithm used to predict the target image based on the image prediction model, based on one or more candidate algorithms.
[0009] Thirdly, a computer device is provided, including a memory, a processor, and a computer program stored not in the memory but executable on the processor, characterized in that, when the processor executes the program, it implements the steps of the method described in the first aspect and any possible implementation of the first aspect.
[0010] Fourthly, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect and any possible implementation thereof.
[0011] Fifthly, a computer program product is provided, the computer program product including instructions, which, when executed, implement the steps of the method described in the first aspect and any possible implementation of the first aspect.
[0012] The algorithm selection method of this application can determine the final algorithm used when predicting a target image using an image prediction model, based on the attribute parameters of the target image. Specifically, the attribute parameters of the target image can be input into the algorithm prediction model, which can output multiple candidate algorithms. The final algorithm used when predicting a target image using the image prediction model can be determined based on these multiple candidate algorithms. The algorithm prediction model is trained using at least one set of historical attribute parameters and at least one set of target algorithms corresponding to those attribute parameters. The target algorithm is the algorithm used for image prediction based on the historical attribute parameters and the image prediction model.
[0013] In existing technologies, for an image input into a neural network model, all algorithms within the model capable of predicting the image are run, and the final algorithm is determined based on the runtime of each algorithm. However, running all algorithms consumes a significant amount of time.
[0014] Compared to existing solutions, the method described in this application allows the algorithm prediction model to select candidate algorithms for the target image from a large pool of algorithms, and then determine the final algorithm used when predicting the target image based on the image prediction model. This avoids the time-consuming problem of existing technologies that traverse all algorithms to determine the final algorithm. The algorithm prediction model can narrow down the search range of candidate algorithms, and it is precisely because the search range of candidate algorithms is narrowed that the time required to determine the final algorithm of the model is greatly reduced. Attached Figure Description
[0015] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0016] Figure 1Structural block diagram of the computer device provided in the embodiments of this application;
[0017] Figure 2 A flowchart illustrating the model algorithm selection method provided in this application embodiment;
[0018] Figure 3 Another flowchart illustrating the model algorithm selection method provided in this application embodiment;
[0019] Figure 4 Another flowchart illustrating the model algorithm selection method provided in this application embodiment;
[0020] Figure 5 Another flowchart illustrating the model algorithm selection method provided in this application embodiment;
[0021] Figure 6 Another flowchart illustrating the model algorithm selection method provided in this application embodiment;
[0022] Figure 7 A schematic diagram of an accumulator counter provided in an embodiment of this application;
[0023] Figure 8 A flowchart of a candidate algorithm for triggering target images provided in an embodiment of this application;
[0024] Figure 9 A flowchart illustrating the training and prediction processes of the algorithm prediction model provided in this application embodiment;
[0025] Figure 10 A flowchart illustrating the complete implementation steps of the model algorithm selection method provided in the embodiments of this application;
[0026] Figure 11 This is a schematic diagram of the structure of the model algorithm selection device provided in the embodiments of this application. Detailed Implementation
[0027] The present application will now be described in further detail with reference to the embodiments and accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, only the parts relevant to the invention are shown in the accompanying drawings.
[0028] It should be noted that, unless otherwise specified, the embodiments and features of the embodiments in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0029] Currently, when an image is input into the model, the model runs all algorithms as candidates and selects the one with the shortest running time as the final algorithm. However, running any one of the algorithms is time-consuming, and running all algorithms would consume even more time.
[0030] Based on this, this application proposes a method, apparatus, device, and storage medium for selecting model algorithms, which can narrow down the range of candidate algorithms for a target image through algorithm prediction models, thereby greatly reducing the time required to determine the final algorithm of the model.
[0031] The model algorithm selection method provided in this application can be applied to, for example... Figure 1 The computer device 10 shown is illustrated in the diagram. The internal structure of the computer device 10 can be seen as follows: Figure 1 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides the operating environment for the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements a model algorithm selection method. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0032] In this embodiment of the application, the computer device 10 can determine the final algorithm used when the target image is predicted using an image prediction model based on the attribute parameters of the target image.
[0033] Previous text Figure 1 An application scenario diagram of this application is presented. In another embodiment of this application, a method for selecting a model algorithm is provided, which can be applied to… Figure 1 The computer device 10 shown. (e.g.) Figure 2 As shown, the method includes the following steps:
[0034] Step 201: Input the attribute parameters of the target image into the algorithm prediction model to obtain one or more candidate algorithms output by the algorithm prediction model; the algorithm prediction model is trained based on at least one set of historical attribute parameters and at least one set of target algorithms corresponding to the attribute parameters, and the target algorithm is the algorithm used when performing image prediction based on historical attribute parameters and the image prediction model;
[0035] This application provides a candidate algorithm acquisition scheme that can narrow down the range of candidate algorithms for a target image. Specifically, all algorithms can be screened to select several algorithms with shorter execution times, and these algorithms can be used as candidate algorithms for the target image.
[0036] The target image can be the image predicted by the input image prediction model. The attribute parameters of the target image include key parameters used by the image prediction model to predict the target image. For example, attribute parameters may include at least one of the following: model operating platform identifier, image information, identifier of the computation rule, and the precision of the computation rule.
[0037] The model running platform identifier is used to characterize the platform or device on which the above image prediction model runs. For example, it can be a device ID (platform number).
[0038] Image information is used to describe information about the target image, such as shape (tensor), pixels, resolution, size, color, color channels, etc.
[0039] The identifier of the operation rule is used to characterize the operation rule used by the image prediction model to predict the target image. For example, the identifier of the operation rule can be "operation", where operation can be convolution operation or matrix multiplication operation.
[0040] The precision of the operation rules is used to characterize the computational precision of the algorithm. For example, the computational precision can be float16 or float32.
[0041] In one possible implementation, the algorithmic prediction model is trained using at least one set of historical attribute parameters and at least one set of target algorithms corresponding to those attribute parameters. This can be understood as follows: during the training process, the attribute parameters of the historical images used in the input image prediction model (i.e., historical attribute parameters) and the corresponding algorithms (i.e., target algorithms) can be used as training samples and sample label values, respectively. During training, the algorithmic prediction model can extract features from the training samples and perform association predictions based on these extracted features to obtain the prediction algorithm output by the algorithmic prediction model.
[0042] Furthermore, the model is iteratively trained based on the loss between the predicted algorithm output by the model and the label until the loss between the learned features and the sample labels converges, thus obtaining the algorithm prediction model. This algorithm prediction model can then be used to predict candidate algorithms for the target image. For example, the algorithm prediction model is used to filter out several algorithms with shorter execution times from all algorithms for the target image, and these algorithms are then used as candidate algorithms for the target image.
[0043] The attribute parameters of historical images include key parameters used by the image prediction model to predict historical images. For example, attribute parameters may include at least one of the following: model operating platform identifier, image information, identifier of the computation rule, and the precision of the computation rule.
[0044] Step 202: Based on one or more candidate algorithms, determine the final algorithm to be used for predicting the target image based on the image prediction model.
[0045] This application provides a final algorithm adoption scheme, which can determine the algorithm with the shortest execution time from the candidate algorithms of the target image, and use the algorithm with the shortest execution time as the final algorithm used to predict the target image.
[0046] Specifically, candidate algorithms can be those algorithms selected when predicting a target image based on an image prediction model; that is, algorithms that the image prediction model can use to predict the target image. All of the above candidate algorithms can produce the same prediction result, but their execution times differ. The image prediction model predicts the target image; specifically, the image prediction model can use the candidate algorithms predicted by the algorithm prediction model to predict the target image and obtain the prediction result. The final algorithm can be the one with the shortest execution time used to predict the target image.
[0047] One possible implementation is that the algorithm prediction model can predict candidate algorithms for the target image, and one of these candidate algorithms can be selected as the final algorithm for predicting the target image.
[0048] The algorithm selection method of this application can determine the final algorithm used when predicting a target image using an image prediction model, based on the attribute parameters of the target image. Specifically, the attribute parameters of the target image can be input into the algorithm prediction model, which can output multiple candidate algorithms. The final algorithm used when predicting a target image using the image prediction model can be determined based on these multiple candidate algorithms. The algorithm prediction model is trained using at least one set of historical attribute parameters and at least one set of target algorithms corresponding to those attribute parameters. The target algorithm is the algorithm used for image prediction based on the historical attribute parameters and the image prediction model.
[0049] In existing technologies, for an image input into a neural network model, all algorithms within the model capable of predicting the image are run, and the final algorithm is determined based on the runtime of each algorithm. However, running all algorithms consumes a significant amount of time.
[0050] Compared to existing solutions, the method described in this application allows the algorithmic prediction model to filter candidate algorithms for the target image from a large pool of algorithms, and then determine the final algorithm used when predicting the target image based on the image prediction model. This avoids the time-consuming problem of existing technologies that traverse all algorithms to determine the final algorithm. The algorithmic prediction model can narrow down the search range of candidate algorithms, and it is precisely because the search range of candidate algorithms is narrowed that the time required to determine the final algorithm of the model is greatly reduced.
[0051] The embodiments described above illustrate a technical solution for determining the final algorithm used in predicting a target image based on an image prediction model, according to the algorithm prediction model. Another embodiment of this application describes a technical solution for determining the final algorithm used in predicting a target image based on an image prediction model, based on candidate algorithms predicted by the algorithm prediction model. For example, the specific implementation of the step described above, "determining the final algorithm used to predict the target image based on an image prediction model, according to one or more candidate algorithms," includes... Figure 3 Steps:
[0052] Step 301: Run one or more candidate algorithms and obtain the execution time of one or more candidate algorithms;
[0053] Specifically, candidate algorithms can be algorithms that are to be selected when predicting a target image based on an image prediction model. For example, the aforementioned candidate algorithms can all produce the same prediction result when predicting a target image based on an image prediction model, but the execution time of each algorithm is different. The execution time of a candidate algorithm can be the running time of each candidate algorithm.
[0054] One possible implementation is that the image prediction model can run various candidate algorithms and obtain the execution time of each candidate algorithm. For example, the execution time of each candidate algorithm can be t1 to t5.
[0055] Step 302: Based on the final algorithm selection mechanism, determine the candidate algorithm with the shortest execution time as the final algorithm.
[0056] Specifically, the final algorithm selection mechanism can determine the candidate algorithm with the shortest execution time as the final algorithm used when predicting the target image based on the image prediction model.
[0057] One possible implementation is that if t1 is the shortest among the execution times of each candidate algorithm from t1 to t5, then the final algorithm selection mechanism can determine the candidate algorithm corresponding to t1 as the final algorithm used to predict the target image based on the image prediction model.
[0058] The preceding implementation described a technical solution for determining the final algorithm used in predicting a target image based on an image prediction model, based on candidate algorithms predicted by the algorithm prediction model. In another embodiment of this application, another technical solution for determining the final algorithm based on candidate algorithms predicted by the algorithm prediction model is described. For example, the specific implementation of the preceding step of "determining the final algorithm used for predicting a target image based on an image prediction model, based on one or more candidate algorithms" includes... Figure 4 Steps:
[0059] Step 401: If one or more candidate algorithms have cached records, determine the execution time of one or more algorithms based on the cached records;
[0060] Specifically, the cache record can be relevant information recorded in the cache when the image prediction model makes a prediction on the input image. For example, it can be recorded in the form of key-value pairs, where the key includes device ID (platform number), operation, shape (tensor), and param (precision of the operation rule), and the value includes algo (equivalent to the target algorithm in the previous embodiment of this application), time (algorithm running time), and workspace (extra space for storing intermediate results of the operation).
[0061] One possible implementation is to input the attribute parameters of the target image into the algorithm prediction model, and the algorithm prediction model outputs multiple candidate algorithms. If the target image has been input into the image prediction model for prediction multiple times, the execution time of the above multiple algorithms can be determined based on the multiple algorithms used by the target image recorded in the cache, without having to run the candidate algorithms one by one.
[0062] Step 402: Select the algorithm with the shortest execution time from one or more candidate algorithms as the final algorithm.
[0063] Specifically, the final algorithm can be the algorithm used when predicting the target image based on an image prediction model.
[0064] One possible implementation is to store a cache record of algorithms used on the target image, numbered 1 through 5. When the target image is input into the image prediction model again, the model can predict multiple candidate algorithms, such as t1 through t7. The algorithm prediction model can then select the algorithm that is both a candidate algorithm and in the cache record, and has the shortest execution time, as the final algorithm. For example, algorithm 1, corresponding to t1 with the shortest execution time, can be selected as the final algorithm.
[0065] The embodiments described above illustrate another technical solution for determining the final algorithm based on candidate algorithms predicted by the algorithm prediction model. In another embodiment of this application, another technical solution for determining the final algorithm based on candidate algorithms is described. For example, the specific implementation of the step described above, "determining the final algorithm used to predict the target image based on an image prediction model according to one or more candidate algorithms," includes the following steps:
[0066] If one or more candidate algorithms lack cache records, the final algorithm used by the image prediction model to predict the target image is determined based on the cache records of the image prediction model and the number of times the target image is input into the image prediction model.
[0067] Specifically, cache records can be information stored in the cache when an image prediction model makes predictions on an input image. For example, they can be recorded in the form of key-value pairs, where the key includes device ID (platform number), operation, shape (tensor), and param (precision of the operation rule), and the value includes algorithm, time (algorithm running time), and workspace (extra space for storing intermediate results of the operation).
[0068] One possible implementation is that if the cache record does not record the algorithm used for the target image, the final algorithm used by the image prediction model to predict the target image can be determined based on the cache record of the image prediction model and the number of times the target image is input into the image prediction model.
[0069] This application also provides a possible implementation: when the target image is input into the image prediction model, if the cache record does not record any algorithm used by the target image, then any algorithm in the cache record can be determined as the final algorithm for the target image, instead of using the algorithm prediction model to predict the candidate algorithm for the target image.
[0070] The embodiments described above introduced another technical solution for determining the final algorithm based on candidate algorithms. In another embodiment of this application, a technical solution for determining the final algorithm based on the number of inputs to the target image and cache records is introduced. For example, the step described above, "determining the final algorithm used by the image prediction model to predict the target image based on the cache records of the image prediction model and the number of inputs of the target image to the image prediction model," includes... Figure 5 Steps:
[0071] Step 501: If the number of inputs reaches the first threshold, obtain the size difference between the target image and one or more historical input images; the attribute parameters of the target image and the historical input images are the same.
[0072] Specifically, the first threshold is used to characterize the upper limit of the number of times the target image is input into the image prediction model, which can be understood as a maximum value. For example, the maximum value could be 5. If the above maximum value is reached, the size difference between the target image and the historical input image is obtained. The historical input image can be a previous input image of the image prediction model, and both the historical input image and the final algorithm it runs in the model are stored in a specific location, such as a cache. The size difference can be the pixel difference between the target image and the historical input image. At least one of the following is included: model running platform identifier, image information, identifier of the operation rule, and precision of the operation rule.
[0073] The model running platform identifier is used to characterize the platform or device on which the above image prediction model runs. For example, it can be a device ID (platform number).
[0074] Image information is used to describe information about the target image, such as shape (tensor), pixels, resolution, size, color, color channels, etc.
[0075] The identifier of the operation rule is used to characterize the operation rule used by the image prediction model to predict the target image. For example, the identifier of the operation rule can be "operation", where operation can be convolution operation or matrix multiplication operation.
[0076] The precision of the operation rules is used to characterize the computational precision of the algorithm. For example, the computational precision can be float16 or float32.
[0077] One possible implementation is that if the number of input attempts is 6 and the first threshold is 5, then if the number of input attempts exceeds the first threshold, the size difference between the target image and one or more historical input images can be obtained. For example, the size difference can be, but is not limited to, 1, 2, ... 100.
[0078] Step 502: If the size difference is less than the second threshold, determine the final algorithm to run on one or more historical input images in the image prediction model;
[0079] Specifically, the size difference can be the pixel difference between the target image and the historical input images. A second threshold is used to characterize the upper limit of the size difference between the target image and multiple historical input images; this upper limit can be understood as the maximum value. For example, the maximum value could be 6. If this maximum value is reached, the final algorithm running on the multiple historical input images in the model can be determined.
[0080] One possible implementation involves setting the size difference to 1, 2, ..., 100, with a second threshold of 6. Since size differences 1 through 5 are all less than the second threshold of 6, the final algorithm for each historical input image corresponding to size differences 1 through 100 can be determined within the model. For example, the final algorithm could be Algorithm 1 through Algorithm 100.
[0081] Step 503: Based on the final algorithm corresponding to one or more historical input images, determine the final algorithm used by the image prediction model to predict the target image.
[0082] Specifically, the final algorithm for the target image can be determined based on the final algorithm run in the model for the historical input images. For example, if the final algorithms run in the model for 10 historical input images are Algorithm 1 to Algorithm 10, and the size difference of 5 of the 10 algorithms is less than a second threshold, then the final algorithm for the target image can be determined based on these 5 algorithms.
[0083] One possible implementation is to obtain the final algorithms for each historical input image running in the model if the size difference between the target image and the historical input images is less than a second threshold. The final algorithms for these historical input images, where the size difference is less than the second threshold, are then used as candidate algorithms for the target image. For example, if size differences 1 to 5 are all less than the second threshold of 6, then the final algorithm for the target image is determined based on the final algorithms for these historical input images with size differences of 1 to 5 running in the model.
[0084] The embodiments described above introduced a technical solution for determining the final algorithm based on the number of times the target image is input and cached records. Another embodiment of this application introduces a technical solution for determining the number of times the target image is input into the model. For example, the specific implementation of determining the "number of times the target image is input into the image prediction model" involved in the preceding steps includes... Figure 6 Steps:
[0085] Step 601: If the attribute parameters of the input images of the image prediction model are the same, then the count value of the number of inputs is incremented by one.
[0086] Specifically, attribute parameters include key parameters used by the image prediction model to predict the input image. For example, key parameters may include at least one of the following: model platform identifier, image information, identifier of the computation rule, and precision of the computation rule. Identical attribute parameters indicate that the key parameters of the input image and historical input images are the same.
[0087] One possible implementation method, Figure 7 This is a schematic diagram of an accumulator counter provided in an embodiment of this application. (See reference...) Figure 7 The current count value is 0. If the attribute parameters of the input image are the same, that is, the key parameters of the input image and the historical input image are the same. For example, if the image information is the same, such as the same pixel size (which can be 20*20), it indicates that the input image has been used in the image prediction model once. In this case, the count value of the number of inputs can be incremented once, that is, the current count value changes from 0 to 1.
[0088] It should be noted that the "size" here can be understood as a shape (tensor). For example, a tensor can be a two-dimensional array, such as the "size" mentioned earlier, or a three-dimensional array, such as an RGB image with a depth of 3, a width of 12, and a height of 12. Here, "depth" can be understood as the three color channels: red, green, and blue.
[0089] Step 602: Determine the number of times the target image is input into the image prediction model based on the count value of the number of inputs.
[0090] Specifically, the input count is used to characterize the frequency of the target image being input into the model. For example, the frequency can be, but is not limited to, 1, 2, or 3 times. The input count characterizes the specific nth time the target image is input into the model. For instance, the target image can be the first time it is input into the model, the second time it is input into the model, or the third time it is input into the model.
[0091] One possible implementation is that if the count of the number of inputs is 3, it indicates that the target image is the 3rd input model.
[0092] The embodiments described above introduced a technical solution for determining the number of times the target image is input into the model. Another embodiment of this application describes a specific solution for what the attribute parameters of the target image specifically include. For example, the attribute parameters involved in the preceding steps include at least one of the following: model running platform identifier, image information, identifier of the computation rule, and precision of the computation rule.
[0093] Specifically, the model running platform identifier is used to characterize the platform or device on which the above image prediction model runs; for example, it can be a device ID (platform number).
[0094] Image information is used to describe information about the target image, such as shape (tensor), pixels, resolution, size, color, color channels, etc.
[0095] The identifier of the operation rule is used to characterize the operation rule used by the image prediction model to predict the target image. For example, the identifier of the operation rule can be "operation", where operation can be convolution operation or matrix multiplication operation.
[0096] The precision of the operation rules is used to characterize the computational precision of the algorithm. For example, the computational precision can be float16 or float32.
[0097] The embodiments described above introduced the technical solution regarding the specific attributes of the target image. In another embodiment of this application, the training process of the algorithm prediction model is described, as follows:
[0098] In one possible implementation, the algorithmic prediction model is trained using at least one set of historical attribute parameters and at least one set of target algorithms corresponding to those attribute parameters. This can be understood as follows: during the training process, the attribute parameters of the historical images used in the input image prediction model (i.e., historical attribute parameters) and the corresponding algorithms (i.e., target algorithms) can be used as training samples and sample label values, respectively. During training, the algorithmic prediction model can extract features from the training samples and perform association predictions based on these extracted features to obtain the prediction algorithm output by the algorithmic prediction model.
[0099] Furthermore, the model is iteratively trained based on the loss between the predicted algorithm output by the model and the label until the loss between the learned features and the sample labels converges, thus obtaining the algorithm prediction model. This algorithm prediction model can then be used to predict candidate algorithms for the target image. For example, the algorithm prediction model is used to filter out several algorithms with shorter execution times from all algorithms for the target image, and these algorithms are then used as candidate algorithms for the target image.
[0100] The foregoing embodiments described the technical solution for training the algorithm prediction model. In another embodiment of this application, the candidate algorithm triggering process for the target image is described. (See [link to relevant documentation]). Figure 8 , Figure 8 The flowchart of the candidate algorithm for triggering target images provided in this application embodiment is as follows:
[0101] W1, New operation starts;
[0102] It should be noted that the operation here is equivalent to the identifier of the operation rule in the previous embodiments of this application, which can be understood as inputting the operation in the input image quadruple into the algorithm prediction model;
[0103] W2. After a new operation is started, the algorithm prediction model determines whether the quadruplets of the input image are the same.
[0104] If yes, execute W3; otherwise, execute W4.
[0105] W3, The count value of the input image is incremented once;
[0106] It should be noted that the count being incremented once indicates that the image prediction model has received the same input image again.
[0107] W4. Run a fixed algorithm in the image prediction model and use this fixed algorithm as the final algorithm to run in the image prediction model with the input image;
[0108] W5. Is the count value greater than the first threshold?
[0109] It should be noted that the count value here is equivalent to the number of inputs in the previous embodiments of this application;
[0110] If yes, then execute W6; otherwise, the step execution ends.
[0111] W6. Obtain the size difference between the input image and the historical input image, and check whether the size difference is less than the second threshold.
[0112] If yes, then execute W7; otherwise, the step execution ends.
[0113] W7. The final algorithm of the historical input image with a size difference less than the second threshold is used as the candidate algorithm for the input image.
[0114] W8. Run the candidate algorithms for the above input image, and use the algorithm with the shortest running time among the candidate algorithms as the final algorithm for the input image in the image prediction model;
[0115] It should be noted that the final algorithm here refers to the final algorithm for the input image;
[0116] W9. Calculate the difference between the total time of running the above candidate algorithms and the total time of running all algorithms;
[0117] W10, Is the difference greater than the third threshold?
[0118] If yes, then W1 will continue to be executed when the new operation starts; otherwise, the execution of the step will end.
[0119] The embodiments described above introduce the technical solution for the candidate algorithm triggering process of target images. In another embodiment of this application, the specific schemes for the training and prediction processes of the algorithm prediction model are described. Figure 9 A flowchart illustrating the training and prediction processes of the algorithm prediction model provided in this application embodiment. (Reference) Figure 9 The specific execution steps in the flowchart are as follows:
[0120] The training samples in P1 and cache data are quadruples of the input image, namely deviceID (platform number), operation (operation), shape (tensor), and param (calculation precision of the algorithm). The label values of the training samples are the algo (algorithm), time (algorithm running time), and workspace (extra space for storing intermediate results of the operation) of the input image.
[0121] It should be noted that cache data is equivalent to the data in the cache in the previous embodiments of this application, and device, operation, shape, and param are respectively equivalent to at least one of the following in the previous embodiments of this application: model running platform identifier, image information, identifier of operation rule, and precision of operation rule. algo is respectively equivalent to the target algorithm in the previous embodiments of this application.
[0122] P2. Train the algorithm prediction model based on the above training sample values and label values;
[0123] P3. The algorithm predicts new data, which includes device, operation, shape, and param.
[0124] P4. The prediction result of the algorithm prediction model can be algo;
[0125] It should be noted that algo here is equivalent to the target algorithm in the previous embodiments of this application.
[0126] The embodiments described above introduce the technical solutions for the training and prediction processes of the algorithm prediction model. In another embodiment of this application, a complete flowchart of the model algorithm selection method of this application is presented. Figure 10 For a complete flowchart of the implementation steps of the model algorithm selection method provided in the embodiments of this application, please refer to [link / reference]. Figure 10 The specific steps for selecting the model algorithm are as follows:
[0127] S1. When the target image is input into the image prediction model, obtain the attribute parameters of the target image;
[0128] It should be noted that the target image here is the input image, and the attribute parameters can be quadruples;
[0129] S2. Input the attribute parameters of the target image into the algorithm prediction model;
[0130] It should be noted that the algorithm prediction model here is used to filter out candidate algorithms for the input image;
[0131] S3. Can the algorithm prediction model output one or more algorithms?
[0132] It should be noted that the one or more algorithms here are equivalent to the algolist in the previous embodiments of this application, i.e., candidate algorithms;
[0133] If yes, then execute S4; otherwise, execute S5.
[0134] S4. The algorithm with the shortest running time among one or more algorithms will be used as the final algorithm for the target image in the image prediction model.
[0135] It should be noted that the final algorithm here refers to the final algorithm of the input image in the image prediction model;
[0136] S5. Obtain the number of times the target image is input into the image prediction model;
[0137] S6. Is the number of inputs less than the first threshold?
[0138] If yes, proceed to step S7; otherwise, the process ends.
[0139] S7. Obtain the size difference between the target image and one or more historical input images;
[0140] S8. Is the size difference less than the second threshold?
[0141] If yes, proceed to step S9; otherwise, the process ends.
[0142] S9. Determine the final algorithm for running one or more historical input images in the image prediction model.
[0143] S10. The final algorithm of the historical input image that meets the second threshold and runs in the image prediction model is used as the candidate algorithm for the target image in the image prediction model.
[0144] S11. Run the candidate algorithms for the target image in the image prediction model, and select the candidate algorithm with the shortest running time as the final algorithm for running the target image in the image prediction model.
[0145] It should be noted that the final algorithm used to run the target image in the image prediction model is the same as the final algorithm used to run the input image in the image prediction model.
[0146] In one embodiment, such as Figure 11 A model algorithm selection device is provided, comprising: a prediction unit 1101 and a determination unit 1102. Wherein:
[0147] The prediction unit 1001 is used to input the attribute parameters of the target image into the algorithm prediction model to obtain one or more candidate algorithms output by the algorithm prediction model. The algorithm prediction model is trained based on at least one set of historical attribute parameters and at least one set of target algorithms corresponding to the attribute parameters. The target algorithm is the algorithm used when performing image prediction based on the historical attribute parameters and the image prediction model.
[0148] The determining unit 1102 is used to determine the final algorithm used to predict the target image based on the image prediction model, according to one or more candidate algorithms.
[0149] In one embodiment, the determining unit 1102 is specifically used to run one or more candidate algorithms to obtain the execution time of one or more candidate algorithms; and to determine the candidate algorithm with the shortest execution time as the final algorithm based on the final algorithm selection mechanism.
[0150] In one embodiment, the determining unit 1102 is specifically used to determine the execution time of one or more algorithms based on the cached records if one or more candidate algorithms have cached records; and to select the algorithm with the shortest execution time among the one or more candidate algorithms as the final algorithm.
[0151] In one embodiment, if one or more candidate algorithms lack cache records, the final algorithm used by the image prediction model to predict the target image is determined based on the cache records of the image prediction model and the number of times the target image is input into the image prediction model.
[0152] In one embodiment, if the number of inputs reaches a first threshold, the size difference between the target image and one or more historical input images is obtained; the target image and the historical input images have the same attribute parameters; if the size difference is less than a second threshold, the final algorithm for the one or more historical input images to run in the image prediction model is determined; based on the final algorithm corresponding to the one or more historical input images, the final algorithm used by the image prediction model to predict the target image is determined.
[0153] In one embodiment, if the attribute parameters of the input images of the image prediction model are the same, the count of the number of inputs is incremented by one; the number of times the target image is input into the image prediction model is determined based on the count of the number of inputs.
[0154] In one embodiment, the attribute parameters include at least one of the following: model running platform identifier, image information, identifier of the operation rule, and precision of the operation rule.
[0155] Specific limitations regarding the model algorithm selection mechanism can be found in the limitations on the model algorithm selection method described above, and will not be repeated here. Each module of the aforementioned model algorithm selection mechanism can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the computer device's memory in software form, so that the processor can call and execute the corresponding operations of each module.
[0156] In one embodiment, a computer device is provided. Figure 1 A structural block diagram of the computer device provided in the embodiments of this application, with reference to Figure 1 The computing device includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0157] The attribute parameters of the target image are input into the algorithm prediction model to obtain one or more candidate algorithms output by the algorithm prediction model. The algorithm prediction model is trained based on at least one set of historical attribute parameters and at least one set of target algorithms corresponding to the attribute parameters. The target algorithm is the algorithm used when performing image prediction based on historical attribute parameters and the image prediction model.
[0158] Based on one or more candidate algorithms, determine the final algorithm used to predict the target image using the image prediction model.
[0159] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0160] Run one or more candidate algorithms and obtain their execution times.
[0161] The candidate algorithm with the shortest execution time is selected as the final algorithm based on the final algorithm selection mechanism.
[0162] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0163] If one or more candidate algorithms have cached records, the execution time of one or more algorithms is determined based on the cached records;
[0164] The algorithm with the shortest execution time among one or more candidate algorithms is selected as the final algorithm.
[0165] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0166] If one or more candidate algorithms lack cache records, the final algorithm used by the image prediction model to predict the target image is determined based on the cache records of the image prediction model and the number of times the target image is input into the image prediction model.
[0167] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0168] If the number of inputs reaches the first threshold, the size difference between the target image and one or more historical input images is obtained; the attribute parameters of the target image and the historical input images are the same.
[0169] If the size difference is less than the second threshold, then one or more historical input images are determined to be the final algorithm to run in the image prediction model;
[0170] Based on the final algorithm corresponding to one or more historical input images, determine the final algorithm used by the image prediction model to predict the target image.
[0171] In one embodiment, the processor, when executing a computer program, also performs the following steps:
[0172] If the input images of the image prediction model have the same attribute parameters, the count of the number of inputs is incremented by one; the attribute parameters include at least one of the following: model running platform identifier, image information, identifier of the operation rule, and precision of the operation rule;
[0173] The number of times the target image is input into the image prediction model is determined based on the count of the number of inputs.
[0174] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0175] This application provides a computer program product including instructions that, when executed, cause the method described in this application to be performed. For example, it can execute... Figure 2 The steps of the model algorithm selection method are shown.
[0176] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0177] The above embodiments merely illustrate several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A method of selecting a model algorithm, characterized by, The method comprises: inputting attribute parameters of a target image into an algorithm prediction model to obtain one or more candidate algorithms output by the algorithm prediction model; the algorithm prediction model is obtained by training according to at least one set of historical attribute parameters and a target algorithm corresponding to the at least one set of attribute parameters, the target algorithm being an algorithm used when the image prediction model is used to predict an image according to the historical attribute parameters, the attribute parameters of the target image including at least one of a model running platform identifier, image information, an identifier of an operation rule, and accuracy of the operation rule; determining a final algorithm used by the image prediction model to predict the target image according to the one or more candidate algorithms; or, determining the final algorithm used by the image prediction model to predict the target image based on a cache record of the image prediction model and a number of times the target image is input into the image prediction model.
2. The method of claim 1, wherein, The determining of the final algorithm used by the image prediction model to predict the target image according to the one or more candidate algorithms comprises: running the one or more candidate algorithms to obtain execution time of the one or more candidate algorithms; determining the candidate algorithm with the shortest execution time as the final algorithm based on an optimal algorithm selection mechanism.
3. The method of claim 1, wherein, The determining of the final algorithm used by the image prediction model to predict the target image according to the one or more candidate algorithms comprises: if the one or more candidate algorithms have a cache record, determining execution time of the one or more algorithms according to the cache record; determining the candidate algorithm with the shortest execution time as the final algorithm.
4. The method of claim 1, wherein, The determining of the final algorithm used by the image prediction model to predict the target image based on the cache record of the image prediction model and the number of times the target image is input into the image prediction model comprises: if the number of times reaches a first threshold value, obtaining a size difference between the target image and one or more historical input images; the attribute parameters of the target image and the historical input images are the same; if the size difference is less than a second threshold value, determining a final algorithm used by the one or more historical input images to run in the image prediction model; determining the final algorithm used by the image prediction model to predict the target image according to the final algorithm corresponding to the one or more historical input images.
5. The method of claim 4, wherein, The method further comprises: if the attribute parameters of the input images of the image prediction model are the same, adding a count value of the number of times by one; determining the number of times the target image is input into the image prediction model according to the count value of the number of times.
6. A model algorithm selection apparatus characterized by comprising: The device comprises: The prediction unit is configured to input attribute parameters of a target image into an algorithm prediction model to obtain one or more candidate algorithms output by the algorithm prediction model; the algorithm prediction model is trained according to at least one set of historical attribute parameters and a target algorithm corresponding to the at least one set of attribute parameters, the target algorithm is an algorithm used when the image prediction model is used to predict an image according to the historical attribute parameters, and the attribute parameters of the target image include at least one of a model running platform identifier, image information, an identifier of an operation rule, and accuracy of the operation rule; The determination unit is configured to determine a final algorithm used to predict the target image based on the image prediction model according to the one or more candidate algorithms; The determination unit is further configured to determine the final algorithm used to predict the target image based on the image prediction model according to cache records of the image prediction model and input times of the target image into the image prediction model.
7. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the program to implement the model algorithm selection method of any one of claims 1-5.
8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the model algorithm selection method of any one of claims 1-5.
9. A computer program product comprising instructions, characterized in that, The instructions are executed to implement the model algorithm selection method of any one of claims 1-5.
Citation Information
Patent Citations
Machine learning algorithm selection method and device
CN111783867A