Method and device for constructing neural network model

By replacing the non-convolutional layers with convolutional layers in the neural network model and using dedicated computing cores for calculations, the problem of low efficiency of general-purpose computing cores is solved and the overall computing efficiency is improved.

CN114492720BActive Publication Date: 2025-09-12HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011148242.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-23
Publication Date
2025-09-12
Estimated Expiration
2040-10-23

AI Technical Summary

Technical Problem

In the architecture of existing computing chips, the computing efficiency of general computing cores in neural network models is low except for specific algorithm network layers, resulting in limited overall computing efficiency and inability to improve.

Method used

In the neural network model, the non-convolutional layer is replaced with the convolutional layer. By obtaining the corresponding relationship between the attribute parameters of the non-convolutional layer and the convolutional layer, the replaced convolutional layer is constructed, the number of convolutional layers is increased, and the number of non-convolutional layers is reduced, so that dedicated computing cores can be used for calculations.

Benefits of technology

The overall computational efficiency of the neural network model has been improved, the number of network layers using dedicated computing cores has been increased, and computational efficiency has been improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114492720B_ABST
    Figure CN114492720B_ABST
Patent Text Reader

Abstract

The present application discloses a method and apparatus for constructing a neural network model, belonging to the field of artificial intelligence technology. The method comprises: determining a target non-convolutional layer in a network layer other than a convolutional layer in a neural network model; obtaining attribute parameters of a target convolutional layer for replacing the target non-convolutional layer based on the correspondence between the type of the stored non-convolutional layer and the attribute parameters of the convolutional layer; constructing the target convolutional layer based on the attribute parameters of the target convolutional layer; replacing the target non-convolutional layer with the target convolutional layer, and obtaining a replaced neural network model. The present application can improve the overall computational efficiency of the neural network model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method and device for constructing a neural network model. Background Art

[0002] With the continuous development of artificial intelligence, all walks of life have increasingly higher requirements for the computational efficiency of neural network models.

[0003] To improve the computational efficiency of neural network models, computing chip architectures are typically designed as a combination of specialized and general-purpose computing cores. Dedicated cores offer superior computing performance compared to general-purpose cores. Dedicated cores are used to execute layers of specific algorithms within a neural network model, such as convolutional layers, while general-purpose cores are used to execute other layers within the model.

[0004] Under the aforementioned computing chip architecture, the computational efficiency of general-purpose computing cores for neural network model layers other than the aforementioned specific algorithm layer is lower than the computational efficiency of specialized computing cores for the aforementioned specific algorithm layer. As a result, the overall computational efficiency of the computing chip for the neural network model is limited by the computational efficiency of the general-purpose computing cores for the aforementioned other layers, preventing improvement. Summary of the Invention

[0005] The present invention provides a method and apparatus for constructing a neural network model, which can improve the overall computational efficiency of the neural network model. The technical solution is as follows:

[0006] In a first aspect, a method for constructing a neural network model is provided, the method comprising:

[0007] In the neural network model, among the network layers other than the convolutional layers, determine the target non-convolutional layers;

[0008] Acquire attribute parameters of a target convolutional layer for replacing the target non-convolutional layer based on a correspondence between the stored types of the non-convolutional layers and the attribute parameters of the convolutional layers;

[0009] The target convolutional layer is constructed based on the attribute parameters of the target convolutional layer, and the target non-convolutional layer is replaced with the target convolutional layer to obtain a replaced neural network model.

[0010] In one possible implementation, the attribute parameters of the convolution layer include the number of convolution kernel input channels, the number of convolution kernels, the convolution kernel sliding window size, the convolution kernel sliding window size, the padding size during convolution kernel calculation, and the weight value of the convolution kernel.

[0011] In a possible implementation, the type of the target non-convolutional layer includes a passthrough layer and / or an average pooling layer.

[0012] In a possible implementation, the type of the target non-convolutional layer is a passthrough layer, and acquiring the attribute parameters of the target convolutional layer for replacing the target non-convolutional layer based on the correspondence between the stored type of the non-convolutional layer and the attribute parameters of the convolutional layer includes:

[0013] The number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernel input channels of the target convolutional layer;

[0014] The number of channels of the input feature image of the target non-convolutional layer is 4 times as large as the number of convolution kernels of the target convolutional layer;

