CN118115607A - Picture coding model distillation method and device based on contrast learning and electronic equipment - Google Patents

Picture coding model distillation method and device based on contrast learning and electronic equipment Download PDF

Info

Publication number
CN118115607A
CN118115607A CN202410424915.9A CN202410424915A CN118115607A CN 118115607 A CN118115607 A CN 118115607A CN 202410424915 A CN202410424915 A CN 202410424915A CN 118115607 A CN118115607 A CN 118115607A
Authority
CN
China
Prior art keywords
model
picture
distillation
teacher
loss
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
CN202410424915.9A
Other languages
Chinese (zh)
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.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202410424915.9A priority Critical patent/CN118115607A/en
Publication of CN118115607A publication Critical patent/CN118115607A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T9/00Image coding
    • G06T9/001Model-based coding, e.g. wire frame
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00Machine learning

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Medical Informatics (AREA)
  • Evolutionary Computation (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Mathematical Physics (AREA)
  • Artificial Intelligence (AREA)
  • Multimedia (AREA)
  • Image Processing (AREA)

Abstract

The invention relates to the field of intelligent decision making, and discloses a picture coding model distillation method, a device, electronic equipment and a storage medium based on contrast learning, wherein the method comprises the following steps: determining picture teacher codes of pictures to be coded by using a teacher coding model, and determining picture student codes of the pictures to be coded and contrast learning codes of contrast learning pictures by using a student coding model; calculating a first comparison learning-distilling loss and a second comparison learning-distilling loss, and performing model joint distillation on the teacher coding model and the student coding model; carrying out picture enhancement on the picture to be encoded, calculating a first contrast learning loss and calculating a second contrast learning loss; and performing model secondary distillation on the distillation teacher model, and taking the secondary distillation model and the distillation student model as model final distillation results. The invention can improve the accuracy of the model distillation training result.

Description

Picture coding model distillation method and device based on contrast learning and electronic equipment
Technical Field
The present invention relates to the field of data processing, and in particular, to a method, an apparatus, an electronic device, and a computer readable storage medium for distilling a picture coding model based on contrast learning.
Background
The distillation of the picture coding model based on the contrast learning refers to a process of realizing the distillation training of the model by utilizing the contrast relation among different pictures and the contrast learning among the size models.
Currently, the method for implementing model distillation in the industry is to train a teacher model (also called a large model) by using a data set, the teacher model outputs a soft predicted value to data, and then train a student model (also called a small model) by using the predicted value of the teacher model instead of training the student model by directly using the data set. Thus, inaccurate model distillation training results result.
Disclosure of Invention
The invention provides a picture coding model distillation method, a device, electronic equipment and a computer readable storage medium based on contrast learning, and mainly aims to improve the accuracy of model distillation training results.
In order to achieve the above object, the present invention provides a method for distilling a picture coding model based on contrast learning, comprising:
Acquiring a picture to be encoded and a corresponding contrast learning picture thereof, determining picture teacher codes of the picture to be encoded by using a teacher coding model, and determining the picture student codes of the picture to be encoded and the contrast learning codes of the contrast learning picture by using a student coding model;
Calculating a first comparison learning-distillation loss between the picture teacher code and the picture student code, and calculating a second comparison learning-distillation loss between the picture teacher code and the comparison learning code, and performing model joint distillation on the teacher code model and the student code model by using the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model;
Carrying out picture enhancement on the picture to be encoded to obtain an enhanced picture, calculating a first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, and calculating a second contrast learning loss between the picture to be encoded and the contrast learning picture by using a distillation teacher model;
And performing model secondary distillation on the distillation teacher model by using the first comparison learning loss and the second comparison learning loss to obtain a secondary distillation model, and taking the secondary distillation model and the distillation student model as model final distillation results.
Optionally, the calculating a first comparative learning-distillation loss between the picture teacher code and the picture student code comprises:
calculating the contrast loss of the picture teacher code;
extracting teacher model probability corresponding to the picture teacher code;
Extracting student model probabilities corresponding to the picture student codes;
determining an initial distillation weight between the picture teacher code and the picture student code;
Calculating an initial distillation loss between the picture teacher code and the picture student code based on the teacher model probability, the student model probability, and the initial distillation weight;
and splicing the contrast loss and the initial distillation loss to obtain a first contrast learning-distillation loss between the picture teacher code and the picture student code.
Optionally, the calculating the contrast loss of the picture teacher code includes:
Acquiring a teacher coding model corresponding to the picture teacher coding, and inquiring temperature parameters of the picture teacher coding in an activation function layer of the teacher coding model;
extracting inquiry vectors and key vectors of the picture teacher codes from the teacher coding model;
Based on the temperature parameter, the query vector and the key vector, calculating the contrast loss of the picture teacher code by using the following formula:
wherein info_NCE Loss represents contrast Loss of the picture teacher code, q represents the query vector, n represents the number of key vectors, k i represents the ith key vector, q.k i represents the inner product of the two vectors, τ represents the temperature constant, and is a super parameter.
Optionally, the calculating the initial distillation loss between the picture teacher code and the picture student code based on the teacher model probability, the student model probability, and the initial distillation weight includes:
Calculating an initial distillation loss between the picture teacher code and the picture student code using the following formula:
L=(1-α)cross_entrophy(y,p)+α*cross_entrophy(q,p)T2
Wherein L represents the initial distillation loss, y represents a real label, p represents the student model probability, q represents the teacher model probability, α represents the initial distillation weight, cross_ entrophy represents a loss function, and T represents time.
Optionally, the performing model joint distillation on the teacher coding model and the student coding model by using the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model includes:
Taking the first contrast learning-distillation loss as positive sample data between the teacher encoding model and the student encoding model, and the second contrast learning-distillation loss as negative sample data between the teacher encoding model and the student encoding model;
Performing positive sample distillation on the teacher coding model and the student coding model by using the positive sample data to obtain a positive sample teacher distillation model and a positive sample student distillation model;
And performing negative sample distillation on the positive sample teacher distillation model and the positive sample student distillation model by using the negative sample data to obtain the distillation teacher model and the distillation student model.
Optionally, the performing picture enhancement on the picture to be encoded to obtain an enhanced picture includes:
Determining the signal-to-noise ratio of the picture to be encoded;
Inquiring the total pixel number of the picture to be coded;
according to the signal-to-noise ratio and the total pixel number, calculating the pixel number to be noisy of the picture to be encoded by using the following formula:
NP=SP(1-SNR)
Wherein NP represents the number of pixels to be noisy, SP represents the total number of pixels, and SNR represents the signal-to-noise ratio; determining random noise adding pixel positions in the picture to be coded based on the number of pixels to be noise added; and configuring a target pixel value at the random noise adding pixel position to obtain the enhanced picture.
Optionally, performing model second distillation on the distillation teacher model by using the first contrast learning loss and the second contrast learning loss to obtain a second distillation model, including:
taking the first contrast learning loss as a distillation positive sample of the distillation teacher model and the second contrast learning loss as a distillation negative sample of the distillation teacher model;
Performing model positive sample distillation on the distillation teacher model by using the distillation positive sample to obtain a positive sample distillation model;
And performing model negative sample distillation on the positive sample distillation model by using the distillation negative sample to obtain the secondary distillation model.
In order to solve the above problems, the present invention further provides a picture coding model distillation apparatus based on contrast learning, the apparatus comprising:
the code determining module is used for acquiring the picture to be coded and the corresponding contrast learning picture thereof, determining picture teacher codes of the picture to be coded by using a teacher coding model, and determining picture student codes of the picture to be coded and the contrast learning codes of the contrast learning picture by using a student coding model;
The model distillation module is used for calculating a first comparison learning-distillation loss between the picture teacher code and the picture student code, calculating a second comparison learning-distillation loss between the picture teacher code and the comparison learning code, and carrying out model joint distillation on the teacher code model and the student code model by utilizing the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model;
The loss calculation module is used for carrying out picture enhancement on the picture to be encoded to obtain an enhanced picture, calculating a first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, and calculating a second contrast learning loss between the picture to be encoded and the contrast learning picture by using a distillation teacher model;
And the secondary distillation module is used for performing model secondary distillation on the distillation teacher model by utilizing the first comparison learning loss and the second comparison learning loss to obtain a secondary distillation model, and taking the secondary distillation model and the distillation student model as model final distillation results.
In order to solve the above-mentioned problems, the present invention also provides an electronic apparatus including:
At least one processor; and
A memory communicatively coupled to the at least one processor; wherein,
The memory stores a computer program executable by the at least one processor to implement the contrast learning-based picture coding model distillation method described above.
In order to solve the above-mentioned problems, the present invention also provides a computer-readable storage medium having stored therein at least one computer program that is executed by a processor in an electronic device to implement the above-mentioned contrast learning-based picture coding model distillation method.
It can be seen that, according to the embodiment of the present invention, the pictures to be encoded and the corresponding comparison learning pictures thereof are firstly obtained, so as to be used as input data of a model which is not trained subsequently, further, according to the embodiment of the present invention, the picture teacher code of the pictures to be encoded and the comparison learning code of the pictures to be encoded are determined by using a teacher code model, so as to be used for converting the pictures into a coding vector form by using the teacher code model and the comparison learning code model, further, according to the embodiment of the present invention, by calculating a first comparison learning-distillation loss between the teacher code and the student code of the pictures, so as to be used for splicing and fusing a loss result output by the teacher model and a loss result of the student model as parameters of a training teacher model and a student model simultaneously, further, according to the embodiment of the present invention, the low accuracy rate of training of the student model under the influence of the teacher model fitting effect is reduced, further, according to the embodiment of the present invention, according to the second comparison learning code between the pictures to the teacher code model and the comparison learning code model is calculated, the first comparison learning-distillation loss is reduced by using the comparison learning-distillation loss between the first comparison learning model and the student code model, and the second comparison learning loss is reduced when the training model is further, and the comparison learning loss is reduced under the training model is further, in order to enable a large model and a small model to be trained together, so that the small model is directly used in the actual use process to achieve the effect of being more efficient and rapid, the training target enables the two models to directly take training data as supervision labels, so that the small model is beneficial to being in contact with data essence, further, the embodiment of the invention enhances the picture to be encoded to be used for taking different intensities of the same picture as contents of contrast learning, further, the embodiment of the invention calculates first contrast learning loss between the picture to be encoded and the enhanced picture by utilizing a distillation teacher model to be used for achieving distillation training of the distillation teacher model by utilizing the first contrast learning loss and the second contrast learning loss, further, the embodiment of the invention enables the large model to be trained by utilizing the first contrast learning loss and the second contrast learning loss to be in a mode for carrying out model secondary distillation, enables the large model to be capable of directly training data to be distributed, then enables the small model to learn the learned characteristics of the large model, and the small model is also enabled to be adjusted to be alternately aligned to the two iterative training models at the moment. Therefore, the image coding model distillation method, the device, the electronic equipment and the computer readable storage medium based on the contrast learning provided by the embodiment of the invention can improve the accuracy of the model distillation training result.
Drawings
FIG. 1 is a schematic flow chart of a method for distilling a picture coding model based on contrast learning according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a distillation apparatus for a picture coding model based on contrast learning according to an embodiment of the present invention;
Fig. 3 is a schematic diagram of an internal structure of an electronic device for implementing a distillation method of a picture coding model based on contrast learning according to an embodiment of the present invention;
the achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
The embodiment of the invention provides a picture coding model distillation method based on contrast learning. The execution subject of the image coding model distillation method based on contrast learning includes, but is not limited to, at least one of a server, a terminal and the like capable of being configured to execute the method provided by the embodiment of the invention. In other words, the image coding model distillation method based on contrast learning may be performed by software or hardware installed in a terminal device or a server device, and the software may be a blockchain platform. The service end includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, and the like. The server may be an independent server, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
Referring to fig. 1, a flow chart of a distillation method of a picture coding model based on contrast learning according to an embodiment of the invention is shown. In the embodiment of the invention, the image coding model distillation method based on contrast learning comprises the following steps S1-S4:
S1, obtaining a picture to be encoded and a corresponding contrast learning picture thereof, determining picture teacher codes of the picture to be encoded by using a teacher coding model, and determining picture student codes of the picture to be encoded and the contrast learning codes of the contrast learning picture by using a student coding model.
The embodiment of the invention acquires the picture to be encoded and the corresponding contrast learning picture thereof, and is used for taking the picture to be encoded and the corresponding contrast learning picture thereof as input data of a subsequent untrained model.
The pictures to be encoded and the contrast learning pictures refer to pictures generated under different service scenes, for example, in a medical industry scene, the pictures to be encoded and the contrast learning pictures can be medical pictures, science popularization knowledge pictures, propaganda pictures of therapy, medical payment pictures and the like; in the financial business scenario, the to-be-encoded picture and the comparison learning picture may be a fund science popularization picture, a stock rising and falling analysis picture, a bank card handling picture, etc., and it is to be noted that the to-be-encoded picture is not completely consistent with the comparison learning picture.
Further, the embodiment of the invention determines the picture teacher code of the picture to be encoded and the contrast learning code of the picture student code of the picture to be encoded and the contrast learning picture by using a teacher code model, so as to convert the picture into a code vector form by using the teacher code model and the student code model. The teacher coding model refers to a teacher model or a big model in the knowledge distillation model, the student coding model refers to a student model or a small model in the knowledge distillation model, and the picture teacher coding refers to a coding vector.
In an embodiment of the present invention, the determining, by using a teacher coding model, picture teacher coding of the picture to be coded is implemented by using a graphic neural network in the teacher coding model.
Wherein the graphic neural network refers to Graph Neural Network, GNN for short, which is a neural network directly acting on the graph structure, the graphic neural network can be created like any other neural network, including a full connection layer, a convolution layer, a pooling layer, etc., and the type and number of layers depend on the type and complexity of graphic data and the required output.
In an embodiment of the present invention, the principle of determining the student coding of the picture to be coded and the comparison learning coding of the comparison learning picture by using the student coding model is similar to the principle of determining the teacher coding of the picture to be coded by using the teacher coding model, and will not be further described herein.
S2, calculating a first comparison learning-distillation loss between the picture teacher code and the picture student code, calculating a second comparison learning-distillation loss between the picture teacher code and the comparison learning code, and carrying out model joint distillation on the teacher code model and the student code model by using the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model.
According to the embodiment of the invention, the first comparison learning-distillation loss between the picture teacher code and the picture student code is calculated, so that the loss result output by the teacher model and the loss result of the student model are spliced and fused to serve as parameters for training the teacher model and the student model at the same time, and the low accuracy rate of training the student model under the influence of bad fitting effect of the teacher model is reduced. Wherein the first contrast learning-distillation loss refers to a combined loss function (InfoNCE + Distillation Loss) consisting of a contrast-based loss function (InfoNCE Loss) and a distillation loss (Distillation Loss).
In an embodiment of the invention, the calculating a first contrast learning-distillation loss between the picture teacher code and the picture student code comprises: calculating the contrast loss of the picture teacher code; extracting teacher model probability corresponding to the picture teacher code; extracting student model probabilities corresponding to the picture student codes; determining an initial distillation weight between the picture teacher code and the picture student code; calculating an initial distillation loss between the picture teacher code and the picture student code based on the teacher model probability, the student model probability, and the initial distillation weight; and splicing the contrast loss and the initial distillation loss to obtain a first contrast learning-distillation loss between the picture teacher code and the picture student code.
In yet another embodiment of the present invention, the calculating the contrast loss of the picture teacher code includes: acquiring a teacher coding model corresponding to the picture teacher coding, and inquiring temperature parameters of the picture teacher coding in an activation function layer of the teacher coding model; extracting inquiry vectors and key vectors of the picture teacher codes from the teacher coding model; based on the temperature parameter, the query vector and the key vector, calculating the contrast loss of the picture teacher code by using the following formula:
wherein info_NCE Loss represents contrast Loss of the picture teacher code, q represents the query vector, n represents the number of key vectors, k i represents the ith key vector, q.k i represents the inner product of the two vectors, τ represents the temperature constant, and is a super parameter.
In yet another embodiment of the present invention, the calculating the initial rethread between the picture teacher code and the picture student code based on the teacher model probability, the student model probability, and the initial rethread weight includes: calculating an initial distillation loss between the picture teacher code and the picture student code using the following formula:
L=(1-α)cross_entrophy(y,p)+α*cross_entrophy(q,p)T2
Wherein L represents the initial distillation loss, y represents a real label, p represents the student model probability, q represents the teacher model probability, α represents the initial distillation weight, cross_ entrophy represents a loss function, and T represents time.
Optionally, the process of stitching the contrast loss with the initial distillation loss to obtain a first contrast learning-distillation loss between the picture teacher code and the picture student code is implemented by InfoNCELoss + Distillation Loss.
Further, the embodiment of the invention calculates the second contrast learning-distilling loss between the picture teacher code and the contrast learning code, so as to realize the contrast learning when the teacher model and the student model are trained simultaneously by using the contrast pictures, thereby reducing the low accuracy of training the student model under the influence of bad fitting effect of the teacher model.
In an embodiment of the present invention, the principle of calculating the second contrast learning-distillation loss between the picture teacher code and the contrast learning code is similar to that of calculating the first contrast learning-distillation loss between the picture teacher code and the picture student code, and further description is omitted herein.
Furthermore, in the embodiment of the invention, the teacher coding model and the student coding model are subjected to model joint distillation by utilizing the first comparison learning-distillation loss and the second comparison learning-distillation loss so as to be used for training the large model and the small model together, so that the small model is directly used in the actual use process to achieve a more efficient and rapid effect, and the training target is that the two models directly use training data as supervision labels, so that the small model is beneficial to being also contacted with the data essence.
In an embodiment of the present invention, the performing model joint distillation on the teacher coding model and the student coding model by using the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model includes: taking the first contrast learning-distillation loss as positive sample data between the teacher encoding model and the student encoding model, and the second contrast learning-distillation loss as negative sample data between the teacher encoding model and the student encoding model; performing positive sample distillation on the teacher coding model and the student coding model by using the positive sample data to obtain a positive sample teacher distillation model and a positive sample student distillation model; and performing negative sample distillation on the positive sample teacher distillation model and the positive sample student distillation model by using the negative sample data to obtain the distillation teacher model and the distillation student model.
S3, carrying out picture enhancement on the picture to be encoded to obtain an enhanced picture, calculating a first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, and calculating a second contrast learning loss between the picture to be encoded and the contrast learning picture by using the distillation teacher model.
According to the embodiment of the invention, the picture to be encoded is enhanced, so that different intensities of the same picture are used as contents of contrast learning.
In an embodiment of the present invention, the performing picture enhancement on the picture to be encoded to obtain an enhanced picture includes: determining the signal-to-noise ratio of the picture to be encoded; inquiring the total pixel number of the picture to be coded; according to the signal-to-noise ratio and the total pixel number, calculating the pixel number to be noisy of the picture to be encoded by using the following formula:
NP=SP(1-SNR)
Wherein NP represents the number of pixels to be noisy, SP represents the total number of pixels, and SNR represents the signal-to-noise ratio; determining random noise adding pixel positions in the picture to be coded based on the number of pixels to be noise added; and configuring a target pixel value at the random noise adding pixel position to obtain the enhanced picture.
Further, the embodiment of the invention calculates the first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, so as to realize distillation training of the distillation teacher model by using the first contrast learning loss. Wherein the first contrast learning loss is InfoNCELoss.
In an embodiment of the present invention, the principle of calculating the first contrast learning loss between the picture to be encoded and the enhanced picture by using the distillation teacher model is similar to the principle of calculating the contrast loss of the picture teacher encoding described above, and will not be further described herein.
In an embodiment of the present invention, the principle of calculating the second contrast learning loss between the picture to be encoded and the contrast learning picture by using the distillation teacher model is similar to the principle of calculating the contrast loss of the picture teacher encoding described above, and will not be further described herein.
And S4, performing model secondary distillation on the distillation teacher model by using the first comparison learning loss and the second comparison learning loss to obtain a secondary distillation model, and taking the secondary distillation model and the distillation student model as model final distillation results.
According to the embodiment of the invention, the distillation teacher model is subjected to model secondary distillation by utilizing the first comparison learning loss and the second comparison learning loss, so that the large model can be trained by using the comparison model to adapt to data distribution by directly training data, and then the small model is used for learning the characteristics learned by the large model, and the large model is also adjusted to align the small model at the moment, so that the two models are alternately and iteratively trained until convergence of the two models is achieved.
In an embodiment of the present invention, the performing model second distillation on the distillation teacher model by using the first contrast learning loss and the second contrast learning loss to obtain a second distillation model includes: taking the first contrast learning loss as a distillation positive sample of the distillation teacher model and the second contrast learning loss as a distillation negative sample of the distillation teacher model; performing model positive sample distillation on the distillation teacher model by using the distillation positive sample to obtain a positive sample distillation model; and performing model negative sample distillation on the positive sample distillation model by using the distillation negative sample to obtain the secondary distillation model.
It can be seen that, according to the embodiment of the present invention, the pictures to be encoded and the corresponding comparison learning pictures thereof are firstly obtained, so as to be used as input data of a model which is not trained subsequently, further, according to the embodiment of the present invention, the picture teacher code of the pictures to be encoded and the comparison learning code of the pictures to be encoded are determined by using a teacher code model, so as to be used for converting the pictures into a coding vector form by using the teacher code model and the comparison learning code model, further, according to the embodiment of the present invention, by calculating a first comparison learning-distillation loss between the teacher code and the student code of the pictures, so as to be used for splicing and fusing a loss result output by the teacher model and a loss result of the student model as parameters of a training teacher model and a student model simultaneously, further, according to the embodiment of the present invention, the low accuracy rate of training of the student model under the influence of the teacher model fitting effect is reduced, further, according to the embodiment of the present invention, according to the second comparison learning code between the pictures to the teacher code model and the comparison learning code model is calculated, the first comparison learning-distillation loss is reduced by using the comparison learning-distillation loss between the first comparison learning model and the student code model, and the second comparison learning loss is reduced when the training model is further, and the comparison learning loss is reduced under the training model is further, in order to enable a large model and a small model to be trained together, so that the small model is directly used in the actual use process to achieve the effect of being more efficient and rapid, the training target enables the two models to directly take training data as supervision labels, so that the small model is beneficial to being in contact with data essence, further, the embodiment of the invention enhances the picture to be encoded to be used for taking different intensities of the same picture as contents of contrast learning, further, the embodiment of the invention calculates first contrast learning loss between the picture to be encoded and the enhanced picture by utilizing a distillation teacher model to be used for achieving distillation training of the distillation teacher model by utilizing the first contrast learning loss and the second contrast learning loss, further, the embodiment of the invention enables the large model to be trained by utilizing the first contrast learning loss and the second contrast learning loss to be in a mode for carrying out model secondary distillation, enables the large model to be capable of directly training data to be distributed, then enables the small model to learn the learned characteristics of the large model, and the small model is also enabled to be adjusted to be alternately aligned to the two iterative training models at the moment. Therefore, the image coding model distillation method based on contrast learning provided by the embodiment of the invention can improve the accuracy of the model distillation training result.
As shown in fig. 2, the present invention is a functional block diagram of a distillation apparatus for picture coding model based on contrast learning.
The image coding model distillation apparatus 100 based on contrast learning according to the present invention may be installed in an electronic device. Depending on the implemented functions, the contrast learning based picture coding model distillation apparatus may include a coding determination module 101, a model distillation module 102, a loss calculation module 103, and a secondary distillation module 104. The module according to the invention, which may also be referred to as a unit, refers to a series of computer program segments, which are stored in the memory of the electronic device, capable of being executed by the processor of the electronic device and of performing a fixed function.
In the present embodiment, the functions concerning the respective modules/units are as follows:
The code determining module 101 is configured to obtain a picture to be encoded and a corresponding contrast learning picture thereof, determine a picture teacher code of the picture to be encoded using a teacher code model, and determine a picture student code of the picture to be encoded and a contrast learning code of the contrast learning picture using a student code model;
The model distillation module 102 is configured to calculate a first contrast learning-distillation loss between the picture teacher code and the picture student code, calculate a second contrast learning-distillation loss between the picture teacher code and the contrast learning code, and perform model joint distillation on the teacher code model and the student code model by using the first contrast learning-distillation loss and the second contrast learning-distillation loss to obtain a distillation teacher model and a distillation student model;
The loss calculation module 103 is configured to perform picture enhancement on the picture to be encoded to obtain an enhanced picture, calculate a first contrast learning loss between the picture to be encoded and the enhanced picture using a distillation teacher model, and calculate a second contrast learning loss between the picture to be encoded and the contrast learning picture using a distillation teacher model;
The secondary distillation module 104 is configured to perform model secondary distillation on the distillation teacher model by using the first contrast learning loss and the second contrast learning loss to obtain a secondary distillation model, and use the secondary distillation model and the distillation student model as model final distillation results.
In detail, the modules in the image coding model distillation apparatus 100 based on contrast learning in the embodiment of the present invention use the same technical means as the image coding model distillation method based on contrast learning described in fig. 1 and can produce the same technical effects, which are not described herein.
Fig. 3 is a schematic structural diagram of an electronic device 1 according to the present invention for implementing a picture coding model distillation method based on contrast learning.
The electronic device 1 may comprise a processor 10, a memory 11, a communication bus 12 and a communication interface 13, and may further comprise a computer program stored in the memory 11 and executable on the processor 10, such as a picture coding model distillation program based on contrast learning.
The processor 10 may be formed by an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be formed by a plurality of integrated circuits packaged with the same function or different functions, including one or more central processing units (Central Processing Unit, CPU), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 10 is a Control Unit (Control Unit) of the electronic device 1, connects the respective components of the entire electronic device 1 using various interfaces and lines, executes various functions of the electronic device 1 and processes data by running or executing programs or modules stored in the memory 11 (for example, executing a picture coding model distillation program based on contrast learning, etc.), and calls data stored in the memory 11.
The memory 11 includes at least one type of readable storage medium including flash memory, a removable hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device 1, such as a removable hard disk of the electronic device 1. The memory 11 may in other embodiments also be an external storage device of the electronic device 1, such as a plug-in mobile hard disk, a smart memory card (SMART MEDIA CARD, SMC), a Secure Digital (SD) card, a flash memory card (FLASH CARD) or the like, which are provided on the electronic device 1. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device 1. The memory 11 may be used not only for storing application software installed in the electronic device 1 and various types of data, such as codes of a picture coding model distillation program based on contrast learning, but also for temporarily storing data that has been output or is to be output.
The communication bus 12 may be a peripheral component interconnect standard (PERIPHERAL COMPONENT INTERCONNECT, PCI) bus, or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, among others. The bus may be classified as an address bus, a data bus, a control bus, etc. The bus is arranged to enable a connection communication between the memory 11 and at least one processor 10 etc.
The communication interface 13 is used for communication between the electronic device 1 and other devices, including a network interface and an employee interface. Optionally, the network interface may comprise a wired interface and/or a wireless interface (e.g. WI-FI interface, bluetooth interface, etc.), typically used to establish a communication connection between the electronic device 1 and other electronic devices 1. The employee interface may be a Display (Display), an input unit such as a Keyboard (Keyboard), or alternatively a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch, or the like. The display may also be referred to as a display screen or display unit, as appropriate, for displaying information processed in the electronic device 1 and for displaying a visual staff interface.
Fig. 3 shows only an electronic device 1 with components, it being understood by a person skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the electronic device 1, and may comprise fewer or more components than shown, or may combine certain components, or may be arranged in different components.
For example, although not shown, the electronic device 1 may further include a power source (such as a battery) for supplying power to each component, and preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that functions of charge management, discharge management, power consumption management, and the like are implemented through the power management device. The power supply may also include one or more of any of a direct current or alternating current power supply, recharging device, power failure detection circuit, power converter or inverter, power status indicator, etc. The electronic device 1 may further include various sensors, bluetooth modules, wi-Fi modules, etc., which will not be described herein.
It should be understood that the embodiments described are for illustrative purposes only and are not limited in scope by this configuration.
The image coding model distillation program stored by the memory 11 in the electronic device 1 is a combination of a plurality of computer programs, which when run in the processor 10, can implement:
Acquiring a picture to be encoded and a corresponding contrast learning picture thereof, determining picture teacher codes of the picture to be encoded by using a teacher coding model, and determining the picture student codes of the picture to be encoded and the contrast learning codes of the contrast learning picture by using a student coding model;
Calculating a first comparison learning-distillation loss between the picture teacher code and the picture student code, and calculating a second comparison learning-distillation loss between the picture teacher code and the comparison learning code, and performing model joint distillation on the teacher code model and the student code model by using the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model;
Carrying out picture enhancement on the picture to be encoded to obtain an enhanced picture, calculating a first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, and calculating a second contrast learning loss between the picture to be encoded and the contrast learning picture by using a distillation teacher model;
And performing model secondary distillation on the distillation teacher model by using the first comparison learning loss and the second comparison learning loss to obtain a secondary distillation model, and taking the secondary distillation model and the distillation student model as model final distillation results.
In particular, the specific implementation method of the processor 10 on the computer program may refer to the description of the relevant steps in the corresponding embodiment of fig. 1, which is not repeated herein.
Further, the integrated modules/units of the electronic device 1 may be stored in a non-volatile computer readable storage medium if implemented in the form of software functional units and sold or used as a stand alone product. The computer readable storage medium may be volatile or nonvolatile. For example, the computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM).
The present invention also provides a computer readable storage medium storing a computer program which, when executed by a processor of an electronic device 1, may implement:
Acquiring a picture to be encoded and a corresponding contrast learning picture thereof, determining picture teacher codes of the picture to be encoded by using a teacher coding model, and determining the picture student codes of the picture to be encoded and the contrast learning codes of the contrast learning picture by using a student coding model;
Calculating a first comparison learning-distillation loss between the picture teacher code and the picture student code, and calculating a second comparison learning-distillation loss between the picture teacher code and the comparison learning code, and performing model joint distillation on the teacher code model and the student code model by using the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model;
Carrying out picture enhancement on the picture to be encoded to obtain an enhanced picture, calculating a first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, and calculating a second contrast learning loss between the picture to be encoded and the contrast learning picture by using a distillation teacher model;
And performing model secondary distillation on the distillation teacher model by using the first comparison learning loss and the second comparison learning loss to obtain a secondary distillation model, and taking the secondary distillation model and the distillation student model as model final distillation results.
In the several embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is merely a logical function division, and there may be other manners of division when actually implemented.
The modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, may be located in one place, or may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional module in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units can be realized in a form of hardware or a form of hardware and a form of software functional modules.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential characteristics thereof.
The present embodiments are, therefore, to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
The embodiment of the invention can acquire and process the related data based on the artificial intelligence technology. Wherein artificial intelligence (ARTIFICIAL INTELLIGENCE, AI) is the theory, method, technique, and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend, and expand human intelligence, sense the environment, acquire knowledge, and use knowledge to obtain optimal results.
Furthermore, it is evident that the word "comprising" does not exclude other elements or steps, and that the singular does not exclude a plurality. A plurality of units or means recited in the system claims can also be implemented by means of software or hardware by means of one unit or means. The terms second, etc. are used to denote a name, but not any particular order.
Finally, it should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present invention and not for limiting the same, and although the present invention has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications and equivalents may be made to the technical solution of the present invention without departing from the spirit and scope of the technical solution of the present invention.

