Block compression encoding method, block compression encoding device, computer equipment and readable storage medium

文档序号:1941294 发布日期:2021-12-07 浏览:7次 中文

阅读说明:本技术 分块压缩编码方法、装置、计算机设备及可读存储介质 (Block compression encoding method, block compression encoding device, computer equipment and readable storage medium ) 是由 杜力 杜源 朱俊翰 于 2020-07-08 设计创作,主要内容包括:本申请涉及数据压缩技术领域,公开了分块压缩编码方法、装置、计算机设备及可读存储介质。分块压缩编码方法包括获取原始数据集,并按照预设的数据长度,将原始数据集划分为多个数据块,然后获取任一数据块的标志数据及标志位宽,通过将每个数据块中的所有数据转换为位宽与所述标志位宽一致的二进制数,获取对应的多个二进制数据块,最后将每个标志位宽记入与之对应的所述二进制数据块的前端,获取原始数据集的压缩编码结果。利用上述分块压缩编码方法压缩得到的数据将占用较小内存,其压缩效果优于binary-mask压缩编码的压缩效果。(The application relates to the technical field of data compression, and discloses a block compression encoding method, a block compression encoding device, computer equipment and a readable storage medium. The block compression coding method comprises the steps of obtaining an original data set, dividing the original data set into a plurality of data blocks according to preset data length, then obtaining mark data and mark bit width of any data block, obtaining a plurality of corresponding binary data blocks by converting all data in each data block into binary numbers with the bit width consistent with the mark bit width, and finally recording the mark bit width into the front end of the corresponding binary data block to obtain a compression coding result of the original data set. The data obtained by the block compression coding method occupies a small memory, and the compression effect of the block compression coding method is superior to that of the bank-mask compression coding.)

1. A method of block compression encoding, the method comprising:

acquiring an original data set;

dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

acquiring the mark data and the mark bit width of any data block, wherein the mark data is the data with the largest bit width of all data in the data block in a binary format, and the mark bit width is the bit width of the mark data in the binary format;

converting all data in each data block into a signed binary number with the bit width consistent with the flag bit width to obtain a plurality of corresponding binary data blocks;

and recording the bit width of each mark into the front end of the binary data block corresponding to the bit width of each mark, and acquiring a compression coding result of the original data set.

2. The method according to claim 1, wherein said obtaining flag data and flag bit width of any of the data blocks comprises:

preprocessing all data in a target data block, wherein the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks;

extracting a maximum value for all data completing the preprocessing in the target data block;

taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block;

and taking the bit width of the mark data in a binary format as the mark bit width.

3. The method of claim 1, wherein the dividing the original data set into a plurality of data blocks according to a preset data length comprises:

and dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is performed on the last data block.

4. A block compression encoding apparatus applied to the block compression encoding method according to any one of claims 1 to 3, the block compression encoding apparatus comprising:

the data set acquisition module is used for acquiring an original data set;

the data set dividing module is used for dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

a flag data obtaining module, configured to obtain flag data and a flag bit width of any data block, where the flag data is data of the data block with the largest bit width in a binary format, and the flag bit width is a bit width of the flag data in the binary format;

a binary conversion module, configured to convert all data in each data block into a signed binary number having a bit width consistent with the flag bit width, and obtain multiple corresponding binary data blocks;

and the compression coding module is used for recording the bit width of each mark into the front end of the binary data block corresponding to the mark bit width to obtain a compression coding result of the original data set.

5. A method of block compression encoding, the method comprising:

acquiring an original data set;

dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

acquiring the mark data and the mark bit width of any data block, wherein the mark data is the data with the largest bit width of all data in the data block in a binary format, and the mark bit width is the bit width of the mark data in the binary format;

converting all data in each data block into a signed binary number with the bit width consistent with the flag bit width to obtain a plurality of corresponding binary data blocks;

setting a marking data block;

sequentially recording the flag bit widths of all the data blocks and the merging times corresponding to the flag bit widths into the marked data blocks, wherein if the flag bit width of a certain data block is different from the flag bit widths of the adjacent data blocks, the merging times corresponding to the flag bit width of the data block are zero, if the flag bit widths of the continuous adjacent data blocks are the same, the flag bit widths of the continuous adjacent data blocks are merged and recorded into the marked data blocks, and the merging times corresponding to the flag bit widths are the number of the continuous adjacent data blocks reduced by one;

and acquiring a compressed encoding result of the original data set, wherein the compressed encoding result comprises a plurality of binary data blocks and one marking data block.

6. The method according to claim 5, wherein said obtaining the flag data and the flag bit width of any one of the data blocks comprises:

preprocessing all data in a target data block, wherein the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks;

extracting a maximum value for all data completing the preprocessing in the target data block;

taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block;

and taking the bit width of the mark data in a binary format as the mark bit width.

7. The method of claim 5, wherein the dividing the original data set into a plurality of data blocks according to a preset data length comprises:

and dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is performed on the last data block.

8. A block compression encoding apparatus, which is applied to the block compression encoding method according to any one of claims 5 to 7, the block compression encoding apparatus comprising:

the data set acquisition module is used for acquiring an original data set;

the data set dividing module is used for dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

