Disclosure of Invention
To solve the above technical problem or at least partially solve the above technical problem, the present application provides a model training method, apparatus, electronic device, and storage medium.
In a first aspect, the present application provides a model training method, including:
acquiring a training data set for retraining a preset classification model;
inputting the training data set into the preset classification model, and retraining the preset classification model until the preset classification model is converged to obtain a new classification model;
and the initial parameters of the preset classification model during retraining are model parameters obtained during the pre-training of the preset classification model.
Optionally, the obtaining a training data set for retraining the preset classification model includes:
acquiring a pre-training data set for pre-training the preset classification model;
and extracting training data from the pre-training data set to construct the training data set.
Optionally, the extracting training data from the pre-training data set to obtain the training data set includes:
acquiring surface electromyographic signals of a preset number of channels corresponding to each gesture action in at least two different gesture actions;
moving the acquired surface electromyographic signals of a preset number of channels corresponding to each gesture action in at least two different gesture actions to the left or right by half a channel position to obtain the training data;
and/or moving the acquisition position of the surface electromyographic signals of the preset number of channels corresponding to each gesture action upwards or downwards by a half channel position in at least two different gesture actions to obtain the training data.
Optionally, the pre-training the preset classification model includes:
acquiring a pre-training data set and a test data set;
initializing pre-training parameters of an original classification model randomly;
pre-training parameters are used as initial parameters when the original classification model is pre-trained;
inputting the pre-training data set into the original classification model, and pre-training the original classification model;
when the pre-training of the original classification model is completed, verifying the original classification model by using the test data set;
and if the original classification model is converged, obtaining the preset classification model.
Optionally, the method further includes:
acquiring surface electromyographic signals of a preset number of channels corresponding to each gesture action in at least two different gesture actions;
preprocessing the surface electromyographic signals corresponding to the at least two gesture actions to obtain electromyographic data corresponding to the at least two gesture actions;
processing the preprocessed myoelectric data corresponding to at least two gesture actions by using a sliding window algorithm to obtain training sample data corresponding to each gesture action;
and grouping the training sample data corresponding to each gesture action to obtain a pre-training data set and a testing data set.
Optionally, the preset classification model includes: the system comprises a cascaded input layer, a convolution pooling layer, a full connection layer, a softmax function layer and an output layer;
the convolution pooling layer comprises at least two convolution layers, the output of each convolution layer is connected with the input of one normalization layer, the output of each normalization layer is connected with the input of one ReLU layer, and the output of each ReLU layer is connected with the inputs of two cascaded maximum pooling layers.
Optionally, the convolution pooling layer includes 5 cascaded convolution layers, where the number of convolution kernels in the first convolution layer is 16, the number of convolution kernels in the second convolution layer is 32, the number of convolution kernels in the third convolution layer is 64, the number of convolution kernels in the fourth convolution layer is 64, the number of convolution kernels in the fifth convolution layer is 16, and the size of each convolution kernel is 3 × 3.
In a second aspect, the present application provides a model training apparatus comprising:
the acquisition module is used for acquiring a training data set for retraining the preset classification model;
the training module is used for inputting the training data set into the preset classification model, retraining the preset classification model and obtaining a new classification model until the preset classification model is converged;
and the initial parameters of the preset classification model during retraining are model parameters obtained during the pre-training of the preset classification model.
In a third aspect, the present application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete mutual communication through the communication bus;
a memory for storing a computer program;
a processor configured to implement the model training method according to any one of the first aspect when executing a program stored in the memory.
In a fourth aspect, the present application provides a computer-readable storage medium having stored thereon a program of a model training method, which when executed by a processor, implements the steps of the model training method of any one of the first aspects.
Compared with the prior art, the technical scheme provided by the embodiment of the application has the following advantages:
in the embodiment of the invention, the model parameters obtained when the preset classification model is trained in advance are used as the initial parameters when the preset classification model is retrained, and the initialization is not random.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The main method for solving the above problems is supervised adaptation, which is to recalibrate the system by short-time retraining, however, in order to be practical and avoid the inconvenience of the user, the calibration duration of the method must be minimized, but this may result in insufficient training data, and thus, the classifier may be insufficiently trained, resulting in lack of robustness. To this end, an embodiment of the present invention provides a model training method, an apparatus, an electronic device, and a storage medium, where the model training method may be applied in a terminal, such as a PC or a prosthesis, and as shown in fig. 1, the model training method may include the following steps:
step S101, acquiring a training data set for retraining a preset classification model;
in the embodiment of the present invention, the preset classification model refers to a classification model that is trained in advance, and for example, the preset classification model may be a convolutional neural network model, where the convolutional neural network model includes: the device comprises an input layer, a convolution layer, a pooling layer, a full-link layer and an output layer which are cascaded.
Since the electromyographic signals may change correspondingly within a few days, in order to prevent the electromyographic classification from degrading over time, in this step, a training data set may be obtained, and the pre-set classification model may be retrained with the training data set.
Step S102, inputting the training data set into the preset classification model, and retraining the preset classification model until the preset classification model is converged to obtain a new classification model;
in the embodiment of the present invention, the initial parameters of the retraining of the preset classification model are model parameters obtained when the preset classification model is trained in advance.
In the embodiment of the invention, the model parameters obtained when the preset classification model is trained in advance are used as the initial parameters when the preset classification model is retrained, and the initialization is not random.
At present, the supervised adaptive method in the prior art is to recalibrate the system by using short-time retraining, however, in order to be practical and avoid the inconvenience of users, the calibration duration of the method needs to be minimized, but the training data is insufficient, so that the situation that the classifier is not trained sufficiently occurs. In another embodiment of the present invention, the obtaining a training data set for retraining the preset classification model includes:
acquiring a pre-training data set for pre-training the preset classification model;
in this step, a pre-training data set used when pre-training the pre-set classification model may be obtained.
And extracting training data from the pre-training data set to construct the training data set.
In this step, part of the training data in the pre-training data set may be extracted, and the training data set may be constructed based on the extracted part of the training data.
The embodiment of the invention retrains the network by using the training data extracted from the pre-training data set, calibrates the network model by using part of the training data in the pre-training data set, and has stronger robustness to electrode displacement because part of the training data can correct parameters of the model part to adapt to the data of the classifier.
In another embodiment of the present invention, the extracting training data from the pre-training data set to obtain the training data set includes:
acquiring surface electromyographic signals of a preset number of channels corresponding to each gesture action in at least two different gesture actions;
moving the acquired surface electromyographic signals of a preset number of channels corresponding to each gesture action in at least two different gesture actions to the left or right by half a channel position to obtain the training data;
and/or moving the acquisition position of the surface electromyographic signals of the preset number of channels corresponding to each gesture action upwards or downwards by a half channel position in at least two different gesture actions to obtain the training data.
According to the embodiment of the invention, the acquisition positions of 5 channels can be uniformly moved leftwards or rightwards by half the channel position (the influence of transverse movement on the classifier is larger than that of longitudinal movement), the network model is calibrated by using the moved data (one fourth of the data amount of original training data), and the performance of the obtained classifier has stronger robustness on electrode displacement.
In another embodiment of the present invention, the pre-training the preset classification model, as shown in fig. 2, includes:
step S201, acquiring a pre-training data set and a testing data set;
in the step, surface electromyographic signals of different gestures can be preprocessed, and the preprocessing comprises filtering 50Hz power frequency interference, band-pass filtering and the like. And performing activity segment detection on the preprocessed data, performing sliding window processing on the action potential data of the gesture actions, and dividing S training sample data for each gesture action to serve as training data and test data of the convolutional neural network.
For example, in the application, collected surface electromyogram signals of 5 channels and 8 types of gesture motions are processed by a 50Hz wave trap, then 4-order 5-500 Hz Butterworth band-pass filtering is performed, the window length is 200 data points, 400 sample quantities are used as the input of a convolutional neural network for each type of gesture motion, and the sample quantities refer to the number of samples, namely how many surface electromyogram signals with the window length of 200 are input into the convolutional neural network.
Step S202, initializing pre-training parameters of an original classification model randomly;
step S203, using a pre-training parameter as an initial parameter when the original classification model is pre-trained;
step S204, inputting the pre-training data set into the original classification model, and pre-training the original classification model;
step S205, when the pre-training of the original classification model is completed, verifying the original classification model by using the test data set;
step S206, if the original classification model is converged, the preset classification model is obtained.
In yet another embodiment of the present invention, the method further comprises:
acquiring surface electromyographic signals of a preset number of channels corresponding to each gesture action in at least two different gesture actions;
preprocessing the surface electromyographic signals corresponding to the at least two gesture actions to obtain electromyographic data corresponding to the at least two gesture actions;
processing the preprocessed myoelectric data corresponding to at least two gesture actions by using a sliding window algorithm to obtain training sample data corresponding to each gesture action;
and grouping the training sample data corresponding to each gesture action to obtain a pre-training data set and a testing data set.
The embodiment of the invention carries out model training on the convolutional neural network based on the training data and the sample labels of the training data to obtain a pre-model, and tests the model classification accuracy by using the test data.
In another embodiment of the present invention, the preset classification model includes: the system comprises a cascaded input layer, a convolution pooling layer, a full connection layer, a softmax function layer and an output layer;
the convolution pooling layer comprises at least two convolution layers, the output of each convolution layer is connected with the input of one normalization layer, the output of each normalization layer is connected with the input of one ReLU layer, and the output of each ReLU layer is connected with the inputs of two cascaded maximum pooling layers.
An input layer: the method comprises the following steps of M channels, wherein the window length is window _ length (namely window _ length electromyographic data), the sample size is L, wherein L is k N, k is k types of gesture motions, each type of gesture motion has N samples as training, and M is window _ length L as the input of a network.
Full connection layer: adopting a softmax function after the full connection layer;
an output layer: and outputting the label of each gesture action.
The convolutional neural network structure in the embodiment of the invention is much simpler than a standard network architecture, the parameter adjustment of the convolutional neural network has the characteristics of self-learning and automatic modification, the learning capability is strong, and the convolutional neural network has obvious superiority compared with classifiers such as SVM, LDA and the like.
In yet another embodiment of the present invention, the convolution pooling layer includes 5 cascaded convolution layers, wherein the number of convolution kernels in the first convolution layer is 16, the number of convolution kernels in the second convolution layer is 32, the number of convolution kernels in the third convolution layer is 64, the number of convolution kernels in the fourth convolution layer is 64, the number of convolution kernels in the fifth convolution layer is 16, and the size of each convolution kernel is 3 x 3.
In another embodiment of the present invention, there is also provided a model training apparatus, as shown in fig. 3, including:
an obtaining module 11, configured to obtain a training data set for retraining a preset classification model;
the training module 12 is configured to input the training data set into the preset classification model, and retrain the preset classification model until the preset classification model converges to obtain a new classification model;
and the initial parameters of the preset classification model during retraining are model parameters obtained during the pre-training of the preset classification model.
In another embodiment of the present invention, an electronic device is further provided, which includes a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing the model training method in the embodiment of the method when executing the program stored in the memory.
In the electronic device provided by the embodiment of the invention, the processor acquires the training data set for retraining the preset classification model by executing the program stored in the memory; inputting the training data set into the preset classification model, and retraining the preset classification model until the preset classification model is converged to obtain a new classification model; the initial parameters obtained when the preset classification model is retrained are the model parameters obtained when the preset classification model is retrained in advance, the model parameters obtained when the preset classification model is retrained in advance are used as the initial parameters when the preset classification model is retrained in advance, and random initialization is not performed.
The communication bus 1140 mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus 1140 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 4, but this does not indicate only one bus or one type of bus.
The communication interface 1120 is used for communication between the electronic device and other devices.
The memory 1130 may include a Random Access Memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The processor 1110 may be a general-purpose processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the integrated circuit may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, or discrete hardware components.
In yet another embodiment of the present invention, a computer-readable storage medium is further provided, on which a program of a model training method is stored, which when executed by a processor implements the steps of the model training method described in the aforementioned method embodiment.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.