WO2020207174A1 - 用于生成量化神经网络的方法和装置 - Google Patents

用于生成量化神经网络的方法和装置 Download PDF

Info

Publication number
WO2020207174A1
WO2020207174A1 PCT/CN2020/078586 CN2020078586W WO2020207174A1 WO 2020207174 A1 WO2020207174 A1 WO 2020207174A1 CN 2020078586 W CN2020078586 W CN 2020078586W WO 2020207174 A1 WO2020207174 A1 WO 2020207174A1
Authority
WO
WIPO (PCT)
Prior art keywords
neural network
network
initial neural
quantized
parameters
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.)
Ceased
Application number
PCT/CN2020/078586
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.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology 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 Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Publication of WO2020207174A1 publication Critical patent/WO2020207174A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/06Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons
    • G06N3/063Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons using electronic means
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • the embodiments of the present disclosure relate to the field of computer technology, and in particular, to a method and device for generating a quantitative neural network.
  • a BN (Batch Normalization) layer is usually connected behind the convolutional layer included in the neural network.
  • the BN layer is used to normalize the output of the convolutional layer before passing the output of the convolutional layer to other layers, so as to improve the convergence speed of the neural network.
  • the BN layer includes a normalization parameter for multiplying the output of the convolution layer to normalize the output of the convolution layer.
  • the output of the convolutional layer is obtained by convolution of the weight of the convolutional layer and the input of the convolutional layer.
  • the data types of weights and normalization parameters are usually floating point.
  • the embodiments of the present disclosure propose a method and apparatus for generating a quantitative neural network.
  • the embodiments of the present disclosure provide a method for generating a quantized neural network.
  • the method includes: obtaining a training sample set and an initial neural network, wherein the training sample includes sample information and a sample predetermined for the sample information
  • the initial neural network includes the original floating-point network parameters.
  • the original floating-point network parameters are the floating-point weight of the convolutional layer in the initial neural network and the floating-point normalization of the batch normalization layer connected to the convolutional layer.
  • a product of parameters convert the original floating-point network parameters in the initial neural network into integer network parameters; generate a quantized initial neural network based on the converted integer network parameters; select training samples from the training sample set, and execute The following training steps: use the sample information in the selected training sample as the input of the quantized initial neural network, use the sample result in the selected training sample as the expected output of the quantized initial neural network, and train the quantized initial neural network; To determine the completion of the quantized initial neural network training, based on the completed quantized initial neural network, a quantized neural network is generated.
  • generating a quantized initial neural network based on the converted integer network parameters includes: converting the converted integer network parameters into floating-point network parameters, and converting the converted into floating-point network parameters The initial neural network is determined as the quantified initial neural network.
  • converting the original floating-point network parameters in the initial neural network into integer network parameters includes: converting floating-point weights corresponding to the original floating-point network parameters into integer weights, and converting the original floating-point network parameters into integer weights.
  • the floating-point normalization parameter corresponding to the floating-point network parameter is converted into an integer normalization parameter; the converted integer weight and the integer normalization parameter are integrated to obtain the integer network parameter.
  • the method further includes: in response to determining that the quantized initial neural network has not been trained, performing the following steps: selecting training samples from the unselected training samples included in the training sample set; adjusting the parameters of the quantized initial neural network , Obtain new floating-point network parameters; convert new floating-point network parameters into new integer network parameters, and generate a new quantized initial neural network based on the new integer network parameters; use the most recently selected training The samples and the newly generated quantized initial neural network continue to perform the training steps.
  • generating a new quantized initial neural network based on the new integer network parameters includes: converting the new integer network parameters into floating-point network parameters, and converting the new integer network parameters into floating-point network parameters The quantized initial neural network is determined as the new quantitative initial neural network.
  • the method further includes: sending the quantitative neural network to the user terminal, so that the user terminal stores the received quantitative neural network.
  • the embodiments of the present disclosure provide a method for processing information, the method comprising: obtaining the information to be processed and a target quantization neural network, wherein the target quantization neural network adopts any one of the above-mentioned first aspect Generated by the method of the embodiment; input the information to be processed into the target quantized neural network to obtain the processing result and output.
  • an embodiment of the present disclosure provides an apparatus for generating a quantized neural network.
  • the apparatus includes: a first acquiring unit configured to acquire a training sample set and an initial neural network, wherein the training sample includes sample information And for the sample results predetermined for the sample information, the initial neural network includes the original floating-point network parameters.
  • the original floating-point network parameters are the floating-point weights of the convolutional layer in the initial neural network and the batches connected to the convolutional layer.
  • the product of floating-point normalization parameters of the one layer is configured to convert the original floating-point network parameters in the initial neural network into integer network parameters; the generation unit is configured to be based on the converted integer Type network parameters to generate a quantized initial neural network; the first execution unit is configured to select training samples from the training sample set, and perform the following training steps: use the sample information in the selected training samples as the input of the quantized initial neural network, The sample results in the selected training samples are used as the expected output of the quantized initial neural network, and the quantized initial neural network is trained; in response to determining that the quantized initial neural network has been trained, a quantized neural network is generated based on the completed quantized initial neural network. .
  • the generating unit is further configured to: convert the converted integer network parameters into floating-point network parameters, and determine the initial neural network including the converted floating-point network parameters as the quantized initial neural network .
  • the conversion unit includes: a conversion module configured to convert floating-point weights corresponding to the original floating-point network parameters into integer weights, and to convert floating-point weights corresponding to the original floating-point network parameters
  • the normalization parameter is converted into an integer normalization parameter
  • the integration module is configured to integrate the converted integer weight and the integer normalization parameter to obtain an integer network parameter.
  • the device further includes: a second execution unit configured to, in response to determining that the quantized initial neural network has not been trained, perform the following steps: select training samples from unselected training samples included in the training sample set ; Adjust the parameters of the quantized initial neural network to obtain new floating-point network parameters; convert the new floating-point network parameters into new integer network parameters, and generate new quantized initial nerves based on the new integer network parameters Network; use the most recently selected training sample and the newly generated quantized initial neural network to continue the training steps.
  • a second execution unit configured to, in response to determining that the quantized initial neural network has not been trained, perform the following steps: select training samples from unselected training samples included in the training sample set ; Adjust the parameters of the quantized initial neural network to obtain new floating-point network parameters; convert the new floating-point network parameters into new integer network parameters, and generate new quantized initial nerves based on the new integer network parameters Network; use the most recently selected training sample and the newly generated quantized initial neural network to continue the training steps.
  • the second execution unit is further configured to: convert the new integer network parameter into a floating-point network parameter, and determine the quantized initial neural network including the converted floating-point network parameter as a new Quantify the initial neural network.
  • the device further includes: a sending unit configured to send the quantized neural network to the user terminal, so that the user terminal can store the received quantized neural network.
  • an embodiment of the present disclosure provides a device for processing information, the device includes: a second acquisition unit configured to acquire the information to be processed and a target quantization neural network, wherein the target quantization neural network is As generated by the method of any one of the embodiments of the above first aspect; the input unit is configured to input the information to be processed into the target quantization neural network to obtain the processing result and output.
  • the embodiments of the present disclosure provide an electronic device, including: one or more processors; a storage device, on which one or more programs are stored, when one or more programs are processed by one or more The processor executes, so that one or more processors implement the method of any one of the foregoing first aspect or second aspect.
  • an embodiment of the present disclosure provides a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method of any one of the foregoing first aspect or second aspect is implemented.
  • the method and device for generating a quantized neural network obtained by the embodiments of the present disclosure obtain a training sample set and an initial neural network, where the initial neural network includes primitive floating-point network parameters, and then the primitive float in the initial neural network Point network parameters are converted into integer network parameters, and based on the converted integer network parameters, a quantized initial neural network is generated.
  • training samples are selected from the training sample set, and the following training steps are performed:
  • the sample information is used as the input of the quantized initial neural network, and the sample results in the selected training samples are used as the expected output of the quantized initial neural network, and the quantized initial neural network is trained; in response to determining that the training of the quantized initial neural network is completed, based on the training completion
  • the quantized initial neural network generates a quantized neural network, so that in the training process of the neural network, the floating-point network parameters in the neural network are converted into integer network parameters, thereby adding quantitative constraints to the network parameters of the neural network , Which helps to reduce the storage space occupied by the neural network, and the CPU consumption when using the neural network for information processing, and to improve the efficiency of information processing; and, it is directly related to the training of the neural network in the prior art.
  • the solution of the present disclosure can reduce the accuracy loss caused by quantizing network parameters and improve the accuracy of the quantized neural network. Furthermore, the quantized neural network of the present disclosure is used for information processing. Electronic equipment, compared to electronic equipment using a quantitative neural network for information processing in the prior art, can have more accurate information processing functions.
  • FIG. 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure can be applied
  • Fig. 2 is a flowchart of an embodiment of a method for generating a quantitative neural network according to the present disclosure
  • Fig. 3 is a schematic diagram of an application scenario of the method for generating a quantitative neural network according to an embodiment of the present disclosure
  • Fig. 4 is a flowchart of another embodiment of a method for generating a quantitative neural network according to the present disclosure
  • Fig. 5 is a schematic structural diagram of an embodiment of an apparatus for generating a quantized neural network according to the present disclosure
  • Fig. 6 is a schematic structural diagram of a computer system suitable for implementing an electronic device of an embodiment of the present disclosure.
  • FIG. 1 shows an exemplary system architecture 100 to which the method for generating a quantitative neural network, an apparatus for generating a quantitative neural network, a method for processing information, or an embodiment of an apparatus for processing information of the present disclosure can be applied. .
  • the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105.
  • the network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105.
  • the network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables.
  • the user can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages and so on.
  • Various communication client applications such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, and social platform software, can be installed on the terminal devices 101, 102, and 103.
  • the terminal devices 101, 102, and 103 may be hardware or software.
  • the terminal devices 101, 102, 103 can be various electronic devices, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, moving picture expert compression Standard audio layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, Motion Picture Experts compress standard audio layer 4) players, laptop portable computers and desktop computers, etc.
  • the terminal devices 101, 102, and 103 are software, they can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules (for example, multiple software or software modules for providing distributed services), or as a single software or software module. There is no specific limitation here.
  • the server 105 may be a server that provides various services, for example, a model processing server that processes the initial neural network sent by the terminal devices 101, 102, and 103.
  • the model processing server can analyze and process the received initial neural network and other data, and feed back the processing result (for example, the quantitative neural network) to the terminal device.
  • the method for generating a quantitative neural network is generally executed by the server 105. Accordingly, the device for generating a quantitative neural network is generally set in the server 105; in addition, the method of the present disclosure
  • the method for processing information provided by the embodiment is generally executed by the terminal equipment 101, 102, 103, and correspondingly, the device for processing information is generally set in 101, 102, 103.
  • the server can be hardware or software.
  • the server can be implemented as a distributed server cluster composed of multiple servers, or as a single server.
  • the server is software, it can be implemented as multiple software or software modules (for example, multiple software or software modules for providing distributed services), or as a single software or software module. There is no specific limitation here.
  • terminal devices, networks, and servers in FIG. 1 are merely illustrative. According to implementation needs, there can be any number of terminal devices, networks and servers.
  • the method for generating a quantitative neural network includes the following steps:
  • Step 201 Obtain a training sample set and an initial neural network.
  • the execution body (for example, the server shown in FIG. 1) of the method for generating a quantitative neural network can obtain the training sample set and the initial neural network remotely or locally through a wired connection or a wireless connection.
  • the training samples in the training sample set include sample information and sample results predetermined for the sample information.
  • the sample information is the information that can be processed by the initial neural network, which can include but is not limited to at least one of the following: text, image, audio, and video.
  • the initial neural network may be a neural network for face recognition
  • the sample information may be a sample face image.
  • the sample result is the expected result obtained by processing the sample information using the initial neural network (for example, gender information used to characterize the gender of the person corresponding to the sample face image).
  • the first-acquainted neural network can be an untrained neural network or a trained neural network.
  • the function or input and output of the initial neural network can be predetermined.
  • the above-mentioned execution subject can obtain a training sample set for training the initial neural network.
  • the initial neural network includes primitive floating-point network parameters.
  • the original floating-point network parameter is the product of the floating-point weight of the convolutional layer in the initial neural network and the floating-point normalization parameter of the batch normalization layer connected to the convolutional layer.
  • the initial neural network includes a convolutional layer and a batch normalization layer.
  • the convolutional layer includes floating-point weights. Floating point weights can be used to perform convolution operations with the input of the convolutional layer to obtain the output of the convolutional layer.
  • the batch normalization layer can be connected to the convolutional layer and used to normalize the output of the convolutional layer.
  • the batch normalization layer includes a floating-point normalization parameter used to multiply the output of the convolutional layer to perform normalization processing on the output of the convolutional layer.
  • the convolutional layer and the batch normalization layer can be regarded as a network structure. The output of the network structure is determined by the product of the output of the convolutional layer and the floating-point normalization parameter.
  • the output of the convolutional layer is determined by the floating
  • the point weight is determined by the convolution of the input of the convolutional layer. Therefore, the output of the above network structure can be convolved with the input of the convolutional layer by integrating the floating-point normalization parameter and the floating-point weight. determine.
  • the input of the convolutional layer is the input variable of the aforementioned network result
  • the product of the floating-point normalization parameter and the floating-point weight is the parameter of the aforementioned network structure.
  • the product of the floating-point normalization parameter and the floating-point weight can be determined as the floating-point network parameter.
  • the original floating-point network parameters are the network parameters included in the initial neural network and to be quantified.
  • the quantization of floating-point data refers to converting floating-point data into integer data within a certain value range.
  • the value range is limited by the number of bits of the integer data. For example, if the integer data to be converted is 8 bits (ie 8 bits), the value range is (0, 255). It should be noted that, in this embodiment, when the original floating-point network parameter is quantized, the number of bits of the integer network parameter to be quantized can be predetermined by a technician.
  • floating-point data since floating-point data can record data information after the decimal point, it has higher precision.
  • the integer type data does not record the data information after the decimal point, so it can occupy less storage space, and the calculation speed is faster when the integer type data is used for calculation.
  • weights and normalization parameters in the neural network in the prior art are usually stored as floating-point types.
  • Step 202 Convert the original floating-point network parameters in the initial neural network into integer network parameters.
  • the above-mentioned executive body can convert the original floating-point network parameters in the initial neural network into integer network parameters.
  • the above-mentioned executive body may first determine the number of bits of the integer network parameters to be converted, and then use various existing methods to convert the original floating-point network parameters in the initial neural network into integer network parameters. It can be understood that converting the original floating-point network parameters in the initial neural network into integer network parameters is equivalent to adding quantitative constraints to the initial neural network.
  • the original floating-point network parameter includes the value "21.323", and it is determined in advance that the number of bits of the integer weight to be converted is eight bits, and the value range of the integer network parameter can be determined as (0, 255) , And then can directly use the rounding method to convert the value "21.323" in the original floating-point network parameter into an integer network parameter "21".
  • the above-mentioned executive body can convert the original floating-point network parameters in the initial neural network into integer network parameters through the following steps: First, the above-mentioned executive body can convert the original floating-point network parameters The floating-point weights corresponding to the network parameters are converted into integer weights, and the floating-point normalization parameters corresponding to the original floating-point network parameters are converted into integer normalization parameters. Then, the above-mentioned execution subject can integrate the converted integer weight and the integer normalization parameter to obtain the integer network parameter.
  • This implementation method first adds quantization constraints to floating-point weights and floating-point normalization parameters, and then uses the integer weights and integer normalization parameters added with quantization constraints to obtain integer network parameters, which can reduce The accuracy loss of the quantized integer network parameters helps to improve the accuracy of the quantized initial neural network.
  • Step 203 Generate a quantized initial neural network based on the converted integer network parameters.
  • the above-mentioned executive body can generate a quantized initial neural network.
  • the above-mentioned execution body may directly determine the initial neural network including the converted integer network parameters as a quantized neural network; or the above-mentioned execution body may also process the initial neural network including the converted integer network parameters, And the initial neural network after processing is determined as the quantitative initial neural network.
  • the above-mentioned executive body can generate a quantized initial neural network through the following steps: the above-mentioned executive body can convert the converted integer network parameters into floating-point network parameters, and include the conversion The initial neural network of the floating-point network parameters is determined as the quantized initial neural network.
  • the conversion of integer network parameters into floating-point network parameters is the inverse process of converting the original floating-point network parameters into integer network parameters. You can refer to the steps of converting the original floating-point network parameters into integer network parameters. Convert the converted integer network parameters to obtain floating-point network parameters.
  • the converted integer network parameter is "21". From the "21.323" in the original floating-point network parameter, it can be seen that the floating-point network parameter is accurate to three decimal places. Therefore, the integer network parameter "21" can be converted into the floating-point network parameter "21.000".
  • floating-point data can have higher precision than integer data. Therefore, after adding quantization constraints to the initial neural network, and then converting the integer network parameters into floating-point network parameters, it helps to improve the training accuracy and obtain more accurate training results in the subsequent training of the initial neural network.
  • Step 204 select training samples from the training sample set, and perform the following training steps: use sample information in the selected training samples as the input of the quantized initial neural network, and use the sample results in the selected training samples as the quantized initial neural network Train the quantized initial neural network for the expected output of, and generate a quantized neural network based on the completed quantized initial neural network in response to determining that the training of the quantized initial neural network is completed.
  • the above-mentioned execution subject may select training samples from the training sample set, and perform the following training steps:
  • Step 2041 Use the sample information in the selected training sample as the input of the quantized initial neural network, and use the sample result in the selected training sample as the expected output of the quantized initial neural network, and train the quantized initial neural network.
  • the above-mentioned executive body can use machine learning methods to train the quantized initial neural network.
  • the above-mentioned execution body inputs the sample information into the quantized initial neural network to obtain the actual result, and then uses the preset loss function to calculate the difference between the actual result and the sample result in the training sample.
  • the L2 norm can be used.
  • the number is the difference between the actual result calculated by the loss function and the sample result in the training sample.
  • Step 2042 in response to determining that the training of the quantized initial neural network is completed, generate a quantized neural network based on the completed quantized initial neural network.
  • the above-mentioned execution subject can determine whether the current training of the quantized initial neural network meets a preset completion condition, and if it is satisfied, it can determine that the training of the quantized initial neural network is completed.
  • the completion condition may include but is not limited to at least one of the following: the training time exceeds the preset duration; the number of training times exceeds the preset number; the calculated difference is less than the preset difference threshold.
  • the above-mentioned execution subject may generate a quantized neural network based on the completed quantized initial neural network in response to determining that the training is completed.
  • the quantized neural network is a neural network that has been trained and the included network parameters are integer network parameters.
  • the above-mentioned execution entity may directly determine the trained quantized initial neural network as a quantized neural network; in response to determining the completed quantized initial neural network
  • the network parameters in the neural network are floating-point network parameters
  • the above-mentioned executive body can convert the floating-point network parameters in the trained quantized initial neural network into integer network parameters, and then include the converted integer network parameters
  • the quantized initial neural network after training is determined to be the quantized neural network.
  • the execution body may perform the following steps: select training samples from the unselected training samples included in the training sample set; adjust the parameters of the quantized initial neural network , Obtain new floating-point network parameters; convert new floating-point network parameters into new integer network parameters, and generate a new quantized initial neural network based on the new integer network parameters; use the most recently selected training
  • select training samples from the unselected training samples included in the training sample set may be adjusted to perform the above training steps.
  • adjust the parameters of the quantized initial neural network Obtain new floating-point network parameters; convert new floating-point network parameters into new integer network parameters, and generate a new quantized initial neural network based on the new integer network parameters; use the most recently selected training
  • the samples and the newly generated quantized initial neural network continue to perform the above training steps (steps 2041-2042).
  • various implementations may be adopted to adjust the parameters of the quantified initial neural network based on the difference between the actual result obtained by calculation and the sample result in the training sample.
  • the BP (Back Propagation) algorithm and the SGD (Stochastic Gradient Descent) algorithm can be used to adjust the parameters of the quantized initial neural network.
  • the parameters are usually adjusted to floating point. Therefore, after adjusting the parameters, the quantized initial neural network will obtain new floating-point network parameters.
  • the above-mentioned executive body can convert the new floating-point network parameters into new integer network parameters to re-include the new floating-point network parameters.
  • the quantization of the parameters of the type network adds quantitative constraints to the initial neural network to generate a new quantized initial neural network.
  • the above-mentioned execution subject may generate a new quantized initial neural network in various ways based on the new integer network parameters.
  • the quantized initial neural network including the new integer network parameters can be directly determined as the new quantized initial neural network.
  • the above-mentioned execution subject may also process the quantized initial neural network including the new integer network parameters, and determine the processed quantized initial neural network as a new quantized initial neural network.
  • the above-mentioned executive body can generate a new quantized initial neural network through the following steps: the above-mentioned executive body can convert new integer network parameters into floating-point network parameters, and will include The quantized initial neural network of the converted floating-point network parameters is determined to be the new quantized initial neural network.
  • the above-mentioned execution subject may send the quantitative neural network to the user terminal, so that the user terminal can store the received quantitative neural network.
  • the quantized neural network with quantized constraints can take up less storage space. Through this implementation, the storage resources of the user terminal can be saved.
  • FIG. 3 is a schematic diagram of an application scenario of the method for generating a neural network according to this embodiment.
  • the server 301 can first obtain the training sample set 302 and the initial neural network 303, where the training samples in the training sample set 302 include sample information and sample results predetermined for the sample information.
  • the initial neural network 303 includes the original floating-point network parameters 304 (for example, "2.134").
  • the original floating-point network parameter 304 is the product of the floating-point weight of the convolutional layer in the initial neural network 303 and the floating-point normalization parameter of the batch normalization layer connected to the convolutional layer.
  • the server 301 converts the original floating-point network parameter 304 in the initial neural network 303 into an integer network parameter 305 (for example, "2").
  • the server 301 generates a quantized initial neural network 306 based on the converted integer network parameters 305.
  • the server 301 can select the training sample 3021 from the training sample set 302, and perform the following training steps: use the sample information 30211 in the selected training sample 3021 as the input of the quantized initial neural network 306, and use the selected training sample 3021
  • the sample result 30212 in is used as the expected output of the quantized initial neural network 306 to train the quantized initial neural network 306; in response to determining that the training of the quantized initial neural network 306 is completed, based on the completed quantized initial neural network 306, a quantized neural network 307 is generated .
  • the method provided by the above-mentioned embodiments of the present disclosure converts the floating-point network parameters in the neural network into integer network parameters during the training process of the neural network, thereby adding quantitative constraints to the network parameters of the neural network, which is helpful
  • the efficiency of information processing is improved; and, in contrast to the prior art, the network parameters in the trained neural network are directly performed Compared with quantization and generating a quantized neural network, the solution of the present disclosure can reduce the accuracy loss caused by quantizing network parameters and improve the accuracy of the quantized neural network.
  • the electronic device that uses the quantized neural network of the present disclosure for information processing Compared with the prior art electronic devices that use quantitative neural networks for information processing, they can have more accurate information processing functions.
  • FIG. 4 shows a flow 400 of an embodiment of a method for processing information.
  • the process 400 of the method for processing information includes the following steps:
  • Step 401 Obtain the information to be processed and the target quantization neural network.
  • the execution body of the method for processing information can remotely or locally obtain the training information and the target quantization neural network through a wired connection or a wireless connection.
  • the target quantization neural network is generated by using the method of any one of the embodiments corresponding to FIG. 2.
  • the target quantitative neural network is a quantitative neural network to be used for information processing.
  • the information to be processed can be the information that the target quantization neural network can process. It can include but is not limited to at least one of the following: text, image, audio, and video.
  • the target quantization neural network is a model used for face recognition, and the information to be processed may be a face image.
  • the information to be processed may be pre-stored on the execution subject, or sent to the execution subject by other electronic devices.
  • the processing result can be the output result of the target quantified neural network.
  • Step 402 Input the information to be processed into the target quantization neural network to obtain the processing result and output.
  • the above-mentioned execution subject may input the information to be processed into the target quantization neural network to obtain the processing result output by the target quantization neural network.
  • the above-mentioned execution body can output the processing result.
  • the above-mentioned execution subject may output the processing result to other electronic devices connected in communication, or may output and display the processing result.
  • the method provided by the embodiment of the present disclosure adopts the quantized neural network generated in any embodiment corresponding to FIG. 2, which can make the quantized neural network suitable for the user terminal and at the same time help reduce the consumption of storage resources of the user terminal; and
  • the user terminal uses the quantized neural network for information processing, due to the low complexity of the quantized neural network, the efficiency of the user terminal’s information processing can be improved, and the CPU consumption of the user terminal can be reduced; in addition, because it is sent to the user
  • the quantitative neural network of the terminal is a neural network obtained by adding quantitative constraints in the training process.
  • the quantitative neural network of the present disclosure Compared with the quantitative neural network generated by adding quantitative constraints to the trained neural network in the prior art, the quantitative neural network of the present disclosure The accuracy loss of the neural network is smaller, and furthermore, the user terminal can realize more accurate information processing and output by using the quantitative neural network of the present disclosure.
  • the present disclosure provides an embodiment of a device for generating a quantized neural network.
  • the device embodiment corresponds to the method embodiment shown in FIG. 2 ,
  • the device can be specifically applied to various electronic equipment.
  • the apparatus 500 for generating a quantized neural network in this embodiment includes: a first acquisition unit 501, a conversion unit 502, a generation unit 503, and a first execution unit 504.
  • the first obtaining unit 501 is configured to obtain a training sample set and an initial neural network, where the training samples include sample information and sample results predetermined for the sample information, and the initial neural network includes original floating-point network parameters and original floating-point network parameters.
  • the type network parameter is the product of the floating-point weight of the convolutional layer in the initial neural network and the floating-point normalization parameter of the batch normalization layer connected to the convolutional layer;
  • the conversion unit 502 is configured to convert the initial neural network
  • the original floating-point network parameters in the, are converted into integer network parameters;
  • the generation unit 503 is configured to generate a quantized initial neural network based on the converted integer network parameters;
  • the first execution unit 504 is configured to select training from the training sample set Sample, and perform the following training steps: use the sample information in the selected training sample as the input of the quantized initial neural network, and use the sample result in the selected training sample as the expected output of the quantized initial neural network. Perform training; in response to determining that the training of the quantized initial neural network is completed, a quantized neural network is generated based on the completed quantized initial neural network.
  • the first acquisition unit 501 of the apparatus 500 for generating a quantized neural network may remotely or locally acquire the training sample set and the initial neural network through a wired connection or a wireless connection.
  • the training samples in the training sample set include sample information and sample results predetermined for the sample information.
  • the sample information is the information that can be processed by the initial neural network, which can include but is not limited to at least one of the following: text, image, audio, and video.
  • the first-acquainted neural network can be an untrained neural network or a trained neural network.
  • the initial neural network includes primitive floating-point network parameters.
  • the original floating-point network parameter is the product of the floating-point weight of the convolutional layer in the initial neural network and the floating-point normalization parameter of the batch normalization layer connected to the convolutional layer.
  • the conversion unit 502 can convert the original floating-point network parameters in the initial neural network into integer network parameters.
  • the generation unit 503 may generate a quantized initial neural network.
  • the first execution unit 504 may select training samples from the training sample set, and perform the following training steps: use sample information in the selected training samples as quantification
  • the input of the initial neural network, the sample results in the selected training samples are used as the expected output of the quantized initial neural network, and the quantized initial neural network is trained; in response to determining that the training of the quantized initial neural network is completed, the quantized initial neural network is based on the completed training Network to generate a quantitative neural network.
  • the generating unit 503 may be further configured to: convert the converted integer network parameter into a floating-point network parameter, and convert the converted integer network parameter into a floating-point network parameter.
  • the initial neural network is determined to be the quantitative initial neural network.
  • the conversion unit 502 may include: a conversion module (not shown in the figure) configured to convert the floating-point weight corresponding to the original floating-point network parameter into an integer Weight, and convert the floating-point normalization parameters corresponding to the original floating-point network parameters into integer normalization parameters; the quadrature module (not shown in the figure) is configured as a pair of converted integer weights Integrate with integer normalization parameters to obtain integer network parameters.
  • a conversion module (not shown in the figure) configured to convert the floating-point weight corresponding to the original floating-point network parameter into an integer Weight, and convert the floating-point normalization parameters corresponding to the original floating-point network parameters into integer normalization parameters
  • the quadrature module (not shown in the figure) is configured as a pair of converted integer weights Integrate with integer normalization parameters to obtain integer network parameters.
  • the apparatus 500 may further include: a second execution unit (not shown in the figure), configured to perform the following steps in response to determining that the quantized initial neural network has not been trained: Select training samples from the unselected training samples included in the training sample set; adjust the parameters of the quantized initial neural network to obtain new floating-point network parameters; convert the new floating-point network parameters into new integer network parameters, And based on the new integer network parameters, generate a new quantized initial neural network; use the most recently selected training sample and the newly generated quantized initial neural network to continue the training step.
  • a second execution unit (not shown in the figure), configured to perform the following steps in response to determining that the quantized initial neural network has not been trained: Select training samples from the unselected training samples included in the training sample set; adjust the parameters of the quantized initial neural network to obtain new floating-point network parameters; convert the new floating-point network parameters into new integer network parameters, And based on the new integer network parameters, generate a new quantized initial neural network; use the most recently selected training sample and the newly generated quantized initial neural
  • the second execution unit may be further configured to: convert the new integer network parameter into a floating-point network parameter, and include the converted floating-point network parameter.
  • the quantized initial neural network is determined as a new quantized initial neural network.
  • the apparatus 500 may further include: a sending unit (not shown in the figure), configured to send the quantized neural network to the user terminal, so that the user terminal can analyze the received quantized neural network Store it.
  • a sending unit (not shown in the figure), configured to send the quantized neural network to the user terminal, so that the user terminal can analyze the received quantized neural network Store it.
  • the device 500 provided by the above-mentioned embodiment of the present disclosure converts the floating point weights in the neural network into integer weights during the training process of the neural network, thereby adding quantitative constraints to the weights of the neural network, which helps reduce The storage space occupied by the small neural network and the consumption of the CPU when the neural network is used for information processing improves the efficiency of information processing; and directly quantifies the weights in the trained neural network as in the prior art to generate Compared with the quantitative neural network, the solution of the present disclosure can reduce the loss of precision caused by weighting, and improve the accuracy of the quantitative neural network. Furthermore, the electronic equipment that uses the quantitative neural network of the present disclosure for information processing is compared with the current situation. There are technical electronic devices that use quantitative neural networks for information processing, which can have more accurate information processing functions.
  • the present disclosure provides an embodiment of a device for processing information.
  • the device embodiment corresponds to the method embodiment shown in FIG. 4.
  • the device can be specifically applied to various electronic devices.
  • the apparatus 600 for processing information in this embodiment includes: a second acquiring unit 601 and an input unit 602.
  • the second obtaining unit 601 is configured to obtain the information to be processed and the target quantized neural network, where the target quantized neural network is generated using the method of any one of the embodiments corresponding to FIG. 2
  • the input unit 602 is It is configured to input the information to be processed into the target quantized neural network to obtain the processing result and output.
  • the second acquiring unit 601 of the apparatus 600 for processing information may remotely or locally acquire the training information and the target quantization neural network through a wired connection or a wireless connection.
  • the target quantization neural network is generated by using the method of any one of the embodiments corresponding to FIG. 2.
  • the target quantitative neural network is a quantitative neural network to be used for information processing.
  • the information to be processed can be the information that the target quantization neural network can process. It can include but is not limited to at least one of the following: text, image, audio, and video.
  • the input unit 602 can input the information to be processed into the target quantization neural network to obtain the processing result and output of the target quantization neural network.
  • the apparatus 600 provided in the above-mentioned embodiment of the present disclosure adopts the quantized neural network generated in any embodiment corresponding to FIG. 2, which can make the quantized neural network applicable to the user terminal and help reduce the consumption of storage resources of the user terminal. ; And, when the user terminal is using the quantitative neural network for information processing, due to the low complexity of the quantitative neural network, the efficiency of the user terminal for information processing can be improved, and the CPU consumption of the user terminal can be reduced; in addition, due to the transmission
  • the quantized neural network for the user terminal is a neural network obtained by adding quantitative constraints in the training process.
  • the quantized neural network generated by adding quantitative constraints to the trained neural network
  • the present disclosure The precision loss of the quantized neural network is smaller, and furthermore, the user terminal can realize more accurate information processing and output by using the quantized neural network of the present disclosure.
  • FIG. 7 shows a schematic structural diagram of an electronic device (for example, the terminal device or the server in FIG. 1) 700 suitable for implementing the embodiments of the present disclosure.
  • the terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablets), PMPs (portable multimedia players), vehicle-mounted terminals (e.g. Mobile terminals such as car navigation terminals) and fixed terminals such as digital TVs, desktop computers, etc.
  • the electronic device shown in FIG. 7 is only an example, and should not bring any limitation to the function and scope of use of the embodiments of the present disclosure.
  • the electronic device 700 may include a processing device (such as a central processing unit, a graphics processor, etc.) 701, which may be loaded into a random access device according to a program stored in a read-only memory (ROM) 702 or from a storage device 708.
  • the program in the memory (RAM) 703 executes various appropriate actions and processing.
  • the RAM 703 also stores various programs and data required for the operation of the electronic device 700.
  • the processing device 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704.
  • An input/output (I/O) interface 705 is also connected to the bus 704.
  • the following devices can be connected to the I/O interface 705: including input devices 606 such as touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; including, for example, liquid crystal display (LCD), speakers, vibration An output device 707 such as a device; a storage device 708 such as a magnetic tape and a hard disk; and a communication device 709.
  • the communication device 709 may allow the electronic device 700 to perform wireless or wired communication with other devices to exchange data.
  • FIG. 7 shows an electronic device 700 having various devices, it should be understood that it is not required to implement or have all the illustrated devices. It may alternatively be implemented or provided with more or fewer devices.
  • the process described above with reference to the flowchart can be implemented as a computer software program.
  • the embodiments of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart.
  • the computer program may be downloaded and installed from the network through the communication device 709, or installed from the storage device 708, or installed from the ROM 702.
  • the processing device 701 the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
  • the computer-readable medium described in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two.
  • the computer-readable storage medium may be, for example, but not limited to, an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), optical fiber, portable compact disk read only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
  • a computer-readable storage medium may be any tangible medium that contains or stores a program, and the program may be used by or in combination with an instruction execution system, apparatus, or device.
  • a computer-readable signal medium may include a data signal propagated in a baseband or as a part of a carrier wave, and a computer-readable program code is carried therein. This propagated data signal can take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing.
  • the computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium.
  • the computer-readable signal medium may send, propagate, or transmit the program for use by or in combination with the instruction execution system, apparatus, or device .
  • the program code contained on the computer-readable medium can be transmitted by any suitable medium, including but not limited to: wire, optical cable, RF (Radio Frequency), etc., or any suitable combination of the above.
  • the above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or it may exist alone without being assembled into the electronic device.
  • the above-mentioned computer-readable medium carries one or more programs.
  • the electronic device obtains a training sample set and an initial neural network, where the training sample includes sample information and targeting Sample information Pre-determined sample results.
  • the initial neural network includes the original floating-point network parameters.
  • the original floating-point network parameters are the floating-point weight of the convolutional layer in the initial neural network and the batch normalization connected to the convolutional layer.
  • the product of floating-point normalization parameters of the layer convert the original floating-point network parameters in the initial neural network into integer network parameters, and generate a quantized initial neural network based on the converted integer network parameters; from training samples Focus on selecting training samples and perform the following training steps: use the sample information in the selected training samples as the input of the quantized initial neural network, and use the sample results in the selected training samples as the expected output of the quantized initial neural network.
  • the initial neural network is trained; in response to determining that the training of the quantized initial neural network is completed, a quantized neural network is generated based on the completed quantized initial neural network.
  • the electronic device can also be caused to: obtain the information to be processed and the target quantization neural network, where the target quantization neural network is any of those in the embodiment corresponding to FIG. 2 Generated by the method of an embodiment; input the information to be processed into the target quantization neural network to obtain the processing result and output.
  • the computer program code used to perform the operations of the present disclosure can be written in one or more programming languages or a combination thereof.
  • the programming languages include object-oriented programming languages—such as Java, Smalltalk, C++, and also conventional Procedural programming language-such as "C" language or similar programming language.
  • the program code can be executed entirely on the user's computer, partly on the user's computer, executed as an independent software package, partly on the user's computer and partly executed on a remote computer, or entirely executed on the remote computer or server.
  • the remote computer can be connected to the user’s computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to pass Internet connection).
  • LAN local area network
  • WAN wide area network
  • Internet service provider for example, using an Internet service provider to pass Internet connection.
  • each block in the flowchart or block diagram can represent a module, program segment, or part of code, and the module, program segment, or part of code contains one or more for realizing the specified logical function Executable instructions.
  • the functions marked in the block may also occur in a different order from the order marked in the drawings. For example, two blocks shown in succession can actually be executed substantially in parallel, or they can sometimes be executed in the reverse order, depending on the functions involved.
  • each block in the block diagram and/or flowchart, and the combination of the blocks in the block diagram and/or flowchart can be implemented by a dedicated hardware-based system that performs the specified functions or operations Or it can be realized by a combination of dedicated hardware and computer instructions.
  • the units involved in the embodiments described in the present disclosure may be implemented in a software manner, or may be implemented in a hardware manner.
  • the name of the unit does not constitute a limitation on the unit itself under certain circumstances.
  • the first acquisition unit can also be described as "a unit for acquiring a training sample set and an initial neural network".

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • General Health & Medical Sciences (AREA)
  • General Physics & Mathematics (AREA)
  • Evolutionary Computation (AREA)
  • Computational Linguistics (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Artificial Intelligence (AREA)
  • Neurology (AREA)
  • Machine Translation (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

本公开的实施例公开了用于生成量化神经网络的方法和装置。该方法的一具体实施方式包括:获取训练样本集和初始神经网络;将初始神经网络中的原始浮点型网络参数转化为整数型网络参数;基于转化成的整数型网络参数,生成量化初始神经网络;从训练样本集中选取训练样本,执行以下训练步骤:将训练样本中的样本信息作为量化初始神经网络的输入,将训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。该实施方式有助于减小神经网络所占用的存储空间,以及利用神经网络进行信息处理时对CPU的消耗,提高信息处理的效率。

Description

用于生成量化神经网络的方法和装置
相关申请的交叉引用
本申请基于申请号为201910288941.2、申请日为2019年04月11日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。
技术领域
本公开的实施例涉及计算机技术领域,尤其涉及用于生成量化神经网络的方法和装置。
背景技术
目前,为了加速神经网络的训练,通常会在神经网络包括的卷积层后面连接一个BN(Batch Normalization,批量归一化)层。BN层用于在将卷积层的输出传递给其他层之前,对卷积层的输出进行归一化处理,以此,提高神经网络的收敛速度。
BN层包括用于与卷积层的输出相乘,以对卷积层的输出进行归一化处理的归一化参数。卷积层的输出由卷积层的权重与卷积层的输入进行卷积获得。实践中,权重和归一化参数的数据类型通常为浮点型。
发明内容
本公开的实施例提出了用于生成量化神经网络的方法和装置。
第一方面,本公开的实施例提供了一种用于生成量化神经网络的方法,该方法包括:获取训练样本集和初始神经网络,其中,训练样本包括样本信息和针对样本信息预先确定的样本结果,初始神经网络包括原始浮点型网络参数,原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化 参数的积;将初始神经网络中的原始浮点型网络参数转化为整数型网络参数;基于转化成的整数型网络参数,生成量化初始神经网络;从训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
在一些实施例中,基于转化成的整数型网络参数,生成量化初始神经网络,包括:将转化成的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的初始神经网络确定为量化初始神经网络。
在一些实施例中,将初始神经网络中的原始浮点型网络参数转化为整数型网络参数,包括:将原始浮点型网络参数所对应的浮点型权重转化为整数型权重,以及将原始浮点型网络参数所对应的浮点型归一化参数转化为整数型归一化参数;对转化成的整数型权重和整数型归一化参数进行求积,获得整数型网络参数。
在一些实施例中,该方法还包括:响应于确定量化初始神经网络未训练完成,执行以下步骤:从训练样本集包括的未被选取的训练样本中选取训练样本;调整量化初始神经网络的参数,获得新的浮点型网络参数;将新的浮点型网络参数转化为新的整数型网络参数,以及基于新的整数型网络参数,生成新的量化初始神经网络;使用最近一次选取的训练样本和最新生成的量化初始神经网络,继续执行训练步骤。
在一些实施例中,基于新的整数型网络参数,生成新的量化初始神经网络,包括:将新的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的量化初始神经网络确定为新的量化初始神经网络。
在一些实施例中,该方法还包括:将量化神经网络发送给用户终端,以便用户终端对接收的量化神经网络进行存储。
第二方面,本公开的实施例提供了一种用于处理信息的方法,该 方法包括:获取待处理信息和目标量化神经网络,其中,目标量化神经网络为采用如上述第一方面中任一实施例的方法生成的;将待处理信息输入目标量化神经网络,获得处理结果及输出。
第三方面,本公开的实施例提供了一种用于生成量化神经网络的装置,该装置包括:第一获取单元,被配置成获取训练样本集和初始神经网络,其中,训练样本包括样本信息和针对样本信息预先确定的样本结果,初始神经网络包括原始浮点型网络参数,原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积;转化单元,被配置成将初始神经网络中的原始浮点型网络参数转化为整数型网络参数;生成单元,被配置成基于转化成的整数型网络参数,生成量化初始神经网络;第一执行单元,被配置成从训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
在一些实施例中,生成单元进一步被配置成:将转化成的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的初始神经网络确定为量化初始神经网络。
在一些实施例中,转化单元包括:转化模块,被配置成将原始浮点型网络参数所对应的浮点型权重转化为整数型权重,以及将原始浮点型网络参数所对应的浮点型归一化参数转化为整数型归一化参数;求积模块,被配置成对转化成的整数型权重和整数型归一化参数进行求积,获得整数型网络参数。
在一些实施例中,该装置还包括:第二执行单元,被配置成响应于确定量化初始神经网络未训练完成,执行以下步骤:从训练样本集包括的未被选取的训练样本中选取训练样本;调整量化初始神经网络的参数,获得新的浮点型网络参数;将新的浮点型网络参数转化为新的整数型网络参数,以及基于新的整数型网络参数,生成新的量化初始神经网络;使用最近一次选取的训练样本和最新生成的量化初始神 经网络,继续执行训练步骤。
在一些实施例中,第二执行单元进一步被配置成:将新的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的量化初始神经网络确定为新的量化初始神经网络。
在一些实施例中,该装置还包括:发送单元,被配置成将量化神经网络发送给用户终端,以便用户终端对接收的量化神经网络进行存储。
第四方面,本公开的实施例提供了一种用于处理信息的装置,该装置包括:第二获取单元,被配置成获取待处理信息和目标量化神经网络,其中,目标量化神经网络为采用如上述第一方面中任一实施例的方法生成的;输入单元,被配置成将待处理信息输入目标量化神经网络,获得处理结果及输出。
第五方面,本公开的实施例提供了一种电子设备,包括:一个或多个处理器;存储装置,其上存储有一个或多个程序,当一个或多个程序被一个或多个处理器执行,使得一个或多个处理器实现上述第一方面或第二方面中任一实施例的方法。
第六方面,本公开的实施例提供了一种计算机可读介质,其上存储有计算机程序,该程序被处理器执行时实现上述第一方面或第二方面中任一实施例的方法。
本公开的实施例提供的用于生成量化神经网络的方法和装置,通过获取训练样本集和初始神经网络,其中,初始神经网络包括原始浮点型网络参数,而后将初始神经网络中的原始浮点型网络参数转化为整数型网络参数,以及基于转化成的整数型网络参数,生成量化初始神经网络,最后从训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络,从而在神经网络的训练过程中,将神经网络中的浮点型网络参数转化为整数型网络参数,以此,为神经网络的网络参数添加了量化约束,有 助于减小神经网络所占用的存储空间,以及利用神经网络进行信息处理时对CPU的消耗,提高信息处理的效率;并且,与现有技术中的直接对训练完成的神经网络中的网络参数进行量化,生成量化神经网络相比,本公开的方案可以减小对网络参数量化所引起的精度损失,提高量化神经网络的准确度,进而,利用本公开的量化神经网络进行信息处理的电子设备,相较于现有技术中的利用量化神经网络进行信息处理的电子设备,可以具有更准确的信息处理功能。
附图说明
通过阅读参照以下附图所作的对非限制性实施例所作的详细描述,本公开的其它特征、目的和优点将会变得更明显:
图1是本公开的一个实施例可以应用于其中的示例性系统架构图;
图2是根据本公开的用于生成量化神经网络的方法的一个实施例的流程图;
图3是根据本公开的实施例的用于生成量化神经网络的方法的一个应用场景的示意图;
图4是根据本公开的用于生成量化神经网络的方法的又一个实施例的流程图;
图5是根据本公开的用于生成量化神经网络的装置的一个实施例的结构示意图;
图6是适于用来实现本公开的实施例的电子设备的计算机系统的结构示意图。
具体实施方式
下面结合附图和实施例对本公开作进一步的详细说明。可以理解的是,此处所描述的具体实施例仅仅用于解释相关发明,而非对该发明的限定。另外还需要说明的是,为了便于描述,附图中仅示出了与有关发明相关的部分。
需要说明的是,在不冲突的情况下,本公开中的实施例及实施例 中的特征可以相互组合。下面将参考附图并结合实施例来详细说明本公开。
图1示出了可以应用本公开的用于生成量化神经网络的方法、用于生成量化神经网络的装置、用于处理信息的方法或用于处理信息的装置的实施例的示例性系统架构100。
如图1所示,系统架构100可以包括终端设备101、102、103,网络104和服务器105。网络104用以在终端设备101、102、103和服务器105之间提供通信链路的介质。网络104可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。
用户可以使用终端设备101、102、103通过网络104与服务器105交互,以接收或发送消息等。终端设备101、102、103上可以安装有各种通讯客户端应用,例如网页浏览器应用、购物类应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等。
终端设备101、102、103可以是硬件,也可以是软件。当终端设备101、102、103为硬件时,可以是各种电子设备,包括但不限于智能手机、平板电脑、电子书阅读器、MP3播放器(Moving Picture Experts Group Audio Layer III,动态影像专家压缩标准音频层面3)、MP4(Moving Picture Experts Group Audio Layer IV,动态影像专家压缩标准音频层面4)播放器、膝上型便携计算机和台式计算机等等。当终端设备101、102、103为软件时,可以安装在上述所列举的电子设备中。其可以实现成多个软件或软件模块(例如用来提供分布式服务的多个软件或软件模块),也可以实现成单个软件或软件模块。在此不做具体限定。
服务器105可以是提供各种服务的服务器,例如对终端设备101、102、103发送的初始神经网络进行处理的模型处理服务器。模型处理服务器可以对接收到的初始神经网络等数据进行分析等处理,并将处理结果(例如量化神经网络)反馈给终端设备。
需要说明的是,本公开的实施例所提供的用于生成量化神经网络的方法一般由服务器105执行,相应地,用于生成量化神经网络的装置一般设置于服务器105中;另外,本公开的实施例所提供的用于处 理信息的的方法一般由终端设备101、102、103执行,相应地,用于处理信息的装置一般设置于101、102、103中。
需要说明的是,服务器可以是硬件,也可以是软件。当服务器为硬件时,可以实现成多个服务器组成的分布式服务器集群,也可以实现成单个服务器。当服务器为软件时,可以实现成多个软件或软件模块(例如用来提供分布式服务的多个软件或软件模块),也可以实现成单个软件或软件模块。在此不做具体限定。
应该理解,图1中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。
继续参考图2,示出了根据本公开的用于生成量化神经网络的方法的一个实施例的流程200。该用于生成量化神经网络的方法,包括以下步骤:
步骤201,获取训练样本集和初始神经网络。
在本实施例中,用于生成量化神经网络的方法的执行主体(例如图1所示的服务器)可以通过有线连接方式或者无线连接方式从远程或本地获取训练样本集和初始神经网络。其中,训练样本集中的训练样本包括样本信息和针对样本信息预先确定的样本结果。样本信息为初始神经网络所能处理的信息,可以包括但不限于以下至少一项:文本、图像、音频、视频。例如,初始神经网络可以为用于进行人脸识别的神经网络,则样本信息可以为样本人脸图像。样本结果为利用初始神经网络对样本信息进行处理所能获得的期望结果(例如用于表征样本人脸图像所对应的人物的性别的性别信息)。
初识神经网络可以为未经训练的神经网络,也可以为经过训练的神经网络。初始神经网络的功能或者说输入、输出可以是预先确定的。进而,上述执行主体可以获取到用于训练初始神经网络的训练样本集。
在本实施例中,初始神经网络包括原始浮点型网络参数。原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积。
具体的,初始神经网络包括卷积层和批量归一化层。卷积层包括 浮点型权重。浮点型权重可以用于与卷积层的输入进行卷积运算,获得卷积层的输出。批量归一化层可以与卷积层连接,用于对卷积层的输出进行归一化处理。具体的,批量归一化层包括用于与卷积层的输出相乘,以对卷积层的输出进行归一化处理的浮点型归一化参数。在这里,可以将卷积层和批量归一化层作为一个网络结构,该网络结构的输出由卷积层的输出与浮点型归一化参数的乘积确定,由于卷积层的输出由浮点型权重与卷积层的输入的卷积确定,因此,上述网络结构的输出可以通过对浮点型归一化参数和浮点型权重进行求积,再与卷积层的输入进行卷积确定。可以理解,卷积层的输入即为上述网络结果的输入变量,浮点型归一化参数与浮点型权重的积即为上述网络结构的参数。进而,在本实施例中,可以将浮点型归一化参数与浮点型权重的积确定为浮点型网络参数。而原始浮点型网络参数即为初始神经网络包括的、待对其进行量化的网络参数。
实践中,对浮点型数据的量化指的是将浮点型数据转化为某个取值范围内的整数型数据。这里,取值范围由整数型数据的比特位数限定。例如欲转化成的整数型数据为8比特位(即8bit),则取值范围为(0,255)。需要说明的是,在本实施例中,在对原始浮点型网络参数进行量化时,欲量化成的整数型网络参数的比特位数可以由技术人员预先确定。
可以理解,对于位数相同的浮点型数据和整数型数据,由于浮点型数据可以记录小数点之后的数据信息,因而具有更高的精度。而整数型数据由于不记录小数点之后的数据信息,因此,可以占用更少的存储空间,且利用整数型数据进行计算时,计算速度更快。
需要说明的是,为了获得更高的精度,现有技术中的神经网络中的权重和归一化参数通常存储为浮点型。
步骤202,将初始神经网络中的原始浮点型网络参数转化为整数型网络参数。
在本实施例中,基于步骤201中得到的初始神经网络,上述执行主体可以将初始神经网络中的原始浮点型网络参数转化为整数型网络参数。
具体的,上述执行主体可以首先确定所要转化的整数型网络参数的比特位数,然后,采用现有的各种方法将初始神经网络中的原始浮点型网络参数转化为整数型网络参数。可以理解,将初始神经网络中的原始浮点型网络参数转化为整数型网络参数,相当于对初始神经网络添加量化约束。
作为示例,原始浮点型网络参数包括数值“21.323”,预先确定出欲转化成的整数型权重的比特位数为八位,即可以确定整数型网络参数的取值范围为(0,255),进而可以直接采用四舍五入的方式将原始浮点型网络参数中的数值“21.323”转化为整数型网络参数“21”。
在本实施例的一些可选的实现方式中,上述执行主体可以通过以下步骤将初始神经网络中的原始浮点型网络参数转化为整数型网络参数:首先,上述执行主体可以将原始浮点型网络参数所对应的浮点型权重转化为整数型权重,以及将原始浮点型网络参数所对应的浮点型归一化参数转化为整数型归一化参数。然后,上述执行主体可以对转化成的整数型权重和整数型归一化参数进行求积,获得整数型网络参数。本实现方式首先对浮点型权重和浮点型归一化参数添加了量化约束,而后利用添加了量化约束的整数型权重和整数型归一化参数获得整数型网络参数,以此,可以减少量化后的整数型网络参数的精度损失,有助于提高量化后的初始神经网络的准确度。
步骤203,基于转化成的整数型网络参数,生成量化初始神经网络。
在本实施例中,基于步骤202中转化成的整数型网络参数,上述执行主体可以生成量化初始神经网络。
具体的,上述执行主体可以直接将包括转化成的整数型网络参数的初始神经网络确定为量化神经网络;或者,上述执行主体也可以对包括转化成的整数型网络参数的初始神经网络进行处理,并将处理后的初始神经网络确定为量化初始神经网络。
在本实施例的一些可选的实现方式中,上述执行主体可以通过以下步骤生成量化初始神经网络:上述执行主体可以将转化成的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参 数的初始神经网络确定为量化初始神经网络。
这里,将整数型网络参数转化为浮点型网络参数为上述将原始浮点型网络参数转化为整数型网络参数的逆过程,可以参考将原始浮点型网络参数化为整数型网络参数的步骤对转化成的整数型网络参数进行转化,获得浮点型网络参数。
继续上述示例,转化成的整数型网络参数为“21”,由原始浮点型网络参数中的“21.323”可知,浮点型网络参数精确到小数点后三位。所以,这里可以将整数型网络参数“21”转化为浮点型网络参数“21.000”。
需要说明的是,浮点型数据相较于整数型数据可以具有更高的精度。所以为初始神经网络添加量化约束后,再将整数型网络参数转化为浮点型网络参数,有助于在后续对初始神经网络的训练过程中,提高训练精度,获得更为准确的训练结果。
步骤204,从训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
在本实施例中,基于步骤201中获得的训练样本集,上述执行主体可以从训练样本集中选取训练样本,以及执行以下训练步骤:
步骤2041,将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练。
在这里,上述执行主体可以利用机器学习方法,对量化初始神经网络进行训练。具体的,上述执行主体将样本信息输入量化初始神经网络,获得实际结果,然后利用预设的损失函数计算所得到的实际结果与训练样本中的样本结果之间的差异,例如,可以采用L2范数作为损失函数计算所得到的实际结果息与训练样本中的样本结果之间的差异。
步骤2042,响应于确定量化初始神经网络训练完成,基于训练完 成的量化初始神经网络,生成量化神经网络。
具体的,上述执行主体可以确定当前对量化初始神经网络的训练是否满足预先设置的完成条件,若满足,则可以确定量化初始神经网络训练完成。其中,完成条件可以包括但不限于以下至少一项:训练时间超过预设时长;训练次数超过预设次数;计算所得的差异小于预设差异阈值。
在本实施例中,上述执行主体可以响应于确定训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。其中,量化神经网络为训练完成的、所包括的网络参数为整数型网络参数的神经网络。
具体的,响应于确定训练完成的量化初始神经网络中的网络参数为整数型权重,则上述执行主体可以直接将训练完成的量化初始神经网络确定为量化神经网络;响应于确定训练完成的量化初始神经网络中的网络参数为浮点型网络参数,则上述执行主体可以将训练完成的量化初始神经网络中的浮点型网络参数转化为整数型网络参数,进而将包括转化成的整数型网络参数的、训练完成的量化初始神经网络确定为量化神经网络。
在本实施例中,上述执行主体还可以响应于确定量化初始神经网络未训练完成,执行以下步骤:从训练样本集包括的未被选取的训练样本中选取训练样本;调整量化初始神经网络的参数,获得新的浮点型网络参数;将新的浮点型网络参数转化为新的整数型网络参数,以及基于新的整数型网络参数,生成新的量化初始神经网络;使用最近一次选取的训练样本和最新生成的量化初始神经网络,继续执行上述训练步骤(步骤2041-2042)。
这里,可以采用各种实现方式基于计算得到的实际结果与训练样本中的样本结果之间的差异调整量化初始神经网络的参数。例如,可以采用BP(Back Propagation,反向传播)算法及SGD(Stochastic Gradient Descent,随机梯度下降)算法来调整量化初始神经网络的参数。需要说明的是,调整参数时,为了不影响训练的收敛情况,保证训练能够重复执行,通常会将参数调整为浮点型。因此,调整参数后量化初始神经网络会获得新的浮点型网络参数,进而,上述执行主体 可以将新的浮点型网络参数转化为新的整数型网络参数,以重新为包括新的浮点型网络参数的量化初始神经网络添加量化约束,生成新的量化初始神经网络。
具体的,上述执行主体可以基于新的整数型网络参数,采用各种方式生成新的量化初始神经网络。例如,可以直接将包括新的整数型网络参数的量化初始神经网络确定为新的量化初始神经网络。或者,上述执行主体也可以对包括新的整数型网络参数的量化初始神经网络进行处理,并将处理后的量化初始神经网络确定为新的量化初始神经网络。
在本实施例的一些可选的实现方式中,上述执行主体可以通过以下步骤生成新的量化初始神经网络:上述执行主体可以将新的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的量化初始神经网络确定为新的量化初始神经网络。
在本实施例的一些可选的实现方式中,上述执行主体可以将量化神经网络发送给用户终端,以便用户终端对接收的量化神经网络进行存储。在这里,添加了量化约束的量化神经网络可以占用更少的存储空间,通过本实现方式,可以节省用户终端的存储资源。
继续参见图3,图3是根据本实施例的用于生成神经网络的方法的应用场景的一个示意图。在图3的应用场景中,服务器301首先可以获取训练样本集302和初始神经网络303,其中,训练样本集302中的训练样本包括样本信息和针对样本信息预先确定的样本结果。初始神经网络303包括原始浮点型网络参数304(例如“2.134”)。原始浮点型网络参数304为初始神经网络303中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积。然后,服务器301将初始神经网络303中的原始浮点型网络参数304转化为整数型网络参数305(例如“2”)。接着,服务器301基于转化成的整数型网络参数305,生成量化初始神经网络306。最后,服务器301可以从训练样本集302中选取训练样本3021,以及执行以下训练步骤:将所选取的训练样本3021中的样本信息30211作为量化初始神经网络306 的输入,将所选取的训练样本3021中的样本结果30212作为量化初始神经网络306的期望输出,对量化初始神经网络306进行训练;响应于确定量化初始神经网络306训练完成,基于训练完成的量化初始神经网络306,生成量化神经网络307。
本公开的上述实施例提供的方法在神经网络的训练过程中,将神经网络中的浮点型网络参数转化为整数型网络参数,以此,为神经网络的网络参数添加了量化约束,有助于减小神经网络所占用的存储空间,以及利用神经网络进行信息处理时对CPU的消耗,提高信息处理的效率;并且,与现有技术中的直接对训练完成的神经网络中的网络参数进行量化,生成量化神经网络相比,本公开的方案可以减小对网络参数量化所引起的精度损失,提高量化神经网络的准确度,进而,利用本公开的量化神经网络进行信息处理的电子设备,相较于现有技术中的利用量化神经网络进行信息处理的电子设备,可以具有更准确的信息处理功能。
进一步参考图4,其示出了用于处理信息的方法的一个实施例的流程400。该用于处理信息的方法的流程400,包括以下步骤:
步骤401,获取待处理信息和目标量化神经网络。
在本实施例中,用于处理信息的方法的执行主体(例如图1所示的终端设备)可以通过有线连接方式或者无线连接方式从远程或本地获取训待处理信息和目标量化神经网络。其中,目标量化神经网络为采用图2对应的实施例中的任一实施例的方法生成的。目标量化神经网络为待利用其进行信息处理的量化神经网络。待处理信息可以为目标量化神经网络所能够处理的信息。可以包括但不限于以下至少一项:文本、图像、音频、视频。作为示例,目标量化神经网络为用于进行人脸识别的模型,则待处理信息可以为人脸图像。待处理信息可以预先存储在上述执行主体上,也可以由其他电子设备发送给上述执行主体。处理结果可以为目标量化神经网络的输出结果。
步骤402,将待处理信息输入目标量化神经网络,获得处理结果及输出。
具体的,上述执行主体可以将待处理信息输入目标量化神经网络,获得目标量化神经网络输出的处理结果。
在这里,获得处理结果后,上述执行主体可以输出处理结果。具体的,上述执行主体可以将处理结果输出给通信连接的其他电子设备,也可以对处理结果进行输出显示。
实践中,由于用户终端的存储空间较小,而一般的神经网络需要消耗大量的存储资源,所以通常神经网络在用户终端上难以适用。本公开的实施例提供的方法采用图2对应的任一实施例中生成的量化神经网络,可以使得量化神经网络适用于用户终端,同时有助于减小对用户终端的存储资源的消耗;并且,当用户终端在利用量化神经网络进行信息处理时,由于量化神经网络的复杂程度低,所以可以提高用户终端进行信息处理的效率,减小对用户终端的CPU的消耗;此外,由于发送给用户终端的量化神经网络是通过在训练过程中添加量化约束而获得的神经网络,与现有技术中的、通过为训练完成的神经网络添加量化约束而生成的量化神经网络相比,本公开的量化神经网络的精度损失更小,进而,用户终端利用本公开的量化神经网络可以实现更为准确的信息处理及输出。
进一步参考图5,作为对上述各图所示方法的实现,本公开提供了一种用于生成量化神经网络的装置的一个实施例,该装置实施例与图2所示的方法实施例相对应,该装置具体可以应用于各种电子设备中。
如图5所示,本实施例的用于生成量化神经网络的装置500包括:第一获取单元501、转化单元502、生成单元503和第一执行单元504。其中,第一获取单元501被配置成获取训练样本集和初始神经网络,其中,训练样本包括样本信息和针对样本信息预先确定的样本结果,初始神经网络包括原始浮点型网络参数,原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积;转化单元502被配置成将初始神经网络中的原始浮点型网络参数转化为整数型网络参数;生成单元503被配置成 基于转化成的整数型网络参数,生成量化初始神经网络;第一执行单元504被配置成从训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
在本实施例中,用于生成量化神经网络的装置500的第一获取单元501可以通过有线连接方式或者无线连接方式从远程或本地获取训练样本集和初始神经网络。其中,训练样本集中的训练样本包括样本信息和针对样本信息预先确定的样本结果。样本信息为初始神经网络所能处理的信息,可以包括但不限于以下至少一项:文本、图像、音频、视频。初识神经网络可以为未经训练的神经网络,也可以为经过训练的神经网络。
在本实施例中,初始神经网络包括原始浮点型网络参数。原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积。
在本实施例中,基于第一获取单元501得到的初始神经网络,转化单元502可以将初始神经网络中的原始浮点型网络参数转化为整数型网络参数。
在本实施例中,基于转化单元502转化成的整数型网络参数,生成单元503可以生成量化初始神经网络。
在本实施例中,基于第一获取单元501获得的训练样本集,第一执行单元504可以从训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
在本实施例的一些可选的实现方式中,生成单元503可以进一步被配置成:将转化成的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的初始神经网络确定为量化初始神经 网络。
在本实施例的一些可选的实现方式中,转化单元502可以包括:转化模块(图中未示出),被配置成将原始浮点型网络参数所对应的浮点型权重转化为整数型权重,以及将原始浮点型网络参数所对应的浮点型归一化参数转化为整数型归一化参数;求积模块(图中未示出),被配置成对转化成的整数型权重和整数型归一化参数进行求积,获得整数型网络参数。
在本实施例的一些可选的实现方式中,装置500还可以包括:第二执行单元(图中未示出),被配置成响应于确定量化初始神经网络未训练完成,执行以下步骤:从训练样本集包括的未被选取的训练样本中选取训练样本;调整量化初始神经网络的参数,获得新的浮点型网络参数;将新的浮点型网络参数转化为新的整数型网络参数,以及基于新的整数型网络参数,生成新的量化初始神经网络;使用最近一次选取的训练样本和最新生成的量化初始神经网络,继续执行训练步骤。
在本实施例的一些可选的实现方式中,第二执行单元可以进一步被配置成:将新的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的量化初始神经网络确定为新的量化初始神经网络。
在本实施例的一些可选的实现方式中,装置500还可以包括:发送单元(图中未示出),被配置成将量化神经网络发送给用户终端,以便用户终端对接收的量化神经网络进行存储。
可以理解的是,该装置500中记载的诸单元与参考图2描述的方法中的各个步骤相对应。由此,上文针对方法描述的操作、特征以及产生的有益效果同样适用于装置500及其中包含的单元,在此不再赘述。
本公开的上述实施例提供的装置500在神经网络的训练过程中,将神经网络中的浮点型权重转化为整数型权重,以此,为神经网络的权重添加了量化约束,有助于减小神经网络所占用的存储空间,以及利用神经网络进行信息处理时对CPU的消耗,提高信息处理的效率;并且,与现有技术中的直接对训练完成的神经网络中的权重进行量化, 生成量化神经网络相比,本公开的方案可以减小对权重量化所引起的精度损失,提高量化神经网络的准确度,进而,利用本公开的量化神经网络进行信息处理的电子设备,相较于现有技术中的利用量化神经网络进行信息处理的电子设备,可以具有更准确的信息处理功能。
进一步参考图6,作为对上述各图所示方法的实现,本公开提供了一种用于处理信息的装置的一个实施例,该装置实施例与图4所示的方法实施例相对应,该装置具体可以应用于各种电子设备中。
如图6所示,本实施例的用于处理信息的装置600包括:第二获取单元601和输入单元602。其中,第二获取单元601被配置成获取待处理信息和目标量化神经网络,其中,目标量化神经网络为采用如图2对应的实施例中的任一实施例的方法生成的;输入单元602被配置成将待处理信息输入目标量化神经网络,获得处理结果及输出。
在本实施例中,用于处理信息的装置600的第二获取单元601可以通过有线连接方式或者无线连接方式从远程或本地获取训待处理信息和目标量化神经网络。其中,目标量化神经网络为采用图2对应的实施例中的任一实施例的方法生成的。目标量化神经网络为待利用其进行信息处理的量化神经网络。待处理信息可以为目标量化神经网络所能够处理的信息。可以包括但不限于以下至少一项:文本、图像、音频、视频。
在本实施例中,输入单元602可以将待处理信息输入目标量化神经网络,获得目标量化神经网络输出的处理结果及输出。
可以理解的是,该装置600中记载的诸单元与参考图4描述的方法中的各个步骤相对应。由此,上文针对方法描述的操作、特征以及产生的有益效果同样适用于装置600及其中包含的单元,在此不再赘述。
本公开的上述实施例提供的装置600采用图2对应的任一实施例中生成的量化神经网络,可以使得量化神经网络适用于用户终端,同时有助于减小对用户终端的存储资源的消耗;并且,当用户终端在利用量化神经网络进行信息处理时,由于量化神经网络的复杂程度低, 所以可以提高用户终端进行信息处理的效率,减小对用户终端的CPU的消耗;此外,由于发送给用户终端的量化神经网络是通过在训练过程中添加量化约束而获得的神经网络,与现有技术中的、通过为训练完成的神经网络添加量化约束而生成的量化神经网络相比,本公开的量化神经网络的精度损失更小,进而,用户终端利用本公开的量化神经网络可以实现更为准确的信息处理及输出。
下面参考图7,其示出了适于用来实现本公开实施例的电子设备(例如图1中的终端设备或服务器)700的结构示意图。本公开实施例中的终端设备可以包括但不限于诸如移动电话、笔记本电脑、数字广播接收器、PDA(个人数字助理)、PAD(平板电脑)、PMP(便携式多媒体播放器)、车载终端(例如车载导航终端)等等的移动终端以及诸如数字TV、台式计算机等等的固定终端。图7示出的电子设备仅仅是一个示例,不应对本公开实施例的功能和使用范围带来任何限制。
如图7所示,电子设备700可以包括处理装置(例如中央处理器、图形处理器等)701,其可以根据存储在只读存储器(ROM)702中的程序或者从存储装置708加载到随机访问存储器(RAM)703中的程序而执行各种适当的动作和处理。在RAM 703中,还存储有电子设备700操作所需的各种程序和数据。处理装置701、ROM 702以及RAM 703通过总线704彼此相连。输入/输出(I/O)接口705也连接至总线704。
通常,以下装置可以连接至I/O接口705:包括例如触摸屏、触摸板、键盘、鼠标、摄像头、麦克风、加速度计、陀螺仪等的输入装置606;包括例如液晶显示器(LCD)、扬声器、振动器等的输出装置707;包括例如磁带、硬盘等的存储装置708;以及通信装置709。通信装置709可以允许电子设备700与其他设备进行无线或有线通信以交换数据。虽然图7示出了具有各种装置的电子设备700,但是应理解的是,并不要求实施或具备所有示出的装置。可以替代地实施或具备更多或更少的装置。
特别地,根据本公开的实施例,上文参考流程图描述的过程可以 被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信装置709从网络上被下载和安装,或者从存储装置708被安装,或者从ROM 702被安装。在该计算机程序被处理装置701执行时,执行本公开实施例的方法中限定的上述功能。
需要说明的是,本公开所述的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本公开中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本公开中,计算机可读信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读信号介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:电线、光缆、RF(射频)等等,或者上述的任意合适的组合。
上述计算机可读介质可以是上述电子设备中所包含的;也可以是单独存在,而未装配入该电子设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被该电子设备执行时,使得该电子设备:获取训练样本集和初始神经网络,其中,训练样本包括样本信息和针对样本信息预先确定的样本结果,初始神经网络包括 原始浮点型网络参数,原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积;将初始神经网络中的原始浮点型网络参数转化为整数型网络参数,以及基于转化成的整数型网络参数,生成量化初始神经网络;从训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
此外,当上述一个或者多个程序被该电子设备执行时,还可以使得该电子设备:获取待处理信息和目标量化神经网络,其中,目标量化神经网络为采用图2对应的实施例中的任一实施例的方法生成的;将待处理信息输入目标量化神经网络,获得处理结果及输出。
可以以一种或多种程序设计语言或其组合来编写用于执行本公开的操作的计算机程序代码,所述程序设计语言包括面向对象的程序设计语言—诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络——包括局域网(LAN)或广域网(WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。
附图中的流程图和框图,图示了按照本公开各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,该模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时 也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。
描述于本公开实施例中所涉及到的单元可以通过软件的方式实现,也可以通过硬件的方式来实现。其中,单元的名称在某种情况下并不构成对该单元本身的限定,例如,第一获取单元还可以被描述为“获取训练样本集和初始神经网络的单元”。
以上描述仅为本公开的较佳实施例以及对所运用技术原理的说明。本领域技术人员应当理解,本公开中所涉及的公开范围,并不限于上述技术特征的特定组合而成的技术方案,同时也应涵盖在不脱离上述公开构思的情况下,由上述技术特征或其等同特征进行任意组合而形成的其它技术方案。例如上述特征与本公开中公开的(但不限于)具有类似功能的技术特征进行互相替换而形成的技术方案。

Claims (16)

  1. 一种用于生成量化神经网络的方法,包括:
    获取训练样本集和初始神经网络,其中,训练样本包括样本信息和针对样本信息预先确定的样本结果,初始神经网络包括原始浮点型网络参数,原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积;
    将初始神经网络中的原始浮点型网络参数转化为整数型网络参数;
    基于转化成的整数型网络参数,生成量化初始神经网络;
    从所述训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
  2. 根据权利要求1所述的方法,其中,所述基于转化成的整数型网络参数,生成量化初始神经网络,包括:
    将转化成的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的初始神经网络确定为量化初始神经网络。
  3. 根据权利要求1所述的方法,其中,所述将初始神经网络中的原始浮点型网络参数转化为整数型网络参数,包括:
    将原始浮点型网络参数所对应的浮点型权重转化为整数型权重,以及将原始浮点型网络参数所对应的浮点型归一化参数转化为整数型归一化参数;
    对转化成的整数型权重和整数型归一化参数进行求积,获得整数型网络参数。
  4. 根据权利要求1所述的方法,其中,所述方法还包括:
    响应于确定量化初始神经网络未训练完成,执行以下步骤:从所述训练样本集包括的未被选取的训练样本中选取训练样本;调整量化初始神经网络的参数,获得新的浮点型网络参数;将新的浮点型网络参数转化为新的整数型网络参数,以及基于新的整数型网络参数,生成新的量化初始神经网络;使用最近一次选取的训练样本和最新生成的量化初始神经网络,继续执行所述训练步骤。
  5. 根据权利要求4所述的方法,其中,所述基于新的整数型网络参数,生成新的量化初始神经网络,包括:
    将新的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的量化初始神经网络确定为新的量化初始神经网络。
  6. 根据权利要求1-5之一所述的方法,其中,所述方法还包括:
    将量化神经网络发送给用户终端,以便用户终端对接收的量化神经网络进行存储。
  7. 一种用于处理信息的方法,包括:
    获取待处理信息和目标量化神经网络,其中,所述目标量化神经网络为采用如权利要求1-6中任一所述的方法生成的;
    将所述待处理信息输入所述目标量化神经网络,获得处理结果及输出。
  8. 一种用于生成量化神经网络的装置,包括:
    第一获取单元,被配置成获取训练样本集和初始神经网络,其中,训练样本包括样本信息和针对样本信息预先确定的样本结果,初始神经网络包括原始浮点型网络参数,原始浮点型网络参数为初始神经网络中的卷积层的浮点型权重和与卷积层连接的批量归一化层的浮点型归一化参数的积;
    转化单元,被配置成将初始神经网络中的原始浮点型网络参数转 化为整数型网络参数;
    生成单元,被配置成基于转化成的整数型网络参数,生成量化初始神经网络;
    第一执行单元,被配置成从所述训练样本集中选取训练样本,以及执行以下训练步骤:将所选取的训练样本中的样本信息作为量化初始神经网络的输入,将所选取的训练样本中的样本结果作为量化初始神经网络的期望输出,对量化初始神经网络进行训练;响应于确定量化初始神经网络训练完成,基于训练完成的量化初始神经网络,生成量化神经网络。
  9. 根据权利要求8所述的装置,其中,所述生成单元进一步被配置成:
    将转化成的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的初始神经网络确定为量化初始神经网络。
  10. 根据权利要求8所述的装置,其中,所述转化单元包括:
    转化模块,被配置成将原始浮点型网络参数所对应的浮点型权重转化为整数型权重,以及将原始浮点型网络参数所对应的浮点型归一化参数转化为整数型归一化参数;
    求积模块,被配置成对转化成的整数型权重和整数型归一化参数进行求积,获得整数型网络参数。
  11. 根据权利要求8所述的装置,其中,所述装置还包括:
    第二执行单元,被配置成响应于确定量化初始神经网络未训练完成,执行以下步骤:从所述训练样本集包括的未被选取的训练样本中选取训练样本;调整量化初始神经网络的参数,获得新的浮点型网络参数;将新的浮点型网络参数转化为新的整数型网络参数,以及基于新的整数型网络参数,生成新的量化初始神经网络;使用最近一次选取的训练样本和最新生成的量化初始神经网络,继续执行所述训练步骤。
  12. 根据权利要求11所述的装置,其中,所述第二执行单元进一步被配置成:
    将新的整数型网络参数转化为浮点型网络参数,以及将包括转化成的浮点型网络参数的量化初始神经网络确定为新的量化初始神经网络。
  13. 根据权利要求8-12之一所述的装置,其中,所述装置还包括:
    发送单元,被配置成将量化神经网络发送给用户终端,以便用户终端对接收的量化神经网络进行存储。
  14. 一种用于处理信息的装置,包括:
    第二获取单元,被配置成获取待处理信息和目标量化神经网络,其中,所述目标量化神经网络为采用如权利要求1-6中任一所述的方法生成的;
    输入单元,被配置成将所述待处理信息输入所述目标量化神经网络,获得处理结果及输出。
  15. 一种电子设备,包括:
    一个或多个处理器;
    存储装置,其上存储有一个或多个程序,
    当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现如权利要求1-7中任一所述的方法。
  16. 一种计算机可读介质,其上存储有计算机程序,其中,该程序被处理器执行时实现如权利要求1-7中任一所述的方法。
PCT/CN2020/078586 2019-04-11 2020-03-10 用于生成量化神经网络的方法和装置 Ceased WO2020207174A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910288941.2 2019-04-11
CN201910288941.2A CN109961141A (zh) 2019-04-11 2019-04-11 用于生成量化神经网络的方法和装置

Publications (1)

Publication Number Publication Date
WO2020207174A1 true WO2020207174A1 (zh) 2020-10-15

Family

ID=67026033

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/078586 Ceased WO2020207174A1 (zh) 2019-04-11 2020-03-10 用于生成量化神经网络的方法和装置

Country Status (2)

Country Link
CN (1) CN109961141A (zh)
WO (1) WO2020207174A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115841136A (zh) * 2022-07-29 2023-03-24 上海阵量智能科技有限公司 神经网络的量化方法、装置、芯片、板卡及设备

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109961141A (zh) * 2019-04-11 2019-07-02 北京字节跳动网络技术有限公司 用于生成量化神经网络的方法和装置
CN110443165B (zh) * 2019-07-23 2022-04-29 北京迈格威科技有限公司 神经网络量化方法、图像识别方法、装置和计算机设备
CN110852421B (zh) * 2019-11-11 2023-01-17 北京百度网讯科技有限公司 模型生成方法和装置
CN111340226B (zh) * 2020-03-06 2022-01-25 北京市商汤科技开发有限公司 一种量化神经网络模型的训练及测试方法、装置及设备
CN112308226B (zh) * 2020-08-03 2024-05-24 北京沃东天骏信息技术有限公司 神经网络模型的量化、用于输出信息的方法和装置
CN113011569B (zh) * 2021-04-07 2024-06-18 开放智能机器(上海)有限公司 离线量化参数加注方法、装置、电子设备和存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107590460A (zh) * 2017-09-12 2018-01-16 北京达佳互联信息技术有限公司 人脸分类方法、装置及智能终端
CN108509179A (zh) * 2018-04-04 2018-09-07 百度在线网络技术(北京)有限公司 用于生成模型的方法和装置
CN109165736A (zh) * 2018-08-08 2019-01-08 北京字节跳动网络技术有限公司 应用于卷积神经网络的信息处理方法和装置
CN109961141A (zh) * 2019-04-11 2019-07-02 北京字节跳动网络技术有限公司 用于生成量化神经网络的方法和装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107590460A (zh) * 2017-09-12 2018-01-16 北京达佳互联信息技术有限公司 人脸分类方法、装置及智能终端
CN108509179A (zh) * 2018-04-04 2018-09-07 百度在线网络技术(北京)有限公司 用于生成模型的方法和装置
CN109165736A (zh) * 2018-08-08 2019-01-08 北京字节跳动网络技术有限公司 应用于卷积神经网络的信息处理方法和装置
CN109961141A (zh) * 2019-04-11 2019-07-02 北京字节跳动网络技术有限公司 用于生成量化神经网络的方法和装置

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115841136A (zh) * 2022-07-29 2023-03-24 上海阵量智能科技有限公司 神经网络的量化方法、装置、芯片、板卡及设备

Also Published As

Publication number Publication date
CN109961141A (zh) 2019-07-02

Similar Documents

Publication Publication Date Title
WO2020207174A1 (zh) 用于生成量化神经网络的方法和装置
CN110009101B (zh) 用于生成量化神经网络的方法和装置
WO2020155907A1 (zh) 用于生成漫画风格转换模型的方法和装置
CN112686031B (zh) 文本特征提取模型的量化方法、装置、设备及存储介质
CN112699991A (zh) 用于加速神经网络训练的信息处理的方法、电子设备和计算机可读介质
CN112364860B (zh) 字符识别模型的训练方法、装置和电子设备
CN110021052B (zh) 用于生成眼底图像生成模型的方法和装置
CN112650841A (zh) 信息处理方法、装置和电子设备
US11651198B2 (en) Data processing method and apparatus for neural network
CN110149238A (zh) 用于预测流量的方法和装置
US12614043B2 (en) Model training method and apparatus, machine translation method and apparatus, and device and storage medium
CN114038465B (zh) 语音处理方法、装置和电子设备
CN112149699A (zh) 用于生成模型的方法、装置和用于识别图像的方法、装置
CN111681661A (zh) 语音识别的方法、装置、电子设备和计算机可读介质
CN109598344B (zh) 模型生成方法和装置
CN115146657A (zh) 模型训练方法、装置、存储介质、客户端、服务器和系统
CN111680754A (zh) 图像分类方法、装置、电子设备及计算机可读存储介质
WO2021068493A1 (zh) 用于处理信息的方法和装置
CN111933122B (zh) 语音识别方法、装置、电子设备和计算机可读介质
CN111915689B (zh) 用于生成目标函数的方法、装置、电子设备和计算机可读介质
CN110046670B (zh) 特征向量降维方法和装置
CN113361678A (zh) 神经网络模型的训练方法和装置
CN112015625B (zh) 报警设备控制方法、装置、电子设备和计算机可读介质
CN112270170B (zh) 一种隐式表述语句的分析方法、装置、介质和电子设备
CN113593527B (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: 20788619

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 02.02.2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20788619

Country of ref document: EP

Kind code of ref document: A1