Claims (10)

1. A picture coding model distillation method based on contrast learning, the method comprising:
Acquiring a picture to be encoded and a corresponding contrast learning picture thereof, determining picture teacher codes of the picture to be encoded by using a teacher coding model, and determining picture student codes of the picture to be encoded and the contrast learning codes of the contrast learning picture by using a student coding model;
Calculating a first comparison learning-distillation loss between the picture teacher code and the picture student code, calculating a second comparison learning-distillation loss between the picture teacher code and the comparison learning code, and performing model joint distillation on the teacher code model and the student code model by using the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model;
Carrying out picture enhancement on the picture to be encoded to obtain an enhanced picture, calculating a first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, and calculating a second contrast learning loss between the picture to be encoded and the contrast learning picture by using a distillation teacher model;
And performing model secondary distillation on the distillation teacher model by using the first comparison learning loss and the second comparison learning loss to obtain a secondary distillation model, and taking the secondary distillation model and the distillation student model as model final distillation results.
2. The contrast learning based picture coding model retorting method as claimed in claim 1, wherein said calculating a first contrast learning-retorting loss between said picture teacher code and said picture student code includes:
calculating the contrast loss of the picture teacher code;
extracting teacher model probability corresponding to the picture teacher code;
Extracting student model probabilities corresponding to the picture student codes;
determining an initial distillation weight between the picture teacher code and the picture student code;
Calculating an initial distillation loss between the picture teacher code and the picture student code based on the teacher model probability, the student model probability, and the initial distillation weight;
and splicing the contrast loss and the initial distillation loss to obtain a first contrast learning-distillation loss between the picture teacher code and the picture student code.
3. The method for distilling a picture coding model based on contrast learning according to claim 2, wherein the calculating the contrast loss of the picture teacher code comprises:
Acquiring a teacher coding model corresponding to the picture teacher coding, and inquiring temperature parameters of the picture teacher coding in an activation function layer of the teacher coding model;
extracting inquiry vectors and key vectors of the picture teacher codes from the teacher coding model;
Based on the temperature parameter, the query vector and the key vector, calculating the contrast loss of the picture teacher code by using the following formula:
wherein info_NCE Loss represents contrast Loss of the picture teacher code, q represents the query vector, n represents the number of key vectors, k i represents the ith key vector, q.k i represents the inner product of the two vectors, τ represents the temperature constant, and is a super parameter.
4. The contrast learning-based picture coding model retorting method as claimed in claim 2, wherein said calculating initial retorting loss between said picture teacher code and said picture student code based on said teacher model probability, said student model probability and said initial retorting weight includes:
Calculating an initial distillation loss between the picture teacher code and the picture student code using the following formula:
L=(1-α)cross_entrophy(y,p)+α*cross_entrophy(q,p)T2
Wherein L represents the initial distillation loss, y represents a real label, p represents the student model probability, q represents the teacher model probability, α represents the initial distillation weight, cross_ entrophy represents a loss function, and T represents time.
5. The method for distilling a picture coding model based on contrast learning according to claim 1, wherein the performing model joint distillation on the teacher coding model and the student coding model by using the first contrast learning-distilling loss and the second contrast learning-distilling loss to obtain a distilled teacher model and a distilled student model comprises:
Taking the first contrast learning-distillation loss as positive sample data between the teacher encoding model and the student encoding model, and the second contrast learning-distillation loss as negative sample data between the teacher encoding model and the student encoding model;
Performing positive sample distillation on the teacher coding model and the student coding model by using the positive sample data to obtain a positive sample teacher distillation model and a positive sample student distillation model;
And performing negative sample distillation on the positive sample teacher distillation model and the positive sample student distillation model by using the negative sample data to obtain the distillation teacher model and the distillation student model.
6. The method for distilling a picture coding model based on contrast learning according to claim 1, wherein the performing picture enhancement on the picture to be coded to obtain an enhanced picture comprises:
Determining the signal-to-noise ratio of the picture to be encoded;
Inquiring the total pixel number of the picture to be coded;
according to the signal-to-noise ratio and the total pixel number, calculating the pixel number to be noisy of the picture to be encoded by using the following formula:
NP=SP(1-SNR)
Wherein NP represents the number of pixels to be noisy, SP represents the total number of pixels, and SNR represents the signal-to-noise ratio; determining random noise adding pixel positions in the picture to be coded based on the number of pixels to be noise added; and configuring a target pixel value at the random noise adding pixel position to obtain the enhanced picture.
7. The method for distilling a picture coding model based on contrast learning according to claim 1, wherein performing model double distillation on the distillation teacher model by using the first contrast learning loss and the second contrast learning loss to obtain a double distillation model comprises:
taking the first contrast learning loss as a distillation positive sample of the distillation teacher model and the second contrast learning loss as a distillation negative sample of the distillation teacher model;
Performing model positive sample distillation on the distillation teacher model by using the distillation positive sample to obtain a positive sample distillation model;
And performing model negative sample distillation on the positive sample distillation model by using the distillation negative sample to obtain the secondary distillation model.
8. A contrast learning-based picture coding model distillation apparatus, the apparatus comprising:
the code determining module is used for acquiring the picture to be coded and the corresponding contrast learning picture thereof, determining picture teacher codes of the picture to be coded by using a teacher coding model, and determining picture student codes of the picture to be coded and the contrast learning codes of the contrast learning picture by using a student coding model;
The model distillation module is used for calculating a first comparison learning-distillation loss between the picture teacher code and the picture student code, calculating a second comparison learning-distillation loss between the picture teacher code and the comparison learning code, and carrying out model joint distillation on the teacher code model and the student code model by utilizing the first comparison learning-distillation loss and the second comparison learning-distillation loss to obtain a distillation teacher model and a distillation student model;
The loss calculation module is used for carrying out picture enhancement on the picture to be encoded to obtain an enhanced picture, calculating a first contrast learning loss between the picture to be encoded and the enhanced picture by using a distillation teacher model, and calculating a second contrast learning loss between the picture to be encoded and the contrast learning picture by using a distillation teacher model;
And the secondary distillation module is used for performing model secondary distillation on the distillation teacher model by utilizing the first comparison learning loss and the second comparison learning loss to obtain a secondary distillation model, and taking the secondary distillation model and the distillation student model as model final distillation results.
9. An electronic device, the electronic device comprising:
At least one processor; and
A memory communicatively coupled to the at least one processor; wherein,
The memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the contrast learning-based picture coding model distillation method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the contrast learning-based picture coding model distillation method according to any one of claims 1to 7.
CN202410424915.9A 2024-04-07 2024-04-07 Picture coding model distillation method and device based on contrast learning and electronic equipment Pending CN118115607A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410424915.9A CN118115607A (en) 2024-04-07 2024-04-07 Picture coding model distillation method and device based on contrast learning and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410424915.9A CN118115607A (en) 2024-04-07 2024-04-07 Picture coding model distillation method and device based on contrast learning and electronic equipment