[0015] Get the convolution kernel sliding window size, convolution kernel sliding window size, padding size when convolution kernel is calculated, and weight value of the convolution kernel of the convolution layer corresponding to the stored passthrough layer, and use them as the convolution kernel sliding window size, convolution kernel sliding window size, padding size when convolution kernel is calculated, and weight value of the convolution kernel of the target convolution layer, respectively.

[0016] In a possible implementation, the type of the target non-convolutional layer is an average pooling layer, and acquiring the attribute parameters of the target convolutional layer for replacing the target non-convolutional layer based on the correspondence between the stored type of the non-convolutional layer and the attribute parameters of the convolutional layer includes:

[0017] The number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernels of the target convolutional layer;

[0018] Obtain the number of convolution kernel input channels of the convolution layer corresponding to the stored average pooling layer as the number of convolution kernel input channels of the target convolution layer;

[0019] The sliding window size, sliding window span size, and padding size of the target non-convolutional layer are used as the convolution kernel sliding window size, convolution kernel sliding window size, and padding size during convolution kernel calculation of the target convolutional layer, respectively;

[0020] The reciprocal of the product of the length and width of the sliding window of the target non-convolutional layer is used as the weight value of the convolution kernel of the target convolutional layer.

[0021] In a possible implementation, the method further includes:

[0022] The target image is input into the replaced neural network model to obtain feature data of the target image.

[0023] In a second aspect, a device for constructing a neural network model is provided, the device comprising:

[0024] A determination module, configured to determine a target non-convolutional layer of a preset type in a network layer other than a convolutional layer in a neural network model;

[0025] an acquisition module, configured to acquire attribute parameters of a target convolutional layer for replacing the target non-convolutional layer based on a stored correspondence between the type of the non-convolutional layer and the attribute parameters of the convolutional layer;

[0026] A replacement module is used to construct the target convolutional layer based on the attribute parameters of the target convolutional layer, replace the target non-convolutional layer with the target convolutional layer, and obtain a replaced neural network model.

[0027] In one possible implementation, the attribute parameters of the convolution layer include the number of convolution kernel input channels, the number of convolution kernels, the convolution kernel sliding window size, the convolution kernel sliding window size, the padding size during convolution kernel calculation, and the weight value of the convolution kernel.

[0028] In a possible implementation, the type of the target non-convolutional layer includes a passthrough layer and / or an average pooling layer.

[0029] In a possible implementation, the target non-convolutional layer is a passthrough layer, and the acquisition module is configured to:

[0030] The number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernel input channels of the target convolutional layer;

[0031] The number of channels of the input feature image of the target non-convolutional layer is 4 times as large as the number of convolution kernels of the target convolutional layer;

[0032] Get the convolution kernel sliding window size, convolution kernel sliding window size, padding size when convolution kernel is calculated, and weight value of the convolution kernel of the convolution layer corresponding to the stored passthrough layer, and use them as the convolution kernel sliding window size, convolution kernel sliding window size, padding size when convolution kernel is calculated, and weight value of the convolution kernel of the target convolution layer, respectively.

[0033] In a possible implementation, the type of the target non-convolutional layer is an average pooling layer, and the acquisition module is configured to:

[0034] The number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernels of the target convolutional layer; the number of convolution kernel input channels of the convolution layer corresponding to the stored average pooling layer is obtained as the number of convolution kernel input channels of the target convolutional layer; the sliding window size, sliding window span size and padding size of the target non-convolutional layer are used as the convolution kernel sliding window size, convolution kernel sliding window size and padding size during convolution kernel calculation of the target convolutional layer respectively; the reciprocal of the product of the length and width of the sliding window of the target non-convolutional layer is used as the weight value of the convolution kernel of the target convolutional layer.

[0035] In a possible implementation, the device further includes an input module, configured to:

[0036] The target image is input into the replaced neural network model to obtain feature data of the target image.

[0037] In a third aspect, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, and the processor loads and executes the at least one instruction to implement the method for constructing a neural network model as described in the first aspect above.

[0038] In a fourth aspect, a computer-readable storage medium is provided, wherein the storage medium stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the method for constructing a neural network model as described in the first aspect above.

[0039] The beneficial effects of the technical solutions provided in the embodiments of the present application include at least:

[0040] In an embodiment of the present application, by obtaining the attribute parameters of the convolutional layer corresponding to the target non-convolutional layer and establishing the corresponding convolutional layer, the target non-convolutional layer in the neural network model can be replaced with the corresponding convolutional layer. In the replaced neural network model, the total number of network layers remains unchanged, the number of convolutional layers increases, and the number of non-convolutional layers decreases. Because the convolutional layer can use a dedicated computing core for calculation, more network layers in the replaced neural network model can use the dedicated computing core for calculation, and the overall computing efficiency is higher. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0042] Figure 1This is a flowchart of a method for constructing a neural network model provided by an embodiment of the present application;

[0043] Figure 2 This is a schematic diagram of the passthrough layer calculation principle provided by an embodiment of the present application;

[0044] Figure 3 This is a schematic diagram of the average pooling layer calculation principle provided in an embodiment of the present application;

[0045] Figure 4 Schematic diagram of a convolution kernel provided in an embodiment of the present application;

[0046] Figure 5 This is another convolution kernel diagram provided in an embodiment of the present application;

[0047] Figure 6 This is a schematic diagram of the structure of a device for constructing a neural network model provided in an embodiment of the present application;

[0048] Figure 7 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.

[0050] The embodiment of the present application provides a method for network layer replacement, which can be implemented by a computer device, wherein the computer device can be a desktop computer, a portable computer, or a server.

[0051] In an embodiment of the present application, the neural network model can be imported into the above-mentioned computer device before being deployed on the computing chip. The computing chip can be an AI (Artificial Intelligence) chip, such as an MLU (machine learning uint, machine learning unit), an Ascend processor, a GPU (Graphics Processing Unit, graphics processing unit), etc. The computer device can replace the specific non-convolutional layer in the neural network model with a convolutional layer, and then deploy it on the computing chip. In this way, since the non-convolutional layer is replaced by the convolutional layer, it can be calculated by the dedicated computing core in the computing chip, which can effectively improve the computing efficiency of the entire neural network model.

[0052] like Figure 1 As shown, the processing flow of the method may include the following steps:

[0053] Step 101: Determine a target non-convolutional layer in the network layers other than the convolutional layer in the neural network model.

[0054] During implementation, the neural network model that needs to be deployed in the computing chip can be imported into the computer device. The neural network model can be a trained neural network model. The neural network model file records the type identifier, name, and other information of each network layer of the neural network. The computer device can judge layer by layer and determine the network layer corresponding to the type identifier of the preset type. Among them, the preset type can include non-convolutional layers such as passthrough layers and average pooling layers. Of course, the preset type can also only include passthrough layers or average pooling layers.

[0055] It should be noted that before implementing this application, technicians can analyze the computational characteristics of various known types of non-convolutional layers, analyze the computational process and principles of the non-convolutional layers, and determine whether the non-convolutional layers meet the conditions for replacement with convolutional layers. Specifically, the conditions for determining whether a non-convolutional layer meets the conditions for replacement with a convolutional layer can be as follows:

[0056] First, determine whether the calculation process of the non-convolutional layer can be represented by a sliding window filter calculation, and whether the weight of the convolutional layer used to replace the non-convolutional layer is a constant.

[0057] Second, determine whether the calculation process of the non-convolutional layer can be represented by matrix multiplication, and the weights of the convolutional layer used to replace the non-convolutional layer are constant.

[0058] If a non-convolutional layer satisfies any of the above conditions, it can be considered that the non-convolutional layer can be replaced by a convolutional layer. In other words, the above preset type can include a non-convolutional layer that satisfies any of the above conditions.

[0059] The following examples illustrate the non-convolutional layers that meet the above two conditions:

[0060] For non-convolutional layers that meet the above condition one, for example: passthrough layer.

[0061] The passthrough layer converts an input feature map of size C*H*W into a feature map of size 4C*(H / 2)*(W / 2), where C is the number of channels, H is the height, and W is the width. Specifically, the passthrough layer extracts one feature from a 2*2 region of the input feature map for each channel. The four features in this 2*2 region are extracted four times and distributed across four different channels in the output feature map. After the passthrough layer completes, the output feature map has four times the number of channels as the input, and the size of each channel is half that of the input. The passthrough calculation essentially involves feature rearrangement: the H*W*C feature map is sampled at alternate points by row and column, resulting in four H / 2*W / 2*C feature maps. These four feature maps are then concatenated channel by channel, resulting in an output feature map of size 4C*H / 2*W / 2.

