Model training method and device, storage medium and electronic device
By using transfer learning and iterative optimization, a new training sample set is formed using clean samples and the target model, which solves the problem of poor model training performance and improves the model's classification accuracy on samples of various categories.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- OPPO CHONGQING INTELLIGENT TECH CO LTD
- Filing Date
- 2019-12-30
- Publication Date
- 2026-06-09
AI Technical Summary
Existing technologies often produce poor model training results with low classification accuracy, especially performing poorly on certain categories of samples.
The transfer learning method is adopted. A new training sample set is formed by extracting clean samples from the target sample library and non-target category samples from the initial sample library. The target model is iteratively optimized, and the transfer learning training is carried out using clean samples and the target model until the preset iteration stopping condition is met.
This improved the training effect of the model, increased the classification accuracy of the model on samples of various categories, and ensured that the model reached the preset accuracy threshold.
Smart Images

Figure CN111191590B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of artificial intelligence technology, and in particular relates to a model training method, apparatus, storage medium and electronic device. Background Technology
[0002] With the development of technology, many fields have begun to apply artificial intelligence (AI) technology. AI technology can be used for tasks such as image recognition, scene recognition, and information prediction. Machine learning is an important technical means to achieve AI, and model training is the focus of machine learning. However, in related technologies, the results of model training are often poor. Summary of the Invention
[0003] This application provides a model training method, apparatus, storage medium, and electronic device, which can iteratively optimize the model during the model training process, thereby improving the model training effect.
[0004] In a first aspect, embodiments of this application provide a model training method, including:
[0005] Obtain an initial sample library and a model to be trained. The initial sample library contains samples of multiple different categories, and the model to be trained is a classification model.
[0006] The model to be trained is trained using samples from the initial sample library to obtain an initial model, and the initial model is then used as the validation model.
[0007] Obtain a verification sample set, which contains samples of multiple different categories;
[0008] The validation model is validated using the validation sample set to obtain the classification accuracy of the validation model, and the classification accuracy of the validation model for each category of samples in the validation sample set is statistically analyzed.
[0009] If the classification accuracy of the verification model is less than a preset first threshold or the classification accuracy of the verification model for each category of samples in the verification sample set is not greater than or equal to a preset second threshold, then the target model and the target category are determined. The target model is the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the verification sample set whose classification accuracy is less than the preset second threshold.
[0010] Obtain a target sample library, which contains samples of multiple different categories, and the samples in the target sample library have accurate category labels;
[0011] Samples of the target category are extracted from the target sample library, and samples of non-target categories are extracted from the initial sample library to form a new training sample set;
[0012] The target model is trained using a new training sample set through transfer learning, and the trained model is determined as the validation model. This triggers the process of obtaining the validation sample set, thereby achieving iterative optimization of the model until a preset iteration stopping condition is met.
[0013] Secondly, embodiments of this application provide a model training apparatus, comprising:
[0014] The first acquisition module is used to acquire an initial sample library and a model to be trained. The initial sample library contains samples of multiple different categories, and the model to be trained is a classification model.
[0015] The first training module is used to train the model to be trained using samples in the initial sample library to obtain an initial model, and to determine the initial model as the validation model.
[0016] The second acquisition module is used to acquire a verification sample set, which contains samples of multiple different categories;
[0017] The verification module is used to verify the verification model using the verification sample set, obtain the classification accuracy of the verification model, and calculate the classification accuracy of the verification model for each category of samples in the verification sample set.
[0018] The determination module is used to determine the target model and the target category if the classification accuracy of the verification model is less than a preset first threshold or the classification accuracy of the verification model for each category of samples in the verification sample set is not greater than or equal to a preset second threshold. The target model is the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the verification sample set whose classification accuracy is less than the preset second threshold.
[0019] The third acquisition module is used to acquire a target sample library, which contains samples of multiple different categories, and the samples in the target sample library have accurate category labels;
[0020] The fourth acquisition module is used to extract samples of the target category from the target sample library and extract samples of non-target categories from the initial sample library to form a new training sample set;
[0021] The second training module is used to perform transfer learning training on the target model using a new training sample set, and to determine the trained model as the verification model, triggering the process of obtaining the verification sample set to achieve iterative optimization of the model until the preset iteration stopping condition is met.
[0022] Thirdly, embodiments of this application provide a storage medium storing a computer program thereon, which, when executed on a computer, causes the computer to execute the process in the model training method provided in embodiments of this application.
[0023] Fourthly, embodiments of this application also provide an electronic device, including a memory and a processor, wherein the processor executes the process in the model training method provided in embodiments of this application by calling a computer program stored in the memory.
[0024] In this embodiment, the electronic device can continuously iteratively optimize the model using transfer learning. During this iterative optimization process, firstly, for the target category corresponding to samples in the validation sample set whose classification accuracy is less than a preset second threshold, the electronic device can extract clean samples from the target sample library and then extract samples of non-target categories from the initial sample library, thus forming new training samples. Secondly, the starting point for each iteration is the target model with the highest classification accuracy among the currently trained models. Therefore, in this embodiment, the electronic device can utilize clean samples and the target model to perform iterative optimization based on transfer learning, thereby improving the model training effect. Attached Figure Description
[0025] The technical solution and its beneficial effects will become apparent from the following detailed description of specific embodiments of this application, in conjunction with the accompanying drawings.
[0026] Figure 1 This is a flowchart illustrating the model training method provided in the embodiments of this application.
[0027] Figure 2 This is another schematic diagram of the model training method provided in the embodiments of this application.
[0028] Figure 3 This is a schematic diagram of the structure of the visualized machine learning training platform provided in the embodiments of this application.
[0029] Figure 4 This is a schematic diagram of the user interface of the visualized machine learning training platform provided in this application embodiment.
[0030] Figure 5 This is a schematic diagram of the structure of the model training device provided in the embodiments of this application.
[0031] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application.
[0032] Figure 7 This is another structural schematic diagram of the electronic device provided in the embodiments of this application. Detailed Implementation
[0033] Please refer to the illustrations, where the same component symbols represent the same components. The principles of this application are illustrated by example in a suitable computing environment. The following description is based on the specific embodiments of this application illustrated, and should not be construed as limiting other specific embodiments not detailed herein.
[0034] It is understood that the execution subject of the embodiments of this application may be an electronic device such as a smartphone, tablet computer, or server.
[0035] Please see Figure 1 , Figure 1 This is a flowchart illustrating the model training method provided in this application embodiment. The process may include:
[0036] 101. Obtain the initial sample library and the model to be trained. The initial sample library contains samples of multiple different categories, and the model to be trained is a classification model.
[0037] With the development of technology, many fields have begun to apply artificial intelligence (AI) technology. AI technology can be used for tasks such as image recognition, scene recognition, and information prediction. Machine learning is an important technical means to achieve AI, and model training is the focus of machine learning. However, in related technologies, the results of model training are often poor.
[0038] In this embodiment of the application, for example, the electronic device may first acquire an initial sample library and a model to be trained. The initial sample library may contain samples of multiple different categories, and the model to be trained may be a classification model.
[0039] For example, the initial sample library could be an image library containing pictures of different categories of animals, such as dogs, chickens, ducks, pigs, birds, and so on. Once the model is trained, it can be used to classify images. For instance, by inputting a given image into the trained model, the model can output the image's category, such as identifying it as a dog image, and so on.
[0040] 102. Use the samples in the initial sample library to train the model to be trained, obtain the initial model, and determine the initial model as the validation model.
[0041] For example, after obtaining the initial sample library and the model to be trained, the electronic device can use the samples in the initial sample library to train the model to be trained, thereby obtaining an initial model, and then using the initial model as the validation model.
[0042] 103. Obtain the verification sample set, which contains samples of multiple different categories.
[0043] For example, after determining the validation model, the electronic device can acquire a validation sample set, which may contain samples from multiple different categories. For instance, the validation sample set may contain images of different categories of animals, such as images of dogs, chickens, ducks, pigs, birds, and so on.
[0044] 104. Validate the validation model using the validation sample set, obtain the classification accuracy of the validation model, and calculate the classification accuracy of the validation model for each category of samples in the validation sample set.
[0045] For example, after obtaining the validation sample set, the electronic device can use the samples in the validation sample set to validate the validation model, thereby obtaining the classification accuracy of the validation model and calculating the classification accuracy of the validation model for each category of samples in the validation sample set.
[0046] It's important to note that the classification accuracy of a validation model refers to the overall classification accuracy when the model is validated using samples from the validation sample set. For example, if the validation sample set contains 1000 samples, including 200 pictures of dogs, 200 pictures of chickens, 200 pictures of ducks, 200 pictures of pigs, and 200 pictures of birds, and the model is validated using these 1000 images, and it accurately identifies 865 images while misidentifying 135, then the overall classification accuracy of this validation model is 86.5%.
[0047] In the above analysis, for 200 dog images, the validation model accurately identified 180 dogs, resulting in a classification accuracy of 90% for dogs. Similarly, for 200 chicken images, the model accurately identified 190 chickens, resulting in a classification accuracy of 95% for chickens. Furthermore, for 200 duck images, the model accurately identified 160 ducks, resulting in a classification accuracy of 80% for ducks. Again, for 200 pig images, the model accurately identified 185 pigs, resulting in a classification accuracy of 92.5% for pigs. Finally, for 200 bird images, the model accurately identified 150 birds, resulting in a classification accuracy of 75% for birds.
[0048] After obtaining the classification accuracy of the validation model and the classification accuracy of the validation model for each category of samples in the validation sample set, the electronic device can detect whether the classification accuracy of the validation model is less than a preset first threshold, and detect whether the classification accuracy of the validation model for each category of samples in the validation sample set is greater than or equal to a preset second threshold.
[0049] If the classification accuracy of the verification model is detected to be greater than or equal to the preset first threshold, and the classification accuracy of the verification model for each category of samples in the verification sample set is detected to be greater than or equal to the preset second threshold, then the training effect of the verification model can be considered to be good and the training is completed. At this time, the electronic device can output and save the verification model.
[0050] If the classification accuracy of the validation model is found to be less than the preset first threshold, or if the classification accuracy of the validation model for each category of samples in the validation sample set is not greater than or equal to the preset second threshold, then the training effect of the validation model can be considered as not meeting the standard, and the training is not complete. At this time, proceed to step 105.
[0051] 105. If the classification accuracy of the validation model is less than the preset first threshold, or if the classification accuracy of the validation model for each category of samples in the validation sample set is not greater than or equal to the preset second threshold, then the target model and the target category are determined. The target model is the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the validation sample set whose classification accuracy of the validation model is less than the preset second threshold.
[0052] For example, if the electronic device detects that the classification accuracy of the validation model is less than a preset first threshold, or that the classification accuracy of the validation model for each category of samples in the validation sample set is not greater than or equal to a preset second threshold, then the model training can be considered incomplete. In this case, the electronic device can determine the target model and the target category. The target model can be the model with the highest classification accuracy among the currently trained models, and the target category can be the category corresponding to the samples in the validation sample set whose classification accuracy is less than the preset second threshold.
[0053] For example, the first threshold is preset to 85%, and the second threshold is also preset to 85%. Of course, in other embodiments, the values of the first threshold and the second threshold can be other values, and they can be unequal.
[0054] For example, since the overall classification accuracy of the validation model reaches 86.5%, which is greater than the preset first threshold of 85%, and the model's classification accuracy for dog images is 90%, which is greater than the preset second threshold of 85%, and for chicken images it is 95%, which is greater than the preset second threshold of 85%, but for duck images it is 80%, which is less than the preset second threshold of 85%, and for pig images it is 92.5%, which is greater than the preset second threshold of 85%, and for bird images it is 75%, which is less than the preset second threshold of 85%, the model's classification accuracy is greater than the preset first threshold. However, the model's classification accuracy for duck and bird samples in the validation sample set is less than the preset second threshold. Therefore, the electronic device can be triggered to determine the target model and the target category. The target model can be the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the validation sample set whose classification accuracy is less than the preset second threshold. In other words, the target model can be the model with the highest overall classification accuracy among the models obtained in all the completed training iterations. For example, if the model has been trained five times, with the overall classification accuracy of the model obtained from the first training being 80%, the second 80.5%, the third 83%, the fourth 86.5%, and the fifth 85%, then the electronic device can identify the model obtained from the fourth training as the target model. That is, the target model is the model with the highest classification accuracy among the currently trained models, i.e., the optimal model obtained so far. Target categories could be, for example, ducks and birds (verifying that the model's classification accuracy for images of these categories is below a preset second threshold).
[0055] 106. Obtain the target sample library, which contains samples of multiple different categories, and the samples in the target sample library have accurate category labels.
[0056] For example, after determining the target model and target category, the electronic device can acquire a target sample library. This target sample library may contain samples from multiple different categories, and all samples in the target sample library have accurate category labels. That is, the samples in the target sample library are all accurately classified samples and are considered clean samples. Or, in other words, the true category and category label of the samples in the target sample library are consistent.
[0057] For example, the target sample library can also contain pictures of different categories of animals, such as pictures of dogs, chickens, ducks, pigs, birds, and so on.
[0058] 107. Extract samples of the target category from the target sample library and extract samples of non-target categories from the initial sample library to form a new training sample set.
[0059] For example, after acquiring the target sample library, the electronic device can extract samples of the target category from the target sample library and extract samples of non-target categories from the initial sample library, thereby forming a new training sample set.
[0060] For example, an electronic device can extract images of ducks and other birds from a target sample library, and extract images of dogs, chickens, and pigs from an initial sample library. These newly extracted samples form a new training sample set.
[0061] 108. Use the new training sample set to train the target model through transfer learning, and determine the trained model as the validation model. Trigger the process of obtaining the validation sample set to achieve iterative optimization of the model until the preset iteration stopping condition is met.
[0062] For example, after obtaining a new training sample set, the electronic device can use the new training sample set to perform transfer learning training on the target model, determine the trained model as the verification model, and trigger the process of obtaining the verification sample set in 103. That is, the electronic device can execute a loop to achieve iterative optimization of the model until the preset iteration stopping condition is met and the loop ends.
[0063] It's important to note that transfer learning is a machine learning method that uses a model developed for task A as a starting point and reuses it in the process of developing a model for task B. In other words, transfer learning refers to using a previously pre-trained model as the starting point for training a new model. These pre-trained models typically consume significant time and computational resources during training; transfer learning allows powerful skills already acquired to be applied to related problems.
[0064] It is understood that in this embodiment, the electronic device can continuously iteratively optimize the model using transfer learning. During this iterative optimization process, firstly, for the target category corresponding to samples in the validation sample set whose classification accuracy is less than a preset second threshold, the electronic device can extract clean samples from the target sample library and then extract samples of non-target categories from the initial sample library, thus forming new training samples. Secondly, the starting point for each iteration is the target model with the highest classification accuracy among the currently trained models. Therefore, in this embodiment, the electronic device can utilize clean samples and the target model to perform iterative optimization based on transfer learning, thereby improving the model training effect.
[0065] Please see Figure 2 , Figure 2 Another schematic diagram of the model training method provided in the embodiments of this application, the process may include:
[0066] 201. The electronic device acquires an initial sample library and a model to be trained. The initial sample library contains samples of multiple different categories, and the model to be trained is a classification model.
[0067] For example, an electronic device can first acquire an initial sample library and a model to be trained. The initial sample library may contain samples of multiple different categories, and the model to be trained may be a classification model.
[0068] For example, the initial sample library could be an image library containing pictures of different categories of animals, such as pictures of dogs, chickens, ducks, pigs, birds, and so on. Once the model is trained, the electronic device can use it to classify images. For instance, if the electronic device takes an image as input and feeds it into the trained model, the model can output the image's category, such as identifying the image as a dog, and so on.
[0069] 202. The electronic device uses samples from the initial sample library to train the model to be trained, obtains the initial model, and determines the initial model as the validation model.
[0070] For example, after obtaining the initial sample library and the model to be trained, the electronic device can use the samples in the initial sample library to train the model to be trained, thereby obtaining an initial model, and then using the initial model as the validation model.
[0071] 203. The electronic device acquires a verification sample set, which contains samples of multiple different categories.
[0072] For example, after determining the validation model, the electronic device can acquire a validation sample set, which may contain samples from multiple different categories. For instance, the validation sample set may contain images of different categories of animals, such as images of dogs, chickens, ducks, pigs, birds, and so on.
[0073] 204. Electronic devices use a validation sample set to validate the validation model, obtain the classification accuracy of the validation model, and statistically analyze the classification accuracy of the validation model for each category of samples in the validation sample set.
[0074] For example, after obtaining the validation sample set, the electronic device can use the samples in the validation sample set to validate the validation model, thereby obtaining the classification accuracy of the validation model and calculating the classification accuracy of the validation model for each category of samples in the validation sample set.
[0075] It's important to note that the classification accuracy of the validation model refers to the overall classification accuracy when the model is validated using samples from the validation sample set. For example, the validation sample set contains 1000 samples, including 200 pictures of dogs, 200 pictures of chickens, 200 pictures of ducks, 200 pictures of pigs, and 200 pictures of birds. When validating the model using these 1000 pictures, if the model accurately identifies 865 pictures and misidentifies 135, then the overall classification accuracy of the model is 86.5%. Specifically, for the 200 dog pictures, the model accurately identifies 180 dog pictures, resulting in a 90% classification accuracy for the dog category. Similarly, for the 200 chicken pictures, the model accurately identifies 190 chicken pictures, resulting in a 95% classification accuracy for the chicken category. For example, given 200 images of ducks, if the validation model accurately identifies 160 duck images, then the classification accuracy for duck images is 80%. Similarly, given 200 images of pigs, if the model accurately identifies 185 pig images, then the classification accuracy for pig images is 92.5%. And given 200 images of birds, if the model accurately identifies 150 birds, then the classification accuracy for birds images is 75%.
[0076] After obtaining the classification accuracy of the validation model and the classification accuracy of the validation model for each category of samples in the validation sample set, the electronic device can detect whether the classification accuracy of the validation model is less than a preset first threshold, and detect whether the classification accuracy of the validation model for each category of samples in the validation sample set is greater than or equal to a preset second threshold.
[0077] If the classification accuracy of the verification model is detected to be greater than or equal to the preset first threshold, and the classification accuracy of the verification model for each category of samples in the verification sample set is detected to be greater than or equal to the preset second threshold, then the training effect of the verification model can be considered to be good and the training is completed. At this time, the electronic device can output and save the verification model.
[0078] If the classification accuracy of the validation model is found to be less than the preset first threshold, or if the classification accuracy of the validation model for each category of samples in the validation sample set is not greater than or equal to the preset second threshold, then the training effect of the validation model can be considered as not meeting the standard, and the training is not complete. At this time, proceed to step 205.
[0079] 205. If the classification accuracy of the validation model is less than the preset first threshold, or if the classification accuracy of the validation model for each category of samples in the validation sample set is not greater than or equal to the preset second threshold, the electronic device determines the target model and the target category. The target model is the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the validation sample set whose classification accuracy is less than the preset second threshold.
[0080] For example, if the electronic device detects that the classification accuracy of the validation model is less than a preset first threshold, or that the classification accuracy of the validation model for each category of samples in the validation sample set is not greater than or equal to a preset second threshold, then the model training can be considered incomplete. In this case, the electronic device can determine the target model and the target category. The target model can be the model with the highest classification accuracy among the currently trained models, and the target category can be the category corresponding to the samples in the validation sample set whose classification accuracy is less than the preset second threshold.
[0081] For example, the first threshold is preset to 85%, and the second threshold is also preset to 85%. Of course, in other embodiments, the values of the first threshold and the second threshold can be other values, and they can be unequal.
[0082] For example, since the overall classification accuracy of the validation model reaches 86.5%, which is greater than the preset first threshold of 85%, and the model's classification accuracy for dog images is 90%, which is greater than the preset second threshold of 85%, and for chicken images it is 95%, which is greater than the preset second threshold of 85%, but for duck images it is 80%, which is less than the preset second threshold of 85%, and for pig images it is 92.5%, which is greater than the preset second threshold of 85%, and for bird images it is 75%, which is less than the preset second threshold of 85%, the model's classification accuracy is greater than the preset first threshold. However, the model's classification accuracy for duck and bird samples in the validation sample set is less than the preset second threshold. Therefore, the electronic device can be triggered to determine the target model and the target category. The target model can be the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the validation sample set whose classification accuracy is less than the preset second threshold. In other words, the target model can be the model with the highest overall classification accuracy among the models obtained in all the completed training iterations. For example, if the model has been trained five times, with the overall classification accuracy of the model obtained from the first training being 80%, the second 80.5%, the third 83%, the fourth 86.5%, and the fifth 85%, then the electronic device can identify the model obtained from the fourth training as the target model. That is, the target model is the model with the highest classification accuracy among the currently trained models, i.e., the optimal model. Target categories could be, for example, ducks and birds (verifying that the model's classification accuracy for images of these categories is below a preset second threshold).
[0083] 206. The electronic device acquires a target sample library containing samples of multiple different categories, and the samples in the target sample library have accurate category labels.
[0084] For example, after determining the target model and target category, the electronic device can acquire a target sample library. This target sample library may contain samples from multiple different categories, and all samples in the target sample library have accurate category labels. That is, the samples in the target sample library are all accurately classified samples and are considered clean samples. Or, in other words, the true category and category label of the samples in the target sample library are consistent.
[0085] For example, the target sample library can also contain pictures of different categories of animals, such as pictures of dogs, chickens, ducks, pigs, birds, and so on.
[0086] 207. For each target category, the electronic device extracts a preset number of samples from the target sample library. For each non-target category, the electronic device extracts a preset number of samples from the initial sample library. The extracted samples of the target category and the samples of the non-target category are used to form a new training sample set.
[0087] For example, after acquiring the target sample library, for each target category, the electronic device can extract a preset number of samples of that target category from the target sample library. For each non-target category, the electronic device can extract a preset number of samples of that non-target category from the initial sample library. Then, the electronic device can combine the extracted target category samples and non-target category samples into a new training sample set.
[0088] For example, an electronic device can extract a preset number of images of ducks and a preset number of images of other birds from a target sample library, and extract a preset number of images of dogs, chickens, and pigs from an initial sample library. These newly extracted samples form a new training sample set.
[0089] 208. The electronic device uses a new training sample set to perform transfer learning training on the target model, and determines the trained model as the verification model, triggering the execution of the process of obtaining the verification sample set to achieve iterative optimization of the model until a preset iteration stopping condition is met. The preset iteration stopping condition is that the classification accuracy of the verification model is greater than or equal to a preset first threshold, and the classification accuracy of each category of samples in the verification sample set is greater than or equal to a preset second threshold.
[0090] For example, after obtaining a new training sample set, the electronic device can use this new training sample set to perform transfer learning training on the target model, and determine the trained model as the validation model. This triggers the process of obtaining the validation sample set in step 203. That is, the electronic device can execute a loop to iteratively optimize the model until a preset iteration stopping condition is met. This preset iteration stopping condition can be that the classification accuracy of the validation model is greater than or equal to a preset first threshold, and the classification accuracy of the validation model for each category of samples in the validation sample set is greater than or equal to a preset second threshold.
[0091] 209. When the preset iteration stopping condition is met, the electronic device will identify the latest obtained verification model as the training completed model and save the output.
[0092] For example, when the classification accuracy of the newly trained validation model is greater than or equal to a preset first threshold, and the classification accuracy of the validation model for each category of samples in the validation sample set is greater than or equal to a preset second threshold, the electronic device can identify the newly obtained validation model as the trained model and save the output.
[0093] In other implementations, the preset iteration stopping condition can also be that the electronic device receives an instruction to stop model training. For example, if the electronic device receives an instruction from the user to stop model training, then the electronic device can stop iterative training.
[0094] In another implementation, the preset iteration stopping condition may be to stop the iteration when it is impossible to obtain clean samples to form a new training sample set multiple times, or to stop the iteration when the classification accuracy of the model obtained by the electronic device after multiple training sessions does not improve.
[0095] Please also refer to Figures 3 to 4 This application also provides a visual machine learning training platform. This platform can encapsulate various models at the underlying level and set corresponding controls for each model on the platform's visual interface. Machine learning training processes can be constructed by dragging and dropping various controls on a canvas, and corresponding running parameters can be set for each control. This visual machine learning platform can also output training results.
[0096] The visualized machine learning training platform provided in this application embodiment may include a text preprocessing module, a deep learning module, an iterative optimization module, a text semantic vector module, an output and display module, etc.
[0097] The text preprocessing module is primarily used to preprocess the text input to the model, such as extracting Chinese characters or performing Chinese word segmentation. The Chinese character extraction process only retrieves Chinese characters, Chinese and English symbols, numbers, etc., from the text. The Chinese word segmentation process can be performed using a word segmenter such as jieba to segment the Chinese characters in the text.
[0098] The deep learning module primarily performs single-run training on a selected deep learning model. This module can include several commonly used models, such as textCNN, LSTM (Long Short-Term Memory), and Attention-based textCNN. Training in this module does not involve iterative optimization after the model has been trained. The deep learning module can automatically display the model's training results (such as classification accuracy) and show the text categories that the trained model can accurately identify, as well as those it cannot yet accurately identify. Furthermore, this deep learning module can output the trained model file.
[0099] The text semantic vector module can be used to output the semantic vector of the text and provide the output semantic vector to the required modules.
[0100] The output and display module can be used to output the trained model file and display the results of validating the trained model using validation set samples, such as the model's classification accuracy. The output and display module can present the model's validation results in the form of tables or graphs.
[0101] The iterative optimization module can be used to iteratively optimize and train a selected model, thereby obtaining a model with better training results.
[0102] Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of a visualized machine learning training platform provided in an embodiment of this application.
[0103] Please refer to the following: Figure 4 , Figure 4 A schematic diagram of the user interface of the visualized machine learning training platform provided in this application embodiment.
[0104] In this embodiment, for example, the user selects a model that needs iterative optimization training through the iterative optimization module. Then, based on this visualized machine learning training platform, the electronic device can iteratively optimize the model in the following way:
[0105] First, the electronic device can obtain an initial sample library through an iterative optimization module. This initial sample library can contain text samples of various categories, such as text of category C, category D, category E, category F, and category G. Each category of text has a corresponding category label.
[0106] Electronic devices can also obtain, for example, a user-selected model to be trained through an iterative optimization module, such as model M0. Model M0 can be a multi-class classification model.
[0107] Then, the electronic device can use text samples of various categories in the initial sample library to train the model M0 to be trained, thereby obtaining an initial model M1, and determining the initial model M1 as the validation model.
[0108] The electronic device can then acquire a verification sample set, which may contain multiple text samples of different categories. For example, the verification sample set may also contain text of category C, category D, category E, category F, category G, and so on.
[0109] After obtaining the validation sample set, the electronic device can use the samples in the validation sample set to validate the model M1 to be validated, thereby obtaining the classification accuracy of the model M1, and statistically analyzing the classification accuracy of the model M1 for each category of samples in the validation sample set.
[0110] For example, the validation sample set contains 1000 text samples, including 200 texts in category C, 200 in category D, 200 in category E, 200 in category F, and 200 in category G. When model M1 is validated using these 1000 texts, it accurately identifies the categories of 865 texts and misclassifies 135 texts. Therefore, the overall classification accuracy of model M1 is 86.5%.
[0111] For example, out of 200 texts in category C, model M1 accurately identified 180 texts in category C. Therefore, the classification accuracy of model M1 for texts in category C is 90%.
[0112] For example, if model M1 accurately identifies 190 out of 200 texts in category D, then the classification accuracy of model M1 for texts in category D is 95%.
[0113] For example, if model M1 accurately identifies 160 out of 200 texts in category E, then the classification accuracy of model M1 for texts in category E is 80%.
[0114] For example, if model M1 accurately identifies 185 out of 200 texts in category F, then the classification accuracy of model M1 for texts in category F is 92.5%.
[0115] For example, if model M1 accurately identifies 150 out of 200 texts in category G, then the classification accuracy of model M1 for texts in category G is 75%.
[0116] After obtaining the classification accuracy of model M1 and its classification accuracy for each category of samples in the validation sample set, the electronic device can detect whether the classification accuracy of model M1 is less than a preset first threshold, and whether the classification accuracy of model M1 for each category of samples in the validation sample set is greater than or equal to a preset second threshold. For example, if both the preset first and second thresholds are 85%, then the electronic device can detect that the classification accuracy of model M1 is greater than the preset first threshold, but the classification accuracy of model M1 for each category of samples in the validation sample set is not greater than or equal to the preset second threshold (because the classification accuracy of model M1 for both category E and category G text samples is less than 85%).
[0117] In this scenario, the electronic device can determine the target model and target category through iterative model optimization. The target model can be the model with the highest classification accuracy among the currently trained models, and the target category can be the category corresponding to samples in the validation sample set whose classification accuracy is less than a preset second threshold. For example, if the model with the highest classification accuracy among the currently trained models is M1, then the electronic device can determine model M1 as the target model and classify text of category E and text of category G as the target categories.
[0118] Next, the electronic device can acquire a target sample library, which may contain multiple text samples of different categories, and all text samples in the target sample library have accurate category labels. That is, the text samples in the target sample library are clean samples. Then, the electronic device can extract a preset number of text samples of categories E and G from the target sample library, and extract a preset number of text samples of categories C, D, and F from the initial sample library, and then combine these newly extracted samples into a new training sample set.
[0119] After obtaining a new training sample set, the electronic device can use this new training sample set to perform transfer learning training based on model M1, and determine the trained model M2 as the validation model (i.e., the validation model is M2 at this time, or model M2 needs to be validated). This triggers the process of obtaining the validation sample set, meaning the electronic device can execute a loop to iteratively optimize the model until a preset iteration stopping condition is met. The preset iteration stopping condition can be that the classification accuracy of the validation model is greater than or equal to a preset first threshold, and the classification accuracy of the validation model for each category of samples in the validation sample set is greater than or equal to a preset second threshold.
[0120] For example, after obtaining model M2, the electronic device can acquire a validation sample set, which contains text of category C, category D, category E, category F, and category G.
[0121] After obtaining the validation sample set, the electronic device can use the samples in the validation sample set to validate the model M2 to be validated, thereby obtaining the classification accuracy of the model M2 and calculating the classification accuracy of the model M2 for each category of samples in the validation sample set. For example, the overall classification accuracy of the model M2 has improved to 87.5%, with the model M2 achieving a classification accuracy of 90% for text of category C, 95.2% for text of category D, 82% for text of category E, 92% for text of category F, and 80% for text of category G.
[0122] Since the classification accuracy of model M2 is 87.5%, which is greater than the preset first threshold of 85%, while the classification accuracy of model M2 for each category of samples in the validation sample set is not greater than or equal to the preset second threshold (because the classification accuracy of model M2 for E category text samples and G category text samples is less than 85%).
[0123] In this scenario, the electronic device can determine the target model and the target category. Since model M2 has the highest classification accuracy among currently trained models, model M2 is identified as the target model, while text in category E and text in category G are again identified as the target categories.
[0124] Afterwards, the electronic device can extract a new set of preset number of text samples of category E and category G from the target sample library, and extract a new set of preset number of text samples of category C, category D and category F from the initial sample library, and then combine these newly extracted samples into a new training sample set.
[0125] After obtaining a new training sample set, the electronic device can use the new training sample set to perform transfer learning training based on model M2, and determine the trained model M3 as the verification model (that is, the verification model is M3 at this time, or model M3 needs to be verified), and trigger the process of obtaining the verification sample set. That is, the electronic device can verify model M3 to achieve iterative optimization of the model until the preset iteration stopping condition is met and the loop ends.
[0126] For example, by repeating the above loop and performing 18 iterations of optimization, the classification accuracy of model M19 trained by the electronic device is greater than the preset first threshold of 85%, and the classification accuracy of model M19 for each category of samples in the validation sample set is also greater than or equal to the preset second threshold of 85%. In this case, the electronic device can stop the iteration, output and save model M19, and prompt the user that the model training is complete and the model training result meets the requirements.
[0127] After training the M19 model, the smart terminal can use it to classify the text information read by the user and push similar texts to the user based on the classification results. For example, if the smart terminal uses the M19 model to determine that the user is reading Tang poetry, it can push information about Tang poetry to the user, such as famous Tang poems and their interpretations.
[0128] In one implementation, a model's running state can be set on a visual machine learning training platform. For example, when dragging and dropping the model's corresponding control onto the visualization interface, the model can be set to an inactive state, indicating that it cannot run. After setting the corresponding running parameters for the model on the visualization interface, the model can be switched from an inactive state to an active idle state, where the active idle state indicates that the model can start running. When starting to run the model (i.e., when training begins), the model can be switched from an active idle state to an active running state, where the active running state indicates that the model is being trained. When a training session is completed or the user pauses the session, the model can be switched from an active running state to an active idle state. When the user deletes the model from the visualization interface, the model can be switched back from an active idle state to an inactive state.
[0129] Please see Figure 5 , Figure 5 This is a schematic diagram of the structure of the model training device provided in an embodiment of this application. The model training device 300 may include: a first acquisition module 301, a first training module 302, a second acquisition module 303, a verification module 304, a determination module 305, a third acquisition module 306, a fourth acquisition module 307, and a second training module 308.
[0130] The first acquisition module 301 is used to acquire an initial sample library and a model to be trained. The initial sample library contains samples of multiple different categories, and the model to be trained is a classification model.
[0131] The first training module 302 is used to train the model to be trained using samples in the initial sample library to obtain an initial model, and to determine the initial model as a validation model.
[0132] The second acquisition module 303 is used to acquire a verification sample set, which contains samples of multiple different categories;
[0133] The verification module 304 is used to verify the verification model using the verification sample set, obtain the classification accuracy of the verification model, and calculate the classification accuracy of the verification model for each category of samples in the verification sample set.
[0134] The determination module 305 is used to determine the target model and the target category if the classification accuracy of the verification model is less than a preset first threshold or the classification accuracy of the verification model for each category of samples in the verification sample set is not greater than or equal to a preset second threshold. The target model is the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the verification sample set whose classification accuracy is less than the preset second threshold.
[0135] The third acquisition module 306 is used to acquire a target sample library, which contains multiple samples of different categories, and the samples in the target sample library have accurate category labels;
[0136] The fourth acquisition module 307 is used to extract samples of the target category from the target sample library and extract samples of non-target categories from the initial sample library to form a new training sample set;
[0137] The second training module 308 is used to perform transfer learning training on the target model using a new training sample set, and to determine the trained model as a verification model, triggering the process of obtaining the verification sample set to achieve iterative optimization of the model until the preset iteration stopping condition is met.
[0138] In one embodiment, the fourth acquisition module 307 can be used to:
[0139] For each target category, a preset number of samples are drawn from the target sample library;
[0140] For each non-target category, the preset number of samples are drawn from the initial sample library;
[0141] A new training sample set is formed by using the extracted samples of the target category and the samples of the non-target category.
[0142] In one implementation, the preset iteration stopping condition is that the classification accuracy of the verification model is greater than or equal to a preset first threshold, and the classification accuracy of the verification model for each category of samples in the verification sample set is greater than or equal to a preset second threshold.
[0143] In one implementation, the preset iteration stopping condition is receiving an instruction to stop model training.
[0144] In one implementation, the second training module 308 can also be used for:
[0145] When the preset iteration stopping condition is met, the latest obtained verification model is determined as the training completed model and the output is saved.
[0146] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed on a computer, causes the computer to perform the process in the model training method provided in this embodiment.
[0147] This application also provides an electronic device, including a memory and a processor, wherein the processor executes the process in the model training method provided in this embodiment by calling a computer program stored in the memory.
[0148] For example, the aforementioned electronic devices can be mobile terminals such as tablets or smartphones. See also Figure 6 , Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0149] The electronic device 400 may include components such as a display unit 401, a memory 402, and a processor 403. Those skilled in the art will understand that... Figure 6 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0150] The display unit 401 can be a display screen or the like, and can be used to display information such as text and images.
[0151] Memory 402 can be used to store applications and data. The applications stored in memory 402 contain executable code. Applications can be composed of various functional modules. Processor 403 executes various functional applications and data processing by running the applications stored in memory 402.
[0152] The processor 403 is the control center of the electronic device. It connects various parts of the electronic device through various interfaces and lines. By running or executing the application program stored in the memory 402 and calling the data stored in the memory 402, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole.
[0153] In this embodiment, the processor 403 in the electronic device loads the executable code corresponding to the processes of one or more applications into the memory 402 according to the following instructions, and the processor 403 runs the applications stored in the memory 402 to execute:
[0154] Obtain an initial sample library and a model to be trained. The initial sample library contains samples of multiple different categories, and the model to be trained is a classification model.
[0155] The model to be trained is trained using samples from the initial sample library to obtain an initial model, and the initial model is then used as the validation model.
[0156] Obtain a verification sample set, which contains samples of multiple different categories;
[0157] The validation model is validated using the validation sample set to obtain the classification accuracy of the validation model, and the classification accuracy of the validation model for each category of samples in the validation sample set is statistically analyzed.
[0158] If the classification accuracy of the verification model is less than a preset first threshold or the classification accuracy of the verification model for each category of samples in the verification sample set is not greater than or equal to a preset second threshold, then the target model and the target category are determined. The target model is the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the verification sample set whose classification accuracy is less than the preset second threshold.
[0159] Obtain a target sample library, which contains samples of multiple different categories, and the samples in the target sample library have accurate category labels;
[0160] Samples of the target category are extracted from the target sample library, and samples of non-target categories are extracted from the initial sample library to form a new training sample set;
[0161] The target model is trained using a new training sample set through transfer learning, and the trained model is determined as the validation model. This triggers the process of obtaining the validation sample set, thereby achieving iterative optimization of the model until a preset iteration stopping condition is met.
[0162] Please see Figure 7 The electronic device 400 may include components such as a display unit 401, a memory 402, a processor 403, a speaker 404, a microphone 405, and a battery 406.
[0163] The display unit 401 can be a display screen or the like, and can be used to display information such as text and images.
[0164] Memory 402 can be used to store applications and data. The applications stored in memory 402 contain executable code. Applications can be composed of various functional modules. Processor 403 executes various functional applications and data processing by running the applications stored in memory 402.
[0165] The processor 403 is the control center of the electronic device. It connects various parts of the electronic device through various interfaces and lines. By running or executing the application program stored in the memory 402 and calling the data stored in the memory 402, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole.
[0166] Microphone 405 can be used to pick up sound signals from the surrounding environment.
[0167] Battery 406 can be used to provide power to various components of electronic devices.
[0168] In this embodiment, the processor 403 in the electronic device loads the executable code corresponding to the processes of one or more applications into the memory 402 according to the following instructions, and the processor 403 runs the applications stored in the memory 402 to execute:
[0169] Obtain an initial sample library and a model to be trained. The initial sample library contains samples of multiple different categories, and the model to be trained is a classification model.
[0170] The model to be trained is trained using samples from the initial sample library to obtain an initial model, and the initial model is then used as the validation model.
[0171] Obtain a verification sample set, which contains samples of multiple different categories;
[0172] The validation model is validated using the validation sample set to obtain the classification accuracy of the validation model, and the classification accuracy of the validation model for each category of samples in the validation sample set is statistically analyzed.
[0173] If the classification accuracy of the verification model is less than a preset first threshold or the classification accuracy of the verification model for each category of samples in the verification sample set is not greater than or equal to a preset second threshold, then the target model and the target category are determined. The target model is the model with the highest classification accuracy among the currently trained models, and the target category is the category corresponding to the samples in the verification sample set whose classification accuracy is less than the preset second threshold.
[0174] Obtain a target sample library, which contains samples of multiple different categories, and the samples in the target sample library have accurate category labels;
[0175] Samples of the target category are extracted from the target sample library, and samples of non-target categories are extracted from the initial sample library to form a new training sample set;
[0176] The target model is trained using a new training sample set through transfer learning, and the trained model is determined as the validation model. This triggers the process of obtaining the validation sample set, thereby achieving iterative optimization of the model until a preset iteration stopping condition is met.
[0177] In one embodiment, when the processor 403 executes the step of extracting samples of the target category from the target sample library and extracting samples of non-target categories from the initial sample library to form a new training sample set, it may perform the following: for each target category, extracting a preset number of samples from the target sample library; for each non-target category, extracting the preset number of samples from the initial sample library; and using the extracted samples of the target category and the samples of the non-target categories to form a new training sample set.
[0178] In one implementation, the preset iteration stopping condition is that the classification accuracy of the verification model is greater than or equal to a preset first threshold, and the classification accuracy of the verification model for each category of samples in the verification sample set is greater than or equal to a preset second threshold.
[0179] In one implementation, the preset iteration stopping condition is receiving an instruction to stop model training.
[0180] In one implementation, the processor 403 may also perform the following: when the preset iteration stopping condition is met, determine the latest obtained verification model as the training completed model and save the output.
[0181] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed description of the model training method above, which will not be repeated here.
[0182] The model training device provided in this application embodiment belongs to the same concept as the model training method in the above embodiment. Any of the methods provided in the model training method embodiment can be run on the model training device. For details of its implementation process, please refer to the model training method embodiment, which will not be repeated here.
[0183] It should be noted that, regarding the model training method described in the embodiments of this application, those skilled in the art will understand that all or part of the process of the model training method described in the embodiments of this application can be implemented by a computer program controlling the relevant hardware. The computer program can be stored in a computer-readable storage medium, such as a memory, and executed by at least one processor. During execution, it can include the process of the embodiments of the model training method described. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), random access memory (RAM), etc.
[0184] For the model training device described in this application embodiment, its functional modules can be integrated into a single processing chip, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0185] The foregoing has provided a detailed description of a model training method, apparatus, storage medium, and electronic device provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for training an image classification model, characterized in that, include: Obtain an initial image sample library and an image classification model to be trained. The initial image sample library contains image samples of multiple different categories. The image classification model to be trained is trained using samples from the initial image sample library to obtain an initial image classification model, and the initial image classification model is determined as the image classification verification model. Obtain a verification image sample set, which contains multiple image samples of different categories; The image classification verification model is validated using the verification image sample set to obtain the classification accuracy of the image classification verification model, and the classification accuracy of the image classification verification model for each category of image samples in the verification image sample set is statistically analyzed. If the classification accuracy of the image classification verification model is less than a preset first threshold, or if the classification accuracy of the image classification verification model for each category of image samples in the verification image sample set is not greater than or equal to a preset second threshold, then the target image classification model and the target image category are determined. The target image classification model is the image classification model with the highest classification accuracy among the currently trained image classification models, and the target image category is the image category corresponding to the image samples in the verification image sample set whose classification accuracy is less than the preset second threshold. Obtain a target image sample library, which contains multiple image samples of different categories, and the image samples in the target image sample library have accurate image category labels; Image samples of the target image category are extracted from the target image sample library, and image samples of non-target image categories are extracted from the initial image sample library to form a new training image sample set; The target image classification model is trained using a new training image sample set through transfer learning. The trained image classification model is then used as the image classification verification model. This triggers the process of obtaining the verification image sample set, thereby achieving iterative optimization of the image classification model until the preset iteration stopping condition is met. Finally, the trained image classification model is output. Obtain the image to be classified, and input the image to be classified into the trained image classification model for classification; Output the corresponding image category for the image to be classified, and push similar images to the user based on the output image category.
2. The image classification model training method according to claim 1, characterized in that, The step of extracting image samples of the target image category from the target image sample library and extracting image samples of non-target image categories from the initial image sample library to form a new training image sample set includes: For each target image category, a preset number of image samples are extracted from the target image sample library; For each non-target image category, the preset number of image samples are extracted from the initial image sample library; A new training image sample set is formed by using the extracted image samples of the target image category and the image samples of the non-target image category.
3. The image classification model training method according to claim 1, characterized in that, The preset iteration stopping condition is that the classification accuracy of the image classification verification model is greater than or equal to a preset first threshold, and the classification accuracy of the image classification verification model for each category of image samples in the verification image sample set is greater than or equal to a preset second threshold.
4. The image classification model training method according to claim 1, characterized in that, The preset iteration stopping condition is receiving an instruction to stop the training of the image classification model.
5. The image classification model training method according to claim 4, characterized in that, The method further includes: When the preset iteration stopping condition is met, the latest obtained image classification verification model is determined as the trained image classification model and the output is saved.
6. A training device for an image classification model, characterized in that, include: The first acquisition module is used to acquire an initial image sample library and an image classification model to be trained. The initial image sample library contains multiple image samples of different categories. The first training module is used to train the image classification model to be trained using samples in the initial image sample library to obtain an initial image classification model, and to determine the initial image classification model as the image classification verification model. The second acquisition module is used to acquire a verification image sample set, which contains multiple image samples of different categories. The verification module is used to verify the image classification verification model using the verification image sample set, obtain the classification accuracy of the image classification verification model, and statistically analyze the classification accuracy of the image classification verification model for each category of image samples in the verification image sample set. The determination module is used to determine the target image classification model and the target image category if the classification accuracy of the image classification verification model is less than a preset first threshold or the classification accuracy of the image classification verification model for each category of image samples in the verification image sample set is not greater than or equal to a preset second threshold. The target image classification model is the image classification model with the highest classification accuracy among the currently trained image classification models, and the target image category is the image category corresponding to the image samples in the verification image sample set whose classification accuracy is less than the preset second threshold. The third acquisition module is used to acquire a target image sample library, which contains multiple image samples of different categories, and the image samples in the target image sample library have accurate image category labels. The fourth acquisition module is used to extract image samples of the target image category from the target image sample library and extract image samples of non-target image categories from the initial image sample library to form a new training image sample set. The second training module is used to perform transfer learning training on the target image classification model using a new training image sample set, and to determine the trained image classification model as the image classification verification model. This triggers the process of obtaining the verification image sample set to achieve iterative optimization of the image classification model until a preset iteration stopping condition is met, and then outputs the trained image classification model. The module also obtains images to be classified, inputs these images into the trained image classification model for classification, outputs the corresponding image category for each image to be classified, and pushes similar images to the user based on the output image category.
7. The image classification model training device according to claim 6, characterized in that, The fourth acquisition module: For each target image category, a preset number of image samples are extracted from the target image sample library; For each non-target image category, the preset number of image samples are extracted from the initial image sample library; A new training image sample set is formed by using the extracted image samples of the target image category and the image samples of the non-target image category.
8. The image classification model training device according to claim 6, characterized in that, The second training module is also used for: When the preset iteration stopping condition is met, the latest image classification verification model is determined as the trained image classification model and the output is saved.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed on a computer, it causes the computer to perform the method as described in any one of claims 1 to 5.
10. An electronic device, comprising a memory and a processor, characterized in that, The processor executes the method as described in any one of claims 1 to 5 by invoking a computer program stored in the memory.