WO2020037512A1 - 一种神经网络计算方法和装置 - Google Patents

一种神经网络计算方法和装置 Download PDF

Info

Publication number
WO2020037512A1
WO2020037512A1 PCT/CN2018/101598 CN2018101598W WO2020037512A1 WO 2020037512 A1 WO2020037512 A1 WO 2020037512A1 CN 2018101598 W CN2018101598 W CN 2018101598W WO 2020037512 A1 WO2020037512 A1 WO 2020037512A1
Authority
WO
WIPO (PCT)
Prior art keywords
vector
processed
neural network
network layer
network
Prior art date
Application number
PCT/CN2018/101598
Other languages
English (en)
French (fr)
Inventor
胡慧
郑成林
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Priority to CN201880090586.1A priority Critical patent/CN111788584A/zh
Priority to PCT/CN2018/101598 priority patent/WO2020037512A1/zh
Publication of WO2020037512A1 publication Critical patent/WO2020037512A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • Embodiments of the present application relate to the field of communications technologies, and in particular, to a method and a device for calculating a neural network.
  • Neural network is an algorithm mathematical model that imitates the behavioral characteristics of animal neural networks and performs distributed parallel information processing. It has been widely used in many fields. At present, structured matrices have achieved good results in the compression and acceleration of neural networks. Among them, the block circular matrix is a type of structured matrix. The block circular matrix is applied to the convolution layer, the fully connected layer, and the short-term and long-term. The memory layer (Long Short-Term Memory, LSTM) can achieve high multiple network parameter compression.
  • LSTM Long Short-Term Memory
  • the embodiments of the present application provide a method and a device for calculating a neural network, which can solve the problems of difficulty in convergence and significant degradation in accuracy when the block size is large when the block cyclic matrix compression neural network is large.
  • a method for calculating a neural network includes multiple network layers, and the multiple network layers include a first network layer to be processed.
  • the foregoing method includes obtaining the first network to be processed.
  • the input vector of the layer obtain the disturbance vector of the first to-be-processed network layer according to the dimension of the reference random vector of the neural network and the random vector of the first to-be-processed network layer, wherein the dimension of the disturbance vector is equal to the A dimension of an input vector of a network layer to be processed, and a dimension of a random vector of the first network layer to be processed is determined based on a weight parameter of the first network layer to be processed and a dimension of an input vector of the first network layer to be processed ; Multiply the elements in the input vector of the first to-be-processed network layer by the corresponding position elements in the disturbance vector to obtain the corrected input vector of the first-to-be-processed network layer; based on the corrected input vector and the neural network Computing model to obtain the output vector of the first to-be-processed network layer.
  • the obtaining the input vector of the first to-be-processed network layer includes using the input vector of the neural network as the input vector of the first-to-be-processed network layer;
  • obtaining the input vector of the first to-be-processed network layer includes using an output vector of a previous network layer of the first to-be-processed network layer as the first The input vector of the pending network layer.
  • the input vector of the first to-be-processed network layer is ⁇ x1, x2 ... xn ⁇ , and the above-mentioned disturbance vector is ⁇ y1, y2 ... yn ⁇
  • the correction input vector of the first to-be-processed network layer is ⁇ x1 ⁇ y1, x2 ⁇ y2 ... xn ⁇ yn ⁇ , where n is a positive integer.
  • the above calculation model based on the corrected input vector and the neural network to obtain the output vector of the first to-be-processed network layer includes: using the weight parameter and the correction input vector of the first to-be-processed network layer as the neural network calculation model respectively.
  • the weight parameter and the input vector are calculated to obtain the output vector of the first to-be-processed network layer.
  • the output vector of the first to-be-processed network layer can be calculated by correcting the input vector and the weight parameter.
  • the weight parameter is a compression matrix corresponding to a block-structured matrix, where the block-structured matrix is the compression matrix
  • the method further includes: decompressing the weight parameter into a score corresponding to the compression matrix.
  • Block structured matrix Based on this solution, for the first to-be-processed network layer of the compression matrix corresponding to the block-structured matrix with the weight parameter, the block-structured matrix can be obtained by decompressing the weight parameter and the output vector can be calculated.
  • the first The dimension of a random vector of the network layer to be processed includes: determining a target interval, and two endpoints of the target interval are the block sizes of the block structured matrix corresponding to the weight parameter of the first network layer to be processed. And the dimension of the input vector of the first to-be-processed network layer; the dimension of the random vector of the first to-be-processed network layer is randomly determined within the target interval. Based on this solution, the dimension of the random vector of the first to-be-processed network layer can be obtained, and the dimension of the random vector is smaller than the dimension of the input vector.
  • the multiple network layers include multiple first to-be-processed network layers, and in the foregoing reference random vector according to the neural network and the first
  • the method further includes: determining a maximum value among the dimensions of the random vectors of the first network layer to be processed as the neural network.
  • the dimension of the reference random vector of the network a random number that meets the dimension of the reference random vector is generated based on a preset random number generation model; and the generated random number is composed of the reference random vector.
  • the dimensions of the reference random vector can be determined according to the dimensions of all the random vectors of the first to-be-processed network layer, and the dimensions of the reference random vector are smaller than the dimensions of the input vector.
  • the first to-be-processed is obtained according to a dimension of the reference random vector of the neural network and a dimension of the random vector of the first to-be-processed network layer.
  • the disturbance vector of the network layer includes: intercepting a vector having the same dimension as the random vector of the first to-be-processed network layer from the reference random vector as the random vector of the first to-be-processed network layer;
  • the random vector of the network layer generates a vector equal to the dimension of the input vector of the first to-be-processed network layer as a disturbance vector of the first to-be-processed network layer by using a cyclic shift or a vector element duplication method.
  • the disturbance vector of the first to-be-processed network layer can be obtained by intercepting and expanding according to the dimensions of the reference random vector and the random vector of the first-to-be-processed network layer, so only a small amount of storage resources and calculations need to be added. Resources, it can ensure that the accuracy of the neural network does not decrease, and the convergence speed is effectively improved.
  • a method for training a neural network model for obtaining weight parameters of each network layer in the neural network.
  • the method includes: Step 1. Initializing the weight parameters of each network layer described above; Step 2: Perform a neural network calculation according to the neural network calculation model corresponding to each network layer to obtain a temporary output vector of the neural network.
  • the weight parameters of the neural network calculation model are initialized weight parameters.
  • a neural network calculation model corresponding to each network layer performs a neural network calculation, and includes a neural network calculation method according to the first aspect or any implementation manner of the first aspect, for one or more of the first A network layer to be processed performs neural network calculation; step 3, through the above-mentioned neural network reverse transfer, update the weight parameters of each of the above network layers; use the updated weight parameters of each network layer as each of the above network layers
  • the corresponding neural network calculates the weight parameters of the model, and repeats step 2 and step 3.
  • the difference in the temporary preset output vector and said output vector of the neural network is less than the predetermined value; step 4, the right to access each of said network layer weight parameters.
  • a neural network computing device includes multiple network layers.
  • the multiple network layers include a first network layer to be processed.
  • the device includes a first obtaining unit for For obtaining an input vector of the first to-be-processed network layer; a second obtaining unit, configured to obtain the first to-be-processed network according to a dimension of the reference random vector of the neural network and a dimension of the random vector of the first to-be-processed network layer; Layer, where the dimension of the disturbance vector is equal to the dimension of the input vector of the first to-be-processed network layer, and the dimension of the random vector of the first to-be-processed network layer is according to the first to-be-processed network layer The weight parameter and the dimension of the input vector of the first to-be-processed network layer are determined; a first calculation unit is configured to combine elements in the input vector of the first to-be-processed network layer with the above obtained by the second obtaining unit
  • the obtaining unit is specifically configured to obtain an input vector of the neural network; when the first to-be-processed network layer is not the input layer of the neural network, the above-mentioned The obtaining unit is specifically configured to obtain an output vector of a previous network layer of the first to-be-processed network layer.
  • the input vector of the first to-be-processed network layer is ⁇ x1, x2 ... xn ⁇ , and the disturbance vector is ⁇ y1, y2 ... yn ⁇
  • the correction input vector of the first to-be-processed network layer is ⁇ x1 ⁇ y1, x2 ⁇ y2 ... xn ⁇ yn ⁇ , where n is a positive integer.
  • the second calculation unit is specifically configured to calculate the weight parameter and the correction input vector of the first to-be-processed network layer as the weight parameters and input vectors of the neural network calculation model, respectively, to obtain the first to-be-processed network layer. Output vector.
  • the weight parameter is a compression matrix corresponding to a block-structured matrix, where the block-structured matrix is unique by the compression matrix It is determined that the device further includes a decompression unit, which is configured to decompress the weight parameters into a block-structured matrix corresponding to the compression matrix.
  • the foregoing apparatus further includes a first determining unit configured to determine a target interval, and two endpoints of the target interval.
  • the block size of the block structured matrix corresponding to the weight parameter of the first to-be-processed network layer and the dimension of the input vector of the first to-be-processed network layer; the first determining unit is further configured to: The dimension of the random vector of the first to-be-processed network layer is randomly determined within the target interval.
  • the multiple network layers include multiple first to-be-processed network layers
  • the foregoing apparatus further includes: a second determining unit and a generating unit, where The second determining unit is further configured to determine a maximum value among the dimensions of all the random vectors of the first to-be-processed network layer as a dimension of the reference random vector of the neural network; the generating unit is configured to be based on a preset The random number generation model generates a random number satisfying the dimension of the reference random vector, and composes the generated random number into the reference random vector.
  • the second obtaining unit is specifically configured to intercept the dimension of the random vector from the random vector of the first to-be-processed network layer in the reference random vector.
  • the vector with the same number is used as the random vector of the first to-be-processed network layer;
  • the second obtaining unit is specifically configured to generate the first random network vector of the first-to-be-processed network layer by using cyclic shift or vector element copying to generate the A vector having the same dimensionality of the input vector of the network layer to be processed is used as the disturbance vector of the first network layer to be processed.
  • a training device for a neural network model for obtaining weight parameters of each network layer in the neural network.
  • the device includes an initialization unit for initializing the weights of each network layer. Parameters; a neural network calculation unit, configured to perform a neural network calculation according to the neural network calculation model corresponding to each of the above network layers to obtain a temporary output vector of the neural network, wherein the weight parameters of the neural network calculation model are initialized as described above Weight parameter; the above-mentioned neural network calculation unit is specifically configured to, according to the above-mentioned first aspect or the implementation method of any one of the above-mentioned first aspects, to one or more of the first Neural network calculation is performed on the to-be-processed network layer; a reverse transfer unit is configured to update the weight parameters of each network layer through the reverse transfer of the neural network described above; and an acquisition unit is configured to obtain the weight parameters of each network layer described above, The weight parameters of each of the above network layers are the temporary output
  • a server is provided.
  • the structure of the server includes a processor and a memory.
  • the memory is used for coupling with the processor, and stores necessary program instructions and data of the server.
  • the program instructions stored in the memory cause the server to execute the above method.
  • a computer storage medium stores computer program code, and when the computer program code runs on a processor, the processor executes the first aspect. Or the neural network calculation method described in any one of the possible implementation manners of the first aspect, or executing the neural network model training method described in the second aspect.
  • a computer program product stores computer software instructions executed by the processor, and the computer software instructions include a program for executing a solution described in the foregoing aspect.
  • a device exists in the form of a chip product.
  • the structure of the device includes a processor and a memory.
  • the memory is used for coupling with the processor and stores necessary programs of the device.
  • the processor is configured to execute program instructions stored in a memory, so that the device executes a function of a neural network computing device or a training device of a neural network model in the above method.
  • FIG. 1 is a schematic diagram of a hardware architecture of a neural network calculation according to an embodiment of the present application
  • FIG. 2 is a schematic diagram of a hardware architecture of another neural network calculation according to an embodiment of the present application.
  • FIG. 3 is a schematic diagram of a hardware architecture of another neural network calculation according to an embodiment of the present application.
  • FIG. 4 is a flowchart of a neural network calculation method according to an embodiment of the present application.
  • FIG. 5 is a flowchart of another method for calculating a neural network according to an embodiment of the present application.
  • FIG. 6 is a flowchart of another method for calculating a neural network according to an embodiment of the present application.
  • FIG. 7 is a flowchart of another method for calculating a neural network according to an embodiment of the present application.
  • FIG. 8 is a flowchart of another method for calculating a neural network according to an embodiment of the present application.
  • FIG. 9 is a schematic diagram of a comparison of effects obtained by using an existing technology and a neural network calculation method in an embodiment of the present application, provided in an embodiment of the present application;
  • FIG. 10 is a flowchart of a method for training a neural network model according to an embodiment of the present application.
  • FIG. 11 is a schematic structural diagram of a neural network computing device according to an embodiment of the present application.
  • FIG. 12 is a schematic structural diagram of a neural network model training device according to an embodiment of the present application.
  • FIG. 13 is a schematic diagram of a composition of another neural network computing device according to an embodiment of the present application.
  • FIG. 14 is a schematic diagram of a composition of another neural network model training device according to an embodiment of the present application.
  • an embodiment of the present application provides a method for calculating a neural network, which can reduce The correlation between small output feature images speeds up training convergence and reduces accuracy loss.
  • the neural network in the embodiment of the present application includes multiple network layers, and the multiple network layers include one or more first to-be-processed network layers.
  • the input vector of the first to-be-processed network layer is an input vector of a neural network;
  • An input vector of the first to-be-processed network layer is an output vector of a previous network layer of the first to-be-processed network layer.
  • the hardware structure includes: a first obtaining module 101, a second obtaining module 102, a first calculating module 103, and a second calculating module 104.
  • the first acquisition module 101 is sequentially connected to the first calculation module 103 and the second calculation module 104
  • the second acquisition module 102 is connected to the first calculation module 103 and the second calculation module 104 in sequence.
  • the first obtaining module 101 is configured to obtain an input vector of each first to-be-processed network layer.
  • its input vector is the input vector of the neural network; for network layers other than the first network layer, its input vector is the output vector of the previous network layer of the network layer.
  • the second obtaining module 102 is configured to obtain a disturbance vector of the first to-be-processed network layer according to the dimensions of the input reference random vector and the dimension of the random vector of the first to-be-processed network layer.
  • the number of dimensions may be equal to the number of dimensions of the input vector of the first to-be-processed network layer.
  • the second obtaining module may include a cyclic shift module or a copy module.
  • the first calculation module 103 is configured to add a disturbance based on the input vector of the first to-be-processed network layer obtained by the first acquisition module 101, and the disturbance is a disturbance vector obtained by the second acquisition module 102.
  • the corrected input vector of the first to-be-processed network layer may be obtained by multiplying elements in the input vector of the first to-be-processed network layer by elements at corresponding positions in the disturbance vector.
  • the second calculation module 104 is configured to calculate an output vector of the first to-be-processed network layer according to the correction input vector obtained by the first calculation module 103 and a calculation model of the neural network.
  • the second calculation module may calculate the output vector of the first layer to be processed in a fast calculation manner.
  • the second calculation module 104 may use fast Fourier transform. The transformation calculates the output vector of the first layer to be processed.
  • FIG. 1 is only an exemplary description.
  • the hardware architecture of the neural network computing device may include more or fewer components than those shown in FIG. 1.
  • the structure shown in FIG. 1 does not constitute any limitation on the hardware architecture provided by the embodiment of the present application.
  • the hardware architecture composition in the embodiment of the present application may include a decompression module 105 shown in FIG. 2 in addition to the module shown in FIG. 1, and the decompression module 105 is connected to the second calculation module 104.
  • the decompression module 105 is configured to decompress the weight parameters into a block-structured matrix corresponding to the compression matrix, and transmit the block-structured matrix to the second calculation module 104 for calculating an output vector of the network layer.
  • the decompression module 105 may be a cyclic shift module, and the weight parameters are decompressed into a block-circular matrix through the cyclic shift module, and then the second calculation module 104 is used to perform the matrix. Multiplication operation to calculate the output vector of the first layer to be processed.
  • an embodiment of the present application further provides a hardware structure.
  • the hardware structure includes a first determination module 301, a second determination module 302, and a generation module 303 that are sequentially connected.
  • a first determining module 301 is configured to determine a dimension of a random vector of a first network layer to be processed according to a dimension of an input vector and a weight parameter.
  • the second determining module 302 is configured to determine the dimension of the reference random vector according to the dimension of the random vector of the one or more first to-be-processed network layers.
  • the dimension of the reference random vector may be a maximum value of the dimensions of the random vectors of all the first to-be-processed network layers.
  • a generating module 303 is configured to generate a reference random vector with the same dimension as the reference random vector according to the dimension of the reference random vector.
  • FIG. 1-3 is only an exemplary description, and the structure shown in FIG. 1-3 does not constitute any limitation on the hardware architecture provided by the embodiment of the present application.
  • the first to-be-processed network layer may be calculated using the calculation method shown in FIG. 4.
  • the method for calculating a neural network provided in the embodiment of the present application may include steps S401-S404.
  • step S401 can be performed by the first obtaining module 101 shown in FIG. 1.
  • the first to-be-processed network layer refers to a network layer of a compression matrix corresponding to a block-structured matrix among a plurality of network layers of a neural network.
  • the block-structured matrix can be uniquely determined by the compression matrix.
  • the above-mentioned block-structured matrix means that the matrix can be divided into multiple blocks, and each block is arranged according to a certain rule.
  • the block structured matrix may include a block cycle matrix, a block Teplitz matrix, and the like.
  • the specific type of the block structured matrix is not limited.
  • only the block cycle matrix is used. As an example.
  • W is a block cyclic matrix.
  • the second column of each block in the block cyclic matrix is obtained by cyclically shifting down the first column, and the third column is obtained by cyclically shifting down the second column.
  • the weight parameter C of the network layer is a compression matrix corresponding to the block cyclic matrix W.
  • the compression matrix C is represented by a matrix composed of N w_bases, where N refers to the number of blocks of the block cyclic matrix, and w_base of each block is the smallest value that uniquely determines each block of the structured matrix of the block. Element collection (for example, w_base can be the first row or first column of a block).
  • the compression matrix of the partitioned cyclic matrix W in the following formula is C (weight parameter).
  • the partitioned cyclic matrix W is divided into 4 blocks, and the partitioned cyclic matrix W can be uniquely determined by the compression matrix C.
  • the neural network in the embodiment of the present application may include one or more first to-be-processed network layers, and one of the one or more to-be-processed network layers may be an input vector of the neural network.
  • the input vector of the first network layer to be processed is the input vector of the neural network; when the first network layer to be processed is any network other than the first network layer Layer, the input vector of the first to-be-processed network layer is the output vector of the previous network layer of the first to-be-processed network layer.
  • the neural network in the embodiment of the present application may be a type of neural network such as a deep neural network (DNN), a convolutional neural network (CNN), or the like
  • the first to-be-processed network layer may be It is a convolution layer, an LSTM layer, a full connection layer, and the like.
  • the embodiment of the present application does not limit the specific neural network type and structure.
  • step S402 may be performed by the second obtaining module 102 shown in FIG. 1.
  • the dimension of the disturbance vector is equal to the dimension of the input vector of the first network layer to be processed.
  • obtaining the disturbance vector of the first to-be-processed network layer in step S402 may include: steps S4021-S4022.
  • a vector equal to the dimension of the random vector of the first to-be-processed network layer is intercepted from the reference random vector as the random vector of the first to-be-processed network layer.
  • the reference random vector may be a maximum value in the dimensions of the random vectors of all the first to-be-processed network layers. Therefore, the dimensions of the random vectors of the reference random vector and the random vectors of the first to-be-processed network layer may be intercepted The equal vectors are used as random vectors in the first network layer to be processed.
  • the above-mentioned interception of a vector in the reference random vector with a dimension equal to that of the random vector of the first to-be-processed network layer may include: starting from a certain position (for example, the first bit) of the reference random vector and sequentially intercepting the A vector of the random vector of the network layer to be processed has the same dimension as the random vector of the first network layer to be processed, and may also be cut according to a certain interception rule, for example, from odd or even bits in the reference random vector to the first random network.
  • the vector having the same number of dimensions of the random vector of the to-be-processed network layer is the random vector of the first to-be-processed network layer.
  • a random vector of the first to-be-processed network layer is cyclically shifted or vector element copied to generate a vector equal to the dimension of the input vector of the first to-be-processed network layer as a disturbance vector of the first to-be-processed network layer.
  • the dimension of the random vector of the first to-be-processed network layer is smaller than the dimension of the input vector of the first to-be-processed network layer, and the dimension of the disturbance vector of the first to-be-processed network layer is equal to the first to-be-processed The dimension of the input vector of the network layer. Therefore, the random vector of the first to-be-processed network layer can be extended by cyclic shifting or vector element copying to obtain the dimension of the input vector of the first-to-be-processed network layer. The equal vector is used as the disturbance vector of the first to-be-processed network layer.
  • the dimension of the input vector of the first to-be-processed network layer is 15, a cyclic shift method is adopted.
  • This embodiment of the present application does not limit the method for obtaining the disturbance vector of the first to-be-processed network layer based on the random vector of the first to-be-processed network layer.
  • the second obtaining module in FIG. 1 includes a cyclic shift module, and when the first to-be-processed network is obtained by using a vector element copy method
  • the copy module is included.
  • step S403 may be performed by the first calculation module 103 shown in FIG. 1.
  • the correction of the first to-be-processed network layer is ⁇ x1 ⁇ y1, x2 ⁇ y2 ... xn ⁇ yn ⁇ , where n is a positive integer.
  • the embodiment of the present application can effectively reduce the correlation of the projection matrix of this layer.
  • step S404 can be performed by the second calculation module 104 shown in FIG. 1.
  • the neural network calculation model is used for the neural network calculation of the j-th layer in multiple network layers. j is an integer.
  • the dimension of the input vector of the first to-be-processed network layer is the input matrix matrix converted by im2col according to the size of the convolution kernel. After the width.
  • the im2col means that the pixel value of a small window on the input image to be processed by the convolution kernel is expanded to one row (column) of the new matrix, and the number of columns (rows) of the new matrix is the volume for an input image. Number of product operations (number of convolution kernel slips).
  • the above calculation model based on the corrected input vector and the neural network to obtain the output vector of the first to-be-processed network layer may include: calculating the weight parameters of the first to-be-processed network layer and the corrected input vector as the neural network respectively. The weight parameters and input vectors of the model are calculated to obtain the output vector of the first to-be-processed network layer.
  • the neural network calculation method obtained in the embodiment of the present application obtains a first to-be-processed network by obtaining an input vector of a first to-be-processed network layer; and according to a dimension of a reference random vector of the neural network and a random vector of the first to-be-processed network layer.
  • the perturbation vector of the layer where the dimension of the perturbation vector is equal to the dimension of the input vector of the first to-be-processed network layer; multiplying elements in the input vector of the first to-be-processed network layer by elements of corresponding positions in the perturbation vector, To obtain a corrected input vector of the first to-be-processed network layer; to obtain an output vector of the first to-be-processed network layer based on the corrected input vector and a calculation model of the neural network.
  • the correlation between the output feature images can be reduced, the training convergence speed can be accelerated, and the accuracy loss can be reduced.
  • a perturbation vector with the same dimension as the input vector of the first to-be-processed network layer can be generated.
  • the dimension of the random vector at the network layer is smaller than the dimension of the input vector. Therefore, only a small amount of storage and computing resources need to be added to ensure that the accuracy and convergence speed of the neural network can be effectively improved.
  • step S405 may be further included.
  • step S405 may be performed by the decompression module 105 shown in FIG. 2.
  • the weight parameter of the first to-be-processed network is a compression matrix corresponding to a block-structured matrix
  • the weight parameter C j may be decompressed to obtain
  • the block structured matrix W j corresponding to the weight parameter (compression matrix) is then used to perform matrix multiplication on the block structured matrix and the input vector to calculate the output vector.
  • the decompression module 105 in FIG. 2 is used to decompress the weight parameters into a block structured matrix (the calculation method shown in FIG. 5), matrix multiplication can be performed through the second calculation module 104 in FIG. 2, Obtain the output vector of the first to-be-processed network layer. If the decompression module 105 (the calculation method shown in FIG. 4) is not used, the output vector of the first to-be-processed network layer may be calculated by using the fast Fourier transform directly through the second calculation module 104 in FIG. 1.
  • the neural network calculation method obtained in the embodiment of the present application obtains a first to-be-processed network by obtaining an input vector of a first to-be-processed network layer; and according to a dimension of a reference random vector of the neural network and a random vector of the first to-be-processed network layer.
  • the perturbation vector of the layer where the dimension of the perturbation vector is equal to the dimension of the input vector of the first to-be-processed network layer; multiplying elements in the input vector of the first to-be-processed network layer by elements of corresponding positions in the perturbation vector, To obtain a corrected input vector of the first to-be-processed network layer; decompress the weight parameters of the first to-be-processed network layer into a block-structured matrix corresponding to the compression matrix; based on the corrected input vector and the computational model of the neural network to obtain the first An output vector of the pending network layer.
  • the correlation between the output feature images can be reduced, the training convergence speed can be accelerated, and the accuracy loss can be reduced.
  • a perturbation vector with the same dimension as the input vector of the first to-be-processed network layer can be generated.
  • the dimension of the random vector at the network layer is smaller than the dimension of the input vector. Therefore, only a small amount of storage and computing resources need to be added to ensure that the accuracy and convergence speed of the neural network can be effectively improved.
  • the above method may further include steps S601-S603.
  • S601. Determine a dimension of a random vector of the first to-be-processed network layer according to a weight parameter of the first to-be-processed network layer and a dimension of an input vector of the first-to-be-processed network layer.
  • step S601 may be performed by the first determining module 301 shown in FIG. 3.
  • determining the dimension of the random vector of the first to-be-processed network layer based on the weight parameter of the first to-be-processed network layer and the dimension of the input vector of the first-to-be-processed network layer may include: determining a target interval, the The two end points of the target interval are the block size of the block structured matrix corresponding to the weight parameter of the first to-be-processed network layer and the dimension of the input vector of the first to-be-processed network layer; Determine the dimension of the random vector of the first to-be-processed network layer.
  • the block size of the block cyclic matrix of the first network layer to be processed in the current neural network is 32
  • the dimension of the input vector of the neural network is 800
  • the dimension of the random vector of the first network layer to be processed may be An integer is randomly selected in the (32,800) interval, for example, it can be 40.
  • the neural network in the embodiment of the present application may include one or more first to-be-processed network layers.
  • the randomness of the first to-be-processed network layers is random.
  • the dimensions of the vectors may be the same or different, which is not limited in the embodiment of the present application.
  • S602. Determine the maximum value of the dimensions of the random vectors of all the first to-be-processed network layers as the reference random vector dimensions of the neural network.
  • step S602 may be performed by the second determining module 302 shown in FIG. 3.
  • the maximum value among the dimensions of the random vectors of all the first to-be-processed network layers is the dimension of the reference random vector of the neural network. number.
  • the dimensions of the random vectors of the five first to-be-processed network layers are: 40, 35, 50, 46, and 55, so the reference of the neural network is random.
  • the dimension of the vector is the maximum dimension of the random vectors of the 5 first to-be-processed network layers, which is 55.
  • step S603 may be performed by the generating module 303 shown in FIG. 3.
  • the model and the dimension of the reference random vector may be generated according to a preset random number, and a set of random numbers satisfying the dimension of the reference random vector is generated.
  • the random number satisfying the dimension of the reference random vector is used as a reference.
  • the embodiment of the present application does not limit the specific form of the random number generation model, and any kind of random number generation model is within the protection scope of the embodiment of the present application, which is only an exemplary description here.
  • the process of determining the basic random vector in steps S601-S603 in the embodiment of the present application may be performed before the following neural network model training.
  • each process that can be obtained according to the neural network model training may be performed.
  • the weight parameters of the network layer and the dimensions of the reference random vector generated before the model training and the random vector of the first to-be-processed network layer are calculated using the neural network calculation methods of steps S401-S406 to calculate the output vector of the neural network.
  • the neural network calculation method obtained in the embodiment of the present application obtains a first to-be-processed network by obtaining an input vector of a first to-be-processed network layer; and according to a dimension of a reference random vector of the neural network and a random vector of the first to-be-processed network layer.
  • the perturbation vector of the layer where the dimension of the perturbation vector is equal to the dimension of the input vector of the first to-be-processed network layer; multiplying elements in the input vector of the first to-be-processed network layer by elements of corresponding positions in the perturbation vector, To obtain a corrected input vector of the first to-be-processed network layer; to obtain an output vector of the first to-be-processed network layer based on the corrected input vector and a calculation model of the neural network.
  • the correlation between the output feature images can be reduced, the training convergence speed can be accelerated, and the accuracy loss can be reduced.
  • a perturbation vector with the same dimension as the input vector of the first to-be-processed network layer can be generated.
  • the dimension of the random vector at the network layer is smaller than the dimension of the input vector. Therefore, only a small amount of storage and computing resources need to be added to ensure that the accuracy and convergence speed of the neural network can be effectively improved.
  • This application also provides another embodiment.
  • different first to-be-processed network layers in the multiple first to-be-processed network layers may use the same calculation method (see FIG. 4). Or the calculation method shown in FIG. 5), different calculation methods can also be used.
  • some of the first to-be-processed network layers may use the calculation methods shown in FIG. 5 and FIG. 6, and another part of the first to-be-processed network layer may use the graphs. 7 calculation method. As shown in FIG. 7, the method includes steps S701-S703.
  • step S701 may be performed by the first obtaining module 101 shown in FIG. 1 or FIG. 2.
  • step S702 may be performed by the decompression module 105 shown in FIG. 2.
  • the weight parameter of the first to-be-processed network is a compression matrix corresponding to a block-structured matrix
  • the weight parameter C n may be decompressed to obtain The block structured matrix W n corresponding to the weight parameter (compression matrix).
  • S703 Obtain an output vector of the first to-be-processed network layer according to an input vector of the first to-be-processed network layer and a calculation model of the neural network.
  • step S703 may be performed by the second calculation module 104 shown in FIG. 1 or FIG. 2.
  • W n is a block structured matrix corresponding to the weight parameter of the first to-be-processed network layer, and b n is a preset offset value of the first to-be-processed network layer.
  • the calculation method shown in FIG. 7 is used to calculate the output of the network layer, which is not limited in the embodiment of the present application, and may be specifically determined according to an actual network structure.
  • the neural network calculation method of the embodiment of the present application is adopted, at least one first to-be-processed network layer should use the calculation method shown in FIG. 5 to calculate the output vector of the network layer.
  • the neural network calculation method obtained in the embodiment of the present application obtains a first to-be-processed network by obtaining an input vector of a first to-be-processed network layer; and according to a dimension of a reference random vector of the neural network and a random vector of the first to-be-processed network layer.
  • the perturbation vector of the layer where the dimension of the perturbation vector is equal to the dimension of the input vector of the first to-be-processed network layer; multiplying elements in the input vector of the first to-be-processed network layer by elements of corresponding positions in the perturbation vector, To obtain a corrected input vector of the first to-be-processed network layer; to obtain an output vector of the first to-be-processed network layer based on the corrected input vector and a calculation model of the neural network.
  • the correlation between the output feature images can be reduced, the training convergence speed can be accelerated, and the accuracy loss can be reduced.
  • a perturbation vector with the same dimension as the input vector of the first to-be-processed network layer can be generated.
  • the dimension of the random vector at the network layer is smaller than the dimension of the input vector. Therefore, only a small amount of storage and computing resources need to be added to ensure that the accuracy and convergence speed of the neural network can be effectively improved.
  • This application also provides another embodiment. If a plurality of network layers included in a neural network includes one or more second network layers to be processed in addition to the first network layer to be processed, for the one or more second network layers to be processed,
  • the processing network layer may calculate an output vector of any second to-be-processed network layer by using the calculation method in the embodiment of the present application. As shown in FIG. 8, the calculation method may include steps S801-S802.
  • step S801 may be performed by the first obtaining module 101 shown in FIG. 1 or FIG. 2.
  • the second to-be-processed network layer refers to a network layer in which a weight parameter is an unstructured matrix among a plurality of network layers of a neural network.
  • the unstructured matrix means that the matrix is not arranged according to a certain rule, and cannot be represented by the smallest set of elements that uniquely determines the structured matrix.
  • Matrix A in the following formula is an unstructured matrix, which cannot be compressed, and there is no compression matrix.
  • the input vector of the second to-be-processed network layer is the input vector of the neural network;
  • the input vector of the second to-be-processed network layer is the output vector of the previous network layer of the second to-be-processed network layer.
  • step S802 may be performed by the second computing module 104 shown in FIG. 1 or FIG. 2.
  • the output vector of the second to-be-processed network layer can be directly based on the input vector and weight of the second to-be-processed network layer.
  • the parameters and preset offset values are calculated without decompressing the weight parameters.
  • FIG. 9 it is an effect diagram of an experiment on a convolutional neural network composed of 2 convolutional layers and 1 fully connected layer on the MNIST database.
  • the second convolutional layer is the first network layer to be processed.
  • the first convolutional layer and the third fully connected layer are the second network to be processed.
  • the abscissa indicates the number of iterations
  • the ordinate indicates accuracy
  • ⁇ the waist plus a straight line indicates that when the block size of the block circulant matrix is 32, the effect obtained by using no sign vector in the prior art is obtained;
  • the straight line indicates When the block size of the block cyclic matrix is 32, the perturbation vector is obtained by cyclic shift.
  • FIG. 5 is used for the first network layer to be processed
  • FIG. 8 is used for the second network layer to be processed.
  • the effect diagram obtained by the calculation method shown by the neural network when the block size of the triangle and the straight line represent the block cyclic matrix with a block size of 40, the perturbation vector is obtained by using the vector element copy (content copy) method.
  • the neural network calculation method shown in FIG. 5 is adopted, and the effect diagram obtained by using the neural network calculation method shown in FIG. 8 is used for the second to-be-processed network layer.
  • the dotted line indicates that the block size of the block cyclic matrix is 40
  • the The perturbation vector is obtained in a cyclic shift manner.
  • the neural network calculation method shown in FIG. 5 is adopted for the first to-be-processed network layer, and the second to-be-processed network layer is adopted.
  • FIG 8 shows the effect of a neural network calculation obtained.
  • the network cannot converge when the block size is large, and the calculation method without adding a symbol vector in the prior art is used, so 32 times compression cannot be achieved.
  • the cyclic shift in the embodiment of the present application is used to obtain the disturbance symbol vector of the first to-be-processed network layer.
  • the network can be rapidly converged, and the beneficial effects compared to the prior art are very obvious.
  • the disturbance copy vector of the first to-be-processed network layer is generated by using the content copy (vector element copy) and content cyclic shift methods in the embodiment of the present application, and FIG. 5 and FIG. 8 are adopted for the above network layer.
  • the network can converge, and when cyclic shift is used, the network converges faster and has higher accuracy. Therefore, when the neural network calculation method in the embodiment of the present application is used to perform forward inference on the network, it can solve the problems of block cyclic matrix compression neural network, when the block size is large, the training is difficult to converge, and the accuracy is significantly reduced.
  • the neural network calculation method obtained in the embodiment of the present application obtains a first to-be-processed network by obtaining an input vector of a first to-be-processed network layer; and according to a dimension of a reference random vector of the neural network and a random vector of the first to-be-processed network layer.
  • the perturbation vector of the layer where the dimension of the perturbation vector is equal to the dimension of the input vector of the first to-be-processed network layer; multiplying elements in the input vector of the first to-be-processed network layer by elements of corresponding positions in the perturbation vector, To obtain a corrected input vector of the first to-be-processed network layer; to obtain an output vector of the first to-be-processed network layer based on the corrected input vector and a calculation model of the neural network.
  • the correlation between the output feature images can be reduced, the training convergence speed can be accelerated, and the accuracy loss can be reduced.
  • a perturbation vector with the same dimension as the input vector of the first to-be-processed network layer can be generated.
  • the dimension of the random vector at the network layer is smaller than the dimension of the input vector. Therefore, only a small amount of storage and computing resources need to be added to ensure that the accuracy and convergence speed of the neural network can be effectively improved.
  • the embodiment of the present application further provides a method for training a neural network model, which is used to obtain weight parameters of each network layer in the neural network before the calculation of the neural network.
  • the method for training a neural network model includes step S1001 -S1004.
  • the weight parameters of each of the one or more first to-be-processed network layers and the one or more second to-be-processed network layers included in the neural network are initialized.
  • the weight parameter of the neural network calculation model is an initialized weight parameter.
  • the above-mentioned neural network calculation according to the neural network calculation model corresponding to each network layer may include:
  • Y m0 W m0 ⁇ X ' m + b m
  • Y m0 the temporary output vector of the first to-be-processed network layer
  • X ' m is a correction input vector of the first to-be-processed network layer
  • W m0 is a block structured matrix corresponding to the initialized weight parameters of the first to-be-processed network layer
  • b m is a preset of the first to-be-processed network layer Offset value.
  • Y n0 W n0 ⁇ X n + b n
  • Y n0 the first network to be processed in the second network layer set.
  • the temporary output vector of the layer X n is the input vector of the first to-be-processed network layer in the second network layer set
  • W n0 is the score corresponding to the initialized weight parameter of the first to-be-processed network layer in the second network layer set.
  • Block structured matrix, b n is a preset offset value of the first to-be-processed network layer in the second network layer set.
  • Y i0 C i0 ⁇ X i + b i
  • Y i to be a second temporary network layer process output vector X i is the second network to be treated
  • the input vector of the layer C i is the initialization weight parameter of the second to-be-processed network layer
  • b i is a preset offset value of the second to-be-processed network layer.
  • the neural network calculation may be performed on each network layer according to the calculation method shown in FIG. 4 or FIG. 5; or, when the neural network When the multiple network layers only include the first network to be processed, the corresponding network layer may also be subjected to a neural network calculation according to the calculation method shown in FIG. 4 or FIG. 5 and the calculation method shown in FIG. 7; or, when the multiple network layers of the neural network include the first to-be-processed network layer and the second to-be-processed network layer, the corresponding network layer may be calculated according to the calculation method shown in FIG. 4 or FIG. 5 and the calculation method described in FIG. 8.
  • the weight parameters of the neural network may make the training converge.
  • the value of the preset value is not limited in the embodiment of the present application, and may be specifically determined according to an actual application.
  • the weight parameter when the neural network training converges is the trained weight parameter.
  • this weight parameter can perform the neural network reasoning shown in Figures 4 to 8 above, which can achieve a larger compression ratio, making the neural network Fast convergence.
  • the method for training a neural network model provided in the embodiment of the present application may further include steps S601-S603, according to the reference random vector determined in steps S601-S603 and the random vector of the first to-be-processed network layer Dimension, adopt the model training method of steps S1001-S1004 to obtain the weight parameters of each network layer, and then perform the aforementioned neural network calculation process.
  • the method for training a neural network model includes initializing weight parameters of each network layer; performing a neural network calculation according to a neural network calculation model corresponding to each network layer to obtain a temporary output vector of the neural network; Reverse transmission of the network, update the weight parameters of each network layer, and use the updated weight parameters of each network layer as the weight parameters of the neural network calculation model corresponding to each network layer, and repeat the calculation until the neural network is temporarily The difference between the output vector and the preset output vector of the neural network is less than the preset value, and the weight parameters of each network layer are obtained.
  • the training process of the embodiment of the present application obtains a corrected input vector by adding a disturbance vector to the input vector of the first to-be-processed network layer, and trains the neural network by correcting the input vector, which can reduce the correlation between the output feature images and speed up Training convergence speed and reducing accuracy loss.
  • the computer includes a hardware structure and / or a software module corresponding to each function.
  • the computer includes a hardware structure and / or a software module corresponding to each function.
  • each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module.
  • the above integrated modules may be implemented in the form of hardware or software functional modules. It should be noted that the division of the modules in the embodiments of the present invention is schematic, and is only a logical function division. In actual implementation, there may be another division manner.
  • FIG. 11 shows a possible structural diagram of a neural network computing device involved in the foregoing embodiment.
  • the neural network computing device 1100 includes a first obtaining unit 1101. , A second acquisition unit 1102, a first calculation unit 1103, a second calculation unit 1104, and a decompression unit 1105.
  • the first obtaining unit 1101 is used to support the neural network computing device 1100 to execute S401 in FIG. 4, or S701 in FIG. 7, or S801 in FIG. 8;
  • the second obtaining unit 1102 is used to support the neural network computing device 1100 to execute FIG. 4.
  • the first computing unit 1103 is used to support the neural network computing device 1100 to execute S403 in FIG.
  • the second computing unit 1104 is used to support the neural network computing device 1100 to execute S404 in FIG. 4 or S703 in FIG. 7 Or S802 in FIG. 8;
  • the decompression unit 1105 is used to support the neural network computing device 1100 to execute S405 in FIG. 5 or S702 in FIG. 7.
  • all relevant content of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module shown in FIG. 1 or FIG. 2, which will not be repeated here.
  • FIG. 12 shows a possible structural schematic diagram of the neural network model training device involved in the foregoing embodiment.
  • the neural network model training device 1200 includes: an initialization unit 1201 , A first determination unit 1202, a second determination unit 1203, a generation unit 1204, a neural network calculation unit 1205, a reverse transmission unit 1206, and an acquisition unit 1207.
  • the initialization unit 1201 is used to support the neural network model training device 1200 to execute S1001 in FIG. 10;
  • the first determination unit 1202 is used to support the neural network model training device 1200 to execute S601 in FIG. 6;
  • the second determination unit 1203 is used to support neural network
  • the model training device 1200 executes S602 in FIG.
  • the generating unit 1204 is used to support the neural network model training device 1200 to execute S603 in FIG. 6; the neural network calculation unit 1205 is used to support the neural network model training device 1200 to execute S1002 in FIG. 10 ;
  • the reverse transmission unit 1206 is used to support the neural network model training device 1200 to execute S1003 in FIG. 10; the obtaining unit 1207 is used to support the neural network model training device 1200 to execute S1004 in FIG. 10.
  • FIG. 13 shows a schematic diagram of a possible structure of the neural network computing device 1300 involved in the above embodiment.
  • the neural network computing device 1300 includes a storage module 1301 and a processing module 1302.
  • the processing module 1302 is used to control and manage the actions of the computer.
  • the processing module 1302 is used to support the neural network computing device 1300 to execute S401-S404 in FIG. 4, or S401-S405 in FIG. 5, or S601 in FIG. -S603, or S701-S703 in FIG. 7, or S801-S802 in FIG. 8, and / or other processes for the technology described herein.
  • the storage module 1301 is configured to store a program code and data of a computer.
  • the structure of the neural network computing device may further include a processor and an interface.
  • the processor and the interface communicate, and the processor is configured to execute the embodiment of the present invention.
  • the processor may be a CPU or other hardware, such as a Field-Programmable Gate Array (FPGA), or a combination of the two.
  • FPGA Field-Programmable Gate Array
  • FIG. 14 shows a schematic diagram of a possible structure of the neural network model training apparatus 1400 involved in the above embodiment.
  • the neural network model training device 1400 includes a storage module 1401 and a processing module 1402.
  • the processing module 1402 is configured to control and manage the actions of the neural network model training device 1400.
  • the processing module 1402 is configured to support the neural network model training device 1400 to execute S601-S703 in FIG. 6 or S1001-S1004 in FIG. 10, And / or other processes for the techniques described herein.
  • the storage module 1401 is configured to store a program code and data of a computer.
  • the structure of the neural network model training device according to the foregoing embodiment may further include a processor and an interface.
  • the processor and the interface communicate, and the processor is configured to execute the embodiment of the present invention.
  • the processor may be a CPU or other hardware, such as a Field-Programmable Gate Array (FPGA), or a combination of the two.
  • FPGA Field-Programmable Gate
  • the steps of the method or algorithm described in combination with the disclosure of this application may be implemented in a hardware manner, or may be implemented in a manner in which a processor executes software instructions.
  • Software instructions can be composed of corresponding software modules.
  • Software modules can be stored in Random Access Memory (RAM), flash memory, Erasable Programmable ROM (EPROM), electrically erasable and erasable.
  • An exemplary storage medium is coupled to the processor such that the processor can read information from, and write information to, the storage medium.
  • the storage medium may also be an integral part of the processor.
  • the processor and the storage medium may reside in an ASIC.
  • the ASIC can be located in a core network interface device.
  • the processor and the storage medium can also exist as discrete components in the core network interface device.
  • the functions described in the present invention may be implemented by hardware, software, firmware, or any combination thereof.
  • the functions may be stored on a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium.
  • Computer-readable media includes computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another.
  • a storage media may be any available media that can be accessed by a general purpose or special purpose computer.