[0062] The order in which the passthrough layer processes the input feature maps is: first extract a (H / 2)*(W / 2) feature map for the feature map of the first channel, then extract a (H / 2)*(W / 2) feature map for the feature map of the second channel, and so on, until a (H / 2)*(W / 2) feature map is extracted for the feature map of the last channel, and then continue to extract a (H / 2)*(W / 2) feature map for the feature map of the first channel, and so on, until (H / 2)*(W / 2) feature maps of 4C channels are extracted.

[0063] like Figure 2 As shown in the figure, an input feature map of size C*4*4 is obtained. After being processed by the passthrough layer, an output feature map of size 4C*2*2 is obtained. Figure 2 The feature map of the first channel in For example, extract a feature data in its 2*2 area in turn, that is, for The first feature data 1 is extracted for the first time. The first feature data 3 is extracted for the first time. The first feature data 9 is extracted for the first time. The first feature data 11 is extracted for the first time, so that the first extraction can obtain the feature map By analogy, the second extraction can obtain the feature map The third extraction can get the feature map The fourth extraction can obtain the feature map

[0064] For non-convolutional layers that meet the above judgment condition 2, for example: average pooling layer.

[0065] The average pooling layer is used to perform sliding window calculation on the feature map of each channel of the input feature map. The calculation process involves three key parameters: sliding window size, sliding window span size, and sliding window padding size.

[0066] like Figure 3 As shown in the figure, an input feature map of size C*4*4 is processed by average pooling with a sliding window size of 2*2, a sliding window span of 2, and a padding size of 0, and an output feature map of size C*2*2 is obtained. Figure 3 The input feature map of the first channel in Taking average pooling as an example, calculate and The mean of each feature data in can be obtained as 3.25, 5.25, 1.75 and 2 respectively, that is, the input feature map can be obtained

[0067] Step 102: Based on the stored correspondence between the type of the non-convolutional layer and the attribute parameters of the convolutional layer, obtain the attribute parameters of the target convolutional layer for replacing the target non-convolutional layer.

[0068] The attribute parameters of the input feature map include the number of channels.

[0069] During implementation, technicians can pre-establish the correspondence between the type of non-convolutional layer and the attribute parameters of the convolutional layer.

[0070] When the input feature maps are the same, the output feature map obtained by the target non-convolutional layer after processing the input feature map is the same as the output feature map obtained by the replacement convolutional layer after processing the input feature map. Construct a replacement convolutional layer corresponding to the target network layer, that is, construct a convolution kernel that conforms to the algorithm characteristics of the target non-convolutional network layer. Specifically, it includes determining the following attribute parameters of the convolutional layer: kernel number (number of convolution kernels), kernel size (convolution kernel sliding window size), stride (sliding window span size when calculating the convolution kernel), pad (pad size when calculating the convolution kernel), c 卷积 (channel, the number of convolution kernel input channels) and the weight value in the convolution kernel.

[0071] The following describes the corresponding relationship between the attribute parameters of the convolution layer corresponding to the passthrough layer and the attribute parameters of the convolution layer corresponding to the average pooling layer:

[0072] 1. Attribute parameters of the convolutional layer corresponding to the passthrough layer.

[0073] The number of convolution kernel input channels is the same as the number of channels of the output feature image of the previous network layer, that is, the same as the number of channels of the input feature image of the target non-convolution layer. The corresponding relationship can be recorded as: 卷积 =c 输入 , where c 卷积 is the number of convolution kernel input channels, c 输入 The number of channels of the input feature map of the target non-convolutional layer.

[0074] Number of convolution kernels: 4 times the number of channels of the output feature map of the previous network layer, which is also 4 times the number of channels of the input feature map of the target non-convolutional layer. It can be recorded as: kernel number = 4c 输入 , where kernel number is the number of convolution kernels, c 输入 The number of channels of the input feature map of the target non-convolutional layer.