a flag data obtaining module, configured to obtain flag data and a flag bit width of any data block, where the flag data is data of the data block with the largest bit width in a binary format, and the flag bit width is a bit width of the flag data in the binary format;

a binary conversion module, configured to convert all data in each data block into a signed binary number having a bit width consistent with the flag bit width, and obtain multiple corresponding binary data blocks;

the marking data block setting module is used for setting a marking data block;

a marking module, configured to sequentially record the flag bit widths of all the data blocks and the merging times corresponding to the flag bit widths into the marked data blocks, where if the flag bit width of a certain data block is different from the flag bit widths of adjacent data blocks, the merging time corresponding to the flag bit width of the data block is zero, and if there are consecutive adjacent data blocks with the same flag bit width, the flag bit widths of the consecutive adjacent data blocks are merged and recorded into the marked data block, and the merging time corresponding to the flag bit width is obtained by subtracting one from the number of the consecutive adjacent data blocks;

and the compression coding module is used for acquiring a compression coding result of the original data set, wherein the compression coding result comprises a plurality of binary data blocks and one marking data block.

9. A computer device, comprising:

a memory for storing a computer program;

a processor for implementing the steps of the block compression encoding method according to any one of claims 1 to 3 or the steps of the block compression encoding method according to any one of claims 5 to 7 when executing the computer program.

10. A computer-readable storage medium, characterized in that a computer program is stored thereon, which, when being processed and executed, carries out the steps of the block compression encoding method according to any one of claims 1 to 3 or the steps of the block compression encoding method according to any one of claims 5 to 7.

Technical Field

The present application relates to the field of data compression technologies, and in particular, to a method and an apparatus for block compression encoding, a computer device, and a readable storage medium.

Background

There is a large amount of weight data in the neural network model, which are stored in a binary format in the computer. At present, in order to reduce the storage space required by the weight data, a compression coding method is often used to reduce the binary bit width occupied by all the weight data, so as to reduce the finally required memory space.

A common compression coding method is binary-mark (binary-mask) compression coding, in which two tables, namely a record table and a data table, need to be established in the compression coding process, see fig. 1, where table 1 is the record table and table 2 is the data table. When compression encoding is performed on an original data set, if a certain data in the original data set is 0, recording 0 in a corresponding position of table 1; if not 0, then 1 is entered in the corresponding location in table 1 and the data is also entered in table 2. After all data are recorded, each data in table 1 is only 0 or 1, and only occupies a bit width of one bit, and the binary bit width of the data in table 2 is consistent with the bit width occupied originally and is not compressed. Therefore, the larger the ratio of 0 in the original data set, the less data in table 2, and the better the compression effect of the binary-mask compression coding.

However, many of the weight data of the neural network model are data concentrated near 0 but not 0, and these data are characterized by: in the case where the value is small, the occupation ratio is high, and is not 0, the compression effect is deteriorated when the data is compressed by the binary-mask compression coding.

Disclosure of Invention

In order to solve the problem that the compression effect of using binary-mask compression coding is poor due to the fact that most of neural network weight data are data concentrated near 0 but not 0, the application discloses a block compression coding method, a block compression coding device, a computer device and a readable storage medium through the following embodiments.

The first aspect of the present application discloses a block compression encoding method, which includes:

acquiring an original data set;

dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

acquiring the mark data and the mark bit width of any data block, wherein the mark data is the data with the largest bit width of all data in the data block in a binary format, and the mark bit width is the bit width of the mark data in the binary format;

converting all data in each data block into a signed binary number with the bit width consistent with the flag bit width to obtain a plurality of corresponding binary data blocks;

and recording the bit width of each mark into the front end of the binary data block corresponding to the bit width of each mark, and acquiring a compression coding result of the original data set.

Optionally, the obtaining the flag data and the flag bit width of any one of the data blocks includes:

preprocessing all data in a target data block, wherein the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks;

extracting a maximum value for all data completing the preprocessing in the target data block;

taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block;

and taking the bit width of the mark data in a binary format as the mark bit width.

Optionally, dividing the original data set into a plurality of data blocks according to a preset data length includes:

and dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is performed on the last data block.

A second aspect of the present application discloses a block compression encoding apparatus, which is applied to the block compression encoding method according to the first aspect of the present application, and the block compression encoding apparatus includes:

the data set acquisition module is used for acquiring an original data set;

the data set dividing module is used for dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

a flag data obtaining module, configured to obtain flag data and a flag bit width of any data block, where the flag data is data of the data block with the largest bit width in a binary format, and the flag bit width is a bit width of the flag data in the binary format;

a binary conversion module, configured to convert all data in each data block into a signed binary number having a bit width consistent with the flag bit width, and obtain multiple corresponding binary data blocks;

and the compression coding module is used for recording the bit width of each mark into the front end of the binary data block corresponding to the mark bit width to obtain a compression coding result of the original data set.

Optionally, the flag data acquiring module includes:

the device comprises a preprocessing unit, a data processing unit and a data processing unit, wherein the preprocessing unit is used for preprocessing all data in a target data block, the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks;

a maximum value extraction unit, configured to extract a maximum value for all data in the target data block that has been subjected to the preprocessing;

a flag data acquiring unit, configured to use original data corresponding to the maximum value without the preprocessing as the flag data of the target data block;