Landscapes

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

Abstract

本申请实施例公开了一种神经网络计算方法和装置,涉及通信技术领域,解决了现有技术中分块循环矩阵压缩神经网络时,分块大小很大时,训练难收敛,以及精度下降明显的问题。具体方案为:获取第一待处理网络层的输入向量;根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量,其中,扰动向量的维数等于第一待处理网络层的输入向量的维数;将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得第一待处理网络层的校正输入向量;基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。

Description

一种神经网络计算方法和装置 技术领域
本申请实施例涉及通信技术领域,尤其涉及一种神经网络计算方法和装置。
背景技术
神经网络是一种模仿动物神经网络行为特征,进行分布式并行信息处理的算法数学模型,在多个领域都有较为广泛的应用。目前,结构化矩阵在神经网络的压缩和加速上取得了良好的效果,其中,分块循环矩阵是结构化矩阵的一种,分块循环矩阵被应用在卷积层、全连接层、长短期记忆层(Long Short-Term Memory,LSTM)上能实现高倍数的网络参数压缩。
但是,现有的分块循环矩阵压缩神经网络的方法,在分块的大小很大时,由于权重参数的结构化,引入了输出特征图像之间的相关性,从而引起信息的损失导致基于神经网络的应用任务的精度损失,使得训练收敛速度慢甚至不收敛,模型的性能降低。
发明内容
本申请实施例提供一种神经网络计算方法和装置,能够解决分块循环矩阵压缩神经网络时,分块大小很大时,训练难收敛,以及精度下降明显的问题。
为达到上述目的,本申请实施例采用如下技术方案:
本申请实施例的第一方面,提供一种神经网络计算方法,该神经网络包括多个网络层,该多个网络层中包括第一待处理网络层,上述方法包括:获取第一待处理网络层的输入向量;根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取所述第一待处理网络层的扰动向量,其中,该扰动向量的维数等于上述第一待处理网络层的输入向量的维数,该第一待处理网络层的随机向量的维数是基于第一待处理网络层的权重参数和第一待处理网络层的输入向量的维数确定的;将上述第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得上述第一待处理网络层的校正输入向量;基于该校正输入向量和上述神经网络的计算模型,以获得上述第一待处理网络层的输出向量。当第一待处理网络层为神经网络的输入层时,上述获取所述第一待处理网络层的输入向量,包括将上述神经网络的输入向量作为上述第一待处理网络层的输入向量;当上述第一待处理网络层不为上述神经网络的输入层时,上述获取第一待处理网络层的输入向量,包括将上述第一待处理网络层的前一网络层的输出向量作为上述第一待处理网络层的输入向量。基于本方案,能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。
结合第一方面和上述可能的实现方式,在另一种可能的实现方式中,上述第一待处理网络层的输入向量为{x1,x2…xn},上述扰动向量为{y1,y2…yn},上述第一待处理网络层的校正输入向量为{x1×y1,x2×y2…xn×yn},其中,n为正整数。基于本方案,通过在第一待处理网络层的输入向量上加扰动向量,可以有效的降低该层投影矩阵的相关性。
结合第一方面和上述可能的实现方式,在另一种可能的实现方式中,上述神经网 络计算模型包括:Y j=C j×X j+b j,其中,Y j为上述神经网络计算模型的输出向量,X j为上述神经网络计算模型的输入向量,C j为上述神经网络计算模型的权重参数,b j为上述神经网络计算模型的预设偏置值,上述神经网络计算模型用于上述多个网络层中第j层的神经网络计算,j为整数。上述基于校正输入向量和神经网络的计算模型,以获得上述第一待处理网络层的输出向量,包括:将上述第一待处理网络层的权重参数和校正输入向量分别作为上述神经网络计算模型的权重参数和输入向量进行计算,以获得上述第一待处理网络层的输出向量。基于本方案,能够通过校正输入向量和权重参数计算第一待处理网络层的输出向量。
结合第一方面和上述可能的实现方式,在另一种可能的实现方式中,上述权重参数为分块结构化的矩阵对应的压缩矩阵,其中,上述分块结构化的矩阵由所述压缩矩阵唯一确定,在上述基于所述校正输入向量,通过神经网络计算,以获得上述第一待处理网络层的输出向量之前,上述方法还包括:将所述权重参数解压为所述压缩矩阵对应的分块结构化的矩阵。基于本方案,对权重参数为分块结构化的矩阵对应的压缩矩阵的第一待处理网络层,能够通过解压权重参数得到分块结构化矩阵再计算输出向量。
结合第一方面和上述可能的实现方式,在另一种可能的实现方式中,基于上述第一待处理网络层的权重参数和上述第一待处理网络层的输入向量的维数,确定上述第一待处理网络层的随机向量的维数,包括:确定目标区间,该目标区间的两个区间端点分别为上述第一待处理网络层的权重参数对应的分块结构化的矩阵的分块尺寸和上述第一待处理网络层的输入向量的维数;在该目标区间内随机确定上述第一待处理网络层的随机向量的维数。基于本方案,能够得到第一待处理网络层的随机向量的维数,而且该随机向量的维数小于输入向量的维数。
结合第一方面和上述可能的实现方式,在另一种可能的实现方式中,上述多个网络层包括多个第一待处理网络层,在上述根据上述神经网络的参考随机向量和上述第一待处理网络层的随机向量的维数,获取上述第一待处理网络层的扰动向量之前,还包括:确定全部上述第一待处理网络层的随机向量的维数中的最大值,作为上述神经网络的参考随机向量的维数;基于预设的随机数生成模型,生成满足上述参考随机向量的维数的随机数;将上述生成的随机数组成参考随机向量。基于本方案,能够根据全部上述第一待处理网络层的随机向量的维数确定参考随即向量的维数,且该参考随机向量的维数小于输入向量的维数。
结合第一方面和上述可能的实现方式,在另一种可能的实现方式中,根据上述神经网络的参考随机向量和上述第一待处理网络层的随机向量的维数,获取上述第一待处理网络层的扰动向量,包括:在上述参考随机向量中截取与上述第一待处理网络层的随机向量的维数相等的向量作为上述第一待处理网络层的随机向量;对上述第一待处理网络层的随机向量采用循环移位或者向量元素复制的方式生成与上述第一待处理网络层的输入向量的维数相等的向量作为上述第一待处理网络层的扰动向量。基于本方案,能够根据参考随机向量和第一待处理网络层的随机向量的维数通过截取和扩展的方式得到第一待处理网络层的扰动向量,因此仅需增加极少的存储资源和计算资源,即可保证神经网络的准确度不下降,收敛速度得到有效提升。
本申请实施例的第二方面,提供一种神经网络模型的训练方法,用于获得神经网 络中每个网络层的权重参数,该方法包括:步骤1、初始化上述每个网络层的权重参数;步骤2、根据上述每个网络层对应的神经网络计算模型进行神经网络计算,以获得上述神经网络的临时输出向量,其中,上述神经网络计算模型的权重参数为初始化的权重参数,上述根据上述每个网络层对应的神经网络计算模型进行神经网络计算,包括根据上述第一方面或上述第一方面的任一实现方式的神经网络计算方法,对上述每个网络层中的一个或多个上述第一待处理网络层进行神经网络计算;步骤3、通过上述神经网络的反向传递,更新上述每个网络层的权重参数;以该更新后的每个网络层的权重参数作为上述每个网络层对应的神经网络计算模型的权重参数,重复步骤2和步骤3,直到上述临时输出向量和上述神经网络的预设输出向量的差异小于预设值;步骤4、获取上述每个网络层的权重参数。基于本方案,能够对神经网络的多个网络层进行训练,得到训练收敛时每个网络层的权重参数。
本申请实施例的第三方面,提供一种神经网络计算装置,该神经网络包括多个网络层,该多个网络层中包括第一待处理网络层,该装置包括:第一获取单元,用于获取上述第一待处理网络层的输入向量;第二获取单元,用于根据上述神经网络的参考随机向量和上述第一待处理网络层的随机向量的维数,获取上述第一待处理网络层的扰动向量,其中,该扰动向量的维数等于上述第一待处理网络层的输入向量的维数,上述第一待处理网络层的随机向量的维数是根据上述第一待处理网络层的权重参数和上述第一待处理网络层的输入向量的维数确定的;第一计算单元,用于将上述第一待处理网络层的输入向量中的元素与上述第二获取单元获取的上述扰动向量中对应位置的元素相乘,以获得上述第一待处理网络层的校正输入向量;第二计算单元,用于基于上述第一计算单元获得的上述校正输入向量和上述神经网络的计算模型,以获得上述第一待处理网络层的输出向量。当上述第一待处理网络层为上述神经网络的输入层时,上述获取单元具体用于获取上述神经网络的输入向量;当上述第一待处理网络层不为上述神经网络的输入层时,上述获取单元具体用于获取上述第一待处理网络层的前一网络层的输出向量。
结合第三方面和上述可能的实现方式,在另一种可能的实现方式中,上述第一待处理网络层的输入向量为{x1,x2…xn},上述扰动向量为{y1,y2…yn},上述第一待处理网络层的校正输入向量为{x1×y1,x2×y2…xn×yn},其中,n为正整数。
结合第三方面和上述可能的实现方式,在另一种可能的实现方式中,上述神经网络计算模型包括:Y j=C j×X j+b j,其中,Y j为上述神经网络计算模型的输出向量,X j为上述神经网络计算模型的输入向量,C j为上述神经网络计算模型的权重参数,b j为上述神经网络计算模型的预设偏置值,上述神经网络计算模型用于上述多个网络层中第j层的神经网络计算,j为整数。上述第二计算单元具体用于:将上述第一待处理网络层的权重参数和校正输入向量分别作为上述神经网络计算模型的权重参数和输入向量进行计算,以获得上述第一待处理网络层的输出向量。
结合第三方面和上述可能的实现方式,在另一种可能的实现方式中,上述权重参数为分块结构化的矩阵对应的压缩矩阵,其中,上述分块结构化的矩阵由上述压缩矩阵唯一确定,上述装置还包括解压单元,该解压单元,用于将上述权重参数解压为上述压缩矩阵对应的分块结构化的矩阵。
结合第三方面和上述可能的实现方式,在另一种可能的实现方式中,上述装置还 包括第一确定单元,该第一确定单元,用于确定目标区间,该目标区间的两个区间端点分别为上述第一待处理网络层的权重参数对应的分块结构化的矩阵的分块尺寸和上述第一待处理网络层的输入向量的维数;上述第一确定单元,还用于在上述目标区间内随机确定上述第一待处理网络层的随机向量的维数。
结合第三方面和上述可能的实现方式,在另一种可能的实现方式中,上述多个网络层包括多个第一待处理网络层,上述装置还包括:第二确定单元和生成单元,该第二确定单元,还用于确定全部上述第一待处理网络层的随机向量的维数中的最大值,作为上述神经网络的参考随机向量的维数;上述生成单元,用于基于预设的随机数生成模型,生成满足上述参考随机向量的维数的随机数,将该生成的随机数组成上述参考随机向量。
结合第三方面和上述可能的实现方式,在另一种可能的实现方式中,上述第二获取单元,具体用于在上述参考随机向量中截取与上述第一待处理网络层的随机向量的维数相等的向量作为上述第一待处理网络层的随机向量;上述第二获取单元,具体用于对上述第一待处理网络层的随机向量采用循环移位或者向量元素复制的方式生成与上述第一待处理网络层的输入向量的维数相等的向量作为上述第一待处理网络层的扰动向量。
本申请实施例的第四方面,提供一种神经网络模型的训练装置,用于获得神经网络中每个网络层的权重参数,该装置包括:初始化单元,用于初始化上述每个网络层的权重参数;神经网络计算单元,用于根据上述每个网络层对应的神经网络计算模型进行神经网络计算,以获得上述神经网络的临时输出向量,其中,上述神经网络计算模型的权重参数为上述初始化的权重参数;上述神经网络计算单元,具体用于根据上述第一方面或上述第一方面的任一实现方式所述的神经网络计算方法,对上述每个网络层中的一个或多个上述第一待处理网络层进行神经网络计算;反向传递单元,用于通过上述神经网络的反向传递,更新上述每个网络层的权重参数;获取单元,用于获取上述每个网络层的权重参数,上述每个网络层的权重参数是在上述神经网络的临时输出向量和所述神经网络的预设输出向量的差异小于预设值时获取的。
上述第三方面以及第三方面的各种实现方式的效果描述可以参考第一方面相应效果的描述,上述第四方面的效果描述可以参考第二方面相应效果的描述,在此不再赘述。
本申请实施例的第五方面,提供了一种服务器,该服务器的结构中包括处理器和存储器,该存储器用于与处理器耦合,保存该服务器必要的程序指令和数据,该处理器用于执行存储器中存储的程序指令,使得该服务器执行上述方法。
本申请实施例的第六方面,提供一种计算机存储介质,所述计算机存储介质中存储有计算机程序代码,当所述计算机程序代码在处理器上运行时,使得所述处理器执行第一方面或第一方面的可能的实现方式中任一所述的神经网络计算方法,或者执行第二方面所述的神经网络模型的训练方法。
本申请实施例的第七方面,提供了一种计算机程序产品,该程序产品储存有上述处理器执行的计算机软件指令,该计算机软件指令包含用于执行上述方面所述方案的程序。
本申请实施例的第八方面,提供了一种装置,该装置以芯片的产品形态存在,该装置的结构中包括处理器和存储器,该存储器用于与处理器耦合,保存该装置必要的程序指令和数据,该处理器用于执行存储器中存储的程序指令,使得该装置执行上述方法中神经网络计算装置或者神经网络模型的训练装置的功能。
附图说明
图1为本申请实施例提供的一种神经网络计算的硬件架构示意图;
图2为本申请实施例提供的另一种神经网络计算的硬件架构示意图;
图3为本申请实施例提供的另一种神经网络计算的硬件架构示意图;
图4为本申请实施例提供的一种神经网络计算方法的流程图;
图5为本申请实施例提供的另一种神经网络计算方法的流程图;
图6为本申请实施例提供的另一种神经网络计算方法的流程图;
图7为本申请实施例提供的另一种神经网络计算方法的流程图;
图8为本申请实施例提供的另一种神经网络计算方法的流程图;
图9为本申请实施例提供的采用现有技术和本申请实施例中的神经网络计算方法得到的效果对比示意图;
图10为本申请实施例提供的一种神经网络模型的训练方法的流程图;
图11为本申请实施例提供的一种神经网络计算装置的组成示意图;
图12为本申请实施例提供的一种神经网络模型训练装置的组成示意图;
图13为本申请实施例提供的另一种神经网络计算装置的组成示意图;
图14为本申请实施例提供的另一种神经网络模型训练装置的组成示意图。
具体实施方式
为了解决现有技术中分块循环矩阵压缩神经网络时,分块大小很大时,训练难收敛,以及精度下降明显的问题,本申请实施例提供了一种神经网络计算方法,该方法能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。
本申请实施例中的神经网络包括多个网络层,该多个网络层中包括一个或多个第一待处理网络层。其中,该第一待处理网络层为神经网络的输入层时,该第一待处理网络层的输入向量为神经网络的输入向量;该第一待处理网络层不为神经网络的输入层时,该第一待处理网络层的输入向量为该第一待处理网络层的前一网络层的输出向量。对于一个或多个待处理网络层中的任一网络层的计算方法可以应用于图1所示的硬件架构。
如图1所示,该硬件结构组成包括:第一获取模块101、第二获取模块102、第一计算模块103以及第二计算模块104。其中,第一获取模块101与第一计算模块103以及第二计算模块104依次连接,第二获取模块102与第一计算模块103以及第二计算模块104依次连接。
第一获取模块101,用于获取每个第一待处理网络层的输入向量。示例性的,对于第一个网络层,其输入向量为神经网络的输入向量;对于出第一个网络层以外的网络层,其输入向量为该网络层的前一网络层的输出向量。
第二获取模块102,用于根据输入的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量,该第一待处理网络层的扰动向量的维 数可以等于该第一待处理网络层的输入向量的维数。示例性的,该第二获取模块可以包括cyclic shift模块或者copy模块。
第一计算模块103,用于在第一获取模块101获取的第一待处理网络层的输入向量的基础上加扰动,该扰动为第二获取模块102获取的扰动向量。示例性的,可以通过将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘的方式,得到该第一待处理网络层的校正输入向量。
第二计算模块104,用于根据上述第一计算模块103得到的校正输入向量和神经网络的计算模型,计算该第一待处理网络层的输出向量。示例性的,该神经网络的计算模型可以为:Y j=C j×X j+b j,其中,Y j为神经网络计算模型的输出向量,X j为神经网络计算模型的输入向量,C j为神经网络计算模型的权重参数,b j为神经网络计算模型的预设偏置值,该神经网络计算模型用于多个网络层中第j层的神经网络计算,j为整数。示例性的,该第二计算模块可以采用快速计算方式计算第一待处理层的输出向量,例如,分块结构化矩阵为分块循环矩阵时,该第二计算模块104可以采用快速傅里叶变换计算第一待处理层的输出向量。
可理解的是,图1仅为示例性说明,实际应用中,神经网络计算装置的硬件架构可以包括比图1所示更多或者更少的部件。图1所示结构不对本申请实施例提供的硬件架构构成任何限制。
示例性的,本申请实施例中的硬件架构组成除图1所示的模块外,还可以包括图2所示的解压模块105,该解压模块105与第二计算模块104连接。
解压模块105,用于将权重参数解压为压缩矩阵对应的分块结构化的矩阵,并将该分块结构化的矩阵传输给第二计算模块104,用于计算网络层的输出向量。示例性的,当分块结构化的矩阵为分块循环矩阵时,该解压模块105可以为cyclic shift模块,通过cyclic shift模块将权重参数解压为分块循环矩阵,再采用第二计算模块104进行矩阵乘法运算,计算第一待处理层的输出向量。
如图3所示,本申请实施例还提供一种硬件结构,该硬件结构包括依次连接的第一确定模块301、第二确定模块302以及生成模块303。
第一确定模块301,用于根据输入向量的维数和权重参数确定第一待处理网络层的随机向量的维数。
第二确定模块302,用于根据一个或多个第一待处理网络层的随机向量的维数确定参考随机向量的维数。示例性的,该参考随机向量的维数可以为所有第一待处理网络层的随机向量的维数的最大值。
生成模块303,用于根据参考随机向量的维数生成与该参考随机向量的维数相同的参考随机向量。
可理解的是,图1-3仅为示例性说明,图1-图3所示结构不对本申请实施例提供的硬件架构构成任何限制。
结合图1、图2,如图4所示,对于神经网络包含的多个网络层中的任意一个第一待处理网络层,可以采用图4所示的计算方法计算该第一待处理网络层的输出向量。如图4所示,本申请实施例提供的神经网络计算方法可以包括步骤S401-S404。
S401、获取第一待处理网络层的输入向量。
可以理解的,可由图1中所示的第一获取模块101执行步骤S401。
示例性的,该第一待处理网络层是指神经网络的多个网络层中,权重参数为分块结构化的矩阵对应的压缩矩阵的网络层。其中,该分块结构化的矩阵可以由压缩矩阵唯一确定。
示例性的,上述分块结构化的矩阵是指该矩阵可以分为多个块,且每个分块均按照某种规律排列。该分块结构化的矩阵可以包括分块循环矩阵、分块特普利茨矩阵等,本申请实施例对于分块结构化的矩阵的具体类型并不进行限定,在此仅以分块循环矩阵为例进行说明。
例如,W为分块循环矩阵,该分块循环矩阵中每个分块的第二列是由第一列向下循环移位所得,第三列是由第二列再向下循环移位所得,该网络层的权重参数C为分块循环矩阵W对应的压缩矩阵。该压缩矩阵C由N个w_base组合成的矩阵表示,其中N是指分块循环矩阵的分块数,每个分块的w_base是唯一确定该分块的结构化矩阵的每个分块的最小元素集合(例如w_base可以为一个分块的第一行或第一列)。如下式中的分块循环矩阵W的压缩矩阵为C(权重参数),该分块循环矩阵分为4块,该分块循环矩阵W可以由压缩矩阵C唯一确定。
Figure PCTCN2018101598-appb-000001
可以理解的,本申请实施例中的神经网络可以包括一个或多个第一待处理网络层,该一个或多个待处理网络层中的一个网络层可以为神经网络的输入向量,当第一待处理为神经网络的第一个网络层时,该第一待处理网络层的输入向量为神经网络的输入向量;当该第一待处理网络层为除第一个网络层以外的任一网络层时,该第一待处理网络层的输入向量为该第一待处理网络层的前一网络层的输出向量。
示例性的,本申请实施例中的神经网络可以为深度神经网络(Deep Neural Network,DNN)、卷积神经网络(Convolutional Neural Network,CNN)等类型的神经网络,上述第一待处理网络层可以是卷积层(convolution layer)、LSTM层、全连接层(full connection layer)等。本申请实施例对于具体的神经网络类型和结构并不进行限定。
S402、根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量。
可以理解的,可由图1中所示的第二获取模块102执行步骤S402。
其中,该扰动向量的维数等于第一待处理网络层的输入向量的维数。
示例性的,上述步骤S402中获取第一待处理网络层的扰动向量可以包括:步骤S4021-S4022。
S4021、在参考随机向量中截取与第一待处理网络层的随机向量的维数相等的向量作为第一待处理网络层的随机向量。
示例性的,该参考随机向量可以为全部第一待处理网络层的随机向量的维数中的最大值,因此可以通过在参考随机向量中截取与第一待处理网络层的随机向量的维数相等的向量作为第一待处理网络层的随机向量。
示例性的,上述在参考随机向量中截取与第一待处理网络层的随机向量的维数相等的向量可以包括:从参考随机向量的某一位置(例如第一位)开始按顺序截取与第一待处理网络层的随机向量的维数相等的向量为该第一待处理网络层的随机向量,也可以按照一定的截取规则,例如从参考随机向量中的奇数位或偶数位截取与第一待处理网络层的随机向量的维数相等的向量为该第一待处理网络层的随机向量,本申请实施例对于从参考随机向量中截取第一待处理网络层的随机向量的具体截取位置和方式并不进行限定,在此仅是示例性说明。
S4022、对第一待处理网络层的随机向量采用循环移位或者向量元素复制的方式生成与第一待处理网络层的输入向量的维数相等的向量作为第一待处理网络层的扰动向量。
示例性的,该第一待处理网络层的随机向量的维数小于该第一待处理网络层的输入向量的维数,该第一待处理网络层的扰动向量的维数等于第一待处理网络层的输入向量的维数,因此,可以通过将第一待处理网络层的随机向量采用循环移位或者向量元素复制的方式进行扩展,得到与第一待处理网络层的输入向量的维数相等的向量作为第一待处理网络层的扰动向量。
例如,若第一待处理网络层的随机向量为A i=[1,-1,1,1,-1],第一待处理网络层的输入向量的维数为15,采用循环移位方式获取的第一待处理网络层的扰动向量可以为A_L i=[1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,-1];采用向量元素复制的方式获取的第一待处理网络层的扰动向量A_L i可以为A_L i=[1,-1,1,1,-1,1,-1,1,1,-1,1,-1,1,1,-1]。本申请实施例对于根据第一待处理网络层的随机向量,具体采用何种方式获取第一待处理网络层的扰动向量并不进行限定。
可以理解的是,当采用循环移位的方式获取第一待处理网络层的扰动向量时,图1中的第二获取模块包括cyclic shift模块,当采用向量元素复制的方式获取第一待处理网络层的扰动向量时,图1中的第二获取模块包括copy模块。
需要说明的是,本申请实施例中仅需通过神经网络的参考随机向量和所有第一待处理网络层的随机向量的维数,即可采用步骤S402中的方式生成与输入向量维数相同的扰动向量,由于第一待处理网络层的随机向量的维数小于输入向量的维数,因此,仅需增加极少的存储资源和计算资源,即可保证神经网络的准确度不下降,收敛速度得到有效提升。
S403、将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得第一待处理网络层的校正输入向量。
可以理解的,可由图1中所示的第一计算模块103执行步骤S403。
示例性的,若第一待处理网络层的输入向量为{x1,x2…xn},第一待处理网络层的扰动向量为{y1,y2…yn},该第一待处理网络层的校正输入向量为{x1×y1,x2×y2…xn×yn},其中,n为正整数。
需要说明的是,本申请实施例通过在第一待处理网络层的输入向量上加扰动向量,可以有效的降低该层投影矩阵的相关性。
S404、基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。
可以理解的,可由图1中所示的第二计算模块104执行步骤S404。
示例性的,上述神经网络计算模型包括:Y j=C j×X j+b j,其中,Y j为神经网络计算模型的输出向量,X j为神经网络计算模型的输入向量,C j为神经网络计算模型的权重参数,b j为神经网络计算模型的预设偏置值,“×”为矩阵乘法运算,该神经网络计算模型用于多个网络层中第j层的神经网络计算,j为整数。
可以理解的,本申请实施例提供的神经网络计算方法可以适用于计算模型能够转换成Y j=C j×X j+b j的所有网络层。例如,对于全连接层,其计算模型和上述计算模型相同;对于LSTM层,可以由多个上述计算模型构成;对于卷积层,其原始计算模型为Y j=C j*X j+b j,其中“*”为卷积运算,但是根据现有技术可以将卷积运算转化成矩阵乘法运算,即卷积层也可转化成上述计算模型。因此,本申请实施例中的神经网络计算方法可以适用于包括全连接层、卷积层、LSTM等网络层。
需要说明的是,对卷积层进行压缩时,将卷积运算转换成矩阵的乘法后,第一待处理网络层的输入向量的维数为根据卷积核大小经过im2col转换后的输入矩阵矩阵后的宽。该im2col是指将卷积核每次要处理的输入图像上的一个小窗的像素值展开到新矩阵的一行(列),新矩阵的列(行)数,就是对于一副输入图像,卷积运算的次数(卷积核滑动的次数)。
示例性的,上述基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量,可以包括:将第一待处理网络层的权重参数和校正输入向量分别作为神经网络计算模型的权重参数和输入向量进行计算,以获得第一待处理网络层的输出向量。
示例性的,可以将加扰动向量后得到的校正输入向量X' j和权重参数C j作为神经网络计算模型的权重参数和输入向量进行计算,该神经网络计算模型的输出向量为Y j=C j×X' j+b j,X' j为神经网络计算模型的校正输入向量,Y j为第一待处理网络层的输出向量。
本申请实施例提供的神经网络计算方法,通过获取第一待处理网络层的输入向量;根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量,其中,扰动向量的维数等于第一待处理网络层的输入向量的维数;将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得第一待处理网络层的校正输入向量;基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。本申请实施例通过在第一待处理网络层的输入向量上加扰动向量,能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。而且本申请实施例通过神经网络的参考随机向量和第一待处理网络层的随机向量的维数,可以生成与第一待处理网络层的输入向量维数相同的扰动向量,由于第一待处理网络层的随机向量的维数小于输入向量的维数,因此,仅需增加极少的存储资源和计算资源,即可保证神经网络的准确度和收敛速度得到有效提升。
本申请还提供一实施例,如图5所示,在上述步骤S404之前,还可以包括步骤S405。
S405、将第一待处理网络层的权重参数解压为压缩矩阵对应的分块结构化的矩阵。
可以理解的,可由图2中所示的解压模块105执行步骤S405。
示例性的,由于第一待处理网络的权重参数为分块结构化的矩阵对应的压缩矩阵, 因此,在计算第一待处理网络层的输出向量之前,可以先将权重参数C j解压,获得该权重参数(压缩矩阵)对应的分块结构化矩阵W j,再采用该分块结构化的矩阵和输入向量进行矩阵相乘计算输出向量。
示例性的,上述第一待处理网络层的输出向量具体为:Y m=W m×X' m+b m,其中,Y m为第一待处理网络层的输出向量,X' m为第一待处理网络层的校正输入向量,W m为第一待处理网络层的权重参数对应的分块结构化的矩阵,b m为第一待处理网络层的预设偏置值。
示例性的,若采用图2中的解压模块105将权重参数解压为分块结构化矩阵(如图5所示的计算方法),可以通过图2中的第二计算模块104进行矩阵乘法运算,获取第一待处理网络层的输出向量。若不采用解压模块105(如图4所示的计算方法),可以直接通过图1中的第二计算模块104采用快速傅里叶变换计算第一待处理网络层的输出向量。
本申请实施例提供的神经网络计算方法,通过获取第一待处理网络层的输入向量;根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量,其中,扰动向量的维数等于第一待处理网络层的输入向量的维数;将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得第一待处理网络层的校正输入向量;将第一待处理网络层的权重参数解压为压缩矩阵对应的分块结构化的矩阵;基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。本申请实施例通过在第一待处理网络层的输入向量上加扰动向量,能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。而且本申请实施例通过神经网络的参考随机向量和第一待处理网络层的随机向量的维数,可以生成与第一待处理网络层的输入向量维数相同的扰动向量,由于第一待处理网络层的随机向量的维数小于输入向量的维数,因此,仅需增加极少的存储资源和计算资源,即可保证神经网络的准确度和收敛速度得到有效提升。
本申请提供又一实施例,如图6所示,上述方法还可以包括步骤S601-S603。
S601、根据第一待处理网络层的权重参数和第一待处理网络层的输入向量的维数确定第一待处理网络层的随机向量的维数。
可以理解的,可由图3中所示的第一确定模块301执行步骤S601。
示例性的,上述基于第一待处理网络层的权重参数和第一待处理网络层的输入向量的维数,确定第一待处理网络层的随机向量的维数可以包括:确定目标区间,该目标区间的两个区间端点分别为第一待处理网络层的权重参数对应的分块结构化的矩阵的分块尺寸和第一待处理网络层的输入向量的维数;在该目标区间内随机确定第一待处理网络层的随机向量的维数。例如,若当前神经网络中第一待处理网络层的分块循环矩阵的分块尺寸为32,该神经网络的输入向量的维数为800,第一待处理网络层的随机向量的维数可以在(32,800)区间内随机选取一个整数,例如可以为40。
可以理解的,本申请实施例中的神经网络可以包括一个或多个第一待处理网络层,当神经网络包括多个第一待处理网络层时,该多个第一待处理网络层的随机向量的维数可以相同也可以不同,本申请实施例对此并不进行限定。
S602、确定全部第一待处理网络层的随机向量的维数中的最大值,作为神经网络 的参考随机向量的维数。
可以理解的,可由图3中所示的第二确定模块302执行步骤S602。
示例性的,当神经网络的多个网络层包括多个第一待处理网络层时,确定所有第一待处理网络层的随机向量的维数中的最大值为神经网络的参考随机向量的维数。例如,神经网络包括5个第一待处理网络层时,这5个第一待处理网络层的随机向量的维数分别为:40、35、50、46、55,那么该神经网络的参考随机向量的维数为这5个第一待处理网络层的随机向量的维数的最大值,即为55。
S603、基于预设的随机数生成模型,生成满足参考随机向量的维数的随机数。
可以理解的,可由图3中所示的生成模块303执行步骤S603。
示例性的,可以根据预设的随机数生成模型和上述参考随机向量的维数,生成一组满足参考随机向量的维数的随机数,该满足参考随机向量的维数的随机数即为参考随机向量。例如,该随机数生成模型可以为服从二项分布的符号向量,若该参考随机向量的维数为55,可以生成一个维数为55的符号向量[1,-1,1,1,-1…1,-1],参考随机向量可以记为A,A可以为A=[1,-1,1,1,-1…1,-1]。本申请实施例对于该随机数生成模型的具体形式并不进行限定,任何一种随机数生成模型均在本申请实施例的保护范围内,在此仅是示例性说明。
需要说明的是,本申请实施例中的步骤S601-S603确定基础随机向量的过程可以是在下述神经网络模型训练之前执行,对神经网络进行前向计算时可以根据神经网络模型训练获取的每个网络层的权重参数、以及模型训练前生成的参考随机向量和第一待处理网络层的随机向量的维数采用步骤S401-S406的神经网络计算方法计算神经网络的输出向量。
本申请实施例提供的神经网络计算方法,通过获取第一待处理网络层的输入向量;根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量,其中,扰动向量的维数等于第一待处理网络层的输入向量的维数;将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得第一待处理网络层的校正输入向量;基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。本申请实施例通过在第一待处理网络层的输入向量上加扰动向量,能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。而且本申请实施例通过神经网络的参考随机向量和第一待处理网络层的随机向量的维数,可以生成与第一待处理网络层的输入向量维数相同的扰动向量,由于第一待处理网络层的随机向量的维数小于输入向量的维数,因此,仅需增加极少的存储资源和计算资源,即可保证神经网络的准确度和收敛速度得到有效提升。
本申请还提供又一实施例,在神经网络包含多个第一待处理网络层时,多个第一待处理网络层中不同的第一待处理网络层可以采用相同的计算方法(如图4或图5所示的计算方法),也可以采用不同的计算方法。当多个不同的第一待处理网络层采用不同的计算方法时,其中一部分第一待处理网络层可以采用图5和图6所示的计算方法,另一部分第一待处理网络层可以采用图7所示的计算方法。如图7所示,该方法包括步骤S701-S703。
S701、获取第一待处理网络层的输入向量。
可以理解的,可由图1或图2中所示的第一获取模块101执行步骤S701。
S702、将第一待处理网络层的权重参数解压为压缩矩阵对应的分块结构化的矩阵。
可以理解的,可由图2中所示的解压模块105执行步骤S702。
示例性的,由于第一待处理网络的权重参数为分块结构化的矩阵对应的压缩矩阵,因此,在计算第一待处理网络层的输出向量之前,可以先将权重参数C n解压,获得该权重参数(压缩矩阵)对应的分块结构化矩阵W n
S703、根据第一待处理网络层的输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。
可以理解的,可由图1或图2中所示的第二计算模块104执行步骤S703。
示例性的,该第一待处理网络层的输出向量为Y n=W n×X n+b n,其中,Y n为第一待处理网络层的输出向量,X n为第一待处理网络层的输入向量,W n为第一待处理网络层的权重参数对应的分块结构化的矩阵,b n为第一待处理网络层的预设偏置值。
需要说明的是,对于神经网络包含的一个或多个第一处理网络层中的哪些第一待处理网络层采用图5所示的计算方式计算该网络层的输出,哪些第一待处理网络层采用图7所示的计算方式计算该网络层的输出,本申请实施例并不进行限定,具体可根据实际的网络结构确定。但是,采用本申请实施例的神经网络计算方法时,至少应该有一个第一待处理网络层采用图5所示的计算方式计算该网络层的输出向量。
本申请实施例提供的神经网络计算方法,通过获取第一待处理网络层的输入向量;根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量,其中,扰动向量的维数等于第一待处理网络层的输入向量的维数;将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得第一待处理网络层的校正输入向量;基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。本申请实施例通过在第一待处理网络层的输入向量上加扰动向量,能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。而且本申请实施例通过神经网络的参考随机向量和第一待处理网络层的随机向量的维数,可以生成与第一待处理网络层的输入向量维数相同的扰动向量,由于第一待处理网络层的随机向量的维数小于输入向量的维数,因此,仅需增加极少的存储资源和计算资源,即可保证神经网络的准确度和收敛速度得到有效提升。
本申请还提供另一实施例,若神经网络包含的多个网络层中除第一待处理网络层以外,还包括一个或多个第二待处理网络层,对于该一个或多个第二待处理网络层可以通过本申请实施例中的计算方法计算任意一个第二待处理网络层的输出向量。如图8所示,该计算方法可以包括步骤S801-S802。
S801、获取第二待处理网络层的输入向量。
可以理解的,可由图1或图2中所示的第一获取模块101执行步骤S801。
该第二待处理网络层是指神经网络的多个网络层中,权重参数为无结构化的矩阵的网络层。该无结构化的矩阵是指该矩阵没有按照一定的规律排列,且不可以用唯一确定该结构化矩阵的最小元素集合表示。如下式中的矩阵A为无结构化的矩阵,无法进行压缩,也不存在压缩矩阵。
Figure PCTCN2018101598-appb-000002
示例性的,该第二待处理网络层为神经网络的第一个网络层时,该第二待处理网络层的输入向量为神经网络的输入向量;当该第二待处理网络层为除第一个网络层以外的任一网络层时,该第二待处理网络层的输入向量为该第二待处理网络层的前一网络层的输出向量。
S802、根据第二待处理网络层的输入向量和神经网络的计算模型,以获得第二待处理网络的输出向量。
可以理解的,可由图1或图2中所示的第二计算模块104执行步骤S802。
示例性的,该第二待处理网络的输出向量为Y i=C i×X i+b i,其中,Y i为第二待处理网络层的输出向量,X i为第二待处理网络层的输入向量,C i为第二待处理网络层的权重参数,b i为第二待处理网络层的预设偏置值。由于该第二待处理网络层的权重参数为无结构化的矩阵,C i=W i,因此该第二待处理网络层的输出向量可以直接根据该第二待处理网络层的输入向量和权重参数以及预设偏置值进行计算,无需对权重参数进行解压处理。
如图9所示,为在MNIST数据库上采用2层卷积和1层全连接层构成的卷积神经网络上实验的效果图,其中,第二层卷积层为第一待处理网络层,第一层卷积层和第三层全连接层为第二待处理网络。图9中的横坐标表示迭代次数,纵坐标表示精度,×拦腰加直线表示分块循环矩阵的分块尺寸为32时,采用现有技术中不加符号向量的方式得到的效果图;直线表示分块循环矩阵的分块尺寸为32时,采用循环移位的方式获得扰动向量,对于第一待处理网络层采用图5所示的神经网络计算方法,对于第二待处理网络层采用图8所示的神经网络计算方法得到的效果图;三角拦腰加直线表示分块循环矩阵的分块尺寸为40时,采用向量元素复制(内容复制)的方式获得扰动向量,对于第一待处理网络层采用图5所示的神经网络计算方法,对于第二待处理网络层采用图8所示的神经网络计算方法得到的效果图;虚点线表示分块循环矩阵的分块尺寸为40时,采用循环移位的方式获得扰动向量,对于第一待处理网络层采用图5所示的神经网络计算方法,对于第二待处理网络层采用图8所示的神经网络计算方法得到的效果图。
结合图9所示,当分块尺寸为32时,由于分块尺寸较大,采用现有技术中不加符号向量的计算方式时,网络并不能收敛,因此不能实现32倍的压缩。而采用本申请实施例中循环移位获取第一待处理网络层的扰动符号向量,根据上述实施例的神经网络计算方法,能够使网络迅速收敛,相对于现有技术的有益效果是非常明显的。而且当分块尺寸为40时,采用本申请实施例中内容复制(向量元素复制)和内容循环移位的方式生成第一待处理网络层的扰动向量,并对上述网络层采用图5和图8所示的计算方法时,网络能够收敛,且采用循环移位时,网络的收敛速度更快,准确度较高。因此,采用本申请实施例中的神经网络计算方法对网络进行前向推理时,能够解决分块 循环矩阵压缩神经网络时,分块大小很大时,训练难以收敛,以及精度下降明显的问题。
本申请实施例提供的神经网络计算方法,通过获取第一待处理网络层的输入向量;根据神经网络的参考随机向量和第一待处理网络层的随机向量的维数,获取第一待处理网络层的扰动向量,其中,扰动向量的维数等于第一待处理网络层的输入向量的维数;将第一待处理网络层的输入向量中的元素与扰动向量中对应位置的元素相乘,以获得第一待处理网络层的校正输入向量;基于校正输入向量和神经网络的计算模型,以获得第一待处理网络层的输出向量。本申请实施例通过在第一待处理网络层的输入向量上加扰动向量,能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。而且本申请实施例通过神经网络的参考随机向量和第一待处理网络层的随机向量的维数,可以生成与第一待处理网络层的输入向量维数相同的扰动向量,由于第一待处理网络层的随机向量的维数小于输入向量的维数,因此,仅需增加极少的存储资源和计算资源,即可保证神经网络的准确度和收敛速度得到有效提升。
本申请实施例还提供一种神经网络模型的训练方法,用于在神经网络计算之前获得神经网络中每个网络层的权重参数,如图10所示,该神经网络模型的训练方法包括步骤S1001-S1004。
S1001、初始化每个网络层的权重参数。
示例性的,将神经网络包含的一个或多个第一待处理网络网络层以及一个或多个第二待处理网络层中的每个网络层的权重参数初始化。
S1002、根据每个网络层对应的神经网络计算模型进行神经网络计算,以获得神经网络的临时输出向量。
其中,该神经网络计算模型的权重参数为初始化的权重参数。
示例性的,上述根据每个网络层对应的神经网络计算模型进行神经网络计算,可以包括:
对于第一网络层集合中的第一待处理网络层,其临时输出向量为:Y m0=W m0×X' m+b m,其中,Y m0为第一待处理网络层的临时输出向量,X' m为第一待处理网络层的校正输入向量,W m0为第一待处理网络层的初始化的权重参数对应的分块结构化的矩阵,b m为第一待处理网络层的预设偏置值。
对于第二网络层集合中的第一待处理网络层,其临时输出向量为:Y n0=W n0×X n+b n,其中,Y n0为第二网络层集合中的第一待处理网络层的临时输出向量,X n为第二网络层集合中的第一待处理网络层的输入向量,W n0为第二网络层集合中的第一待处理网络层的初始化的权重参数对应的分块结构化的矩阵,b n为第二网络层集合中的第一待处理网络层的预设偏置值。
对于第二待处理网络层,其临时输出向量为:Y i0=C i0×X i+b i,其中,Y i为第二待处理网络层的临时输出向量,X i为第二待处理网络层的输入向量,C i为第二待处理网络层的初始化的权重参数,b i为第二待处理网络层的预设偏置值。
示例性的,当神经网络的多个网络层中仅包含第一待处理网络时,可以根据图4或图5所示的计算方法,对每个网络层进行神经网络计算;或者,当神经网络的多个网络层中仅包含第一待处理网络时,也可以根据图4或图5所示的计算方法,以及图 7所示的计算方法,对相应网络层进行神经网络计算;或者,当神经网络的多个网络层中包含第一待处理网络层和第二待处理网络层时,可以根据图4或图5所示的计算方法,以及图8所述的计算方法,对相应网络层进行神经网络计算;或者,当神经网络的多个网络层中包含第一待处理网络层和第二待处理网络层时,也可以根据图4或图5所示的计算方法,以及图7和图8所述的计算方法,对相应网络层进行神经网络计算。具体采用上述何种计算方法可以根据实际应用的网络架构确定,在此并不进行限定。需要说明的是,本申请实施例在训练过程对每个网络层采用的计算方式与神经网络推理过程采用的计算方式应相同。
S1003、通过神经网络的反向传递,更新每个网络层的权重参数。
示例性的,以更新后的每个网络层的权重参数作为每个网络层对应的神经网络计算模型的权重参数,重复步骤S1002-S1003,直到神经网络的临时输出向量和神经网络的预设输出向量的差异小于预设值。
示例性的,神经网络的临时输出向量与神经网络的预设输出向量的差异小于预设值时,该神经网络的权重参数可以使得训练收敛。本申请实施例对于该预设值的取值并不进行限定,具体可以根据实际应用确定。
S1004、获取每个网络层的权重参数。
示例性的,神经网络训练收敛时的权重参数即为训练好的权重参数,采用该权重参数可以进行上述图4-图8所示的神经网络推理,能够实现更大的压缩比,使得神经网络快速收敛。
示例性的,本申请实施例提供的神经网络模型的训练方法在步骤S901之前,还可以包括步骤S601-S603,根据步骤S601-S603确定的参考随机向量和第一待处理网络层的随机向量的维数,采用步骤S1001-S1004的模型训练方法获取每个网络层的权重参数,再进行前述的神经网络计算流程。
本申请实施例提供的神经网络模型的训练方法,通过初始化每个网络层的权重参数;根据每个网络层对应的神经网络计算模型进行神经网络计算,以获得神经网络的临时输出向量;通过神经网络的反向传递,更新每个网络层的权重参数,并以更新后的每个网络层的权重参数作为每个网络层对应的神经网络计算模型的权重参数,重复计算,直至神经网络的临时输出向量和神经网络的预设输出向量的差异小于预设值,获取每个网络层的权重参数。本申请实施例的训练过程通过在第一待处理网络层的输入向量上加扰动向量获取校正输入向量,并通过校正输入向量进行神经网络训练,能够减小输出特征图像之间的相关性,加快训练收敛速度,减少精度损失。
上述主要从方法步骤的角度对本发明实施例提供的方案进行了介绍。可以理解的是,计算机为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请能够以硬件和计算机软件的结合形式来实现。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。
本申请实施例可以根据上述方法示例对计算机进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模 块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本发明实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
在采用对应各个功能划分各个功能模块的情况下,图11示出了上述实施例中所涉及的神经网络计算装置的一种可能的结构示意图,该神经网络计算装置1100包括:第一获取单元1101、第二获取单元1102、第一计算单元1103、第二计算单元1104以及解压单元1105。第一获取单元1101用于支持神经网络计算装置1100执行图4中的S401,或图7中的S701,或图8中的S801;第二获取单元1102用于支持神经网络计算装置1100执行图4中的S402;第一计算单元1103用于支持神经网络计算装置1100执行图4中的S403;第二计算单元1104用于支持神经网络计算装置1100执行图4中的S404,或图7中的S703,或图8中的S802;解压单元1105用于支持神经网络计算装置1100执行图5中的S405,或图7中的S702。其中,上述方法实施例涉及的各步骤的所有相关内容均可以援引到图1或图2所示的对应功能模块的功能描述,在此不再赘述。
在采用对应各个功能划分各个功能模块的情况下,图12示出了上述实施例中所涉及的神经网络模型训练装置的一种可能的结构示意图,该神经网络模型训练装置1200包括:初始化单元1201、第一确定单元1202、第二确定单元1203、生成单元1204、神经网络计算单元1205、反向传递单元1206以及获取单元1207。初始化单元1201用于支持神经网络模型训练装置1200执行图10中的S1001;第一确定单元1202用于支持神经网络模型训练装置1200执行图6中的S601;第二确定单元1203用于支持神经网络模型训练装置1200执行图6中的S602;生成单元1204用于支持神经网络模型训练装置1200执行图6中的S603;神经网络计算单元1205用于支持神经网络模型训练装置1200执行图10中的S1002;反向传递单元1206用于支持神经网络模型训练装置1200执行图10中的S1003;获取单元1207用于支持神经网络模型训练装置1200执行图10中的S1004。
在采用集成的单元的情况下,图13示出了上述实施例中所涉及的神经网络计算装置1300的一种可能的结构示意图。该神经网络计算装置1300包括:存储模块1301和处理模块1302。处理模块1302用于对计算机的动作进行控制管理,例如,处理模块1302用于支持神经网络计算装置1300执行图4中的S401-S404,或图5中的S401-S405,或图6中的S601-S603,或图7中的S701-S703,或图8中的S801-S802,和/或用于本文所描述的技术的其它过程。存储模块1301,用于存储计算机的程序代码和数据。另一种实现,上述实施例所涉及的神经网络计算装置的结构还可以为包括处理器和接口,处理器和接口通信,处理器用于执行本发明实施例。处理器可以是CPU,也可以是其他硬件,如现场可编程门阵列(Field-Programmable Gate Array,FPGA)等,或者两者的组合。
在采用集成的单元的情况下,图14示出了上述实施例中所涉及的神经网络模型训练装置1400的一种可能的结构示意图。该神经网络模型训练装置1400包括:存储模块1401和处理模块1402。处理模块1402用于对神经网络模型训练装置1400的动作进行控制管理,例如,处理模块1402用于支持神经网络模型训练装置1400执行图6中的S601-S703,或图10中的S1001-S1004,和/或用于本文所描述的技术的其它过程。 存储模块1401,用于存储计算机的程序代码和数据。另一种实现,上述实施例所涉及的神经网络模型训练装置的结构还可以为包括处理器和接口,处理器和接口通信,处理器用于执行本发明实施例。处理器可以是CPU,也可以是其他硬件,如现场可编程门阵列(Field-Programmable Gate Array,FPGA)等,或者两者的组合。
结合本申请公开内容所描述的方法或者算法的步骤可以硬件的方式来实现,也可以是由处理器执行软件指令的方式来实现。软件指令可以由相应的软件模块组成,软件模块可以被存放于随机存取存储器(Random Access Memory,RAM)、闪存、可擦除可编程只读存储器(Erasable Programmable ROM,EPROM)、电可擦可编程只读存储器(Electrically EPROM,EEPROM)、寄存器、硬盘、移动硬盘、只读光盘(CD-ROM)或者本领域熟知的任何其它形式的存储介质中。一种示例性的存储介质耦合至处理器,从而使处理器能够从该存储介质读取信息,且可向该存储介质写入信息。当然,存储介质也可以是处理器的组成部分。处理器和存储介质可以位于ASIC中。另外,该ASIC可以位于核心网接口设备中。当然,处理器和存储介质也可以作为分立组件存在于核心网接口设备中。
本领域技术人员应该可以意识到,在上述一个或多个示例中,本发明所描述的功能可以用硬件、软件、固件或它们的任意组合来实现。当使用软件实现时,可以将这些功能存储在计算机可读介质中或者作为计算机可读介质上的一个或多个指令或代码进行传输。计算机可读介质包括计算机存储介质和通信介质,其中通信介质包括便于从一个地方向另一个地方传送计算机程序的任何介质。存储介质可以是通用或专用计算机能够存取的任何可用介质。
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已,并不用于限定本发明的保护范围,凡在本发明的技术方案的基础之上,所做的任何修改、等同替换、改进等,均应包括在本发明的保护范围之内。