[0075] Convolution kernel sliding window size: Each time the window is slid by the set span, it can cover the next 2*2 feature map area where feature data needs to be extracted, such as 2*2, 3*3, and so on. Of course, to reduce the amount of computation and improve computational efficiency, the convolution kernel sliding window size can be set to 2*2. For example, the kernel size can be recorded as 2*2 in this mapping.

[0076] The sliding window span size when calculating the convolution kernel: According to the calculation principle of the passthrough layer, this value can be set to 2, that is, stride = 2.

[0077] Padding size during convolution kernel calculation: Padding can be set to valid mode, that is, no padding is performed and the padding size is 0. In addition, the padding can also be set to same mode, that is, the padding size is determined according to the convolution kernel sliding window size, the size of the input feature map, and the sliding window span size during convolution kernel calculation. The calculation method can be mod(xa, stride), where mod() is the remainder function, x is the length or width of the input feature map, a is the length or width of the convolution kernel sliding window, and stride is the sliding window span size during convolution kernel calculation. For example, if the input feature map size W*H is 4*4, the convolution kernel sliding window size is 2*2, and the sliding window span size during convolution kernel calculation is 2, the padding size is mod(4-2, 2) = 0; if the input feature map size W*H is 4*4, the convolution kernel sliding window size is 3*3, and the sliding window span size during convolution kernel calculation is 2, the padding size is mod(4-3, 2) = 1.

[0078] Convolution kernel weights: The passthrough layer extracts and rearranges features from the feature map, but does not change the values ​​of the feature data in the feature map. Convolution itself is a data feature extraction operation. To ensure that the values ​​of the feature data in the input feature map are not changed, the weights at the locations in the convolution kernel corresponding to the feature data to be extracted are set to 1, and the weights at all other locations are set to 0.

[0079] Specifically, when the convolution kernel sliding window size is 2*2, the sliding window span size is 2, the number is 4C, and the number of input channels is C, the convolution kernel weight value is set as follows:

[0080] like Figure 4 As shown, the first weight of the first channel of the first convolution kernel in the 4C convolution kernels is 1, and the remaining weights of the first channel and the weights of the remaining channels of the first convolution kernel are all 0; the first weight of the second channel of the second convolution kernel is 1, and the remaining weights of the second channel and the weights of the remaining channels of the second convolution kernel are all 0, and so on. The first weight of the Cth channel in the Cth convolution kernel is 1, and the remaining weights of the Cth channel and the weights of the remaining channels of the Cth convolution kernel are all 0.

[0081] The second weight of the first channel of the C+1th convolution kernel in the convolution kernel is 1, and the remaining weights of the first channel and the weights of the remaining channels of the C+1th convolution kernel are all 0; the second weight of the second channel of the C+2th convolution kernel is 1, and the remaining weights of the second channel and the weights of the remaining channels of the C+2th convolution kernel are all 0. And so on, the second weight of the Cth channel in the 2Cth convolution kernel is 1, and the remaining weights of the Cth channel and the weights of the remaining channels of the 2Cth convolution kernel are all 0.

[0082] The third weight of the first channel of the 2C+1th convolution kernel in the convolution kernel is 1, and the remaining weights of the first channel and the weights of the remaining channels of the 2C+1th convolution kernel are all 0; the third weight of the second channel of the 2C+2th convolution kernel is 1, and the remaining weights of the second channel and the weights of the remaining channels of the 2C+2th convolution kernel are all 0. And so on, the third weight of the Cth channel in the 3Cth convolution kernel is 1, and the remaining weights of the Cth channel and the weights of the remaining channels of the 2Cth convolution kernel are all 0.

[0083] The 4th weight of the 1st channel of the 3C+1th convolution kernel in the convolution kernel is 1, and the remaining weights of the 1st channel and the weights of the remaining channels of the 3C+1th convolution kernel are all 0; the 4th weight of the 2nd channel of the C+2th convolution kernel is 1, and the remaining weights of the 2nd channel and the weights of the remaining channels of the 3C+2th convolution kernel are all 0. And so on, the 4th weight of the Cth channel in the 4Cth convolution kernel is 1, and the remaining weights of the Cth channel and the weights of the remaining channels of the 4Cth convolution kernel are all 0.

[0084] In summary, a possible scenario of the attribute parameters of the convolutional layer corresponding to the passthrough layer other than the weight value can be shown in Table 1 below.

[0085] Table 1

