A method, device, electronic device and storage medium for converting feature map data
By dividing feature map data into data conversion units and performing position switching, the problem of low conversion efficiency of feature map data in the prior art is solved, and more efficient data conversion and resource conservation are achieved.
Patent Information
- Application Number
- CN202110910501.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-09
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2041-08-09
AI Technical Summary
The existing feature map data conversion scheme can only obtain part of the channel data in one addressing, resulting in repeated data readings multiple times, which is inefficient and wasteful of resources.
By dividing the original data of the feature map into multiple data conversion units, the channel data in each data conversion unit is positionally converted, so that the data of the same channel is aggregated and sorted in the order of feature points, and the data of different channel are sorted in the order of channel, thereby reducing the number of reads.
It improves the efficiency of feature map data conversion, reduces bandwidth consumption and resource consumption, and reduces the number of reads of feature map original data.
Smart Images

Figure CN113628099B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of feature map conversion, and in particular to a feature map data conversion method, device, electronic device and storage medium. Background Art
[0002] In order to meet the computing requirements of convolutional neural networks when designing embedded neural network processors (NPUs), feature maps (vector matrices) are usually stored in hwc format. However, in the convolutional neural network framework, data is usually stored in chw format, which requires the embedded neural network processor to convert the hwc to chw when outputting feature maps.
[0003] The feature map of the hwc method has multiple rows and columns of feature points, each feature point has multiple channel data. For example, taking 3X3 feature points, each feature point has 8 channels as an example, its form can be:
[0004] First row: a11a12a13a14a15a16a17a18, a21a22a23a24a25a26a27a28, a31a32a33a34a35a36a37a38.
[0005] Second row: b11b12b13b14b15b16b17b18, b21b22b23b24b25b26b27b28, b31b32b33b34b35b36b37b38
[0006] Third row: c11c12c13c14c15c16c17c18, c21c22c23c24c25c26c27c28, c31c32c33c34c35c36c37c38.
[0007] The feature map in chw form forms the data of the same channel adjacently. The feature map in hwc mode is converted into chw as follows:
[0008] a11a21a31b11b21b31c11c21c31a12a22a32b12b22b32c12c22c32a13a23a33b13b23b33c13c23c33…a18a28a38b18b28b38c18c28c38.
[0009] The existing hardware has an addressing capacity of 128 bits per address and a channel of 8 bits, which means that data of 16 channels can be obtained by one addressing, namely a11a12a13a14a15a16a17a18, a21a22a23a24a25a26a27a28. Among the data obtained by this addressing, only a11 and a21 can be used to form a feature map in the form of chw (the feature map in the form of chw needs to be formed in sequence according to the channel order, and the data of the first channel is formed first). In other words, most of the data read at one time are currently unavailable. As a result, the existing feature map data conversion scheme must read the data repeatedly for multiple times to complete the conversion, resulting in low conversion efficiency and waste of resources. Summary of the invention
[0010] The purpose of the embodiments of the present application is to provide a feature map data conversion method, device, electronic device and storage medium to solve the above-mentioned problems.
[0011] In a first aspect, the present invention provides a feature map data conversion method, comprising: obtaining feature map original data, the feature map original data comprising M rows of feature data sorted in sequence, each row of feature data comprising N feature point data sorted in sequence, and each feature point data comprising K channel data sorted in sequence; dividing the M rows of feature data into Q data conversion units, and swapping the channel data in each data conversion unit, so that the channel data in each data conversion unit after the swap satisfies the following rules: channel data belonging to the same channel are clustered together and sorted in sequence according to the order of their corresponding feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels; starting from the channel with the frontmost sorting, the channel data belonging to the same channel in the Q data conversion units are read in sequence to obtain feature map conversion data.
[0012] In the feature map data conversion method designed above, the present application scheme divides the M rows of feature data of the feature map original data into Q data conversion units, and then swaps the channel data in each data conversion unit, so that after the swap, the channel data belonging to the same channel in each data conversion unit are gathered together, sorted in sequence according to the order of their corresponding feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels, and then starting from the channel with the frontmost sorting, the channel data belonging to the same channel in the Q data conversion units are read in sequence to obtain the feature map conversion data; in this scheme, it is only necessary to swap the channel data in each data conversion unit, and there is no need to read the feature map original data multiple times, therefore, the number of times the feature map original data is read is reduced, thereby improving the efficiency of feature map data conversion, reducing bandwidth consumption and saving resource consumption.
[0013] In an optional implementation of the first aspect, dividing the M rows of feature data into Q data conversion units includes: determining each row of feature data in the M rows of feature data as a data conversion unit to obtain Q data conversion units, wherein M=Q; swapping the channel data in each data conversion unit, so that the channel data in each data conversion unit satisfies the following rule after the swap: channel data belonging to the same channel are clustered together and sorted in sequence according to the order of their corresponding feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels, including: swapping the channel data in each row of feature data, so that the channel data in each row of feature data satisfies the following rule after the swap: N channel data belonging to the same channel are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels.
[0014] In an optional implementation of the first aspect, dividing M rows of feature data into Q data conversion units includes: merging all row feature data in the M rows of feature data into one row of feature data to obtain one data conversion unit, wherein the first channel data of H+1 rows of feature data is adjacent to the last channel data of H rows of feature data, and Q=1.
[0015] In an optional implementation of the first aspect, the position swapping of the channel data in each data conversion unit includes: performing log2K rounds of the following position swapping on the channel data in each data conversion unit: gathering together the channel data with an odd arrangement order in each data conversion unit, and sorting them in sequence according to their order; gathering together the channel data with an even arrangement order in each data conversion unit, and sorting them in sequence according to their order, and the last channel data with an odd arrangement order is adjacent to the first channel data with an even arrangement order, wherein L+1 rounds of data position swapping are performed on the basis of the data after L rounds of data position swapping, log2K is an integer, and 1≤L<log2K.
[0016] In the implementation mode of the above design, when performing position replacement processing, the present application solution only needs to read the original data of the feature map log2K times. Assuming 8-channel data, the present application solution only needs to read the original data of the feature map 3 times. For the existing solution, when it uses each channel data, it needs to read the original data of the feature map once. Therefore, the present application solution reduces the reading of the original data of the feature map from K times to log2K times, thereby reducing the number of readings of the original data of the feature map, thereby improving the efficiency of feature map data conversion, reducing bandwidth consumption and saving resource consumption.
[0017] In an optional implementation of the first aspect, after obtaining the feature map conversion data, the method further includes: assigning a write address to each read channel data in turn according to the reading order; and writing each channel data into the memory in turn according to the assigned write address.
[0018] In a second aspect, the present invention provides a feature map data conversion device, including: an acquisition module, used to acquire feature map original data, the feature map original data includes M rows of feature data sorted in sequence, each row of feature data includes N feature point data sorted in sequence, and each feature point data includes K channel data sorted in sequence; a position exchange module, used to divide the M rows of feature data into Q data conversion units, and exchange the position of the channel data in each data conversion unit, so that the channel data in each data conversion unit after the exchange satisfies the following rules: channel data belonging to the same channel are clustered together and sorted in sequence according to the order of their corresponding feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels; a reading module, also used to start from the channel with the frontmost sorting, and read the channel data belonging to the same channel in the Q data conversion units in sequence to obtain feature map conversion data.
[0019] In the feature map data conversion device designed above, the present application scheme divides M rows of feature data of the feature map original data into Q data conversion units, and then swaps the channel data in each data conversion unit, so that after the swap, the channel data belonging to the same channel in each data conversion unit are gathered together, sorted in sequence according to the order of their corresponding feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels, and then starting from the channel with the frontmost sorting, the channel data belonging to the same channel in the Q data conversion units are read in sequence to obtain the feature map conversion data; in this scheme, it is only necessary to swap the channel data in each data conversion unit without reading the feature map original data multiple times, thereby reducing the number of times the feature map original data is read, thereby improving the efficiency of feature map data conversion, reducing bandwidth consumption and saving resource consumption.
[0020] In an optional implementation of the second aspect, the position swap module is specifically used to determine each row of feature data in M rows of feature data as a data conversion unit to obtain Q data conversion units, where M=Q; the channel data in each row of feature data is swapped, and after the swap, the channel data in each row of feature data satisfies the following rules: N channel data belonging to the same channel are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels.
[0021] In an optional implementation manner of the second aspect, the position swap module is further specifically used to perform log2K rounds of position swap on the channel data in each data conversion unit as follows: the channel data with odd arrangement orders in each data conversion unit are gathered together, and sorted in sequence according to their order; the channel data with even arrangement orders in each data conversion unit are gathered together, and sorted in sequence according to their order, and the last channel data with odd arrangement orders is adjacent to the first channel data with even arrangement orders, wherein L+1 rounds of data position swap are performed on the basis of the data after L rounds of data position swap, log2K is an integer, and 1≤L<log2K.
[0022] In a third aspect, an embodiment provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method in the first aspect and any optional implementation of the first aspect is executed.
[0023] In a fourth aspect, an embodiment provides a storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method in the first aspect or any optional implementation of the first aspect is performed.
[0024] In a fifth aspect, an embodiment provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the method in the first aspect or any optional implementation manner of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0026] Figure 1 A first flow chart of a method for converting feature graph data provided in an embodiment of the present application;
[0027] Figure 2 A second flow chart of the feature map data conversion method provided in an embodiment of the present application;
[0028] Figure 3 A third flow chart of the feature map data conversion method provided in an embodiment of the present application;
[0029] Figure 4 A fourth flow chart of the feature map data conversion method provided in an embodiment of the present application;
[0030] Figure 5 A schematic diagram of the structure of a feature graph data conversion device provided in an embodiment of the present application;
[0031] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0032] Icons: 500 - acquisition module; 510 - position exchange module; 520 - reading module; 6 - electronic device; 601 - processor; 602 - memory; 603 - communication bus. DETAILED DESCRIPTION
[0033] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0034] The present application embodiment provides a method for converting feature graph data, which can be applied to an embedded neural network processor, such as Figure 1 As shown, the method comprises the following steps:
[0035] Step S100: Acquire original data of a feature map, where the original data of the feature map includes M rows of feature data sorted in sequence, each row of feature data includes N feature point data sorted in sequence, and each feature point data includes K channel data sorted in sequence.
[0036] Step S110: Divide M rows of feature data into Q data conversion units, and swap the positions of channel data in each data conversion unit.
[0037] Step S120: Starting from the channel with the highest sorting position, the channel data belonging to the same channel in the Q data conversion units are read in sequence to obtain feature map conversion data.
[0038] In step S100, the feature map original data is based on the example of 3X3, 8 channels in the background technology. The feature map original data includes 3 rows of feature data sorted in sequence. For example, the first row is: a11a12a13a14a15a16a17a18, a21a22a23a24a25a26a27a28, a31a32a33a34a35a36a37a38.
[0039] Each row of feature data includes N feature point data sorted in sequence. For example, the first row of data includes 3 feature points sorted in sequence, a1, a2 and a3; each feature point data includes K channel data sorted in sequence, such as a1 feature point data includes 8 channel data sorted in sequence, a11a12a13a14a15a16a17a18.
[0040] There are many ways to obtain the original data of the feature map. It can be obtained by transmitting it to the embedded neural network processor from an external device, or it can be obtained by reading it from a memory previously stored in a corresponding connection of the embedded neural network processor.
[0041] On the basis of the original data of the feature map obtained above, step S110 can be executed to divide the M rows of feature data into Q data conversion units, and swap the channel data in each data conversion unit so that the channel data in each data conversion unit after the swap satisfies the following rules: the channel data belonging to the same channel are clustered together and sorted in sequence according to the order of their corresponding feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels.
[0042] As a possible implementation, step S110 may specifically include the following steps:
[0043] Step S200: Determine each line of feature data in the M lines of feature data as a data conversion unit, and obtain Q data conversion units.
[0044] Step S210: swap the positions of the channel data in each row of feature data, so that the channel data in each row of feature data satisfies the following rules after the swap: N channel data belonging to the same channel are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels.
[0045] In the above-mentioned embodiment, the present application scheme regards each row of feature data as a data conversion unit, that is, Q is equal to M at this time, and then M data conversion units are obtained. The M data conversion units are consistent with the order of the M rows of feature data. According to the example of the aforementioned 3X3 feature graph, 3 data conversion units can be obtained, and the order of these three data conversion units is consistent with the order of the three rows of feature data. For example, the first row of feature data is arranged before the second row of feature data, then the data conversion unit corresponding to the first row of feature data is arranged before the data conversion unit corresponding to the second row of feature data.
[0046] Based on the above determination of each row of feature data as a data conversion unit, the present scheme executes step S210 to swap the position of the channel data in each row of feature data, so that the N channel data belonging to the same channel in each row of feature data after the swap are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels.
[0047] According to the example of the 3×3 feature map, step S1120 is described as follows:
[0048] First row: a11a12a13a14a15a16a17a18, a21a22a23a24a25a26a27a28, a31a32a33a34a35a36a37a38.
[0049] The first row is a data conversion unit, and the position of the first row of data is swapped so that the data of the first row is converted into:
[0050] a11 a21 a31 a12 a22 a32 a13 a23 a33 a14 a24 a34 a15 a25 a35 a16 a26a36 a17 a27 a37 a18 a28 a38.
[0051] In the above data converted for the first row, the N channel data belonging to the same channel are gathered together and arranged in sequence according to the order of the corresponding N feature point data, which means that the three channel data a11 a21a31 belonging to the first channel are gathered together and arranged in sequence according to the order of a1, a2 and a3, that is, the first channel data a1 of a1 is consistent with it and arranged in the front, the first channel data a21 of a2 is consistent with it and arranged in the middle, and the first channel data a31 of a3 is consistent with it and arranged at the end; the three channel data a12 a22 a32 belonging to the second channel are gathered together and arranged in sequence according to the order of a1, a2 and a3, and so on, the three channel data a18 a28 a38 belonging to the eighth channel are gathered together and arranged in sequence according to the order of a1, a2 and a3.
[0052] And the channel data belonging to different channels are sorted in the order of K channels. For example, the original data is sorted as channel 1, channel 2, channel 3 ... channel 8, then the converted data is also sorted as channel 1, channel 2 ... channel 8. According to the above example, after the channel 1 data a11 a21 a31 are arranged, the channel data of the second channel a12 a22 a32 are arranged, and so on.
[0053] In an optional implementation of this embodiment, if Figure 3 As shown, the position exchange of the channel data in each data conversion unit can be specifically implemented in the following manner:
[0054] Step S300: perform log2K rounds of position transposition on the channel data in each data conversion unit as follows: gather the channel data with odd arrangement order in each data conversion unit together, and sort them in sequence according to their order; gather the channel data with even arrangement order in each data conversion unit together, and sort them in sequence according to their order, and the last channel data with odd arrangement order is adjacent to the first channel data with even arrangement order, wherein L+1 rounds of data position transposition are performed on the basis of the data after L rounds of data position transposition, log2K is an integer, 1≤L<log2K.
[0055] The above step S300 can be explained by taking the following example, where the first line is a data conversion unit:
[0056] a11a12a13a14a15a16a17a18,a21a22a23a24a25a26a27a28,a31a32a33a34a35a36a37a38.
[0057] Since each characteristic data point of the data conversion unit has 8 channels, log28=3, ie, three rounds of position exchange, are required.
[0058] The data conversion unit is subjected to the first position transposition, that is, the channel data with odd arrangement orders are gathered together and sorted in sequence according to their order, the channel data with even arrangement orders are gathered together and sorted in sequence according to their order, and the last channel data with odd arrangement orders is adjacent to the first channel data with even arrangement orders, and the form after the first conversion is obtained:
[0059] a11 a13 a15 a17 a21 a23 a25 a27 a31 a33 a35 a37 a12 a14 a16 a18 a22a24 a26 a28 a32 a34 a36 a38.
[0060] Continue to perform the above rule to permute the position of the data after the first conversion to obtain the form after the second conversion:
[0061] a11 a15 a21 a25 a31 a35 a12 a16 a22 a26 a32 a36 a13 a17 a23 a27 a33a37 a14 a18 a24 a28 a34 a38.
[0062] Continue to perform the above rule to permute the data after the second conversion, and get the form after the third conversion:
[0063] a11 a21 a31 a12 a22 a32 a13 a23 a33 a14 a24 a34 a15 a25 a35 a16 a26a36 a17 a27 a37 a18 a28 a38.
[0064] It can be seen from the above that after three rounds of position permutations of the first conversion unit, the channel data in the first conversion unit can meet the rule: the N channel data belonging to the same channel are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels.
[0065] The data of each conversion unit is swapped by the above-mentioned position swapping method, so that the channel data of each conversion unit meets the above-mentioned rules. According to the above-mentioned example, after the second row is used as the second conversion unit, the converted form is:
[0066] b11 b21 b31 b12 b22 b32 b13 b23 b33 b14 b24 b34 b15 b25 b35 b16 b26b36 b17 b27 b37 b18 b28 b38.
[0067] After the third line is used as the third conversion unit, the converted form is:
[0068] c11 c21 c31 c12 c22 c32 c13 c23 c33 c14 c24 c34 c15 c25 c35 c16 c26c36 c17 c27 c37 c18 c28 c38.
[0069] It should be noted here that in addition to using the characteristic data of each row as a data conversion unit as shown in the above example, characteristic data of multiple rows can also be used as a data conversion unit. For example, in the case of using every two rows of characteristic data as a data conversion unit, the characteristic data of the first row a1, a2, a3 and the characteristic data of the second row b1, b2, b3 can be combined into one data conversion unit, that is, a1, a2, a3, b1, b2, b3 are one data conversion unit; the application plan can determine the size of the data conversion unit according to the data processing capability, and the determined data conversion unit can be made as large as possible within the data processing capability.
[0070] In addition to the above method, when the data processing capability is strong, the data of all rows can be swapped as a data conversion unit, that is, a1, a2, a3, b1, b2, b3, c1, c2, c3 can be used as a data conversion unit, so that there is no need for multiple position swap processing, and one position swap processing can be performed to adjust it into place.
[0071] The above implementation manner is different only in the amount of data contained in the data conversion unit, while the process of replacing the position of the channel data in the data conversion unit is consistent with the above process, which will not be repeated here.
[0072] Based on the above implementation, after the channel data position in each data conversion unit is swapped to meet the preset rules, step S120 can be executed, starting from the channel with the highest sorting, and the channel data belonging to the same channel in Q data units are read in sequence to obtain the feature map conversion data.
[0073] The above process can be understood by the following explanation according to the above examples:
[0074] In the above example, each row is used as a data conversion unit, and three data conversion units can be obtained after the position is swapped, namely:
[0075] a11 a21 a31 a12 a22 a32 a13 a23 a33 a14 a24 a34 a15 a25 a35 a16 a26a36 a17 a27 a37 a18 a28 a38.
[0076] b11 b21 b31 b12 b22 b32 b13 b23 b33 b14 b24 b34 b15 b25 b35 b16 b26b36 b17 b27 b37 b18 b28 b38.
[0077] c11 c21 c31 c12 c22 c32 c13 c23 c33 c14 c24 c34 c15 c25 c35 c16 c26c36 c17 c27 c37 c18 c28 c38.
[0078] When executing step S120, this solution will first start from the first channel which is ranked first, and read the channel data belonging to the same channel in the three data conversion units in sequence, that is, first read the data of the first channel in the three data conversion units in sequence, and obtain a11 a21 a31 b11 b21 b31 c11 c21 c31.
[0079] Then read the data of the second channel in the three data conversion units in sequence, and get a11 a21 a31 b11b21 b31 c11 c21 c31 a12 a22 a32 b12 b22 b32 c12 c22 c32; until the data of the eighth channel in the three data conversion units is read and stopped, you can get: a11a21a31b11b21b31c11c21c31a12a22a32b12b22b32c12c22c32a13a23a33b13b23b33c13c23c33……a18a28a38b18b28b38c18c28c38, that is, the characteristic map conversion data in the form of chw is obtained.
[0080] In the feature map data conversion method designed above, the present application scheme divides the M rows of feature data of the feature map original data into Q data conversion units, and then swaps the channel data in each data conversion unit, so that after the swap, the channel data belonging to the same channel in each data conversion unit are gathered together, sorted in sequence according to the order of their corresponding feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels, and then starting from the channel with the frontmost sorting, the channel data belonging to the same channel in the Q data conversion units are read in sequence to obtain the feature map conversion data; in this scheme, it is only necessary to swap the channel data in each data conversion unit, and there is no need to read the feature map original data multiple times, therefore, the number of times the feature map original data is read is reduced, thereby improving the efficiency of feature map data conversion, reducing bandwidth consumption and saving resource consumption. In addition, when the present application solution performs position exchange processing, the present application solution only needs to read the original data of the feature map log2K times. Assuming 8-channel data, the present application solution only needs to read the original data of the feature map 3 times. For the existing solution, when each channel data is used, it needs to read the original data of the feature map once. Therefore, the present application solution reduces the reading of the original data of the feature map from K times to log2K times, reducing the number of times the original data of the feature map is read, thereby improving the efficiency of the feature map data conversion, reducing bandwidth consumption and saving resource consumption. Furthermore, the present application solution is applied to an embedded neural network processor, so that during the neural network processing process, there is no need to occupy CPU resources.
[0081] In an optional implementation of this embodiment, after obtaining the feature map conversion data in step S120, as shown in FIG. Figure 4 As shown, the present application scheme may also include the following steps:
[0082] Step S400: allocating a write address to each read channel data in sequence according to the reading order.
[0083] Step S410: writing each channel data into the memory in sequence according to the assigned write address.
[0084] In the above steps, the present application scheme will assign a write address to each channel data according to the reading order of the channel data in step S120, and the write addresses will be sorted in sequence according to the reading order, and then each channel data will be written into the memory in sequence according to the assigned write address, so that when the feature map conversion data is needed for subsequent convolutional neural network processing, the feature map conversion data in chw form can be read from the memory in sequence according to the written address.
[0085] Figure 5 The schematic structural block diagram of the characteristic graph data conversion device provided by the present application is shown. It should be understood that the device is similar to the above-mentioned Figures 1 to 4 The method embodiment executed in the embodiment corresponds to the method embodiment executed in the embodiment, and the steps involved in the aforementioned method can be executed. The specific functions of the device can be referred to the description above. To avoid repetition, the detailed description is appropriately omitted here. The device includes at least one software function module that can be stored in a memory in the form of software or firmware or fixed in the operating system (OS) of the device. Specifically, the device includes: an acquisition module 500, used to acquire original data of a feature map, the original data of the feature map includes M rows of feature data sorted in sequence, each row of feature data includes N feature point data sorted in sequence, and each feature point data includes K channel data sorted in sequence; a position exchange module 510, used to divide the M rows of feature data into Q data conversion units, and exchange the position of the channel data in each data conversion unit, so that the channel data in each data conversion unit after the exchange satisfies the following rules: channel data belonging to the same channel are clustered together and sorted in sequence according to the order of their corresponding feature point data, and channel data belonging to different channels are sorted in sequence according to the order of K channels; a reading module 520, also used to start from the channel with the frontmost sorting, and sequentially read the channel data belonging to the same channel in the Q data conversion units to obtain feature map conversion data.
[0086] In the feature map data conversion device designed above, the present application scheme divides M rows of feature data of the feature map original data into Q data conversion units, and then swaps the channel data in each data conversion unit, so that after the swap, the channel data belonging to the same channel in each data conversion unit are gathered together, sorted in sequence according to the order of their corresponding feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels, and then starting from the channel with the frontmost sorting, the channel data belonging to the same channel in the Q data conversion units are read in sequence to obtain the feature map conversion data; in this scheme, it is only necessary to swap the channel data in each data conversion unit without reading the feature map original data multiple times, thereby reducing the number of times the feature map original data is read, thereby improving the efficiency of feature map data conversion, reducing bandwidth consumption and saving resource consumption.
[0087] In an optional implementation manner of the present embodiment, the position swap module 510 is specifically used to determine each row of feature data in M rows of feature data as a data conversion unit, and obtain Q data conversion units, where M=Q; the channel data in each row of feature data is swapped, and after the swap, the channel data in each row of feature data satisfies the following rules: N channel data belonging to the same channel are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and the channel data belonging to different channels are sorted in sequence according to the order of the K channels.
[0088] In an optional implementation manner of the present embodiment, the position swap module 510 is further specifically used to perform log2K rounds of position swap on the channel data in each data conversion unit as follows: the channel data with an odd arrangement order in each data conversion unit are gathered together, and are sequentially sorted in order; the channel data with an even arrangement order in each data conversion unit are gathered together, and are sequentially sorted in order, and the last channel data with an odd arrangement order is adjacent to the first channel data with an even arrangement order, wherein L+1 rounds of data position swap are performed on the basis of the data after L rounds of data position swap, log2K is an integer, and 1≤L<log2K.
[0089] like Figure 6As shown, the present application provides an electronic device 6, including: a processor 601 and a memory 602, the processor 601 and the memory 602 are interconnected and communicate with each other through a communication bus 603 and / or other forms of connection mechanisms (not marked), the memory 602 stores a computer program executable by the processor 601, and when the computing device is running, the processor 601 executes the computer program to execute the method in any of the aforementioned optional implementations, such as steps S100 to S120: obtaining feature map original data, the feature map original data including M rows of feature data sorted in sequence, each row of feature data including N feature point data sorted in sequence, and each feature point data including K channel data sorted in sequence; dividing the M rows of feature data into Q data conversion units, and transposing the channel data in each data conversion unit; starting from the channel with the frontmost sorting, reading the channel data belonging to the same channel in the Q data conversion units in sequence to obtain feature map conversion data.
[0090] The present application provides a storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method in any of the aforementioned optional implementations is executed.
[0091] Among them, the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable red-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, disk or optical disk.
[0092] The present application provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the method in any of the aforementioned optional implementations.
[0093] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0094] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0095] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0096] It should be noted that if the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can essentially be embodied in the form of a software product, or the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM) random access memory (RAM), disk or optical disk, and other media that can store program codes.
[0097] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0098] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A method for converting feature map data, characterized in that: include: Acquire original data of the feature map, wherein the original data of the feature map includes M rows of feature data sorted in sequence, each row of feature data includes N feature point data sorted in sequence, and each feature point data includes K channel data sorted in sequence; The M rows of feature data are divided into Q data conversion units, and the channel data in each data conversion unit are swapped, so that the channel data in each data conversion unit after the swap meets the following rules: channel data belonging to the same channel are gathered together and sorted in sequence according to the order of their corresponding feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels; Starting from the channel with the highest sorting level, the channel data belonging to the same channel in the Q data conversion units are read in sequence to obtain feature map conversion data; The step of swapping the channel data in each data conversion unit includes: Perform log2K rounds of position transposition on the channel data in each data conversion unit as follows: gather the channel data with odd arrangement order in each data conversion unit together, and sort them in sequence according to their order; gather the channel data with even arrangement order in each data conversion unit together, and sort them in sequence according to their order, and the last channel data with odd arrangement order is adjacent to the first channel data with even arrangement order, wherein L+1 rounds of data position transposition are performed on the basis of the data after L rounds of data position transposition, log2K is an integer, 1≤L<log2K.
2. The method according to claim 1, characterized in that The dividing the M rows of feature data into Q data conversion units includes: Determine each row of feature data in the M rows of feature data as a data conversion unit, and obtain Q data conversion units, where M=Q; The channel data in each data conversion unit are swapped, and after the swap, the channel data in each data conversion unit satisfies the following rule: channel data belonging to the same channel are gathered together and sorted in sequence according to the order of their corresponding feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels, including: The channel data in each row of feature data are swapped, and after the swap, the channel data in each row of feature data satisfies the following rules: N channel data belonging to the same channel are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels.
3. The method according to claim 1, characterized in that: The step of dividing the M rows of feature data into Q data conversion units includes: The feature data of all rows in the M rows of feature data are determined as a data conversion unit, wherein the first channel data of the H+1 row of feature data in the data conversion unit is adjacent to the last channel data of the H row of feature data, Q=1, 1≤H≤M-1.
4. The method according to claim 1, characterized in that: After obtaining the characteristic map conversion data, the method further includes: Allocate a write address to each read channel data in turn according to the reading order; Each channel data is written into the memory in sequence according to the assigned write address.
5. A characteristic graph data conversion device, characterized in that: include: An acquisition module, used to acquire original data of a feature map, wherein the original data of the feature map includes M rows of feature data sorted in sequence, each row of feature data includes N feature point data sorted in sequence, and each feature point data includes K channel data sorted in sequence; A position exchange module is used to divide the M rows of feature data into Q data conversion units, and exchange the channel data in each data conversion unit. After the exchange, the channel data in each data conversion unit meets the following rules: channel data belonging to the same channel are gathered together and sorted in sequence according to the order of their corresponding feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels; The reading module is also used to read the channel data belonging to the same channel in the Q data conversion units in sequence, starting from the channel with the highest sorting, to obtain the feature map conversion data; The position swap module is specifically used to perform log2K rounds of position swap on the channel data in each data conversion unit as follows: the channel data with an odd arrangement order in each data conversion unit are gathered together and sorted in sequence according to their order; the channel data with an even arrangement order in each data conversion unit are gathered together and sorted in sequence according to their order, and the last channel data with an odd arrangement order is adjacent to the first channel data with an even arrangement order, wherein L+1 rounds of data position swap are performed on the basis of the data after L rounds of data position swap, log2K is an integer, and 1≤L<log2K.
6. The device according to claim 5, characterized in that The position swap module is specifically used to determine each row of feature data in M rows of feature data as a data conversion unit to obtain Q data conversion units, where M=Q; and swap the channel data in each row of feature data, so that after the swap, the channel data in each row of feature data meets the following rules: N channel data belonging to the same channel are clustered together and sorted in sequence according to the order of the corresponding N feature point data, and channel data belonging to different channels are sorted in sequence according to the order of the K channels.
7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
8. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Feature map data processing method and device based on convolutional neural network
CN110309837A
Convolutional neural network acceleration method and device and storage medium
CN110399971A