Claims (21)

  1. 一种神经网络计算方法,其特征在于,所述神经网络包括多个网络层,所述多个网络层中包括第一待处理网络层,所述方法包括:
    获取所述第一待处理网络层的输入向量;
    根据所述神经网络的参考随机向量和所述第一待处理网络层的随机向量的维数,获取所述第一待处理网络层的扰动向量,其中,所述扰动向量的维数等于所述第一待处理网络层的输入向量的维数,所述第一待处理网络层的随机向量的维数是基于所述第一待处理网络层的权重参数和所述第一待处理网络层的输入向量的维数确定的;
    将所述第一待处理网络层的输入向量中的元素与所述扰动向量中对应位置的元素相乘,以获得所述第一待处理网络层的校正输入向量;
    基于所述校正输入向量和所述神经网络的计算模型,以获得所述第一待处理网络层的输出向量。
  2. 根据权利要求1所述的神经网络计算方法,其特征在于,当所述第一待处理网络层为所述神经网络的输入层时,所述获取所述第一待处理网络层的输入向量,包括将所述神经网络的输入向量作为所述第一待处理网络层的输入向量;当所述第一待处理网络层不为所述神经网络的输入层时,所述获取所述第一待处理网络层的输入向量,包括将所述第一待处理网络层的前一网络层的输出向量作为所述第一待处理网络层的输入向量。
  3. 根据权利要求1或2所述的神经网络计算方法,其特征在于,所述第一待处理网络层的输入向量为{x1,x2…xn},所述扰动向量为{y1,y2…yn},所述第一待处理网络层的校正输入向量为{x1×y1,x2×y2…xn×yn},其中,n为正整数。
  4. 根据权利要求1至3任一项所述的神经网络计算方法,其特征在于,所述神经网络计算模型包括:
    Y j=C j×X j+b j,其中,Y j为所述神经网络计算模型的输出向量,X j为所述神经网络计算模型的输入向量,C j为所述神经网络计算模型的权重参数,b j为所述神经网络计算模型的预设偏置值,所述神经网络计算模型用于所述多个网络层中第j层的神经网络计算,j为整数。
  5. 根据权利要求4所述的神经网络计算方法,其特征在于,所述基于所述校正输入向量和所述神经网络的计算模型,以获得所述第一待处理网络层的输出向量,包括:
    将所述第一待处理网络层的权重参数和校正输入向量分别作为所述神经网络计算模型的权重参数和输入向量进行计算,以获得所述第一待处理网络层的输出向量。
  6. 根据权利要求4或5所述的神经网络计算方法,其特征在于,所述权重参数为分块结构化的矩阵对应的压缩矩阵,其中,所述分块结构化的矩阵由所述压缩矩阵唯一确定,在所述基于所述校正输入向量,通过神经网络计算,以获得所述第一待处理网络层的输出向量之前,所述方法还包括:
    将所述权重参数解压为所述压缩矩阵对应的分块结构化的矩阵。
  7. 根据权利要求6所述的神经网络计算方法,其特征在于,基于所述第一待处理网络层的权重参数和所述第一待处理网络层的输入向量的维数,确定所述第一待处理网络层的随机向量的维数,包括:
    确定目标区间,所述目标区间的两个区间端点分别为所述第一待处理网络层的权重参数对应的分块结构化的矩阵的分块尺寸和所述第一待处理网络层的输入向量的维数;
    在所述目标区间内随机确定所述第一待处理网络层的随机向量的维数。
  8. 根据权利要求1至7任一项所述的神经网络计算方法,其特征在于,所述多个网络层包括多个第一待处理网络层,在所述根据所述神经网络的参考随机向量和所述第一待处理网络层的随机向量的维数,获取所述第一待处理网络层的扰动向量之前,还包括:
    确定全部所述第一待处理网络层的随机向量的维数中的最大值,作为所述神经网络的参考随机向量的维数;
    基于预设的随机数生成模型,生成满足所述参考随机向量的维数的随机数;
    将所述生成的随机数组成所述参考随机向量。
  9. 根据权利要求1至8任一项所述的神经网络计算方法,其特征在于,根据所述神经网络的参考随机向量和所述第一待处理网络层的随机向量的维数,获取所述第一待处理网络层的扰动向量,包括:
    在所述参考随机向量中截取与所述第一待处理网络层的随机向量的维数相等的向量作为所述第一待处理网络层的随机向量;
    对所述第一待处理网络层的随机向量采用循环移位或者向量元素复制的方式生成与所述第一待处理网络层的输入向量的维数相等的向量作为所述第一待处理网络层的扰动向量。
  10. 一种神经网络模型的训练方法,用于获得神经网络中每个网络层的权重参数,其特征在于,所述方法包括:
    步骤1、初始化所述每个网络层的权重参数;
    步骤2、根据所述每个网络层对应的神经网络计算模型进行神经网络计算,以获得所述神经网络的临时输出向量,其中,所述神经网络计算模型的权重参数为所述初始化的权重参数,所述根据所述每个网络层对应的神经网络计算模型进行神经网络计算,包括根据权利要求1至9任一项所述的神经网络计算方法,对所述每个网络层中的一个或多个所述第一待处理网络层进行神经网络计算;
    步骤3、通过所述神经网络的反向传递,更新所述每个网络层的权重参数;
    以所述更新后的每个网络层的权重参数作为所述每个网络层对应的神经网络计算模型的权重参数,重复步骤2和步骤3,直到所述临时输出向量和所述神经网络的预设输出向量的差异小于预设值;
    步骤4、获取所述每个网络层的权重参数。
  11. 一种神经网络计算装置,其特征在于,所述神经网络包括多个网络层,所述多个网络层中包括第一待处理网络层,所述装置包括:
    第一获取单元,用于获取所述第一待处理网络层的输入向量;
    第二获取单元,用于根据所述神经网络的参考随机向量和所述第一待处理网络层的随机向量的维数,获取所述第一待处理网络层的扰动向量,其中,所述扰动向量的维数等于所述第一待处理网络层的输入向量的维数,所述第一待处理网络层的随机向 量的维数是根据所述第一待处理网络层的权重参数和所述第一待处理网络层的输入向量的维数确定的;
    第一计算单元,用于将所述第一待处理网络层的输入向量中的元素与所述第二获取单元获取的所述扰动向量中对应位置的元素相乘,以获得所述第一待处理网络层的校正输入向量;
    第二计算单元,用于基于所述第一计算单元获得的所述校正输入向量和所述神经网络的计算模型,以获得所述第一待处理网络层的输出向量。
  12. 根据权利要求11所述的神经网络计算装置,其特征在于,当所述第一待处理网络层为所述神经网络的输入层时,所述获取单元具体用于获取所述神经网络的输入向量;当所述第一待处理网络层不为所述神经网络的输入层时,所述获取单元具体用于获取所述第一待处理网络层的前一网络层的输出向量。
  13. 根据权利要求11或12所述的神经网络计算装置,其特征在于,所述第一待处理网络层的输入向量为{x1,x2…xn},所述扰动向量为{y1,y2…yn},所述第一待处理网络层的校正输入向量为{x1×y1,x2×y2…xn×yn},其中,n为正整数。
  14. 根据权利要求11至13任一项所述的神经网络计算装置,其特征在于,所述神经网络计算模型包括:
    Y j=C j×X j+b j,其中,Y j为所述神经网络计算模型的输出向量,X j为所述神经网络计算模型的输入向量,C j为所述神经网络计算模型的权重参数,b j为所述神经网络计算模型的预设偏置值,所述神经网络计算模型用于所述多个网络层中第j层的神经网络计算,j为整数。
  15. 根据权利要求14所述的神经网络计算装置,其特征在于,所述第二计算单元具体用于:将所述第一待处理网络层的权重参数和校正输入向量分别作为所述神经网络计算模型的权重参数和输入向量进行计算,以获得所述第一待处理网络层的输出向量。
  16. 根据权利要求14或15所述的神经网络计算装置,其特征在于,所述权重参数为分块结构化的矩阵对应的压缩矩阵,其中,所述分块结构化的矩阵由所述压缩矩阵唯一确定,所述装置还包括解压单元,
    所述解压单元,用于将所述权重参数解压为所述压缩矩阵对应的分块结构化的矩阵。
  17. 根据权利要求16所述的神经网络计算装置,其特征在于,所述装置还包括第一确定单元,
    所述第一确定单元,用于确定目标区间,所述目标区间的两个区间端点分别为所述第一待处理网络层的权重参数对应的分块结构化的矩阵的分块尺寸和所述第一待处理网络层的输入向量的维数;
    所述第一确定单元,还用于在所述目标区间内随机确定所述第一待处理网络层的随机向量的维数。
  18. 根据权利要求11至17任一项所述的神经网络计算装置,其特征在于,所述多个网络层包括多个第一待处理网络层,所述装置还包括:第二确定单元和生成单元,
    所述第二确定单元,还用于确定全部所述第一待处理网络层的随机向量的维数中 的最大值,作为所述神经网络的参考随机向量的维数;
    所述生成单元,用于基于预设的随机数生成模型,生成满足所述参考随机向量的维数的随机数,将所述生成的随机数组成所述参考随机向量。
  19. 根据权利要求11至18任一项所述的神经网络计算装置,其特征在于,
    所述第二获取单元,具体用于在所述参考随机向量中截取与所述第一待处理网络层的随机向量的维数相等的向量作为所述第一待处理网络层的随机向量;
    所述第二获取单元,具体用于对所述第一待处理网络层的随机向量采用循环移位或者向量元素复制的方式生成与所述第一待处理网络层的输入向量的维数相等的向量作为所述第一待处理网络层的扰动向量。
  20. 一种神经网络模型的训练装置,用于获得神经网络中每个网络层的权重参数,其特征在于,所述装置包括:
    初始化单元,用于初始化所述每个网络层的权重参数;
    神经网络计算单元,用于根据所述每个网络层对应的神经网络计算模型进行神经网络计算,以获得所述神经网络的临时输出向量,其中,所述神经网络计算模型的权重参数为所述初始化的权重参数;
    所述神经网络计算单元,具体用于根据权利要求1至9任一项所述的神经网络计算方法,对所述每个网络层中的一个或多个所述第一待处理网络层进行神经网络计算;
    反向传递单元,用于通过所述神经网络的反向传递,更新所述每个网络层的权重参数;
    获取单元,用于获取所述每个网络层的权重参数,所述每个网络层的权重参数是在所述神经网络的临时输出向量和所述神经网络的预设输出向量的差异小于预设值时获取的。
  21. 一种计算机存储介质,所述计算机存储介质中存储有计算机程序代码,其特征在于,当所述计算机程序代码在处理器上运行时,使得所述处理器执行如权利要求1-9任一项所述的神经网络计算方法,或执行权利要求10所述的神经网络模型的训练方法。