[0086] Convolution kernel attribute parameters Parameter setting value Number of convolution kernel input channels C Number of convolution kernels 4C Convolution kernel sliding window size 2*2 Convolution kernel sliding window span size 2 The padding size when calculating the convolution kernel 0

[0087] 2. Attribute parameters of the convolutional layer corresponding to the average pooling layer.

[0088] Number of convolution kernel input channels: The average pooling layer can be replaced by a depthwise convolution layer, that is, the number of convolution kernel input channels is 1.

[0089] The number of convolution kernels: The same as the number of channels of the feature map output by the previous network layer, that is, the same as the number of channels of the feature map input by the target network layer. It can be recorded as: kernel number = c 输入 , where kernel number is the number of convolution kernels, c 输入 The number of channels of the input feature map of the target non-convolutional layer.

[0090] Convolution kernel sliding window size: the same as the sliding window size of the average pooling layer. It can be recorded as: kernelsize = S pooling , where S pooling is the sliding window size of the average pooling layer.

[0091] The sliding window span size when calculating the convolution kernel: the same as the sliding window span size of the average pooling layer. It can be recorded as stride 卷 =stride pooling , where stride 卷 stride is the sliding window span size when calculating the convolution kernel, pooling is the sliding window span size of the average pooling layer.

[0092] The padding size when calculating the convolution kernel is the same as the padding size of the average pooling layer. It can be recorded as: pad 卷 =pad pooling , among which, pad 卷 Pad is the padding size when calculating the convolution kernel. pooling is the padding size of the average pooling layer.

[0093] Convolution kernel weight: The reciprocal of the product of the length and width of the average pooling layer window is used as the convolution kernel weight. That is, weight = 1 / (a*b), where weight is the convolution kernel weight and a*b is the product of the length and width of the average pooling window.

[0094] For example, the convolution kernel sliding window size is 2*2, the sliding window span size is 2, the number is C, the number of input channels is 1, and the convolution kernel with a weight value of 1 / 4 can be as follows Figure 5 shown.

[0095] In summary, a possible scenario of the attribute parameters of the convolution layer corresponding to the average pooling layer other than the weight value can be shown in Table 2 below.

[0096] Table 2

[0097] Convolution kernel related parameters Parameter setting value Number of convolution kernel input channels 1 Number of convolution kernels C Convolution kernel sliding window size <![CDATA[S pooling ]]> Convolution kernel sliding window span size <![CDATA[stride pooling ]]> The padding size when calculating the convolution kernel <![CDATA[pad pooling ]]>

[0098] Step 103: construct the target convolutional layer based on the attribute parameters of the target convolutional layer, replace the target non-convolutional layer with the target convolutional layer, and obtain a replaced neural network model.

[0099] In implementation, after determining the attribute parameters of the target convolutional layer, the relevant attribute parameters of the target non-convolutional layer, as well as the connection relationship between the target non-convolutional layer and the upper and lower layers, are deleted. The layer type of the layer containing the target non-convolutional layer is changed to a convolutional layer, and the layer name can be customized as needed. Then, the attribute parameters of the target convolutional layer determined above are added to establish the convolutional layer. Finally, the connection relationship between the convolutional layer and the upper and lower layers is reestablished to obtain the replaced neural network model.

[0100] After replacing all preset target non-convolutional layers, the replaced neural network model can be exported and deployed in a computing chip to perform image processing, such as image feature extraction. Specifically, it can be face image feature extraction, vehicle image feature extraction, etc.

[0101] When extracting features from an image, the target image is input into the replaced neural network model, and the neural network model can output feature data corresponding to the target image.

[0102] In an embodiment of the present application, by obtaining the attribute parameters of the convolutional layer corresponding to the preset type of non-convolutional layer and establishing the corresponding convolutional layer, the preset type of convolutional layer in the neural network model can be replaced with the corresponding convolutional layer. In the replaced neural network model, the total number of network layers remains unchanged, the number of convolutional layers increases, and the number of non-convolutional layers decreases. Because the convolutional layer can use a dedicated computing core for calculation, more network layers in the replaced neural network model can use the dedicated computing core for calculation, and the overall computing efficiency is higher.

[0103] Based on the same technical concept, the embodiment of the present application also provides a device for constructing a neural network model, such as Figure 6 As shown, the device includes:

[0104] A determination module 610 is configured to determine a target non-convolutional layer in the network layers other than the convolutional layer in the neural network model;

[0105] An acquisition module 620 is configured to acquire attribute parameters of a target convolutional layer for replacing the target non-convolutional layer based on a stored correspondence between the type of the non-convolutional layer and the attribute parameters of the convolutional layer;

[0106] The replacement module 630 is used to construct the target convolutional layer based on the attribute parameters of the target convolutional layer, replace the target non-convolutional layer with the target convolutional layer, and obtain a replaced neural network model.

[0107] In one possible implementation, the attribute parameters of the convolution layer include the number of convolution kernel input channels, the number of convolution kernels, the convolution kernel sliding window size, the convolution kernel sliding window size, the padding size during convolution kernel calculation, and the weight value of the convolution kernel.

[0108] In a possible implementation, the type of the target non-convolutional layer includes a passthrough layer and / or an average pooling layer.

[0109] In a possible implementation, the type of the target non-convolutional layer is a passthrough layer, and the acquisition module 620 is configured to:

[0110] The number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernel input channels of the target convolutional layer;

[0111] The number of channels of the input feature image of the target non-convolutional layer is 4 times as large as the number of convolution kernels of the target convolutional layer;

[0112] Get the convolution kernel sliding window size, convolution kernel sliding window size, padding size when convolution kernel is calculated, and weight value of the convolution kernel of the convolution layer corresponding to the stored passthrough layer, and use them as the convolution kernel sliding window size, convolution kernel sliding window size, padding size when convolution kernel is calculated, and weight value of the convolution kernel of the target convolution layer, respectively.

[0113] In a possible implementation, the type of the target non-convolutional layer is an average pooling layer, and the acquisition module 620 is configured to:

[0114] The number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernels of the target convolutional layer;

[0115] Obtain the number of convolution kernel input channels of the convolution layer corresponding to the stored average pooling layer as the number of convolution kernel input channels of the target convolution layer;

[0116] The sliding window size, sliding window span size, and padding size of the target non-convolutional layer are used as the convolution kernel sliding window size, convolution kernel sliding window size, and padding size during convolution kernel calculation of the target convolutional layer, respectively;

[0117] The reciprocal of the sliding window size of the target non-convolutional layer is used as the weight value of the convolution kernel of the target convolutional layer.

[0118] In a possible implementation, the device further includes an input module, configured to:

[0119] The target image is input into the replaced neural network model to obtain feature data of the target image.

[0120] It should be noted that the apparatus for constructing a neural network model provided in the above embodiment only uses the division of the above functional modules as an example to illustrate when constructing a neural network model. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus for constructing a neural network model provided in the above embodiment and the method embodiment for constructing a neural network model are of the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0121] Figure 7: This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device 700 may have relatively large differences due to different configurations or performances, and may include one or more CPUs (central processing units, processors) 701 and one or more memories 702, wherein the memory 702 stores at least one instruction, and the at least one instruction is loaded and executed by the processor 701 to implement the method for constructing a neural network model provided by the above-mentioned various method embodiments. Of course, the computer device may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The computer device may also include other components for realizing the functions of the device, which will not be described in detail here.

[0122] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including instructions, which can be executed by a processor in a computer device to complete the method of constructing a neural network model in the above embodiment. The computer-readable storage medium can be non-transitory. For example, the computer-readable storage medium can be ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage device, etc.

[0123] Those skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.

[0124] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.

Claims