and the flag bit width obtaining unit is used for taking the bit width of the flag data in a binary format as the flag bit width.

Optionally, the data set partitioning module includes:

and the dividing and zero-padding unit is used for dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is carried out on the last data block.

A third aspect of the present application discloses a block compression encoding method, including:

acquiring an original data set;

dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

acquiring the mark data and the mark bit width of any data block, wherein the mark data is the data with the largest bit width of all data in the data block in a binary format, and the mark bit width is the bit width of the mark data in the binary format;

converting all data in each data block into a signed binary number with the bit width consistent with the flag bit width to obtain a plurality of corresponding binary data blocks;

setting a marking data block;

sequentially recording the flag bit widths of all the data blocks and the merging times corresponding to the flag bit widths into the marked data blocks, wherein if the flag bit width of a certain data block is different from the flag bit widths of the adjacent data blocks, the merging times corresponding to the flag bit width of the data block are zero, if the flag bit widths of the continuous adjacent data blocks are the same, the flag bit widths of the continuous adjacent data blocks are merged and recorded into the marked data blocks, and the merging times corresponding to the flag bit widths are the number of the continuous adjacent data blocks reduced by one;

and acquiring a compressed encoding result of the original data set, wherein the compressed encoding result comprises a plurality of binary data blocks and one marking data block.

Optionally, the obtaining the flag data and the flag bit width of any one of the data blocks includes:

preprocessing all data in a target data block, wherein the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks;

extracting a maximum value for all data completing the preprocessing in the target data block;

taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block;

and taking the bit width of the mark data in a binary format as the mark bit width.

Optionally, dividing the original data set into a plurality of data blocks according to a preset data length includes:

and dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is performed on the last data block.

A fourth aspect of the present application discloses a block compression encoding apparatus, which is applied to the block compression encoding method according to the third aspect of the present application, and the block compression encoding apparatus includes:

the data set acquisition module is used for acquiring an original data set;

the data set dividing module is used for dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data;

a flag data obtaining module, configured to obtain flag data and a flag bit width of any data block, where the flag data is data of the data block with the largest bit width in a binary format, and the flag bit width is a bit width of the flag data in the binary format;

a binary conversion module, configured to convert all data in each data block into a signed binary number having a bit width consistent with the flag bit width, and obtain multiple corresponding binary data blocks;

the marking data block setting module is used for setting a marking data block;

a marking module, configured to sequentially record the flag bit widths of all the data blocks and the merging times corresponding to the flag bit widths into the marked data blocks, where if the flag bit width of a certain data block is different from the flag bit widths of adjacent data blocks, the merging time corresponding to the flag bit width of the data block is zero, and if there are consecutive adjacent data blocks with the same flag bit width, the flag bit widths of the consecutive adjacent data blocks are merged and recorded into the marked data block, and the merging time corresponding to the flag bit width is obtained by subtracting one from the number of the consecutive adjacent data blocks;

and the compression coding module is used for acquiring a compression coding result of the original data set, wherein the compression coding result comprises a plurality of binary data blocks and one marking data block.

Optionally, the flag data acquiring module includes:

the device comprises a preprocessing unit, a data processing unit and a data processing unit, wherein the preprocessing unit is used for preprocessing all data in a target data block, the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks;

a maximum value extraction unit, configured to extract a maximum value for all data in the target data block that has been subjected to the preprocessing;

a flag data acquiring unit, configured to use original data corresponding to the maximum value without the preprocessing as the flag data of the target data block;

and the flag bit width obtaining unit is used for taking the bit width of the flag data in a binary format as the flag bit width.

Optionally, the data set partitioning module includes:

and the dividing and zero-padding unit is used for dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is carried out on the last data block.

A fifth aspect of the present application discloses a computer device, comprising:

a memory for storing a computer program;

a processor for implementing the steps of the block compression encoding method according to the first aspect of the present application or the steps of the block compression encoding method according to the third aspect of the present application when executing the computer program.

A sixth aspect of the present application discloses a computer readable storage medium having stored thereon a computer program which, when processed and executed, implements the steps of the block compression encoding method as described in the first aspect of the present application or the steps of the block compression encoding method as described in the third aspect of the present application.

The application discloses a block compression encoding method, a block compression encoding device, a computer device and a readable storage medium. The method comprises the steps of obtaining an original data set, dividing the original data set into a plurality of data blocks according to a preset data length, then obtaining mark data and mark bit width of any data block, obtaining a plurality of corresponding binary data blocks by converting all data in each data block into binary numbers with the bit width consistent with the mark bit width, and finally recording each mark bit width into the front end of the corresponding binary data block to obtain a compression coding result of the original data set. In another block compression coding method, after a plurality of corresponding binary data blocks are obtained, a flag data block is set, flag bit widths of all the data blocks and corresponding merging times are sequentially recorded into the flag data block, and a compression coding result of the original data set is obtained, wherein the compression coding result comprises the binary data blocks and one flag data block.

In the block compression coding method, all data are converted into binary numbers by using the flag bit width corresponding to each data block, and all non-zero data are converted into binary numbers by using a uniform fixed bit width in the bank-mask compression coding, wherein the used fixed bit width is a default bit width and is usually greater than or equal to the maximum bit width corresponding to all non-zero data, so that the data obtained by compression by using the block compression coding method occupy a small memory, and the compression effect of the block compression coding method is better than that of the bank-mask compression coding.