PCT/CN2018/101598 2018-08-21 2018-08-21 一种神经网络计算方法和装置 WO2020037512A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201880090586.1A CN111788584A (zh) 2018-08-21 2018-08-21 一种神经网络计算方法和装置
PCT/CN2018/101598 WO2020037512A1 (zh) 2018-08-21 2018-08-21 一种神经网络计算方法和装置

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2018/101598 WO2020037512A1 (zh) 2018-08-21 2018-08-21 一种神经网络计算方法和装置

Publications (1)

Publication Number Publication Date
WO2020037512A1 true WO2020037512A1 (zh) 2020-02-27

Family

ID=69591896

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/101598 WO2020037512A1 (zh) 2018-08-21 2018-08-21 一种神经网络计算方法和装置

Country Status (2)

Country Link
CN (1) CN111788584A (zh)
WO (1) WO2020037512A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112541593B (zh) * 2020-12-06 2022-05-17 支付宝(杭州)信息技术有限公司 基于隐私保护的联合训练业务模型的方法及装置
CN112765616B (zh) * 2020-12-18 2024-02-02 百度在线网络技术(北京)有限公司 多方安全计算方法、装置、电子设备和存储介质

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130212052A1 (en) * 2012-02-15 2013-08-15 Microsoft Corporation Tensor deep stacked neural network
CN104951787A (zh) * 2015-06-17 2015-09-30 江苏大学 一种src框架下判别字典学习的电能质量扰动识别方法
CN105391179A (zh) * 2015-12-23 2016-03-09 南京邮电大学 一种基于多智能体的环形直流微电网协调控制方法
CN106443598A (zh) * 2016-12-08 2017-02-22 中国人民解放军海军航空工程学院 基于卷积神经网络的雷达网协同航迹欺骗干扰鉴别方法
US20170076199A1 (en) * 2015-09-14 2017-03-16 National Institute Of Information And Communications Technology Neural network system, and computer-implemented method of generating training data for the neural network
CN106780468A (zh) * 2016-12-22 2017-05-31 中国计量大学 基于视觉感知正反馈的显著性检测方法

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130212052A1 (en) * 2012-02-15 2013-08-15 Microsoft Corporation Tensor deep stacked neural network
CN104951787A (zh) * 2015-06-17 2015-09-30 江苏大学 一种src框架下判别字典学习的电能质量扰动识别方法
US20170076199A1 (en) * 2015-09-14 2017-03-16 National Institute Of Information And Communications Technology Neural network system, and computer-implemented method of generating training data for the neural network
CN105391179A (zh) * 2015-12-23 2016-03-09 南京邮电大学 一种基于多智能体的环形直流微电网协调控制方法
CN106443598A (zh) * 2016-12-08 2017-02-22 中国人民解放军海军航空工程学院 基于卷积神经网络的雷达网协同航迹欺骗干扰鉴别方法
CN106780468A (zh) * 2016-12-22 2017-05-31 中国计量大学 基于视觉感知正反馈的显著性检测方法

Also Published As

Publication number Publication date
CN111788584A (zh) 2020-10-16

Similar Documents

Publication Publication Date Title
US11645529B2 (en) Sparsifying neural network models
WO2022257316A1 (zh) 量子体系基态能量估计方法及系统
WO2022166199A1 (zh) 量子纠错解码系统、方法、容错量子纠错系统及芯片
US11775832B2 (en) Device and method for artificial neural network operation
CN113435682A (zh) 分布式训练的梯度压缩
CN112633482B (zh) 一种高效宽度图卷积神经网络模型系统及训练方法
CN113159287B (zh) 一种基于梯度稀疏的分布式深度学习方法
CN109032630B (zh) 一种参数服务器中全局参数的更新方法
TWI775210B (zh) 用於卷積運算的資料劃分方法及處理器
WO2020037512A1 (zh) 一种神经网络计算方法和装置
CN111381968A (zh) 一种高效运行深度学习任务的卷积运算优化方法及系统
CN112836787A (zh) 通过高效混合并行化减少深度神经网络训练次数
WO2022222578A1 (zh) 一种聚合通信的方法、系统和计算机设备
TWI740338B (zh) 具有動態最小批次尺寸之運算方法,以及用於執行該方法之運算系統及電腦可讀儲存媒體
US11853391B1 (en) Distributed model training
Peng et al. MBFQuant: A Multiplier-Bitwidth-Fixed, Mixed-Precision Quantization Method for Mobile CNN-Based Applications
EP4141751A1 (en) Error mitigation for sampling on quantum devices
Li et al. The monostable cooperative system with nonlocal diffusion and free boundaries
JP7227322B2 (ja) 位相演算を行うための方法および装置
WO2020177863A1 (en) Training of algorithms
Bian et al. A parameterized douglas–rachford splitting algorithm for nonconvex optimization
JP7238376B2 (ja) 情報処理システム及び情報処理システムの制御方法
Bosch et al. Random Features Model with General Convex Regularization: A Fine Grained Analysis with Precise Asymptotic Learning Curves
Karnik et al. Neural network approximation of continuous functions in high dimensions with applications to inverse problems
Byrne Lecture notes on iterative optimization algorithms

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: 18930962

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18930962

Country of ref document: EP

Kind code of ref document: A1