1. A method for constructing a neural network model, characterized in that: The method comprises: In the neural network model, among the network layers other than the convolutional layers, determine the target non-convolutional layers; Based on the correspondence between the stored type of the non-convolutional layer and the attribute parameters of the convolutional layer, obtaining the attribute parameters of the target convolutional layer for replacing the target non-convolutional layer, wherein the obtaining the attribute parameters of the target convolutional layer for replacing the target non-convolutional layer based on the correspondence between the stored type of the non-convolutional layer and the attribute parameters of the convolutional layer includes: if the type of the target non-convolutional layer is a passthrough layer, then using the number of channels of the input feature image of the target non-convolutional layer as the number of channels of the convolution kernel input of the target convolutional layer, using 4 times the number of channels of the input feature image of the target non-convolutional layer as the number of convolution kernels of the target convolutional layer, obtaining the convolution kernel sliding window size, convolution kernel sliding window size, padding size when calculating the convolution kernel, and convolution kernel weight value of the convolution layer corresponding to the stored passthrough layer, and using them as the convolution kernel sliding window size, convolution kernel sliding window size, padding size when calculating the convolution kernel, and convolution kernel weight value of the target convolutional layer, respectively; The target convolution layer is constructed based on the attribute parameters of the target convolution layer, and the target non-convolution layer is replaced with the target convolution layer to obtain a replaced neural network model, wherein the attribute parameters of the target convolution layer include the number of convolution kernel input channels, the number of convolution kernels, the convolution kernel sliding window size, the convolution kernel sliding window size, the padding size during convolution kernel calculation, and the weight value of the convolution kernel.

2. The method according to claim 1, characterized in that The method further comprises: If the type of the target non-convolutional layer is an average pooling layer, the number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernels of the target convolutional layer; Obtain the number of convolution kernel input channels of the convolution layer corresponding to the stored average pooling layer as the number of convolution kernel input channels of the target convolution layer; The sliding window size, sliding window span size, and padding size of the target non-convolutional layer are used as the convolution kernel sliding window size, convolution kernel sliding window size, and padding size during convolution kernel calculation of the target convolutional layer, respectively; The reciprocal of the product of the length and width of the sliding window of the target non-convolutional layer is used as the weight value of the convolution kernel of the target convolutional layer.

3. The method according to claim 1 or 2, characterized in that The method further comprises: The target image is input into the replaced neural network model to obtain feature data of the target image.

4. A device for constructing a neural network model, characterized in that: The device comprises: A determination module, used for determining a target non-convolutional layer in a network layer other than a convolutional layer in a neural network model; An acquisition module is configured to acquire the attribute parameters of a target convolutional layer for replacing the target non-convolutional layer based on the correspondence between the type of the stored non-convolutional layer and the attribute parameters of the convolutional layer, wherein the acquiring the attribute parameters of the target convolutional layer for replacing the target non-convolutional layer based on the correspondence between the type of the stored non-convolutional layer and the attribute parameters of the convolutional layer includes: if the type of the target non-convolutional layer is a passthrough layer, then using the number of channels of the input feature image of the target non-convolutional layer as the number of channels of the convolution kernel input of the target convolutional layer; using 4 times the number of channels of the input feature image of the target non-convolutional layer as the number of convolution kernels of the target convolutional layer; acquiring the convolution kernel sliding window size, convolution kernel sliding window size, padding size when calculating the convolution kernel, and convolution kernel weight value of the convolution layer corresponding to the stored passthrough layer, and using them as the convolution kernel sliding window size, convolution kernel sliding window size, padding size when calculating the convolution kernel, and convolution kernel weight value of the target convolutional layer, respectively; A replacement module is used to construct the target convolution layer based on the attribute parameters of the target convolution layer, replace the target non-convolution layer with the target convolution layer, and obtain a replaced neural network model, wherein the attribute parameters of the target convolution layer include the number of convolution kernel input channels, the number of convolution kernels, the convolution kernel sliding window size, the convolution kernel sliding window size, the padding size during convolution kernel calculation, and the weight value of the convolution kernel.

5. The device according to claim 4, characterized in that The acquisition module is further used to: If the type of the target non-convolutional layer is an average pooling layer, the number of channels of the input feature image of the target non-convolutional layer is used as the number of convolution kernels of the target convolutional layer; Obtain the number of convolution kernel input channels of the convolution layer corresponding to the stored average pooling layer as the number of convolution kernel input channels of the target convolution layer; The sliding window size, sliding window span size, and padding size of the target non-convolutional layer are used as the convolution kernel sliding window size, convolution kernel sliding window size, and padding size during convolution kernel calculation of the target convolutional layer, respectively; The reciprocal of the product of the length and width of the sliding window of the target non-convolutional layer is used as the weight value of the convolution kernel of the target convolutional layer.

6. The device according to claim 4 or 5, characterized in that The device further comprises an input module for: The target image is input into the replaced neural network model to obtain feature data of the target image.

Citation Information

Patent Citations

  • Information processing method and device applied to convolutional neural network

    CN109165736A