Drawings

In order to more clearly explain the technical solution of the present application, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious to those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.

FIG. 1 is a diagram of a prior art binary-mask compression encoding;

fig. 2 is a schematic workflow diagram of a block compression encoding method disclosed in a first embodiment of the present application;

FIG. 3 is a diagram illustrating the result of block compression encoding according to the first embodiment of the present application;

FIG. 4 is a schematic diagram of a raw data set disclosed in the first embodiment of the present application;

FIG. 5 is a diagram illustrating the result of compression encoding by the block compression encoding method disclosed in the first embodiment of the present application with respect to the original data set in FIG. 4;

FIG. 6 is a graph comparing the compression effect of the block compression coding method and the bank-mask compression coding method according to the first embodiment of the present application;

fig. 7 is a schematic workflow diagram of a block compression encoding method disclosed in a third embodiment of the present application;

FIG. 8 is a diagram illustrating the result of block compression encoding according to the third embodiment of the present application;

FIG. 9 is a diagram illustrating the result of compression encoding by the block compression encoding method disclosed in the third embodiment of the present application for the original data set in FIG. 4;

fig. 10 is a comparison graph of compression effects of the block compression coding method and the binary-mask compression coding method disclosed in the third embodiment of the present application.

Detailed Description

In order to solve the problem that the compression effect of using binary-mask compression coding is poor due to the fact that most of neural network weight data are data concentrated near 0 but not 0, the application discloses a block compression coding method, a block compression coding device, a computer device and a readable storage medium through the following embodiments.

A first embodiment of the present application discloses a block compression encoding method, referring to a work flow diagram shown in fig. 2, the method includes:

in step S11, an original data set is acquired.

The weight data of many neural network models are 32-bit floating point numbers, and before compression coding, the 32-bit floating point numbers are usually converted into fixed point data in advance, so that the subsequent compression effect can be improved. Therefore, any data in the original data set acquired in this step is fixed point data. In this embodiment, the fixed point data in the original data set is int8 type, which is 8-bit signed integer.

Step S12, dividing the original data set into a plurality of data blocks according to a preset data length, where any of the data blocks includes at least two data.

Specifically, the original data set is divided according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last data block obtained by dividing is shorter than the preset data length, zero padding operation is performed on the last data block, so that the data length of the last data block reaches the preset data length.

For example, if the original data set contains 55736160 weighted data, the original data set may be partitioned into 127 data blocks, in which case the original data set will be partitioned into 438868 data blocks, and the last data block needs to be added with 76 zeros by the zero padding operation. Alternatively, the original data set may be partitioned according to the data length 207, in which case the original data set will be partitioned into 269257 data blocks, and the last data block needs to be added with 39 zeros by the zero padding operation.

As an example, for the inclusion respet V2 neural network model containing 55736160 weighted data, the present embodiment presets the data length to 127, and finally obtains 438868 data blocks, where the last data block adds 76 zeros through a zero padding operation; for a DenseNet 121 neural network model, which contains 7894208 weighted data, the present embodiment presets the data length to 87, and finally obtains 90739 data blocks, wherein the last data block adds 85 zeros through zero padding; for the NASNetmobile neural network model, which contains 3517626 pieces of weight data, in this embodiment, the data length is preset to 207, and finally 169994 data blocks are obtained, wherein 136 zeros are added to the last data block through a zero padding operation.

Step S13, obtaining the flag data and the flag bit width of any data block, where the flag data is the data with the largest bit width of all data in the data block in binary format, and the flag bit width is the bit width of the flag data in binary format.

In this embodiment, the fixed point data in the original data set is int8 type, so the data format in any data block is also int8 type, and based on this, the flag data and flag bit width of any data block can be obtained by the following method:

preprocessing all data in a target data block, wherein the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks.

And extracting a maximum value aiming at all the data which are preprocessed in the target data block.

And taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block.

And taking the bit width of the mark data in a binary format as the mark bit width.

Step S14, converting all data in each data block into a signed binary number with a bit width consistent with the flag bit width, and acquiring a plurality of corresponding binary data blocks. The first bit of the signed binary number is a sign bit, if the sign bit is "1", the binary number is a negative number, and if the sign bit is "0", the binary number is a positive number.

Before this step is performed, since the data format in any data block is int8 type, each data is 8-bit binary number, that is, each data occupies 8-bit width. After the step is executed, the data in each data block is converted into a signed binary number having the same bit width as the respective flag bit, at this time, only when the flag bit width is 8, each data in the corresponding data block will continue to occupy 8 bit width, and for the flag bit width being less than 8, the bit width occupied by each data in the corresponding data block will be less than 8 bits, so that the memory space required by the multiple binary data blocks obtained in the step will be much smaller than that of the original data set.

Based on the above principle, in step S12, the preset data length size may be set to an appropriate size according to the total number of the neural network weight data, as long as the total number of the data blocks is not too small or too large in principle. At least two data blocks are ensured in each data block under the condition of the maximum number of the data blocks, because if only one data block exists in each data block, no compression effect can be generated, and at least one data block is ensured to exist under the condition of the minimum number of the data blocks, the flag bit width of the flag bit is less than 8 bits, because if the flag bit widths of all the data blocks are 8 bits, the compression effect can not be generated. If the flag bit width of each data block is 8 bits, the data length can be adjusted to divide the original data set again.

Step S15, recording the bit width of each flag into the front end of the binary data block corresponding to the flag bit width, and obtaining the compression encoding result of the original data set.

The flag bit width is also recorded in binary format at the front end of the binary data block, and since the flag bit width can only be 8 at most, in this embodiment, 3-bit binary numbers are used to represent all flag bit widths.

When the computer operates each data block in the compression encoding result, the data can be read according to the bit width of the flag recorded at the front end.

Fig. 3 is a schematic diagram of a final compression encoding result obtained in this embodiment, where the compression encoding result includes n binary data blocks, and each binary data block includes m data (that is, when an original data set is divided into multiple data blocks, the preset data length is m). The data of the first binary data block are Num 11, … … and Num 1m respectively, and the flag bit Width recorded at the front end of the first binary data block is Width 1; the data of the second binary data block are Num 21, … … and Num 2m respectively, and the bit Width of the mark recorded at the front end is Width 2; the data of the nth binary data block are Num n1, … … and Num nm, respectively, and the flag bit Width recorded at the front end is Width n.

The present solution is explained below with reference to a simple example:

if the original data set contains 45 data in total, which are {6, 0, 4, 1, -4, 2, -1, -5, -15, 1, -7, 9, 12, 0, -2, 0, -21, 15, -33, 5, 7, 9, 8, 1, -16, 17, 4, 32, 2, 0, 7, 14, 3, -10, -2, 26, 3, 17, 5, -1, 0, 9, 6, -3}, the preset data length is 8, the original data set can be divided into 6 data blocks, see fig. 4, and the last data block needs to be complemented by 3 zeros through a zero padding operation (for convenience of understanding and description, the decimal format is used for illustration, but in practical application, the format of any data in the original data set is signed binary).

For the first data block, the obtained flag data is 6, the flag bit width corresponding to the flag data is 4 bits, each data in the binary data block obtained by conversion is represented by a 4-bit binary number, the front end of the binary data block is marked with a flag bit width (4 bits), and the flag bit width is represented by a 3-bit binary number, namely 100.

And aiming at the second data block, obtaining mark data as-15, wherein the corresponding mark bit width is 5 bits, each datum in the binary data block obtained by conversion is represented by a binary number of 5 bits, the front end of the binary data block is marked with a mark bit width (5 bits), and the mark bit width is represented by a binary number of 3 bits, namely 101.

For the third data block, the obtained flag data is-33, the flag bit width corresponding to the flag data is 7 bits, each data in the binary data block obtained by conversion is represented by a 7-bit binary number, the front end of the binary data block is marked with a flag bit width (7 bits), and the flag bit width is represented by a 3-bit binary number, that is, 111.

For the fourth data block, the obtained flag data is 32, the flag bit width corresponding to the flag data is 7 bits, each data in the binary data block obtained by conversion is represented by a 7-bit binary number, the front end of the binary data block is marked with a flag bit width (7 bits), and the flag bit width is represented by a 3-bit binary number, that is, 111.

For the fifth data block, the obtained flag data is 34, the flag bit width corresponding to the flag data is 7 bits, each data in the binary data block obtained by conversion is represented by a 7-bit binary number, the front end of the binary data block is marked with a flag bit width (7 bits), and the flag bit width is represented by a 3-bit binary number, that is, 111.

For the sixth data block, the obtained flag data is 9, the flag bit width corresponding to the flag data is 5 bits, each data in the binary data block obtained by conversion is represented by a 5-bit binary number, the front end of the binary data block is marked with a flag bit width (5 bits), and the flag bit width is represented by a 3-bit binary number, that is, 101.

The final compression encoding result is shown in fig. 5. As can be seen from the figure, the space occupied by any data in each binary data block is less than 8 bits, and the result of the compression encoding can save a larger memory space compared to the original data set.

The compression effect of the block compression coding method is better than that of the bank-mask compression coding method, because the original data set only has 5 zeros, for non-zero data, the compression coding mode of the bank-mask compression coding still uses binary number with 8 bit width to represent, and the compression effect is not obvious. In this embodiment, the bit width of data in all the binary data blocks is less than 8 bits, and the memory space required for compressing the encoding result is much smaller than the result of the binary-mask compression encoding method.

In addition, even if the original data set does not contain a zero, the compression coding using the method disclosed in this embodiment still can obtain the compression effect equivalent to that when 5 zeros exist, but the compression coding using the binary-mask compression coding does not have any compression effect because there is no zero.

Referring to fig. 6, fig. 6 is a compression ratio comparison diagram of the binary-mask compression encoding method and the block compression encoding method of the present embodiment respectively compressing a DenseNet 121 network model, a DenseNet 169 network model, a DenseNet 201 network model, an inclusion V3 network model, an inclusion respet V2 network model, a NASNetlarge network model, a NASNetmobile network model, a rest network model, and an Xception network model, wherein the compression ratio is a value obtained by dividing the data amount after compression by the data amount before compression. As is apparent from fig. 6, the compression ratios of the block compression encoding method of this embodiment are all lower than the compression ratio of the bank-mask compression encoding method, i.e., the compression effects are all better than the bank-mask compression encoding method.

The second embodiment of the present application discloses a block compression encoding apparatus, which is applied to the block compression encoding method described in the first embodiment of the present application, and for details not disclosed in the present embodiment, please refer to the contents disclosed in the first embodiment.

The block compression encoding device includes:

and the data set acquisition module is used for acquiring the original data set.

And the data set dividing module is used for dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data.

And the flag data acquisition module is used for acquiring flag data and flag bit width of any data block, the flag data is data with the largest bit width of all data in the data block in a binary format, and the flag bit width is the bit width of the flag data in the binary format.

And the binary conversion module is used for converting all data in each data block into a signed binary number with the bit width consistent with the flag bit width, and acquiring a plurality of corresponding binary data blocks.

And the compression coding module is used for recording the bit width of each mark into the front end of the binary data block corresponding to the mark bit width to obtain a compression coding result of the original data set.

Further, the tag data acquiring module includes:

the device comprises a preprocessing unit and a target data block processing unit, wherein the preprocessing unit is used for preprocessing all data in the target data block, the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks.

And the maximum value extraction unit is used for extracting the maximum value aiming at all the data which are preprocessed in the target data block.

And the mark data acquisition unit is used for taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block.

And the flag bit width obtaining unit is used for taking the bit width of the flag data in a binary format as the flag bit width.

Further, the data set partitioning module includes:

and the dividing and zero-padding unit is used for dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is carried out on the last data block.

A third embodiment of the present application discloses a block compression encoding method, and compared with the first embodiment, the block compression encoding method disclosed in the third embodiment is different in that: in the compression encoding result obtained in the first embodiment, 3-bit redundancy for recording the flag bit width is added to the front end of each binary data block, and in practical application, since the amount of weight data is very large, the number of binary data blocks may be very large, in this case, the redundancy generated by the superposition of all flag bit widths is very large, and a large amount of space is required. Considering that the flag bit width value is only between 0 and 8, and the flag bit widths of many binary data blocks are necessarily the same, the third embodiment additionally sets a data block dedicated for recording the flag bit width, and in the process of recording the flag bit width, merges and records the adjacent same flag bit widths, and records the merging times of the flag bit widths, so as to reduce the memory space occupied by all the flag bit widths as much as possible.

Referring to the workflow diagram shown in fig. 7, the block compression encoding method disclosed in this embodiment includes:

in step S21, an original data set is acquired.

Like the first embodiment, in this embodiment, the fixed point data in the original data set is int8 type, i.e. 8-bit signed integer.

Step S22, dividing the original data set into a plurality of data blocks according to a preset data length, where any of the data blocks includes at least two data.

Specifically, the original data set is divided according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last data block obtained by dividing is shorter than the preset data length, zero padding operation is performed on the last data block, so that the data length of the last data block reaches the preset data length.

Step S23, obtaining the flag data and the flag bit width of any data block, where the flag data is the data with the largest bit width of all data in the data block in binary format, and the flag bit width is the bit width of the flag data in binary format.

In this embodiment, the fixed point data in the original data set is int8 type, so the data format in any data block is also int8 type, and the flag data and the flag bit width of any data block can be obtained by the following method:

preprocessing all data in a target data block, wherein the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks.

And extracting a maximum value aiming at all the data which are preprocessed in the target data block.

And taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block.

And taking the bit width of the mark data in a binary format as the mark bit width.

Step S24, converting all data in each data block into a signed binary number with a bit width consistent with the flag bit width, and acquiring a plurality of corresponding binary data blocks. The first bit of the signed binary number is a sign bit, if the sign bit is "1", the binary number is a negative number, and if the sign bit is "0", the binary number is a positive number.

It should be noted that steps S21-S24 are the same as steps S11-S14 in the first embodiment, and therefore, the details of the implementation process can be referred to the contents disclosed in the first embodiment.

In step S25, a flag data block is set.

Step S26, sequentially entering the flag bit widths of all the data blocks and the merging times corresponding to the flag bit widths into the flag data blocks, where if the flag bit width of a certain data block is different from the flag bit widths of adjacent data blocks, the merging times corresponding to the flag bit width of the data block are zero, and if the flag bit widths of consecutive adjacent data blocks are the same, the flag bit widths of the consecutive adjacent data blocks are merged and entered into the flag data block, and the merging times corresponding to the flag bit widths are the number of consecutive adjacent data blocks minus one.

In one implementation, the data length of the marker data block is the same as the length of any of the data blocks. In this case, if the flag bit width of all the data blocks and the corresponding merging times are recorded and a space still exists in the marked data block, zero padding is performed.

Step S27, obtaining a compressed encoding result of the original data set, where the compressed encoding result includes a plurality of the binary data blocks and one of the flag data blocks.

Fig. 8 is a schematic diagram of a final compression encoding result obtained in this embodiment, where the compression encoding result includes n binary data blocks and one flag data block. Each binary data block contains m data (i.e. when the original data set is divided into a plurality of data blocks, the preset data length is m). The data of the first binary data block are Num 11, Num 12, … … and Num 1m respectively; the data of the second binary data block are Num 21, Num 22, … … and Num 2m respectively; the data of the nth binary data block are Num n1, … … and Num nm respectively.

In fig. 8, the last data block is a flag data block and is used to record the flag bit Width and the merging frequency, where Width 1 corresponds to the flag bit Width of the first data block, and CB 1 is the merging frequency of the flag bit Width of the first data block and the flag bit Width of the adjacent data block; width X corresponds to the mark bit Width of the first data block, and CB X is the merging times of the mark bit Width of the first data block and the mark bit Width of the adjacent data block.

If the flag bit Width of the first data block is different from the flag bit Width of the second data block, the flag bit Width CB 1 is marked as 0 (indicating that the merging frequency of Width 1 is 0), and then Width 2 is marked in the flag bit Width of the second data block; if the flag bit Width of the first data block is the same as that of the second data block but different from that of the third data block, CB 1 is marked as 1 (indicating that Width 1 is merged and written once), and then Width 2 is written into the flag bit Width of the third data block; if the flag bit Width of the first data block is the same as the flag bit widths of the second and third data blocks, but is different from the flag bit Width of the fourth data block, CB 1 is marked as 2 (indicating that Width 1 is merged and written twice), and then Width 2 is subsequently written into the flag bit Width of the fourth data block.

The flag bit width and the number of times of merging are both entered into the marked data block in binary format. Since the flag bit width can only be 8 at most, this embodiment uses 3-bit binary numbers to represent all flag bit widths.

For the number of merges, a bit width of 1 bit, 2 bits, 3 bits, or 4 bits may be used for representation, and once selected, all the merge times are represented by a binary number of the same bit width. As an example, if 2-bit binary numbers are used to represent the merging times, the merging times per entry can only be 3 at most (because the 2-bit binary numbers are 11 at most), that is, only the flag bit Width of 4 consecutive adjacent data blocks can be merged at most at a single time, if the flag bit widths of five consecutive adjacent data blocks are the same, the flag bit Width of the fifth data block is entered into the next Width, and the corresponding merging times are 0.

The present solution is explained below with reference to a simple example:

if the original data set contains 45 data in total, which are {6, 0, 4, 1, -4, 2, -1, -5, -15, 1, -7, 9, 12, 0, -2, 0, -21, 15, -33, 5, 7, 9, 8, 1, -16, 17, 4, 32, 2, 0, 7, 14, 3, -10, -2, 26, 3, 17, 5, -1, 0, 9, 6, -3}, respectively, the preset data length is 8, the original data set can be divided into 6 data blocks, and the last data block needs to be zero-padded by 3 zeros through a zero-padding operation (for convenience of understanding and description, the decimal format is used here for example, but in practical application, the format of any data in the original data set is signed binary). The original data set is the same as in the first embodiment, and can be seen in particular in fig. 4.

For the first data block, the obtained flag data is 6, the flag bit width corresponding to the flag data is 4 bits, each data in the binary data block obtained by conversion is represented by a 4-bit binary number, the flag bit width (4 bits) is recorded in the flag bit width 1 of the flag data block, the flag bit width is represented by a 3-bit binary number, namely 100, because the flag bit width is different from that of the second data block, the merging time 1 is 0, and the flag bit width is represented by a 2-bit binary number, namely 00.

And aiming at the second data block, obtaining mark data as-15, wherein the corresponding mark bit width is 5 bits, each data in the binary data block obtained by conversion is represented by a binary number with 5 bits, the mark bit width (5 bits) is recorded in the mark bit width 2 of the mark data block, the mark bit width is represented by a binary number with 3 bits, namely 101, because the mark bit width is different from the mark bit widths of the first data block and the third data block, the merging time 2 is recorded as 0, and the mark bit width is represented by a binary number with 2 bits, namely 00.

For the third data block, the obtained flag data is-33, the flag bit width corresponding to the flag data is 7 bits, each data in the binary data block obtained by conversion is represented by a 7-bit binary number, the flag bit width (7 bits) is recorded in the flag bit width 3 of the flag data block, the flag bit width is represented by a 3-bit binary number, that is, 111, since the flag bit width is the same as the flag bit width of the fourth and fifth data blocks, the merging time 3 is represented by 2, and the flag bit width is represented by a 2-bit binary number, that is, 10.

And aiming at the fourth data block, obtaining that the flag data is 32, the bit width of the corresponding flag is 7 bits, each data in the binary data block obtained by conversion is represented by a 7-bit binary number, and because the bit width (7 bits) of the flag is combined with the third data block and the fifth data block, the flag data is not repeatedly recorded in the flag data block, and correspondingly, the combining times are not recorded.

For the fifth data block, the flag data is found to be 34, the flag bit width corresponding thereto is 7 bits, and since the flag bit width (7 bits) has been merged with the third and fourth data blocks, the flag data block is not repeatedly entered, and accordingly, the number of times of merging is not entered.

For the sixth data block, the obtained flag data is 9, the flag bit width corresponding to the flag data is 5 bits, each data in the binary data block obtained by conversion is represented by a 5-bit binary number, the flag bit width (5 bits) is recorded in the flag bit width 4 of the flag data block, the flag bit width is represented by a 3-bit binary number, that is, 101, since the flag bit width is different from that of the fifth data block and there is no seventh data block, the merging time 4 is recorded as 0, and a 2-bit binary number is used for representation, that is, 00.