Publications (1)

Publication Number Publication Date
CN118115607A true CN118115607A (en) 2024-05-31

Family

ID=91218178

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410424915.9A Pending CN118115607A (en) 2024-04-07 2024-04-07 Picture coding model distillation method and device based on contrast learning and electronic equipment

Country Status (1)

Country Link
CN (1) CN118115607A (en)

Similar Documents

Publication Publication Date Title
CN111898696A (en) Method, device, medium and equipment for generating pseudo label and label prediction model
CN113704531A (en) Image processing method, image processing device, electronic equipment and computer readable storage medium
CN111104941B (en) Image direction correction method and device and electronic equipment
CN112767320A (en) Image detection method, image detection device, electronic equipment and storage medium
CN111414916A (en) Method and device for extracting and generating text content in image and readable storage medium
CN112269875B (en) Text classification method, device, electronic equipment and storage medium
CN115205225A (en) Training method, device and equipment of medical image recognition model and storage medium
CN111522979B (en) Picture sorting recommendation method and device, electronic equipment and storage medium
CN111444339B (en) Text question difficulty labeling method and device and computer readable storage medium
CN114780701B (en) Automatic question-answer matching method, device, computer equipment and storage medium
CN113240585B (en) Image processing method, device and storage medium based on generation countermeasure network
CN114022841A (en) Personnel monitoring and identifying method and device, electronic equipment and readable storage medium
CN112132037B (en) Pavement detection method, device, equipment and medium based on artificial intelligence
CN116630712A (en) Information classification method and device based on modal combination, electronic equipment and medium
CN115098644B (en) Image and text matching method and device, electronic equipment and storage medium
CN116665878A (en) Intelligent inquiry method, device, equipment and storage medium for improving accumulated errors
CN118115607A (en) Picture coding model distillation method and device based on contrast learning and electronic equipment
CN115049836A (en) Image segmentation method, device, equipment and storage medium
CN114548114A (en) Text emotion recognition method, device, equipment and storage medium
CN113255456A (en) Non-active living body detection method, device, electronic equipment and storage medium
CN114913371B (en) Multi-task learning model training method and device, electronic equipment and storage medium
CN117542085B (en) Park scene pedestrian detection method, device and equipment based on knowledge distillation
CN114627535B (en) Coordinate matching method, device, equipment and medium based on binocular camera
CN116644801A (en) Medical visual question-answering method and device based on transfer learning and electronic equipment
CN116645630A (en) Video classification method, device, equipment and medium based on feature fusion

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination