WO2025209385A1 - 一种模型训练方法、缺陷检测方法以及相关装置 - Google Patents

一种模型训练方法、缺陷检测方法以及相关装置

Info

Publication number
WO2025209385A1
WO2025209385A1 PCT/CN2025/086114 CN2025086114W WO2025209385A1 WO 2025209385 A1 WO2025209385 A1 WO 2025209385A1 CN 2025086114 W CN2025086114 W CN 2025086114W WO 2025209385 A1 WO2025209385 A1 WO 2025209385A1
Authority
WO
WIPO (PCT)
Prior art keywords
model
detection model
training
image set
initial detection
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
PCT/CN2025/086114
Other languages
English (en)
French (fr)
Inventor
曾怡
刘俊
汪铖杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology (Shenzhen) Co Ltd
Original Assignee
Tencent Technology (Shenzhen) Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology (Shenzhen) Co Ltd filed Critical Tencent Technology (Shenzhen) Co Ltd
Publication of WO2025209385A1 publication Critical patent/WO2025209385A1/zh
Anticipated expiration legal-status Critical
Pending legal-status Critical Current

Links

Classifications

    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00—Arrangements for image or video recognition or understanding
    • G06V10/70—Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/77—Processing image or video features in feature spaces; using data integration or data reduction, e.g. principal component analysis [PCA] or independent component analysis [ICA] or self-organising maps [SOM]; Blind source separation
    • G06V10/774—Generating sets of training patterns; Bootstrap methods, e.g. bagging or boosting
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00—Image analysis
    • G06T7/0002—Inspection of images, e.g. flaw detection
    • G06T7/0004—Industrial image inspection
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00—Arrangements for image or video recognition or understanding
    • G06V10/70—Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/764—Arrangements for image or video recognition or understanding using pattern recognition or machine learning using classification, e.g. of video objects
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00—Indexing scheme for image analysis or image enhancement
    • G06T2207/30—Subject of image; Context of image processing
    • G06T2207/30108—Industrial image inspection

Definitions

  • This application relates to the field of artificial intelligence technology, and in particular to model training and defect detection.
  • Industrial quality inspection refers to the process of quality inspection and control of products or components during the industrial production process. Its purpose is to ensure that the products meet the prescribed quality standards and requirements, thereby improving the product qualification rate and quality stability.
  • Obtaining a first training image set, a second training image set, and an initial detection model wherein the initial detection model is trained based on the first training image set, the first training image set includes a first sample defect image, the second training image set includes a second sample defect image, and the second sample defect image is different from the first sample defect image, and the initial detection model includes a first weight parameter set, the first weight parameter set includes first weight parameters of multiple model parameters in the initial detection model, and the first weight parameters are used to represent the importance of the multiple model parameters of the initial detection model;
  • the initial detection model is trained based on the first sampling image set, the second training image set and the first weight parameter to adjust multiple model parameters of the initial detection model to obtain a trained optimized detection model, wherein the first sampling image set includes some sample defect images in the first training image set, and the first weight parameter set is used to limit the adjustment range of the model parameters in the initial detection model.
  • a training image and initial model acquisition module configured to acquire a first training image set, a second training image set, and an initial detection model, wherein the initial detection model is obtained by training based on the first training image set, the first training image set includes a first sample defect image, the second training image set includes a second sample defect image, and the second sample defect image is different from the first sample defect image;
  • the initial detection model includes a first weight parameter set, the first weight parameter set includes first weight parameters of multiple model parameters in the initial detection model, and the first weight parameters are used to characterize the importance of the model parameters of the initial detection model;
  • a model training module is used to train the initial detection model based on the first sampling image set, the second training image set and the first weight parameter to adjust multiple model parameters of the initial detection model to obtain a trained optimized detection model, wherein the first sampling image set includes some sample defect images in the first training image set, and the first weight parameter set is used to limit the adjustment range of the model parameters in the initial detection model.
  • Another aspect of the present application provides a defect detection method, comprising:
  • the optimized detection model includes a feature extraction network and a classification network, and the optimized detection model is obtained using any of the above-mentioned model training methods;
  • defect classification is performed on the features of the image to be detected to obtain predicted defect information of the image to be detected, wherein the predicted defect information is used to represent the classification result of whether the image to be detected contains defects.
  • a defect detection device comprising:
  • An image acquisition module to be detected used to acquire the image to be detected
  • An image input module to be detected is used to input the image to be detected into an optimized detection model, wherein the optimized detection model includes a feature extraction network and a classification network, and the optimized detection model is obtained using any of the above-mentioned model training methods;
  • the feature extraction module of the image to be detected is used to extract features of the image to be detected based on the feature extraction network in the optimized detection model to obtain features of the image to be detected;
  • the feature classification module of the image to be detected is used to classify defects of the features of the image to be detected based on the classification network to obtain predicted defect information of the image to be detected, wherein the predicted defect information is used to represent the classification result of whether the image to be detected contains defects.
  • an embodiment of the present application provides a computer device, including:
  • the processor, the communication interface and the memory complete communication with each other through the communication bus;
  • the communication interface is an interface of the communication module;
  • the memory is used to store a computer program and transmit the computer program to the processor; the processor is used to call the computer program in the memory to execute the above method.
  • an embodiment of the present application provides a storage medium, which is used to store a computer program, and the computer program is used to execute the method of the above aspect.
  • an embodiment of the present application provides a computer program product including a computer program, which, when executed on a computer, enables the computer to execute the above method.
  • the present application provides a model training method and related devices.
  • the model training method trains an initial detection model by using part of the historical training data that has been trained (a first sampling image set) and the fully newly added training data (a second training image set). Compared with using the full amount of historical training data and the fully newly added training data to train the initial detection model, it saves time and reduces the consumption of GPU cards.
  • the update amplitude of the training data for some important model parameters is limited during the training phase.
  • the present application also provides a defect detection method and related devices, which detect defects in the image to be detected by the optimized detection model obtained by the above-mentioned model training method, and obtain a classification result of whether the image to be detected contains defects, thereby improving the recognition effect and accuracy of defect identification.
  • FIG1 is a schematic diagram of an architecture of a model training system provided in one embodiment of the present application.
  • FIG3 is a flow chart of a model training method provided by another embodiment of the present application.
  • FIG4 is a flow chart of a model training method provided by another embodiment of the present application.
  • FIG6 is a flow chart of a model training method provided by another embodiment of the present application.
  • FIG9 is a flow chart of a model training method provided by another embodiment of the present application.
  • FIG11 is a schematic diagram of the structure of a model training device provided in one embodiment of the present application.
  • FIG12 is a schematic structural diagram of a model training device provided in another embodiment of the present application.
  • FIG13 is a schematic structural diagram of a model training device provided in another embodiment of the present application.
  • FIG15 is a schematic diagram of a server structure provided in an embodiment of the present application.
  • An embodiment of the present application provides a model training method, which trains an initial detection model by using part of the trained historical training data (a first sampling image set) and the fully newly added training data (a second training image set). Compared with using the full amount of historical training data and the fully newly added training data to train the initial model, it saves time and reduces the consumption of GPU cards.
  • the update of the model parameters based on the historical training data is limited, which solves the problem of knowledge forgetting caused by fine-tuning the model using only the fully added data, improves the learning ability of the detection model, and detects defects in the image to be detected by using the optimized detection model obtained by the model training method, thereby improving the recognition effect and accuracy of defect recognition.
  • module refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof.
  • a processor or multiple processors or memories
  • each module or unit can be part of an overall module or unit that includes the function of the module or unit.
  • Defect detection technology This technology determines the presence of defects in captured images. In modern industrial manufacturing, defective parts are inevitably present. Detecting these defects using defect detection technology plays a crucial role in improving production processes and boosting factory efficiency.
  • Incremental learning refers to a learning system that can continuously learn new knowledge from new samples and can retain most of the knowledge that has been learned previously. Incremental learning is very similar to the human learning model. Because humans learn and accept new things every day during the process of growth, learning is gradual, and humans generally do not forget the knowledge that has been learned. In the embodiment of the present application, incremental learning is used for the training of the defect detection model. Since the number of defects is constantly updated in different production cycles, the defect detection model also needs to continuously learn knowledge from new defect images.
  • Incremental learning includes data increment scenarios and category increment scenarios.
  • Incremental data scenarios This refers to scenarios where the data category distribution remains roughly the same between incremental stages, with only a simple increase in the amount of data.
  • incremental data learning is used to train the defect detection model. Since the number of defects is constantly updated during different production cycles, the defect detection model also needs to continuously learn from new defect images.
  • Category increment scenario refers to the scenario where data categories do not overlap between different incremental stages.
  • Full data model refers to a deep learning model obtained by iterative model training using all accumulated data.
  • Incremental data model refers to a model that is trained iteratively using a small amount of existing data and new data, or using only new data without using existing data.
  • Catastrophic forgetting refers to the ability of a model in incremental learning to forget previously learned tasks when learning a new task. Specifically, when a model learns a new task, it adjusts its parameters to adapt to the requirements of the new task. However, these parameter adjustments may cause the model's performance on the previously learned task to degrade, or even completely forget the previously learned task. Catastrophic forgetting is a significant issue in incremental learning, limiting its scope of application. There are two main causes of catastrophic forgetting: first, parameter conflict, where the parameter adjustments for a new task conflict with those for an old task, causing information from the old task to be forgotten; second, representation space limitations, where the model's limited representation space prevents it from simultaneously representing information from multiple tasks.
  • defect detection technology has achieved high accuracy. Specifically, a large amount of training data is acquired in advance for model training, and then the trained neural network model is used for defect detection. Taking industrial quality inspection of steel strip as an example, during this process, defect detection is often performed on strip images to achieve defect detection and identification. Specifically, deep learning-based defect detection methods are trained on a large amount of strip image data to establish a defect detection model. The defect detection model then analyzes and identifies images of the strip surface to detect defects.
  • using the full amount of training data for model iteration means that in the full amount of data increment scenario, the full amount of historical training data for training the current model and the newly added data are used as the entire training data of the model to iteratively train the model.
  • This method can stably improve and iterate the model, but as the amount of data increases, the training time and cost will also increase. If the amount of data is large, the computing resources and time cost required for training are very high.
  • Using incremental data for model fine-tuning means fine-tuning an existing model using only newly added data. Therefore, when training a model, to maintain the model's existing capabilities, a smaller learning rate can be used or only the last few layers of the deep learning model can be trained. Because fine-tuning doesn't utilize past historical data, even with a reduced learning rate and training parameter range, the model still risks forgetting previously learned knowledge, leading to a decrease in overall performance and overfitting to the current data. This risk increases significantly with increasing fine-tuning cycles.
  • Transfer learning is a method of migrating the capabilities of a model to a target data domain.
  • the target data domain is usually quite different from the original data domain of the model, and the performance on the original data domain is not considered. Therefore, the effect of the model on the original data after transfer learning is usually greatly reduced.
  • the newly added data is usually not much different from the original data in terms of domain, and the actual requirements in the business must maintain the performance on the original data, so this type of method is not applicable.
  • the model training method includes: first, obtaining a first training image set, a second training image set and an initial detection model, wherein the initial detection model is obtained by training based on the first training image set, the first training image set includes sample defect images, the second training image set includes sample defect images and is different from the sample defect images included in the first training image set, and the initial detection model includes a first weight parameter set, the first weight parameter set includes first weight parameters of multiple model parameters in the initial detection model, and the first weight parameter is used to characterize the importance of the model parameters of the initial detection model; then, based on the first sampling image set, the second training image set and the first weight parameter, the initial detection model is trained to adjust the model parameters of the initial detection model to obtain a trained optimized detection model, wherein the first sampling image set includes some sample defect images in the first training image set, and the first weight parameter set is used to limit the adjustment range of the model parameters in the initial detection model.
  • the model training method provided in the embodiment of the present application uses a partially trained first sampling image set and a fully newly added second training image set to train the initial detection model. Compared with using the full amount of historical training data and the fully newly added training data to train the initial model, it saves time and reduces the consumption of GPU cards. By adaptively evaluating the corresponding first weights of the model parameters, the update of the model parameters based on historical training data is limited. Compared with the problem of knowledge forgetting caused by fine-tuning the model using only the full amount of newly added data, the learning ability of the model is improved, and the recognition effect and accuracy of the model for defect recognition are enhanced.
  • the embodiment of the present application also provides a defect detection method and related devices, the defect detection method includes: first, obtaining an image to be detected; then, inputting the image to be detected into an optimized detection model, wherein the optimized detection model includes a feature extraction network and a classification network, and the optimized detection model is obtained using the model training method as described above; then, based on the feature extraction network in the optimized detection model, feature extraction is performed on the image to be detected to obtain features of the image to be detected; finally, based on the classification network, defect classification is performed on the features of the image to be detected to obtain predicted defect information of the image to be detected, wherein the predicted defect information is used to characterize the classification result of whether the image to be detected contains defects.
  • the defect detection method provided in the embodiment of the present application detects defects in the image to be detected using the optimized detection model obtained by the model training method, and obtains a classification result of whether the image to be detected contains defects, thereby improving the recognition effect and accuracy of defect recognition.
  • Figure 1 is an application environment diagram of the model training method or defect detection method in the embodiment of the present application.
  • the model training method in the embodiment of the present application is applied to the model training system
  • the defect detection method is applied to the defect detection system.
  • the model training system includes: a server and a terminal device; wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
  • the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
  • CDN content delivery networks
  • the terminal can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this.
  • the terminal and the server can be directly or indirectly connected by wired or wireless communication, and the embodiment of the present application does not limit this.
  • the server first obtains a first training image set, a second training image set and an initial detection model, wherein the initial detection model is trained based on the first training image set, the first training image set includes sample defect images, the second training image set contains sample defect images and is different from the sample defect images contained in the first training image set, and the initial detection model contains a first weight parameter set, the first weight parameter set contains first weight parameters of multiple model parameters in the initial detection model, and the first weight parameter is used to characterize the importance of the model parameters of the initial detection model; then, the server trains the initial detection model based on the first sampling image set, the second training image set and the first weight parameter to adjust the model parameters of the initial detection model to obtain the trained optimized detection model, wherein the first sampling image set contains some sample defect images in the first training image set, and the first weight parameter set is used to limit the adjustment range of the model parameters in the initial detection model.
  • the model training method provided in this embodiment includes: Step S110 to Step S120. Specifically:
  • S110 Obtain a first training image set, a second training image set, and an initial detection model.
  • the initial detection model is obtained by training based on the first training image set, the first training image set includes a first sample defect image, the second training image set contains a second sample defect image and the second sample defect image is different from the first sample defect image, the initial detection model includes a first weight parameter set, the first weight parameter set includes the first weight parameters of multiple model parameters in the initial detection model, and the first weight parameter is used to characterize the importance of multiple model parameters of the initial detection model.
  • the first training image set includes at least one first sample defect image, which is the basic data used to train the initial detection model.
  • the second training image set includes at least one second sample defect image sampled during the production cycle, which contains data on over-detection and missed detection situations that occurred during the actual use of the initial detection model for defect detection.
  • the initial detection model is a model that has been trained based on the first training image set. It has a feature extraction network and a classification network and can identify product quality defects in images. Specifically:
  • the sample defect images in the first training image set are the full amount of training data when training the initial detection model.
  • the initial detection model is obtained by training based on the first training image set.
  • the initial detection model can recognize defects in products in the image, such as strip steel.
  • the initial detection model includes a feature extraction network and a classification network.
  • the feature extraction network is used to extract features from the image input into the initial detection model, while the classification network is used to classify image features to obtain a prediction result of whether the product in the image contains defects.
  • the classification network in the initial detection model has a first weight parameter set, which can be in a matrix form or a set form.
  • the first weight parameter set includes multiple first weight parameters, each weight parameter corresponds to a model parameter in the classification network. Therefore, the first weight parameter is used to characterize the importance of the model parameters of the initial detection model to the identification of quality defects.
  • Over-detection refers to the situation where the initial detection model mistakenly judges normal products or samples as defective or unqualified. This means that the initial detection model makes excessive judgments on normal products, resulting in misjudgment of them as problematic products.
  • Missed detection refers to the situation where the initial detection model fails to detect products or samples that are actually defective or unqualified. This means that the model misses some problematic products that should have been detected, resulting in missed detections.
  • the amount of data generated by these over-detection and missed detection situations is smaller than the amount of data in the first training image set used for training before the initial detection model was put online, but this data is still crucial for the optimization and performance improvement of the initial detection model. Therefore, after the initial detection model has been put online for a period of time, the over-detection and missed detection situations in the production cycle are counted and sampled to obtain the second training image set.
  • the first sampling image set includes some sample defect images in the first training image set, and the first weight parameter set is used to limit the adjustment range of the model parameters in the initial detection model.
  • the first sampling image set is obtained by sampling the sample defect images in the first training image set according to the sampling ratio.
  • the purpose of sampling is to reduce the size of the training data while retaining important information.
  • the sample defect images in the first sampling image set obtained after sampling the first training image set and the sample defect images in the second training image set are used together as training samples for the initial detection model to further train the initial detection model. Compared with using the full first training image set and the second training image set to train the initial detection model, this reduces the time required to train the initial model and reduces the consumption of GPU card time.
  • the initial detection model is fine-tuned using the first sampling image set and the second training image set to obtain the trained optimized detection model.
  • the parameter adjustment range of these model parameters will be relatively limited, so that the optimized detection model after training will not excessively forget the knowledge that has been learned before, and maintain the recognition accuracy of the defects that can be originally recognized.
  • the update of the model parameters in the initial detection model is targetedly restricted by the first weight parameter set, and the update amplitude of the important model parameters in the initial detection model is limited to ensure that the knowledge learned before is not excessively forgotten during the fine-tuning process.
  • the optimized detection model obtained in this way can make correct detection results for the over-killing and missed detection situations of the original initial detection model, thereby improving the accuracy of defect detection.
  • the model parameters in the initial model are crucial for accurately identifying sample categories (e.g., whether a sample is defective). Some model parameters are crucial (highly important), while others may be less important (lowly important). That is, for input images that were originally accurately identified (e.g., the first sample defect image), significant changes in important model parameters will directly affect the initial model's recognition accuracy for these images.
  • the method provided in the embodiments of this application optimizes the initial detection model by utilizing sampling data and weight constraints to address over-detection and missed detection issues and improve model performance.
  • This method can effectively improve the model's effectiveness with limited computing resources. In practical applications, it is necessary to appropriately set the sampling ratio and training strategy based on the specific situation to achieve optimal detection results.
  • the initial detection model launched at time t is Among them, t represents the time node when the initial detection model is launched, i represents the model parameters in the initial detection model, and the initial detection model It is obtained by training on all the sample defect data in the first training image set D 1: t . After the initial detection model is deployed online for a period of time, the time node is t+1, and the over-kill data and missed detection data of the initial detection model are counted to obtain the second training image set D t+1 . In the related art, the full amount of training data is generally used, that is, D 1: t +D t+1 .
  • the method provided in the embodiment of the present application determines the sampling ratio p% of the first training image set, and samples the sample defect images in the first training image set D 1: t at the sampling ratio p% to obtain the first sampling image set.
  • the first sampling image set and the second training image set D t+1 are merged together to form new training data D′ t+1 .
  • the training data D′ t+1 formed by merging the first sampling image set and the second training image set D t+1 is Perform training to adjust the model parameters of the initial detection model to obtain the optimized detection model after training
  • the model training method provided in the embodiment of the present application uses a partially trained first training image set and a fully newly added second training image set to train the initial detection model. Compared with using the full amount of historical training data and the fully newly added training data to train the initial model, it saves time and reduces the consumption of GPU cards. By adaptively evaluating the corresponding first weights of the model parameters, the update range of the training data for some important model parameters is limited. Compared with the problem of knowledge forgetting caused by fine-tuning the model using only the full amount of newly added data, the learning ability of the model is improved, and the recognition effect and accuracy of the model for defect recognition are enhanced.
  • step S120 further includes sub-steps S121 to S123. Specifically:
  • the initial detection model is obtained by adjusting the model parameters of the basic detection model.
  • the initial detection model can be obtained by training the basic detection model based on the first training image set.
  • t-1 represents the time node when the basic detection model is launched
  • i represents the model parameters in the basic detection model
  • the basic detection model It is obtained by training on the sample defect data in all the previous basic training image sets Dt -1 .
  • the overkill data and missed detection data are counted to obtain the third training image set.
  • the sampling ratio p% of the basic training image set Dt -1 the sample defect images in the basic training image set Dt -1 are sampled at the sampling ratio p% to obtain the second sampling image set.
  • the second sampling image set is combined with the third training image set to form new training data.
  • the new training data formed by combining the second sampling image set and the third training image set is used to train the basic detection model. Perform training to adjust the model parameters of the basic detection model to obtain the trained initial detection model
  • S122 Calculate the objective function of the initial detection model according to the first weight parameter, the model parameters of the initial detection model, the model parameters of the basic detection model, the first sampling image set, and the second training image set.
  • the objective function of the initial detection model is calculated based on the first weight parameter, the model parameters of the initial detection model, the model parameters of the basic detection model, the first sampled image set, and the second training image set.
  • the objective function is generally a metric used to evaluate model performance, and can be accuracy, misclassification rate, recall rate, etc.
  • the purpose of calculating the objective function is to quantitatively evaluate the performance of the initial detection model on the second training image set.
  • sub-step S122 further includes sub-steps S1221 to S1224. Specifically:
  • the optimized detection model includes a feature extraction network and a classification network, and the optimized detection model is obtained using the above-mentioned model training method.
  • the feature extraction network in the optimized detection model processes the image to be inspected and extracts key features from the image.
  • These features can be information such as color, shape, texture, etc., which can represent the characteristics of defects in the image.
  • the predicted defect information is used to represent the classification result of whether the image to be detected contains defects.
  • the classification network will classify defects based on the extracted features of the image to be inspected and output predicted defect information.
  • the predicted defect information is used to indicate whether the image to be inspected contains defects and the type of defects.
  • the method provided in the embodiments of the present application inputs the image to be inspected into an optimized inspection model, processes and analyzes it using the model's feature extraction network and classification network, and ultimately obtains predicted defect information for the image to be inspected.
  • defect detection can be performed quickly and automatically on the image to be inspected, improving inspection efficiency and accuracy.
  • the optimized inspection model can be continuously trained and updated to adapt to different types of defects and images, thereby improving the model's generalization capabilities.
  • a training image and initial model acquisition module 110 is configured to acquire a first training image set, a second training image set, and an initial detection model, wherein the initial detection model is obtained by training based on the first training image set, the first training image set includes a first sample defect image, the second training image set includes a second sample defect image, and the second sample defect image is different from the first sample defect image; the initial detection model includes a first weight parameter set, the first weight parameter set includes first weight parameters of multiple model parameters in the initial detection model, and the first weight parameters are used to represent the importance of the multiple model parameters of the initial detection model;
  • the model training device trains the initial detection model by using a partially trained first training image set and a fully newly added second training image set. Compared with using the full amount of historical training data and the fully newly added training data to train the initial model, it saves time and reduces the consumption of GPU cards. By adaptively evaluating the corresponding first weights of the model parameters, the update of the model parameters based on historical training data is limited. Compared with the problem of knowledge forgetting caused by fine-tuning the model using only the full amount of newly added data, the learning ability of the model is improved, and the recognition effect and accuracy of the model for defect recognition are enhanced.
  • the initial detection model is trained to adjust model parameters of the initial detection model.
  • the apparatus provided in the embodiments of the present application calculates the objective function of the initial detection model by processing sampled data, comparing model parameters, and applying weights.
  • This objective function can be used as an indicator to evaluate model performance, helping us understand the model's performance on a specific dataset and guiding further optimization and improvement.
  • This calculation process can help us more accurately evaluate and improve the detection model to enhance its performance and accuracy.
  • the clipping threshold is used to represent a gradient threshold when updating parameters of the initial detection model, so as to limit a gradient range when updating parameters of the initial detection model;
  • An objective function of the initial detection model is constructed according to the cropping threshold, the first weight parameter, the model parameters of the initial detection model, the model parameters of the basic detection model, the first sampling image set, and the second training image set.
  • model training module 120 is further configured to:
  • the objective function of the initial detection model is calculated based on the clipping threshold, the first weight parameter, the model parameters of the initial detection model, the model parameters of the basic detection model, the first sampling image set and the second training image set.
  • the model training device 10 further includes a weight calculation module 130 .
  • the weight calculation module 130 is configured to:
  • the weight calculation module 130 is further configured to:
  • the device provided in the embodiment of the present application can more accurately evaluate the importance of model parameters for optimizing the detection model, which helps to improve the performance and generalization ability of the model.
  • the ratio of new and old data is maintained at 1:1 in the training of each batch, and the device with dynamic weight limitation is used to limit the changes in parameters that are very important for the old tasks, so that the model will not suffer from catastrophic forgetting when using only a small amount of historical data, meeting the project requirements while greatly reducing the iteration cost.
  • the sample defect images in the first training image set are sampled according to a sampling ratio to obtain a first sampled image set.
  • the device provided in the embodiment of the present application further trains the initial detection model by using the sample defect images in the first sampling image set obtained after sampling the first training image set and the sample defect images in the second training image set as training samples of the initial detection model.
  • the training of the initial model is reduced, which saves time and reduces the consumption of GPU cards.
  • the image feature extraction module 230 is used to extract features of the image to be detected based on the feature extraction network in the optimized detection model to obtain features of the image to be detected;
  • the image feature classification module 240 is used to classify the features of the image to be detected based on the classification network to obtain predicted defect information of the image to be detected, wherein the predicted defect information is used to represent the classification result of whether the image to be detected contains defects.
  • the device provided in the embodiments of the present application inputs the image to be inspected into an optimized inspection model, processes and analyzes it using the model's feature extraction network and classification network, and ultimately obtains predicted defect information for the image to be inspected.
  • an optimized inspection model uses the trained optimized inspection model to detect defects in the image to be inspected, quickly and automatically detected, improving inspection efficiency and accuracy.
  • the optimized inspection model can be continuously trained and updated to adapt to different types of defects and images, improving the model's generalization capabilities.
  • FIG. 15 is a schematic diagram of a server structure provided by an embodiment of the present application.
  • the server 300 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 322 (for example, one or more processors) and memory 332, and one or more storage media 330 (for example, one or more mass storage devices) for storing application programs 342 or data 344.
  • the memory 332 and the storage medium 330 can be temporary storage or permanent storage.
  • the program stored in the storage medium 330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server.
  • the central processing unit 322 can be configured to communicate with the storage medium 330 to execute a series of instruction operations in the storage medium 330 on the server 300.
  • the steps executed by the server in the above embodiment may be based on the server structure shown in FIG15 .
  • an embodiment of the present application further provides a storage medium, which is used to store a computer program, and the computer program is used to execute the method provided by the above embodiment.
  • An embodiment of the present application further provides a computer program product including a computer program, which, when executed on a computer, enables the computer to execute the method provided in the above embodiment.
  • the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit.
  • the aforementioned integrated units may be implemented in the form of hardware or software functional units.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Databases & Information Systems (AREA)
  • Evolutionary Computation (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Software Systems (AREA)
  • Multimedia (AREA)
  • Quality & Reliability (AREA)
  • Image Analysis (AREA)
  • Image Processing (AREA)

Abstract

本申请提供了一种模型训练方法、缺陷检测方法以及相关装置。本申请实施例可应用于计算机视觉等各种场景。模型训练方法通过使用部分已经训练过的第一采样图像集和全量新增的第二训练图像集对初始检测模型进行训练,相比于使用全量的历史训练数据与全量新增的训练数据对初始模型进行训练更节省时间、降低对GPU卡时的消耗;通过自适应评估模型参数的对应的第一权重,限制对历史训练数据对模型参数的更新,解决了只使用全量新增数据对模型进行微调造成的知识遗忘的问题,提高了检测模型的学习能力,通过使用模型训练方法得到的优化检测模型对待检测图像中的缺陷进行检测,提高了缺陷识别的识别效果及准确性。

Description

一种模型训练方法、缺陷检测方法以及相关装置
本申请要求于2024年04月02日提交中国专利局、申请号为2024103936252、申请名称为“一种模型训练方法、缺陷检测方法以及相关装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及人工智能技术领域,尤其涉及模型训练、缺陷检测。
背景技术
工业质检是指在工业生产过程中,对产品或零部件进行质量检测和控制的过程,其目的是确保产品符合规定的质量标准和要求,从而提高产品的合格率和质量稳定性。
目前,基于深度学习的缺陷检测技术已经能够达到较高的精度,具体地,预先获取大量的训练数据进行模型训练,然后使用训练得到的神经网络模型进行缺陷检测。然而,随着工业质检项目的进行,所收集到的用于训练深度学习模型的数据量会呈现逐步增大的情况。而在项目进行到中后期时,由于训练数据巨大,训练时间很长,训练卡数的消耗很多,造成迭代一次成本非常大。
在相关技术中,主要采用两种技术方案:使用全量训练数据进行模型迭代和使用增量数据进行模型微调。然而,这两种方案都存在一些问题。使用全量数据进行模型迭代时,如果数据量很大,训练所需的计算资源和时间成本都很高。使用增量数据进行模型微调时,随着训练时间的延长或微调次数的增加,模型会逐渐偏离原有知识,导致对历史数据发生灾难性的遗忘,进而导致模型整体能力快速下降,不够稳定。
发明内容
本申请实施例提供了一种模型训练方法、缺陷检测方法以及相关装置,在模型训练方法中,通过使用部分已经训练过的历史训练数据和全量新增的训练数据对初始检测模型进行训练,解决了相关技术中使用全量训练数据进行模型更新造成的计算资源和时间成本过高的问题,以及使用全量新增的训练数据对模型微调时造成的灾难性遗忘的问题。在缺陷检测方法中,通过模型训练方法得到的优化检测模型对待检测图像中的缺陷进行检测,提高了缺陷识别的识别效果及准确性。
本申请的一方面提供一种模型训练方法,包括:
获取第一训练图像集、第二训练图像集及初始检测模型,其中,初始检测模型为基于第一训练图像集训练得到的,第一训练图像集包括第一样本缺陷图像,第二训练图像集包含第二样本缺陷图像且第二样本缺陷图像与第一样本缺陷图像不同,初始检测模型包含第一权重参数集,第一权重参数集中包含初始检测模型中多个模型参数的第一权重参数,第一权重参数用于表征初始检测模型的多个模型参数的重要程度;
基于第一采样图像集、第二训练图像集及第一权重参数对初始检测模型进行训练,以调整初始检测模型的多个模型参数,得到训练后的优化检测模型,其中,第一采样图像集合包含第一训练图像集中的部分样本缺陷图像,第一权重参数集用于限制初始检测模型中的模型参数的调整幅度。
本申请的另一方面提供了一种模型训练装置,包括:训练图像及初始模型获取模块及模型训练模块;具体的:
训练图像及初始模型获取模块,用于获取第一训练图像集、第二训练图像集及初始检测模型,其中,初始检测模型为基于第一训练图像集训练得到的,第一训练图像集包括第一样本缺陷图像,第二训练图像集包含第二样本缺陷图像且第二样本缺陷图像与第一样本缺陷图像不同,初始检测模型包含第一权重参数集,第一权重参数集中包含初始检测模型中多个模型参数的第一权重参数,第一权重参数用于表征初始检测模型的模型参数的重要程度;
模型训练模块,用于基于第一采样图像集、第二训练图像集及第一权重参数对初始检测模型进行训练,以调整初始检测模型的多个模型参数,得到训练后的优化检测模型,其中,第一采样图像集合包含第一训练图像集中的部分样本缺陷图像,第一权重参数集用于限制初始检测模型中的模型参数的调整幅度。
本申请的另一方面提供了一种缺陷检测方法,包括:
获取待检测图像;
将待检测图像输入至优化检测模型中,其中,优化检测模型包括特征提取网络和分类网络,优化检测模型是利用上述任一的模型训练方法获得的;
基于优化检测模型中的特征提取网络对待检测图像进行特征提取,得到待检测图像特征;
基于分类网络对待检测图像特征进行缺陷分类,得到待检测图像的预测缺陷信息,其中,预测缺陷信息用于表征待检测图像中是否包含缺陷的分类结果。
本申请的另一方面提供了一种缺陷检测装置,包括:
待检测图像获取模块,用于获取待检测图像;
待检测图像输入模块,用于将待检测图像输入至优化检测模型中,其中,优化检测模型包括特征提取网络和分类网络,优化检测模型是利用上述任一的模型训练方法获得的;
待检测图像特征提取模块,用于基于优化检测模型中的特征提取网络对待检测图像进行特征提取,得到待检测图像特征;
待检测图像特征分类模块,用于基于分类网络对待检测图像特征进行缺陷分类,得到待检测图像的预测缺陷信息,其中,预测缺陷信息用于表征待检测图像中是否包含缺陷的分类结果。
再一方面,本申请实施例提供一种计算机设备,包括:
处理器、通信接口、存储器和通信总线;
其中,所述处理器、所述通信接口和所述存储器通过所述通信总线完成相互间的通信;所述通信接口为通信模块的接口;
所述存储器,用于存储计算机程序,并将所述计算机程序传输给所述处理器;处理器,用于调用存储器中计算机程序执行以上方面的方法。
又一方面,本申请实施例提供一种存储介质,所述存储介质用于存储计算机程序,所述计算机程序用于执行以上方面的方法。
又一方面,本申请实施例提供了一种包括计算机程序的计算机程序产品,当其在计算机上运行时,使得所述计算机执行以上方面的方法。
从以上技术方案可以看出,本申请实施例具有以下优点:
本申请提供了一种模型训练方法以及相关装置,模型训练方法通过使用部分已经训练过的历史训练数据(第一采样图像集)和全量新增的训练数据(第二训练图像集)对初始检测模型进行训练,相比于使用全量的历史训练数据与全量新增的训练数据对初始检测模型进行训练更节省时间、降低对GPU卡时的消耗;通过自适应评估模型参数重要程度的第一权重参数集,在训练阶段限制训练数据对一些重要的模型参数的更新幅度,由于这些重要的模型参数对第一训练图像集合中所涉及缺陷的准确识别具有重要影响,基于第一权重参数集的准确指示,这些模型参数的参数调整的范围会相对局限,从而解决了只使用全量新增的训练数据对模型进行微调造成的知识遗忘的问题,提高了检测模型的学习能力,增强了检测模型对于缺陷识别的识别效果及准确性。
本申请还提供了一种缺陷检测方法以及相关装置,通过上述模型训练方法得到的优化检测模型对待检测图像中的缺陷进行检测,得到待检测图像中是否包含缺陷的分类结果,提高了缺陷识别的识别效果及准确性。
附图说明
图1为本申请某一实施例提供的模型训练系统的一个架构示意图;
图2为本申请某一实施例提供的模型训练方法的流程图;
图3为本申请另一实施例提供的模型训练方法的流程图;
图4为本申请另一实施例提供的模型训练方法的流程图;
图5为本申请另一实施例提供的模型训练方法的流程图;
图6为本申请另一实施例提供的模型训练方法的流程图;
图7为本申请另一实施例提供的模型训练方法的流程图;
图8为本申请另一实施例提供的模型训练方法的流程图;
图9为本申请又一实施例提供的模型训练方法的流程图;
图10为本申请某一实施例提供的缺陷检测方法的流程图;
图11为本申请某一实施例提供的模型训练装置的结构示意图;
图12为本申请另一实施例提供的模型训练装置的结构示意图;
图13为本申请又一实施例提供的模型训练装置的结构示意图;
图14为本申请某一实施例提供的缺陷检测装置的结构示意图;
图15为本申请某一实施例提供的服务器结构示意图。
具体实施方式
本申请实施例提供了一种模型训练方法,通过使用部分已经训练过的历史训练数据(第一采样图像集)和全量新增的训练数据(第二训练图像集)对初始检测模型进行训练,相比于使用全量的历史训练数据与全量新增的训练数据对初始模型进行训练更节省时间、降低对GPU卡时的消耗;通过自适应评估模型参数的对应的第一权重,限制对历史训练数据对模型参数的更新,解决了只使用全量新增数据对模型进行微调造成的知识遗忘的问题,提高了检测模型的学习能力,通过使用模型训练方法得到的优化检测模型对待检测图像中的缺陷进行检测,提高了缺陷识别的识别效果及准确性。
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例例如能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“对应于”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
本申请实施例中,术语“模块”或“单元”是指有预定功能的计算机程序或计算机程序的一部分,并与其他相关部分一起工作以实现预定目标,并且可以通过使用软件、硬件(如处理电路或存储器)或其组合来全部或部分实现。同样的,一个处理器(或多个处理器或存储器)可以用来实现一个或多个模块或单元。此外,每个模块或单元都可以是包含该模块或单元功能的整体模块或单元的一部分。
为便于理解本申请实施例提供的技术方案,这里先对本申请实施例使用的一些关键名词进行解释:
缺陷检测技术:根据采集图像,判断采集图像中存在何种缺陷的技术。在现代工业制造中,生产的各类零部件中不可避免会有一定概率出现不良品,通过缺陷检测技术检测出不良品,对于改良生产工艺,提高工厂效益具有重要作用。
增量学习:是指一个学习系统能不断地从新样本中学习新的知识,并能保存大部分以前已经学习到的知识。增量学习非常类似于人类自身的学习模式。因为人类在成长过程中,每天学习和接收新的事物,学习是逐步进行的,而且,对已经学习到的知识,人类一般是不会遗忘的。在本申请实施例中,对于缺陷检测模型的训练就用到了增量学习,由于缺陷数量在不同生产周期是不断更新的,缺陷检测模型也需要不断从新的缺陷图像中学习知识。
增量学习包括数据增量场景和类别增量场景。
数据增量场景:指不同增量阶段间,数据类别分布大致无差异,只是单纯新增数据量的场景。在本申请实施例中,对于缺陷检测模型的训练就用到了数据增量学习,由于缺陷数量在不同生产周期是不断更新的,缺陷检测模型也需要不断从新的缺陷图像中学习知识。
类别增量场景:指不同增量阶段间,数据类别不重叠的场景。
全量数据模型:指利用已积累的所有数据进行模型训练迭代得到的深度学习模型。
增量数据模型:指使用少量已有数据及新增数据或者不使用已有数据只使用新增数据训练迭代得到的模型。
灾难性遗忘:灾难性遗忘是指在增量学习中,当模型学习新任务时,会遗忘之前学习的任务的能力。具体来说,当模型在学习新任务时,它会调整自己的参数,以适应新任务的需求。但是,这些参数的调整可能会导致模型在之前学习的任务上的表现下降,甚至完全遗忘之前学习的任务。灾难性遗忘是增量学习中的一个重要问题,它限制了增量学习的应用范围。灾难性遗忘的原因主要有两个:一是参数冲突,即新任务的参数调整与旧任务的参数调整发生冲突,导致旧任务的信息被遗忘;二是表示空间限制,即模型的表示空间有限,无法同时表示多个任务的信息。
下面对本申请实施例的设计思想进行简要介绍:
在工业制造中,企业所生产的各类零部件中不可避免会有一定概率出现不良品。一方面,为保证产品质量,企业必须将不良品检出以进行后续处理;另一方面,找到不良品并且分析各类缺陷形态特征及占比,对于改良生产工艺、提高产线良率至关重要。
在传统工业制造过程中,企业多采用人工观察的方式对产品进行缺陷检测和分类。然而对于质检人员而言,存在工作强度大与工作内容单一的问题,导致员工流失率大;对于企业而言,存在检测成本大(人员成本)、质检效率低等问题。而机器学习技术,在数据量充足的情况下,可超越人工质检准确率,极大程度地替换人工质检,为企业降本增效。
目前,基于深度学习的缺陷检测技术已经能够达到较高的精度,具体地,预先获取大量的训练数据进行模型训练,然后使用训练得到的神经网络模型进行缺陷检测。以对带钢进行工业质检为例,在对带钢进行工业质检过程中,常常通过对带钢图片进行缺陷检测,以实现对带钢的缺陷检测识别。具体的,基于深度学习的缺陷检测方法,通过对大量带钢图像数据进行训练,来建立缺陷检测模型,通过缺陷检测模型对带钢表面的图像进行分析和识别来检测缺陷。
由于现有的普通的机器学习技术是批量学习模式,即假设在训练之前所有训练样本一次都可以得到,学习这些样本之后,学习过程就终止了,不再学习新的知识,随着工业质检项目的进行,所收集到的用于训练深度学习模型的数据量会呈现逐步增大的情况。对于同一个缺陷类别,需要将历史的训练数据与新增的数据统一进行整理,并在获得的全量训练数据下,重新训练新的模型,以保证新的模型能够对该类别的缺陷进行准确的识别。
在相关技术中,主要采用两种技术方案:使用全量训练数据进行模型迭代和使用增量数据进行模型微调。
其中,使用全量训练数据进行模型迭代是指,在全量数据增量场景中,使用对当前模型进行训练的全量历史训练数据与新增数据共同作为模型的全部训练数据对模型进行迭代训练,这种方法可以稳定地提升和迭代模型,但随着数据量的增加,训练时间和成本也会增加,如果数据量很大,训练所需的计算资源和时间成本都很高
使用增量数据进行模型微调是指,只利用新增数据对已有模型进行微调。因此,在训练模型时,为了保持模型已有的能力,可以使用较小的学习率或仅训练深度学习模型的最后几层。由于微调没有使用过去的历史数据,虽然减小了学习率和训练参数范围,模型仍然存在遗忘已学知识的风险,导致整体能力下降并过拟合到当前数据上。随着微调次数的增加,这种风险会显著增加。
为了解决由于使用全量数据进行模型迭代时,训练所需的计算资源和时间成本较高的问题,以及使用增量数据进行模型微调时,导致对历史数据发生灾难性的遗忘,进而导致模型整体能力快速下降,不够稳定的问题,迁移学习算法和增量学习算法应运而生。
迁移学习是将一个模型的能力迁移到目标数据域上的方法,通常目标数据域与模型原来的数据域有较大差异,并且不考虑原有数据域上的表现。因此,迁移学习后的模型在原有数据上的效果通常会大幅下降。而在本申请实施例所处理的实际业务中,新增数据通常与原始数据并没有太大的域上改变,且业务中实际要求一定要保持在原有数据上的性能,因此该类方法并不适用。
增量学习主要用于增量任务学习,尽管数据增量是其中的一个特殊形式,但相关研究较少。现有的迁移学习和增量学习技术在实际业务场景中都没有取得良好的效果,并且在应用上较为复杂。
有鉴于此,本申请提供了一种模型训练方法以及相关装置。模型训练方法包括:首先,获取第一训练图像集、第二训练图像集及初始检测模型,其中,初始检测模型为基于第一训练图像集训练得到的,第一训练图像集包括样本缺陷图像,第二训练图像集包含样本缺陷图像且与第一训练图像集包含的样本缺陷图像不同,初始检测模型包含第一权重参数集,第一权重参数集中包含初始检测模型中多个模型参数的第一权重参数,第一权重参数用于表征初始检测模型的模型参数的重要程度;然后,基于第一采样图像集、第二训练图像集及第一权重参数对初始检测模型进行训练,以调整初始检测模型的模型参数,得到训练后的优化检测模型,其中,第一采样图像集合包含第一训练图像集中的部分样本缺陷图像,第一权重参数集用于限制初始检测模型中的模型参数的调整范围。本申请实施例提供的模型训练方法,通过使用部分已经训练过的第一采样图像集和全量新增的第二训练图像集对初始检测模型进行训练,相比于使用全量的历史训练数据与全量新增的训练数据对初始模型进行训练更节省时间、降低对GPU卡时的消耗;通过自适应评估模型参数的对应的第一权重,限制对历史训练数据对模型参数的更新,相比于只使用全量新增数据对模型进行微调造成的知识遗忘的问题,提高了模型的学习能力,增强了模型对于缺陷识别的识别效果及准确性。
此外,本申请实施例还提供了一种缺陷检测方法以及相关装置,缺陷检测方法包括:首先,获取待检测图像;接着,将待检测图像输入至优化检测模型中,其中,优化检测模型包括特征提取网络和分类网络,优化检测模型是利用如上述的模型训练方法获得的;然后,基于优化检测模型中的特征提取网络对待检测图像进行特征提取,得到待检测图像特征;最后,基于分类网络对待检测图像特征进行缺陷分类,得到待检测图像的预测缺陷信息,其中,预测缺陷信息用于表征待检测图像中是否包含缺陷的分类结果。本申请实施例提供的缺陷检测方法,通过模型训练方法得到的优化检测模型对待检测图像中的缺陷进行检测,得到待检测图像中是否包含缺陷的分类结果,提高了缺陷识别的识别效果及准确性。
为了便于理解,请参阅图1,图1为本申请实施例中模型训练方法或缺陷检测方法的应用环境图,如图1所示,本申请实施例中模型训练方法应用于模型训练系统,缺陷检测方法应用于缺陷检测系统。模型训练系统包括:服务器和终端设备;其中,服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、内容分发网络(Content Delivery Network,CDN)、以及大数据和人工智能平台等基础云计算服务的云服务器。终端可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表等,但并不局限于此。终端和服务器可以通过有线或无线通信方式进行直接或间接地连接,本申请实施例在此不做限制。
服务器首先获取第一训练图像集、第二训练图像集及初始检测模型,其中,初始检测模型为基于第一训练图像集训练得到的,第一训练图像集包括样本缺陷图像,第二训练图像集包含样本缺陷图像且与第一训练图像集包含的样本缺陷图像不同,初始检测模型包含第一权重参数集,第一权重参数集中包含初始检测模型中多个模型参数的第一权重参数,第一权重参数用于表征初始检测模型的模型参数的重要程度;然后,服务器基于第一采样图像集、第二训练图像集及第一权重参数对初始检测模型进行训练,以调整初始检测模型的模型参数,得到训练后的优化检测模型,其中,第一采样图像集合包含第一训练图像集中的部分样本缺陷图像,第一权重参数集用于限制初始检测模型中的模型参数的调整范围。
下面将从服务器的角度,对本申请中模型训练方法进行介绍。请参阅图2,本申请实施例提供的模型训练方法包括:步骤S110至步骤S120。具体的:
S110、获取第一训练图像集、第二训练图像集及初始检测模型。
其中,初始检测模型为基于第一训练图像集训练得到的,第一训练图像集包括第一样本缺陷图像,第二训练图像集包含第二样本缺陷图像且第二样本缺陷图像与第一样本缺陷图像不同,初始检测模型包含第一权重参数集,第一权重参数集中包含初始检测模型中多个模型参数的第一权重参数,第一权重参数用于表征初始检测模型的多个模型参数的重要程度。
可以理解的是,第一训练图像集包含了至少一张第一样本缺陷图像,这些图像是用于训练得到初始检测模型的基础数据。第二训练图像集包括在生产周期内采样得到的至少一张第二样本缺陷图像,它包含了在实际使用初始检测模型进行缺陷检测的过程中出现的过杀和漏检情况的数据。初始检测模型是已经基于第一训练图像集进行训练得到的模型,它具有特征提取网络和分类网络,可以对图像中的产品质量缺陷进行识别。具体的:
第一训练图像集中的样本缺陷图像是在训练得到初始检测模型时的全量训练数据。初始检测模型为基于第一训练图像集训练得到的,初始检测模型可以实现对图像中的产品例如带钢的缺陷进行识别。初始检测模型包括特征提取网络和分类网络,特征提取网络用于对输入至初始检测模型中的图像进行特征提取,而分类网络用于对图像特征进行分类,以得到图像中的产品是否包含缺陷的预测结果。初始检测模型中的分类网络具有第一权重参数集,该第一权重参数集可以是矩阵形式,还可以是集合形式,第一权重参数集中包括多个第一权重参数,每个权重参数对应于分类网络中的一个模型参数,因此,第一权重参数用于表征初始检测模型的模型参数对质量缺陷识别的重要程度。
将该初始检测模型上线部署后,随着初始检测模型的使用,会产生一些过杀和漏检情况。过杀是指初始检测模型将正常的产品或样本错误地判断为有缺陷或不合格的情况,这意味着初始检测模型对正常的产品进行了过度的判断,导致误判为有问题的产品。漏检是指初始检测模型未能检测出实际存在缺陷或不合格的产品或样本,这意味着模型错过了一些应该被检测出来的问题产品,导致漏检的情况发生。这些过杀和漏检情况所产生的数据数量相比初始检测模型上线前进行训练的第一训练图像集中的数据的数量较少,但是这些数据对于初始检测模型的优化和性能的提升还是至关重要的。因此,当初始检测模型上线使用一段时间后,对生产周期内的过杀和漏检情况进行统计和采样,得到第二训练图像集。
S120、基于第一采样图像集、第二训练图像集及第一权重参数对初始检测模型进行训练,以调整初始检测模型的多个模型参数,得到训练后的优化检测模型。
其中,第一采样图像集合包含第一训练图像集中的部分样本缺陷图像,第一权重参数集用于限制初始检测模型中的模型参数的调整幅度。
可以理解的是,第一采样图像集是根据采样比例对第一训练图像集中的样本缺陷图像进行采样得到的。采样的目的是为了减少训练数据的规模,同时保留重要的信息。通过第一训练图像集采样后得到的第一采样图像集中的样本缺陷图像与第二训练图像集中的样本缺陷图像共同作为初始检测模型的训练样本,对初始检测模型进行进一步训练,相比于使用全量的第一训练图像集与第二训练图像集对初始检测模型进行训练,减少了对初始模型进行训练的时间、降低对GPU卡时的消耗。
通过第一采样图像集、第二训练图像集对初始检测模型进行微调,以得到训练后的优化检测模型。在对初始检测模型进行微调的过程中,对于那些在初始检测模型中非常重要的模型参数,即对第一训练图像集合中所涉及缺陷的准确识别具有重要影响的模型参数,在本次训练中,在第一权重参数集的准确指示下,这些模型参数的参数调整的范围会相对局限,使得训练后的优化检测模型不会过度遗忘之前已经学习到的知识,维持对原本能够识别的缺陷的识别精度。因此,通过第一权重参数集对初始检测模型中的模型参数的更新进行针对性限制,限制初始检测模型中重要模型参数的更新幅度,确保在微调过程中不会过度遗忘之前学习到的知识,通过这种方式得到的优化检测模型,能够对原本初始检测模型会过杀和漏检情况做出正确的检测结果,提高缺陷检测的准确性。
初始模型中的模型参数,对于准确识别样本类别(例如是否有缺陷)来说,有些模型参数能起到决定性作用(重要程度高),有些可能作用不大(重要程度低)。即针对原本能够准确识别的输入图像(例如第一样本缺陷图像)来说,重要的模型参数如果出现大幅度的变化,会直接影响初始模型对这些图像的识别准确度。
一般来说,一个模型参数的第一权重参数所标识的重要程度越高,这个模型参数在模型训练阶段,能被调整的数值幅度就越小。
本申请实施例提供的方法,通过利用采样数据和权重限制来优化初始检测模型,以解决过杀和漏检问题,并提高模型的性能。这样的方法可以在有限的计算资源下,有效地改进模型的效果。在实际应用中,需要根据具体情况合理设置采样比例和训练策略,以达到最佳的检测效果。
为便于理解,假设在t时刻上线的初始检测模型为其中,t表示初始检测模型上线的时间节点,i表示初始检测模型中的模型参数,初始检测模型是在第一训练图像集D1:t中的全部样本缺陷数据上进行训练得到的。当初始检测模型上线部署一段时间以后,时间节点为t+1,对初始检测模型的过杀数据及漏检数据进行统计,得到第二训练图像集Dt+1。在相关技术中,一般会使用全量训练数据,即D1:t+Dt+1,而本申请实施例提供的方法,通过确定第一训练图像集的采样比例p%,通过采样比例p%从第一训练图像集D1:t中的样本缺陷图像进行采样,得到第一采样图像集。将第一采样图像集与第二训练图像集Dt+1合并在一起,构成新的训练数据D′t+1,通过第一采样图像集与第二训练图像集Dt+1合并在一起构成的训练数据D′t+1对初始检测模型为进行训练,以调整初始检测模型的模型参数,得到训练后的优化检测模型
本申请实施例提供的模型训练方法,通过使用部分已经训练过的第一训练图像集和全量新增的第二训练图像集对初始检测模型进行训练,相比于使用全量的历史训练数据与全量新增的训练数据对初始模型进行训练更节省时间、降低对GPU卡时的消耗;通过自适应评估模型参数的对应的第一权重,限制训练数据对一些重要的模型参数的更新幅度,相比于只使用全量新增数据对模型进行微调造成的知识遗忘的问题,提高了模型的学习能力,增强了模型对于缺陷识别的识别效果及准确性。
在本申请的图2对应的实施例提供的模型训练方法的一个可选实施例中,请参阅图3,步骤S120还包括子步骤S121至步骤S123。具体的:
S121、获取基础检测模型的模型参数。
其中,初始检测模型为基于对基础检测模型的模型参数进行调整后得到的。例如,基于第一训练图像集对基础检测模型进行训练,可以得到初始检测模型。
可以理解的是,假设在t-1时刻上线的基础检测模型为其中,t-1表示基础检测模型上线的时间节点,i表示基础检测模型中的模型参数,基础检测模型是在之前所有的基础训练图像集Dt-1中的样本缺陷数据上进行训练得到的。当基础检测模型上线部署一段时间以后,时间节点为t,对过杀数据及漏检数据进行统计,得到第三训练图像集。通过确定基础训练图像集Dt-1的采样比例p%,通过采样比例p%从基础训练图像集Dt-1中的样本缺陷图像进行采样,得到第二采样图像集。将第二采样图像集与第三训练图像集合并在一起,构成新的训练数据,通过第二采样图像集与第三训练图像集合并在一起构成的新的训练数据对基础检测模型为进行训练,以调整基础检测模型的模型参数,得到训练后的初始检测模型
S122、根据第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,计算初始检测模型的目标函数。
可以理解的是,根据第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集来计算初始检测模型的目标函数,目标函数通常是用于评估模型性能的指标,它可以是准确率、误分类率、召回率等。计算目标函数的目的是为了定量地评估初始检测模型在第二训练图像集上的表现。
S123、基于初始检测模型的目标函数,对初始检测模型进行训练,以调整初始检测模型的模型参数。
为便于理解,初始检测模型的目标函数可以通过以下公式(1)计算:
其中,Lt+1表示时间节点为t+1对应的初始检测模型的目标函数。λ为可调节的超参数,用于控制检测模型的可塑性(对于t+1时刻的新任务的学习能力)和稳定性(对于t时刻的旧任务的记忆能力)。表示t时刻初始检测模型对应的第一权重参数集,第一权重参数集包括初始检测模型中多个模型参数的第一权重参数,第一权重参数用于表征初始检测模型的模型参数的重要程度,通过第一权重可以衡量初始检测模型的多个模型参数对于旧任务的重要性,该重要性权重迭代得到。表示t时刻的初始检测模型的模型参数。表示t-1时刻的基础检测模型的模型参数。p(D′t+1|θ)表示概率函数。D′t+1表示第一采样图像集与第二训练图像集Dt+1合并在一起构成的数据。θ表示基础检测模型的模型参数。
当通过第二训练图像集Dt+1对初始检测模型进行微调得到优化检测模型后,在全部的epoch中对全量训练数据均进行计算,以保证全量训练数据都会被访问到,进而学习模型参数对于当前任务的重要性。此时,每次迭代都由一次前向传播和一次反向传播构成,但需要注意的是,在学习参数重要性过程中,反向传播时模型不会根据梯度下降算法进行更新。
本申请实施例提供的方法,通过目标函数对初始检测模型进行更精细的调整和优化。目标函数的计算提供了对模型在特定数据集上表现的定量评估。这样的过程可以帮助我们找到更优的模型配置,提高模型的准确性和可靠性。在实际应用中,需要根据具体的问题和数据特点选择合适的目标函数和权重计算方法。同时,也需要进行多次实验和验证,以找到最优的参数设置和模型结构。这些步骤的精细调整和优化是为了使模型在实际应用中能够更好地适应数据的变化和需求,提高其性能和泛化能力。
在本申请的图3对应的实施例提供的模型训练方法的一个可选实施例中,请参阅图4,子步骤S122进一步包括子步骤S1221至子步骤S1224。具体的:
S1221、根据第一采样图像集及第二训练图像集,生成初始检测模型的增量数据目标函数作为第一优化项。
可以理解的是,初始检测模型的增量数据目标函数可以通过以下公式(2)计算:
LZT=-logp(D′t+1|θ)          (2);
其中,p(D′t+1|θ)表示概率函数。D′t+1表示第一采样图像集与第二训练图像集Dt+1合并在一起构成的数据。θ表示检测模型的基础模型参数。
该增量数据目标函数可以体现出在由第一采样图像集及第二训练图像集所构成的训练样本,对初始检测模型进行训练时的损失函数。
S1222、计算初始检测模型的模型参数与基础检测模型的模型参数的参数差。
可以理解的是,初始检测模型的模型参数与基础检测模型的模型参数的参数差可以体现出两个检测模型的模型参数间的参数数值差异。
初始检测模型的模型参数与基础检测模型的模型参数的参数差可以通过以下公式(3)计算:
其中,θi表示初始检测模型的模型参数与基础检测模型的模型参数的参数差,表示t时刻的初始检测模型的模型参数。表示t-1时刻的基础检测模型的模型参数。
S1223、根据所述第一权重参数、所述参数差和超参数生成第二优化项。
所述第二优化项用于限制重要参数在训练中的调整幅度,所述重要参数为通过所述第一权重参数标识,所述超参数用于标识所述第二优化项在训练所述初始检测模型时的影响程度。
S1224、根据所述第一优化项和所述第二优化项构建所述初始检测模型的目标函数。
可以理解的是,超参数λ为可调节的超参数,用于控制检测模型的可塑性(对于t+1时刻的新任务的学习能力)和稳定性(对于t时刻的旧任务的记忆能力)。
可选的,可通过如下方式,根据所述第一权重参数、所述参数差和超参数生成第二优化项,以及根据第一优化项和第二优化项构建目标函数:
将超参数、第一权重参数与参数差的平方结果相乘,将相乘结果与初始检测模型的增量数据目标函数相加,得到初始检测模型的目标函数。
可以理解的是,初始检测模型的目标函数可以通过以下公式(4)计算:
其中,Lt+1表示时间节点为t+1对应的初始检测模型的目标函数。λ为可调节的超参数。表示t时刻初始检测模型对应的第一权重参数集,通过第一权重参数集可以衡量初始检测模型的模型参数对于旧任务的重要性,该第一权重参数集中的权重参数可以迭代得到。表示t时刻的初始检测模型的模型参数。表示t-1时刻的基础检测模型的模型参数。p(D′t+1|θ)表示概率函数。D′t+1表示第一采样图像集与第二训练图像集Dt+1合并在一起构成的数据。θ表示检测模型的基础模型参数。
本申请实施例提供的方法,通过对采样数据的处理、模型参数的比较和权重的应用,来计算出初始检测模型的目标函数。这个目标函数可以作为评估模型性能的指标,帮助我们了解模型在特定数据集上的表现,并指导进一步的优化和改进。这样的计算过程可以帮助我们更准确地评估和改进检测模型,以提高其性能和准确性。
在本申请的图3对应的实施例提供的模型训练方法的一个可选实施例中,请参阅图5,步骤S122还包括子步骤S124至步骤S125。
S124、获取裁切阈值。
其中,裁切阈值用于表征对初始检测模型进行参数更新时的梯度阈值,以限制对初始检测模型进行参数更新时的梯度范围。
S125、根据裁切阈值、第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集、第二训练图像集,构建初始检测模型的目标函数。
优选的,步骤S125包括以下3个子步骤:
步骤1)、计算第一权重参数的根式,以及计算初始检测模型的模型参数与基础检测模型的模型参数的参数差,将第一权重参数的根式与参数差相乘,得到第一计算值;
步骤2)、若第一计算值小于等于裁切阈值时,根据第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,计算初始检测模型的目标函数;
步骤3)、若第一计算值大于裁切阈值时,根据裁切阈值、第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,计算初始检测模型的目标函数。
可以理解的是,初始检测模型的目标函数可以通过以下公式(5)计算:
公式(5)中的超参数λ实际是在平衡对旧任务的记忆能力和对新任务的学习能力,即用于控制检测模型的可塑性(对于t+1时刻的新任务的学习能力)和稳定性(对于t时刻的旧任务的记忆能力)。当λ=0时,模型的优化实际就是最普通的微调,这会导致灾难性遗忘。而当λ等于正无穷时,新模型会一直保持与旧模型一模一样的参数,因此模型无法学习到新任务的知识。在实际业务中,本申请尝试了λ取0.2,0.4,1,2等值,发现模型准确性会越来越好。但是当λ取值达到10时,训练将变得极其不稳定,这使得本申请无法继续寻找新旧任务间的最佳平衡。通过进一步观察,在训练梯度爆炸前,某些参数的梯度会变得非常大。
以公式(5)中单独的一个参数θ为例,二次项的关于θ梯度是由于不同任务间的数据分布差异较大,因此在增量微调的初始阶段模型参数会快速地根据新数据分布进行适配变化,此时梯度非常容易剧烈增长导致最终梯度爆炸。为了解决这样的问题,本申请采用如下方式来将梯度限制在一个合理的范围内。具体地,将公式(5)中的二次项替换为公式(6):
其中,β是一个超参数,代表一个预先设定的裁切阈值,也就是说当梯度超过这一阈值时,将需要采取限制措施。
因此,在计算初始检测模型的目标函数时需要进行分情况计算,具体的,首先计算第一权重参数的根式,以及计算初始检测模型的模型参数与基础检测模型的模型参数的参数差,将第一权重参数的根式与参数差相乘,得到第一计算值;若第一计算值小于等于裁切阈值时,根据第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,计算初始检测模型的目标函数;若第一计算值大于裁切阈值时,根据裁切阈值、第一权重参数的根式、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,计算初始检测模型的目标函数。
初始检测模型的目标函数可以通过以下公式(7)表示:
公式(6)对θ求导,可以得到以下公式(8):
从公式(8)中可知,梯度被有效限制在了范围内,且当 时,初始检测模型的目标函数可以使用公式(7)进行计算。通过上述改造后,公式(7)中的λ可取较大值,以使得模型有更好的性能,同时也不会发生梯度爆炸。
对于λ较大时出现梯度爆炸的问题,也可以通过梯度裁剪的方式,具体的可以通过以下公式(9)实现:
其中,g是损失函数关于参数θ的梯度向量,gi表示该向量中的某一项,βg是g的范数的裁剪阈值。通过公式(9)虽然也能起到防止梯度爆炸的作用,但最终模型的学习效果不如公式(6)及公式(7)的效果,其原因在于,在公式(9)中所有的参数的梯度裁剪是耦合到一起的,且裁剪比例是固定的;而使用公式(7)的方案是解耦的,每个梯度是否裁剪以及裁剪后的值均与其他梯度无关,只取决于当前参数对旧任务的重要性。
本申请实施例提供的方法,通过目标函数的计算对优化检测模型进行更精细的调整和优化。目标函数的计算提供了对模型在特定数据集上表现的定量评估。这样的过程可以帮助我们找到更优的模型配置,提高模型的准确性和可靠性。在实际应用中,需要根据具体的问题和数据特点选择合适的目标函数和权重计算方法。同时,也需要进行多次实验和验证,以找到最优的参数设置和模型结构。这些步骤的精细调整和优化是为了使模型在实际应用中能够更好地适应数据的变化和需求,提高其性能和泛化能力。
在本申请的图3对应的实施例提供的模型训练方法的一个可选实施例中,请参阅图6,步骤S120之后还包括步骤S130,具体的:
S130、根据初始检测模型的目标函数及第一权重参数集,计算优化检测模型的第二权重参数集。
其中,第二权重参数集中包含优化检测模型中多个模型参数的第二权重参数,第二权重参数用于表征优化检测模型的模型参数的重要程度,第二权重参数集用于限制优化检测模型中的模型参数的调整范围。
可以理解的是,第二权重参数集的计算是基于目标函数和第一权重参数集计算得到的,它反映了优化检测模型的性能以及不同模型参数对性能的影响,通过计算第二权重参数集,可以进一步调整和优化模型的参数重要性,以提高模型的性能和泛化能力,并对后续优化检测模型的训练提供基础。在后续通过新增的训练数据进行模型迭代时,需要计算每一个迭代后的模型对应的权重参数,以在模型迭代时限制模型参数的调整范围。
优化检测模型对应的第二权重参数集可以通过以下公式(10)计算:
其中,表示优化检测模型对应的第二权重参数集,表示初始检测模型对应的第一权重参数集,该第一权重参数集同样可以通过公式(10)迭代得到,j表示损失的个数,表示对目标函数进行求导。表示第二训练图像集对于优化检测模型的模型参数的重要程度的权重矩阵,将该权重矩阵与初始检测模型的模型参数的重要程度的权重矩阵累加,得到优化检测模型的模型参数的重要程度的权重矩阵即第二权重参数集,该权重矩阵代表对于所有已学习的任务而言的参数重要程度。当在t+2时刻对初始检测模型进行模型微调时,该权重矩阵用于更好地记住时刻1到时刻t+1的知识。
当通过第二训练图像集Dt+1对初始检测模型进行微调得到优化检测模型后,在全部的epoch中对全量训练数据均进行了计算,以保证全量训练数据都会在训练过程中被访问到,进而学习模型参数对于当前任务的重要性。此时,每次迭代都由一次前向传播和一次反向传播构成,但需要注意的是,在学习参数重要性过程中,反向传播时模型不会根据梯度下降算法进行更新。
本申请实施例提供的方法,通过第二权重参数集的确定,对优化检测模型进行更精细的调整和优化。而第二权重参数集的计算则根据评估结果对模型的参数重要性进行调整。这样的过程可以帮助我们找到更优的模型配置,提高模型的准确性和可靠性。在实际应用中,需要根据具体的问题和数据特点选择合适的目标函数和权重计算方法。同时,也需要进行多次实验和验证,以找到最优的参数设置和模型结构。这些步骤的精细调整和优化是为了使模型在实际应用中能够更好地适应数据的变化和需求,提高其性能和泛化能力。
在本申请的图6对应的实施例提供的模型训练方法的一个可选实施例中,请参阅图7,步骤S130进一步包括子步骤S131至子步骤S132。具体的:
S131、对初始检测模型的目标函数进行多次损失计算,得到多个第三权重参数集。
其中,损失计算是通过对初始检测模型的目标函数进行导数计算,第三权重参数集中包含多个第三权重参数,第三权重参数用于表征针对正确识别所述第二训练图像集,所述初始检测模型的模型参数的重要程度。
其中第三权重参数集的数量可以与损失计算的次数相关,例如每一次损失计算,可以得到一个对应的第三权重参数集。
可以理解的是,第三权重参数集为第二训练图像集对于优化检测模型的模型参数的重要程度的权重矩阵,可以通过以下公式(11)表示:
其中,表示对目标函数进行求导。
S132、将多个第三权重参数集与第一权重参数集相加,得到优化检测模型对应的第二权重参数集。
可以理解的是,优化检测模型对应的第二权重参数集可以通过以下公式计算:
其中,表示优化检测模型对应的第二权重参数集,表示初始检测模型对应的第一权重参数集,该第一权重同样可以通过公式(12)迭代得到,j表示损失的个数,表示对目标函数进行求导。表示第二训练图像集对于优化检测模型的模型参数的重要程度的权重矩阵,将该权重矩阵与初始检测模型的模型参数的重要程度的权重矩阵累加,得到优化检测模型的模型参数的重要程度的权重矩阵即第二权重参数集,该权重矩阵代表对于所有已学习的任务而言的参数重要程度。当在t+2时刻对初始检测模型进行模型微调时,该权重矩阵用于更好地记住时刻1到时刻t+1的知识。
本申请实施例提供的方法,对优化检测模型的模型参数的重要性被更准确地评估,这有助于提高模型的性能和泛化能力。
在本申请的图2对应的实施例提供的模型训练方法的一个可选实施例中,请参阅图8,步骤S120进一步包括子步骤S126至步骤S129。具体的:
S126、获取对初始检测模型进行训练时训练批次对应的图像数量。
其中,图像数量为N,N为大于1的整数。
可以理解的是,训练批次对应的图像数是指训练batch图片数。
S127、从第一采样图像集中取K个第一样本缺陷图像,以及从第二训练图像集中取L个第二样本缺陷图像。
其中,K与L均为大于等于1的整数,且K+L=N。
可以理解的是,通过采样比例p%从第一训练图像集D1:t中的样本缺陷图像进行采样,得到第一采样图像集,第一采样图像集与第二训练图像集合并在一起构成新的训练数据。从第一采样图像集中取K个样本缺陷图像,以及从第二训练图像集中取L个样本缺陷图像,优选的,控制K与L尽可能相等,即:
其中,表示向下取整。
从第一采样图像集中取张图,从第二训练图像集中取张图,合并构成新的训练数据D′t+1。
S128、基于第一采样图像集中的K个第一样本缺陷图像、第二训练图像集中的L个第二样本缺陷图像及第一权重参数对初始检测模型进行迭代训练。
S129、将K个第一样本缺陷图像从第一采样图像集中删除,得到更新后的第一采样图像集。
其中,更新后的第一采样图像集作为迭代训练时的K个样本缺陷图像的采样集。
可以理解的是,为了在每次迭代训练时使用第一采样图像集中不同的K个样本缺陷图像,需要在每次取走K个样本缺陷图像后,将该次取走的K个样本缺陷图像从第一采样图像集中删除,以对第一采样图像集进行更新。
为便于理解,假设t+1时刻任务的全量新数据构成的第二训练图像集为Dt+1,而t时刻的全量历史训练数据构成的第一训练图像集为D1:t。相关技术中,全量数据模型为使用Dt+1+D1:t为训练数据得到的新模型,性能好,但是训练成本高;普通微调模型为使用Dt+1训练的模型,训练成本低但是性能最差,对于旧的训练数据会发生灾难性遗忘。本申请实施例为了使得能在新数据的迭代过程中,仅加入少量历史训练数据,进而降低训练成本,并且达到与使用全量数据基本相当的训练效果,采用对旧的训练数据进行动态平衡采样的策略。具体的,在每一个训练epoch中,本方法都会随机采样p%的第一训练图像集中的样本缺陷数据和第二训练图像集中的样本缺陷数据组成当前epoch的训练数据。之后在每次迭代中,会从第一训练图像集中的样本缺陷数据中采样得到第一采样图像集,从第一采样图像集与第二训练图像集中采样出1:1的历史的样本缺陷图像和新增的样本缺陷图像,组成一个batch用于模型参数更新。每个epoch随机采样能够保证每次训练用到的历史的样本缺陷图像处于一个动态的变化过程,从而尽可能地在整个任务训练完毕后(通常需要几十个epoch)保持模型已在旧任务数据下学到的能力或知识。每个batch中的1:1平衡采样有助于进一步提高模型性能,防止模型只在新任务或只在旧任务上表现优异。也改变每个batch中历史的样本缺陷图像与新的样本缺陷图像的比例为1:2或者2:1,但效果远不如1:1平衡采样。全量数据模型,由于其每个batch数据由历史数据和增量数据随机组成,因而在一个batch中历史数据和增量数据的比例接近于其整体数据比例。通常增量数据远小于历史数据,从而一定程度限制了这样训练得到的模型在新任务上的性能。反之,普通微调的模型,由于只使用新增数据,模型会完全向新增数据偏移,导致对旧任务的灾难性遗忘。本方法使用一种简单的方式,有效地避免了全量数据训练和普通模型微调存在的问题,同时大大降低了训练成本。
本申请实施例提供的方法,可以使得模型迭代更新的过程大大加快(降本),同时保持和全量数据模型相当的效果。随着业务数据的累积,全量数据模型训练所需时间不断增长,甚至几天才能完成一次训练。而本方法所提出的增量训练模式,训练时间能够维持在一个较低的水平,大大缩减GPU卡时。这是因为所提出的方法在每个epoch随机选取部分历史数据用于训练,保证了参与训练的历史数据的动态变化性。同时每个batch的训练中保持新旧数据1:1的比例,且通过动态权重限制的方法,限制对旧任务而言非常重要的参数的变化,从而使得模型在仅用少量历史数据的情况下,也不会发生灾难性遗忘,满足项目需求的同时大大降低了迭代成本。
在本申请的图2对应的实施例提供的模型训练方法的一个可选实施例中,请参阅图9,步骤S120之前还包括步骤S111至步骤S112。具体的:
S111、获取第一训练图像集的采样比例。
S112、根据采样比例对第一训练图像集中的样本缺陷图像进行采样,得到第一采样图像集。
可以理解的是,第一训练图像集的采样比例为预先设置的采样比例,目的在于从第一训练图像集中选出部分样本缺陷图像用于后续的对初始检测模型的训练过程。获取了第一训练图像集的采样比例,并根据该比例对第一训练图像集中的样本缺陷图像进行采样。采样的目的是为了减少训练数据的规模,同时保留重要的信息。
本申请实施例提供的方法,通过第一训练图像集采样后得到的第一采样图像集中的样本缺陷图像与第二训练图像集中的样本缺陷图像共同作为初始检测模型的训练样本对初始检测模型进行进一步训练,相比于使用全量的第一训练图像集与第二训练图像集进行训练,减少了对初始模型进行训练更节省时间、降低对GPU卡时的消耗。
下面将从服务器的角度,对本申请中缺陷检测方法进行介绍。请参阅图10,本申请实施例提供的缺陷检测方法包括:步骤S210至步骤S240。具体的:
S210、获取待检测图像。
可以理解的是,获取需要进行缺陷检测的待检测图像。
S220、将待检测图像输入至优化检测模型中。
其中,优化检测模型包括特征提取网络和分类网络,优化检测模型是利用上述的模型训练方法获得的。
可以理解的是,将获取到的待检测图像输入到优化检测模型中。优化检测模型是通过上述的模型训练方法得到的,它包括特征提取网络和分类网络。特征提取网络用于对输入的图像进行特征提取,而分类网络则用于对提取到的图像特征进行缺陷分类。
S230、基于优化检测模型中的特征提取网络对待检测图像进行特征提取,得到待检测图像特征。
可以理解的是,优化检测模型中的特征提取网络会对待检测图像进行处理,提取出图像中的关键特征。这些特征可以是图像的颜色、形状、纹理等信息,它们能够代表图像中的缺陷特征。
S240、基于分类网络对待检测图像特征进行缺陷分类,得到待检测图像的预测缺陷信息。
其中,预测缺陷信息用于表征待检测图像中是否包含缺陷的分类结果。
可以理解的是,分类网络会根据提取到的待检测图像特征进行缺陷分类,并输出预测缺陷信息。预测缺陷信息用于表征待检测图像中是否包含缺陷以及缺陷的类型。
本申请实施例提供的方法,通过将待检测图像输入到优化检测模型中,利用模型中的特征提取网络和分类网络进行处理和分析,最终得到待检测图像的预测缺陷信息。利用训练好的优化检测模型快速、自动地对待检测图像进行缺陷检测,提高检测效率和准确性。同时,优化检测模型可以通过不断的训练和更新来适应不同类型的缺陷和图像,提高模型的泛化能力。
下面对本申请中的模型训练装置进行详细描述,请参阅图11。图11为本申请实施例中模型训练装置10的一个实施例示意图,模型训练装置10包括:训练图像及初始模型获取模块110及模型训练模块120;具体的:
训练图像及初始模型获取模块110,用于获取第一训练图像集、第二训练图像集及初始检测模型,其中,初始检测模型为基于第一训练图像集训练得到的,第一训练图像集包括第一样本缺陷图像,第二训练图像集包含第二样本缺陷图像且第二样本缺陷图像与第一样本缺陷图像不同,初始检测模型包含第一权重参数集,第一权重参数集中包含初始检测模型中多个模型参数的第一权重参数,第一权重参数用于表征初始检测模型的多个模型参数的重要程度;
模型训练模块120,用于基于第一采样图像集、第二训练图像集及第一权重参数对初始检测模型进行训练,以调整初始检测模型的多个模型参数,得到训练后的优化检测模型,其中,第一采样图像集合包含第一训练图像集中部分的第一样本缺陷图像,第一权重参数集用于限制初始检测模型中的模型参数的调整幅度。
本申请实施例提供的模型训练装置,通过使用部分已经训练过的第一训练图像集和全量新增的第二训练图像集对初始检测模型进行训练,相比于使用全量的历史训练数据与全量新增的训练数据对初始模型进行训练更节省时间、降低对GPU卡时的消耗;通过自适应评估模型参数的对应的第一权重,限制对历史训练数据对模型参数的更新,相比于只使用全量新增数据对模型进行微调造成的知识遗忘的问题,提高了模型的学习能力,增强了模型对于缺陷识别的识别效果及准确性。
在本申请实施例的另一种实现方式中,模型训练模块120,还用于:
获取基础检测模型的模型参数,其中,初始检测模型为基于对基础检测模型的模型参数进行调整后得到的;
根据第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,构建初始检测模型的目标函数;
基于初始检测模型的目标函数,对初始检测模型进行训练,以调整初始检测模型的模型参数。
本申请实施例提供的装置,通过目标函数对初始检测模型进行更精细的调整和优化。目标函数的计算提供了对模型在特定数据集上表现的定量评估。这样的过程可以帮助我们找到更优的模型配置,提高模型的准确性和可靠性。在实际应用中,需要根据具体的问题和数据特点选择合适的目标函数和权重计算装置。同时,也需要进行多次实验和验证,以找到最优的参数设置和模型结构。这些步骤的精细调整和优化是为了使模型在实际应用中能够更好地适应数据的变化和需求,提高其性能和泛化能力。
在本申请实施例的另一种实现方式中,模型训练模块120,还用于:
根据第一采样图像集、第二训练图像集,生成初始检测模型的增量数据目标函数作为第一优化项;
计算初始检测模型的模型参数与基础检测模型的模型参数的参数差;
根据所述第一权重参数、所述参数差和超参数生成第二优化项,所述第二优化项用于限制重要参数在训练中的调整幅度,所述重要参数为通过所述第一权重参数标识,所述超参数用于标识所述第二优化项在训练所述初始检测模型时的影响程度;
根据所述第一优化项和所述第二优化项构建所述初始检测模型的目标函数。
本申请实施例提供的装置,通过对采样数据的处理、模型参数的比较和权重的应用,来计算出初始检测模型的目标函数。这个目标函数可以作为评估模型性能的指标,帮助我们了解模型在特定数据集上的表现,并指导进一步的优化和改进。这样的计算过程可以帮助我们更准确地评估和改进检测模型,以提高其性能和准确性。
在本申请实施例的另一种实现方式中,模型训练模块120,还用于:
获取裁切阈值,其中,裁切阈值用于表征对初始检测模型进行参数更新时的梯度阈值,以限制对所述初始检测模型进行参数更新时的梯度范围;
根据裁切阈值、所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集、所述第二训练图像集,构建初始检测模型的目标函数。
在本申请实施例的另一种实现方式中,模型训练模块120,还用于:
计算第一权重参数的根式,以及计算初始检测模型的模型参数与基础检测模型的模型参数的参数差,将第一权重参数的根式与参数差相乘,得到第一计算值;
若第一计算值小于等于裁切阈值时,根据第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,计算初始检测模型的目标函数;
若第一计算值大于裁切阈值时,根据裁切阈值、第一权重参数、初始检测模型的模型参数、基础检测模型的模型参数、第一采样图像集及第二训练图像集,计算初始检测模型的目标函数。
本申请实施例提供的装置,通过目标函数的计算对优化检测模型进行更精细的调整和优化。目标函数的计算提供了对模型在特定数据集上表现的定量评估。这样的过程可以帮助我们找到更优的模型配置,提高模型的准确性和可靠性。在实际应用中,需要根据具体的问题和数据特点选择合适的目标函数和权重计算装置。同时,也需要进行多次实验和验证,以找到最优的参数设置和模型结构。这些步骤的精细调整和优化是为了使模型在实际应用中能够更好地适应数据的变化和需求,提高其性能和泛化能力。
在本申请实施例的另一种实现方式中,请参阅图12,模型训练装置10,还包括:权重计算模130;具体的,权重计算模块130,用于:
根据初始检测模型的目标函数及第一权重参数集,计算优化检测模型的第二权重参数集,其中,第二权重参数集中包含优化检测模型中多个模型参数的第二权重参数,第二权重参数用于表征优化检测模型的模型参数的重要程度,第二权重参数集用于限制优化检测模型中的模型参数的调整范围。
本申请实施例提供的装置,通过第二权重的确定,对优化检测模型进行更精细的调整和优化。而第二权重的计算则根据评估结果对模型的参数重要性进行调整。这样的过程可以帮助我们找到更优的模型配置,提高模型的准确性和可靠性。在实际应用中,需要根据具体的问题和数据特点选择合适的目标函数和权重计算装置。同时,也需要进行多次实验和验证,以找到最优的参数设置和模型结构。这些步骤的精细调整和优化是为了使模型在实际应用中能够更好地适应数据的变化和需求,提高其性能和泛化能力。
在本申请实施例的另一种实现方式中,请参阅图12,权重计算模块130,还用于:
对初始检测模型的目标函数进行多次损失计算,得到多个第三权重参数集,其中,损失计算是通过对初始检测模型的目标函数进行导数计算,第三权重参数集中包含多个第三权重参数,第三权重参数用于表征针对正确识别所述第二训练图像集,所述初始检测模型的模型参数的重要程度;
将多个第三权重参数集与第一权重参数集相加,得到优化检测模型对应的第二权重参数集。
本申请实施例提供的装置,对优化检测模型的模型参数的重要性被更准确地评估,这有助于提高模型的性能和泛化能力。
在本申请实施例的另一种实现方式中,请参阅图11,模型训练模块120,还用于:
获取对初始检测模型进行训练时训练批次对应的图像数量,其中,图像数量为N,N为大于1的整数;
从第一采样图像集中取K个第一样本缺陷图像,以及从第二训练图像集中取L个第二样本缺陷图像,其中,K与L均为大于等于1的整数,且K+L=N;
基于第一采样图像集中的K个第一样本缺陷图像、第二训练图像集中的L个第二样本缺陷图像及第一权重参数对初始检测模型进行迭代训练。
将K个第一样本缺陷图像从第一采样图像集中删除,得到更新后的第一采样图像集,其中,更新后的第一采样图像集作为迭代训练时的K个第一样本缺陷图像的采样集。
本申请实施例提供的装置,可以使得模型迭代更新的过程大大加快(降本),同时保持和全量数据模型相当的效果。随着业务数据的累积,全量数据模型训练所需时间不断增长,甚至几天才能完成一次训练。而本装置所提出的增量训练模式,训练时间能够维持在一个较低的水平,大大缩减GPU卡时。这是因为所提出的装置在每个epoch随机选取部分历史数据用于训练,保证了参与训练的历史数据的动态变化性。同时每个batch的训练中保持新旧数据1:1的比例,且通过动态权重限制的装置,限制对旧任务而言非常重要的参数的变化,从而使得模型在仅用少量历史数据的情况下,也不会发生灾难性遗忘,满足项目需求的同时大大降低了迭代成本。
在本申请实施例的另一种实现方式中,请参阅图13,模型训练装置10,还包括:图像采样模块111;具体的,图像采样模块111,用于:
获取第一训练图像集的采样比例;
根据采样比例对第一训练图像集中的样本缺陷图像进行采样,得到第一采样图像集。
本申请实施例提供的装置,通过第一训练图像集采样后得到的第一采样图像集中的样本缺陷图像与第二训练图像集中的样本缺陷图像共同作为初始检测模型的训练样本对初始检测模型进行进一步训练,相比于使用全量的第一训练图像集与第二训练图像集进行训练,减少了对初始模型进行训练更节省时间、降低对GPU卡时的消耗。
下面对本申请中的缺陷检测装置进行详细描述,请参阅图14。图14为本申请实施例中缺陷检测装置20的一个实施例示意图,缺陷检测装置20包括:待检测图像获取模块210、待检测图像输入模块220、待检测图像特征提取模块230及待检测图像特征分类模块240;具体的:
待检测图像获取模块210,用于获取待检测图像;
待检测图像输入模块220,用于将待检测图像输入至优化检测模型中,其中,优化检测模型包括特征提取网络和分类网络,优化检测模型是利用如上述模型训练装置获得的;
待检测图像特征提取模块230,用于基于优化检测模型中的特征提取网络对待检测图像进行特征提取,得到待检测图像特征;
待检测图像特征分类模块240,用于基于分类网络对待检测图像特征进行缺陷分类,得到待检测图像的预测缺陷信息,其中,预测缺陷信息用于表征待检测图像中是否包含缺陷的分类结果。
本申请实施例提供的装置,通过将待检测图像输入到优化检测模型中,利用模型中的特征提取网络和分类网络进行处理和分析,最终得到待检测图像的预测缺陷信息。利用训练好的优化检测模型快速、自动地对待检测图像进行缺陷检测,提高检测效率和准确性。同时,优化检测模型可以通过不断的训练和更新来适应不同类型的缺陷和图像,提高模型的泛化能力。
图15是本申请实施例提供的一种服务器结构示意图,该服务器300可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(central processing units,CPU)322(例如,一个或一个以上处理器)和存储器332,一个或一个以上存储应用程序342或数据344的存储介质330(例如一个或一个以上海量存储设备)。其中,存储器332和存储介质330可以是短暂存储或持久存储。存储在存储介质330的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对服务器中的一系列指令操作。更进一步地,中央处理器322可以设置为与存储介质330通信,在服务器300上执行存储介质330中的一系列指令操作。
服务器300还可以包括一个或一个以上电源326,一个或一个以上有线或无线网络接口350,一个或一个以上输入输出接口358,和/或,一个或一个以上操作系统341,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。
上述实施例中由服务器所执行的步骤可以基于该图15所示的服务器结构。
另外,本申请实施例还提供了一种存储介质,所述存储介质用于存储计算机程序,所述计算机程序用于执行上述实施例提供的方法。
本申请实施例还提供了一种包括计算机程序的计算机程序产品,当其在计算机上运行时,使得计算机执行上述实施例提供的方法。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(read-only memory,ROM)、随机存取存储器(random access memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。

Claims (16)

  1. 一种模型训练方法,所述方法由计算机设备执行,所述方法包括:
    获取第一训练图像集、第二训练图像集及初始检测模型,其中,所述初始检测模型为基于第一训练图像集训练得到的,所述第一训练图像集包括第一样本缺陷图像,所述第二训练图像集包含第二样本缺陷图像且所述第二样本缺陷图像与所述第一样本缺陷图像不同,所述初始检测模型包含第一权重参数集,所述第一权重参数集中包含所述初始检测模型中多个模型参数的第一权重参数,所述第一权重参数用于表征所述初始检测模型的所述多个模型参数的重要程度;
    基于第一采样图像集、所述第二训练图像集及所述第一权重参数对所述初始检测模型进行训练,以调整所述初始检测模型的所述多个模型参数,得到训练后的优化检测模型,其中,所述第一采样图像集合包含所述第一训练图像集中部分的所述第一样本缺陷图像,所述第一权重参数集用于限制所述初始检测模型中的所述多个模型参数的调整幅度。
  2. 如权利要求1所述的模型训练方法,所述基于第一采样图像集、所述第二训练图像集及所述第一权重参数对所述初始检测模型进行训练,以调整所述初始检测模型的所述多个模型参数,包括:
    获取基础检测模型的模型参数,其中,所述初始检测模型为基于对所述基础检测模型的模型参数进行调整后得到的;
    根据所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集及所述第二训练图像集,构建所述初始检测模型的目标函数,其中;
    基于所述初始检测模型的目标函数,对所述初始检测模型进行训练,以调整所述初始检测模型的所述多个模型参数。
  3. 如权利要求2所述的模型训练方法,所述根据所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集、所述第二训练图像集,构建所述初始检测模型的目标函数,包括:
    根据所述第一采样图像集及所述第二训练图像集,生成所述初始检测模型的增量数据目标函数作为第一优化项;
    计算所述初始检测模型的模型参数与所述基础检测模型的模型参数的参数差;
    根据所述第一权重参数、所述参数差和超参数生成第二优化项,所述第二优化项用于限制重要参数在训练中的调整幅度,所述重要参数为通过所述第一权重参数标识,所述超参数用于标识所述第二优化项在训练所述初始检测模型时的影响程度;
    根据所述第一优化项和所述第二优化项构建所述初始检测模型的目标函数。
  4. 如权利要求2所述的模型训练方法,所述根据所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集、所述第二训练图像集,构建所述初始检测模型的目标函数,包括:
    获取裁切阈值,其中,所述裁切阈值用于表征对所述初始检测模型进行参数更新时的梯度阈值,以限制对所述初始检测模型进行参数更新时的梯度范围;
    根据所述裁切阈值、所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集、所述第二训练图像集,构建所述初始检测模型的目标函数。
  5. 如权利要求4所述的模型训练方法,所述根据所述裁切阈值、所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集、所述第二训练图像集,构建所述初始检测模型的目标函数,包括:
    计算所述第一权重参数的根式,以及计算所述初始检测模型的模型参数与所述基础检测模型的模型参数的参数差,将所述第一权重参数的根式与所述参数差相乘,得到第一计算值;
    若所述第一计算值小于等于所述裁切阈值时,根据所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集及所述第二训练图像集,计算所述初始检测模型的目标函数;
    若所述第一计算值大于所述裁切阈值时,根据所述裁切阈值、所述第一权重参数、所述初始检测模型的模型参数、所述基础检测模型的模型参数、所述第一采样图像集及所述第二训练图像集,计算所述初始检测模型的目标函数。
  6. 如权利要求1所述的模型训练方法,所述基于第一采样图像集、所述第二训练图像集及所述第一权重对所述初始检测模型进行训练,以调整所述初始检测模型的模型参数,得到训练后的优化检测模型之后,还包括:
    根据所述初始检测模型的目标函数及所述第一权重参数集,计算所述优化检测模型的第二权重参数集,其中,所述第二权重参数集中包含所述优化检测模型中多个模型参数的第二权重参数,所述第二权重参数用于表征所述优化检测模型的模型参数的重要程度,所述第二权重参数集用于限制所述优化检测模型中的模型参数的调整范围。
  7. 如权利要求6所述的模型训练方法,所述根据所述初始检测模型的目标函数及所述第一权重参数集,计算所述优化检测模型的第二权重参数集,包括:
    对所述初始检测模型的目标函数进行多次损失计算,得到多个第三权重参数集,其中,所述损失计算是通过对所述初始检测模型的目标函数进行导数计算,所述第三权重参数集中包含多个第三权重参数,所述第三权重参数用于表征针对正确识别所述第二训练图像集,所述初始检测模型的模型参数的重要程度;
    将所述多个第三权重参数集与所述第一权重参数集相加,得到所述优化检测模型对应的第二权重参数集。
  8. 如权利要求1所述的模型训练方法,所述基于所述第一采样图像集、所述第二训练图像集及所述第一权重对所述初始检测模型进行训练,包括:
    获取对所述初始检测模型进行训练时训练批次对应的图像数量,其中,所述图像数量为N,N为大于1的整数;
    从所述第一采样图像集中取K个所述第一样本缺陷图像,以及从所述第二训练图像集中取L个所述第二样本缺陷图像,其中,K与L均为大于等于1的整数,且K+L=N;
    基于所述第一采样图像集中的K个所述第一样本缺陷图像、所述第二训练图像集中的L个所述第二样本缺陷图像及所述第一权重参数对所述初始检测模型进行迭代训练。
  9. 如权利要求8所述的模型训练方法,所述从所述第一采样图像集中取K个所述第一样本缺陷图像之后,还包括:
    将所述K个所述第一样本缺陷图像从所述第一采样图像集中删除,得到更新后的第一采样图像集,其中,所述更新后的第一采样图像集作为迭代训练时的K个所述第一样本缺陷图像的采样集。
  10. 如权利要求1所述的模型训练方法,所述基于第一采样图像集、所述第二训练图像集及所述第一权重对所述初始检测模型进行训练,以调整所述初始检测模型的所述多个模型参数,得到训练后的优化检测模型之前,还包括:
    获取第一训练图像集的采样比例;
    根据所述采样比例对所述第一训练图像集中的样本缺陷图像进行采样,得到第一采样图像集。
  11. 一种缺陷检测方法,所述方法由执行,所述方法包括:
    获取待检测图像;
    将所述待检测图像输入至优化检测模型中,其中,所述优化检测模型包括特征提取网络和分类网络,所述优化检测模型是利用如权利要求1-10任一所述的模型训练方法获得的;
    基于所述优化检测模型中的特征提取网络对所述待检测图像进行特征提取,得到待检测图像特征;
    基于所述分类网络对所述待检测图像特征进行缺陷分类,得到所述待检测图像的预测缺陷信息,其中,所述预测缺陷信息用于表征待检测图像中是否包含缺陷的分类结果。
  12. 一种模型训练装置,包括:
    训练图像及初始模型获取模块,用于获取第一训练图像集、第二训练图像集及初始检测模型,其中,所述初始检测模型为基于第一训练图像集训练得到的,所述第一训练图像集包括第一样本缺陷图像,所述第二训练图像集包含第二样本缺陷图像且所述第二样本缺陷图像与所述第一样本缺陷图像不同,所述初始检测模型包含第一权重参数集,所述第一权重参数集中包含所述初始检测模型中多个模型参数的第一权重参数,所述第一权重参数用于表征所述初始检测模型的所述多个模型参数的重要程度;
    模型训练模块,用于基于第一采样图像集、所述第二训练图像集及所述第一权重参数对所述初始检测模型进行训练,以调整所述初始检测模型的所述多个模型参数,得到训练后的优化检测模型,其中,所述第一采样图像集合包含所述第一训练图像集中部分的所述第一样本缺陷图像,所述第一权重参数集用于限制所述初始检测模型中的所述多个模型参数的调整幅度。
  13. 一种缺陷检测装置,包括:
    待检测图像获取模块,用于获取待检测图像;
    待检测图像输入模块,用于将所述待检测图像输入至优化检测模型中,其中,所述优化检测模型包括特征提取网络和分类网络,所述优化检测模型是利用如权利要求1-10任一所述的模型训练方法获得的;
    待检测图像特征提取模块,用于基于所述优化检测模型中的特征提取网络对所述待检测图像进行特征提取,得到待检测图像特征;
    待检测图像特征分类模块,用于基于所述分类网络对所述待检测图像特征进行缺陷分类,得到所述待检测图像的预测缺陷信息,其中,所述预测缺陷信息用于表征待检测图像中是否包含缺陷的分类结果。
  14. 一种计算机设备,包括:存储器、处理器以及总线系统;
    其中,所述存储器用于存储程序;
    所述处理器用于执行所述存储器中的程序,包括执行如权利要求1至10中任一项所述的模型训练方法或如权利要求11所述的缺陷检测方法;
    所述总线系统用于连接所述存储器以及所述处理器,以使所述存储器以及所述处理器进行通信。
  15. 一种计算机可读存储介质,包括指令,当其在计算机上运行时,使得计算机执行如权利要求1至10中任一项所述的模型训练方法或如权利要求11所述的缺陷检测方法。
  16. 一种计算机程序产品,包括计算机程序,该计算机程序被处理器执行如权利要求1至10中任一项所述的模型训练方法或如权利要求11所述的缺陷检测方法。
PCT/CN2025/086114 2024-04-02 2025-03-31 一种模型训练方法、缺陷检测方法以及相关装置 Pending WO2025209385A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202410393625.2A CN117975204B (zh) 2024-04-02 2024-04-02 一种模型训练方法、缺陷检测方法以及相关装置
CN202410393625.2 2024-04-02

Publications (1)

Publication Number Publication Date
WO2025209385A1 true WO2025209385A1 (zh) 2025-10-09

Family

ID=90856670

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2025/086114 Pending WO2025209385A1 (zh) 2024-04-02 2025-03-31 一种模型训练方法、缺陷检测方法以及相关装置

Country Status (2)

Country Link
CN (1) CN117975204B (zh)
WO (1) WO2025209385A1 (zh)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121017912A (zh) * 2025-10-30 2025-11-28 济南东方结晶器有限公司 结晶器铜管的焊接方法、系统及存储介质
CN121103507A (zh) * 2025-11-13 2025-12-12 浙江丰利粉碎设备有限公司 一种竹粉粉碎加工成套机组控制方法及系统
CN121424608A (zh) * 2025-11-05 2026-01-30 陕西尊荣智能科技有限公司 一种机器人辅助的汽车注塑件缺陷分拣方法及系统
CN121437519A (zh) * 2025-12-31 2026-01-30 苏州深视信息科技有限公司 基于多维度的缺陷检测标注质量自动评估方法及系统
CN121485969A (zh) * 2025-10-23 2026-02-06 北京自然原数科技有限公司 网络传输数据的安全检测方法和装置

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113269255B (zh) * 2021-05-26 2025-09-05 全芯智造技术有限公司 用于检测缺陷的方法、设备和计算机可读存储介质
CN117975204B (zh) * 2024-04-02 2024-07-05 腾讯科技(深圳)有限公司 一种模型训练方法、缺陷检测方法以及相关装置
CN119091250A (zh) * 2024-08-28 2024-12-06 珠海博韬科技有限公司 一种工业缺陷检测预训练模型的微调方法
CN118897992A (zh) * 2024-10-09 2024-11-05 深圳思谋信息科技有限公司 缺陷检测模型训练方法、装置、计算机设备及存储介质
CN121707965A (zh) * 2025-12-16 2026-03-20 北京如易行科技有限公司 一种道路缺陷自适应检测方法和系统

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113269255A (zh) * 2021-05-26 2021-08-17 全芯智造技术有限公司 用于检测缺陷的方法、设备和计算机可读存储介质
WO2023155069A1 (zh) * 2022-02-16 2023-08-24 佛山市南海区广工大数控装备协同创新研究院 一种基于深度学习的手机电池表面缺陷检测方法
CN117197589A (zh) * 2023-11-03 2023-12-08 武汉大学 一种目标分类模型对抗训练方法及系统
CN117408959A (zh) * 2023-10-16 2024-01-16 重庆腾讯信息技术有限公司 模型的训练方法、缺陷检测方法、装置、电子设备及介质
CN117788925A (zh) * 2023-12-26 2024-03-29 深圳市凌云视迅科技有限责任公司 铝塑膜缺陷分类模型训练方法、装置及电子设备
CN117975204A (zh) * 2024-04-02 2024-05-03 腾讯科技(深圳)有限公司 一种模型训练方法、缺陷检测方法以及相关装置

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021126531A1 (en) * 2019-12-19 2021-06-24 Qeexo, Co. Automated machine vision-based defect detection
SE1930421A1 (en) * 2019-12-30 2021-07-01 Unibap Ab Method and means for detection of imperfections in products
CN111275104A (zh) * 2020-01-16 2020-06-12 重庆金山医疗技术研究院有限公司 一种模型训练方法、装置、服务器及存储介质
CN114387483B (zh) * 2022-01-06 2025-12-16 上海商汤智能科技有限公司 目标检测方法、模型的训练方法及装置、设备、存储介质
CN117036843B (zh) * 2022-09-09 2024-12-10 腾讯科技(深圳)有限公司 目标检测模型训练方法、目标检测方法和装置
CN117011630B (zh) * 2022-09-16 2024-08-06 腾讯科技(深圳)有限公司 一种目标检测模型的训练方法及装置

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113269255A (zh) * 2021-05-26 2021-08-17 全芯智造技术有限公司 用于检测缺陷的方法、设备和计算机可读存储介质
WO2023155069A1 (zh) * 2022-02-16 2023-08-24 佛山市南海区广工大数控装备协同创新研究院 一种基于深度学习的手机电池表面缺陷检测方法
CN117408959A (zh) * 2023-10-16 2024-01-16 重庆腾讯信息技术有限公司 模型的训练方法、缺陷检测方法、装置、电子设备及介质
CN117197589A (zh) * 2023-11-03 2023-12-08 武汉大学 一种目标分类模型对抗训练方法及系统
CN117788925A (zh) * 2023-12-26 2024-03-29 深圳市凌云视迅科技有限责任公司 铝塑膜缺陷分类模型训练方法、装置及电子设备
CN117975204A (zh) * 2024-04-02 2024-05-03 腾讯科技(深圳)有限公司 一种模型训练方法、缺陷检测方法以及相关装置

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121485969A (zh) * 2025-10-23 2026-02-06 北京自然原数科技有限公司 网络传输数据的安全检测方法和装置
CN121017912A (zh) * 2025-10-30 2025-11-28 济南东方结晶器有限公司 结晶器铜管的焊接方法、系统及存储介质
CN121424608A (zh) * 2025-11-05 2026-01-30 陕西尊荣智能科技有限公司 一种机器人辅助的汽车注塑件缺陷分拣方法及系统
CN121424608B (zh) * 2025-11-05 2026-04-21 陕西尊荣智能科技有限公司 一种机器人辅助的汽车注塑件缺陷分拣方法及系统
CN121103507A (zh) * 2025-11-13 2025-12-12 浙江丰利粉碎设备有限公司 一种竹粉粉碎加工成套机组控制方法及系统
CN121437519A (zh) * 2025-12-31 2026-01-30 苏州深视信息科技有限公司 基于多维度的缺陷检测标注质量自动评估方法及系统

Also Published As

Publication number Publication date
CN117975204A (zh) 2024-05-03
CN117975204B (zh) 2024-07-05

Similar Documents

Publication Publication Date Title
JP7345530B2 (ja) SuperLoss:堅牢なカリキュラム学習のための一般的な損失
CN117975204B (zh) 一种模型训练方法、缺陷检测方法以及相关装置
CN110210560B (zh) 分类网络的增量训练方法、分类方法及装置、设备及介质
CN111860573B (zh) 模型训练方法、图像类别检测方法、装置和电子设备
CN109800807B (zh) 分类网络的训练方法及分类方法和装置、电子设备
JP2022141931A (ja) 生体検出モデルのトレーニング方法及び装置、生体検出の方法及び装置、電子機器、記憶媒体、並びにコンピュータプログラム
WO2022262757A1 (zh) 模型训练方法、图像检测方法及检测装置
US20190311258A1 (en) Data dependent model initialization
CN113011532A (zh) 分类模型训练方法、装置、计算设备及存储介质
CN112183326B (zh) 人脸年龄识别模型训练方法及相关装置
CN108228684B (zh) 聚类模型的训练方法、装置、电子设备和计算机存储介质
CN120523955B (zh) 基于伪标签的意图识别模型训练方法、意图识别方法和装置
CN108985190A (zh) 目标识别方法和装置、电子设备、存储介质、程序产品
CN109977977A (zh) 一种识别潜在用户的方法及对应装置
CN111985279A (zh) 多元属性预测模型的训练方法、装置和存储介质
CN114565879A (zh) 特征融合方法及装置、视频抖动消除方法及装置
CN110135435A (zh) 一种基于广度学习系统的显著性检测方法及装置
CN111767419A (zh) 图片搜索方法、装置、设备及计算机可读存储介质
CN117011536B (zh) 特征提取模型处理及特征提取方法、装置和计算机设备
CN113688655A (zh) 干扰信号的识别方法、装置、计算机设备和存储介质
CN114610953B (zh) 一种数据分类方法、装置、设备及存储介质
CN114722941A (zh) 信贷违约识别方法、装置、设备和介质
CN120338037A (zh) 模型优化方法、设备以及存储介质
CN120014677A (zh) 基于难例挖掘的人脸识别模型训练方法、装置和设备
CN112784165B (zh) 关联关系预估模型的训练方法以及预估文件热度的方法

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 25781680

Country of ref document: EP

Kind code of ref document: A1