The final compression encoding result is shown in fig. 9. As can be seen from the figure, the space occupied by any data in each binary data block is less than 8 bits, and the result of the compression encoding can save a larger memory space compared to the original data set.

The compression effect of the block compression coding method disclosed in this embodiment is better than that of the bank-mask compression coding method, because the original data set only has 5 zeros, for non-zero data, the bank-mask compression coding method still uses binary number with 8 bit width to represent, and the compression effect is not obvious. In this embodiment, the bit width of data in all the binary data blocks is less than 8 bits, and the memory space required for compressing the encoding result is much smaller than the result of the binary-mask compression encoding method.

In addition, even if the original data set does not contain a zero, the compression coding using the method disclosed in this embodiment still can obtain the compression effect equivalent to that when 5 zeros exist, but the compression coding using the binary-mask compression coding does not have any compression effect because there is no zero.

Referring to fig. 10, fig. 10 is a compression ratio comparison diagram of the binary-mask compression encoding method and the block compression encoding method of the present embodiment respectively compressing a DenseNet 121 network model, a DenseNet 169 network model, a DenseNet 201 network model, an inclusion V3 network model, an inclusion respet V2 network model, a NASNetlarge network model, a NASNetmobile network model, a respet network model, and an Xception network model, wherein the compression ratio is a value obtained by dividing the data amount after compression by the data amount before compression. As is apparent from fig. 10, the compression ratios of the block compression encoding method of this embodiment are all lower than the compression ratio of the bank-mask compression encoding method, i.e., the compression effects are all better than the bank-mask compression encoding method.

The fourth embodiment of the present application discloses a block compression encoding apparatus, which is applied to the block compression encoding method according to the third embodiment of the present application, and for details not disclosed in the present embodiment, please refer to the content disclosed in the third embodiment.

The block compression encoding device includes:

and the data set acquisition module is used for acquiring the original data set.

And the data set dividing module is used for dividing the original data set into a plurality of data blocks according to a preset data length, wherein any data block at least comprises two data.

And the flag data acquisition module is used for acquiring flag data and flag bit width of any data block, the flag data is data with the largest bit width of all data in the data block in a binary format, and the flag bit width is the bit width of the flag data in the binary format.

And the binary conversion module is used for converting all data in each data block into a signed binary number with the bit width consistent with the flag bit width, and acquiring a plurality of corresponding binary data blocks.

And the marking data block setting module is used for setting the marking data block.

And the marking module is used for sequentially recording the flag bit widths of all the data blocks and the merging times corresponding to the flag bit widths into the marked data blocks, wherein if the flag bit width of one data block is different from the flag bit widths of the adjacent data blocks, the merging times corresponding to the flag bit width of the data block are zero, if the flag bit widths of the continuous adjacent data blocks are the same, the flag bit widths of the continuous adjacent data blocks are merged and recorded into the marked data blocks, and the merging times corresponding to the flag bit widths are obtained by subtracting one from the number of the continuous adjacent data blocks.

And the compression coding module is used for acquiring a compression coding result of the original data set, wherein the compression coding result comprises a plurality of binary data blocks and one marking data block.

Further, the tag data acquiring module includes:

the device comprises a preprocessing unit and a target data block processing unit, wherein the preprocessing unit is used for preprocessing all data in the target data block, the preprocessing comprises positive number preprocessing and negative number preprocessing, the positive number preprocessing is used for taking an absolute value of a positive number, the negative number preprocessing is used for subtracting one after taking the absolute value of a negative number, and the target data block is any one of the data blocks.

And the maximum value extraction unit is used for extracting the maximum value aiming at all the data which are preprocessed in the target data block.

And the mark data acquisition unit is used for taking the original data which is not preprocessed and corresponds to the maximum value as the mark data of the target data block.

And the flag bit width obtaining unit is used for taking the bit width of the flag data in a binary format as the flag bit width.

Further, the data set partitioning module includes:

and the dividing and zero-padding unit is used for dividing the original data set according to the preset data length to obtain a plurality of data blocks, wherein if the data length of the last divided data block is shorter than the preset data length, zero padding operation is carried out on the last data block.

A fifth embodiment of the present application discloses a computer device, comprising:

a memory for storing a computer program.

A processor for implementing the steps of the block compression encoding method according to the first embodiment of the present application or the steps of the block compression encoding method according to the third embodiment of the present application when executing the computer program.

A sixth embodiment of the present application discloses a computer-readable storage medium having stored thereon a computer program which, when being processed and executed, implements the steps of the block compression encoding method according to the first embodiment of the present application or the steps of the block compression encoding method according to the third embodiment of the present application.

The present application has been described in detail with reference to specific embodiments and illustrative examples, but the description is not intended to limit the application. Those skilled in the art will appreciate that various equivalent substitutions, modifications or improvements may be made to the presently disclosed embodiments and implementations thereof without departing from the spirit and scope of the present disclosure, and these fall within the scope of the present disclosure. The protection scope of this application is subject to the appended claims.

24页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:基于云字符概率表的数据编码系统以及方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类