Data compression method, device, equipment and storage medium

By simplifying the encoding process of non-zero data, and using preset rules and target encoding methods to encode feature map data blocks, the problem of excessive hardware power consumption caused by the complexity of non-zero data encoding in the EBPC method is solved, and a more efficient hardware implementation is achieved.

CN119815032BActive Publication Date: 2025-05-20AXERA SEMICON (SHANGHAI) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510272172.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-10
Publication Date
2025-05-20
Estimated Expiration
2045-03-10

AI Technical Summary

Technical Problem

The extended bit plane compression (EBPC) method has problems with the complexity of non-zero data encoding, resulting in excessive hardware power consumption and difficulty in achieving effective hardware implementation.

Method used

By obtaining the block of feature map to be compressed, non-zero feature map data is identified, and encoding is performed based on preset rules and target encoding methods, the encoding process of non-zero data is simplified, and the encoding results are combined to generate compressed data packets.

Benefits of technology

This method simplifies the encoding process of non-zero data, saves hardware power consumption, and improves the efficiency and performance of hardware implementation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119815032B_ABST
    Figure CN119815032B_ABST
Patent Text Reader

Abstract

The present application relates to the field of data processing technology, and provides a data compression method, device, equipment and storage medium, the method comprising: obtaining a feature map data block to be compressed; the feature map data block to be compressed is a part of a feature map data stream to be compressed; identifying the feature map data block to be compressed, and obtaining non-zero feature map data; encoding the feature map data block to be compressed based on a preset rule, and obtaining a first encoding result; encoding the non-zero feature map data based on a target encoding method, and obtaining a second encoding result; the target encoding method is obtained by searching a first preset encoding table based on a target data type; the target data type is determined based on the continuous state of a preset value in the non-zero feature map data; each optional encoding mode includes an optional data type and an optional encoding method; merging the first encoding result and the second encoding result to obtain a compressed data packet. The technical solution of the present application can simplify the encoding process of non-zero data, thereby saving hardware power consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data processing, and particularly to a data compression method, apparatus, device and storage medium. Background Art

[0002] Extended bit plane compression (EBPC) is a commonly used lossless compression method. EBPC compresses data containing consecutive zeros or data with strong data continuity, and belongs to a lightweight compression algorithm; currently, it is mainly applied to compressing intermediate data for AI (Artificial Intelligence) processing operations.

[0003] However, EBPC has the problem of complex non-zero data encoding, which leads to excessive hardware power consumption and is not conducive to hardware implementation. Summary of the Invention

[0004] Embodiments of the present application provide a data compression method, apparatus, device and storage medium, which can simplify the encoding process of non-zero data and thus save hardware power consumption. The technical solution is as follows:

[0005] According to a first aspect of the embodiments of the present application, there is provided a data compression method, the method comprising:

[0006] Obtain a to-be-compressed feature map data block; the to-be-compressed feature map data block is a part of a to-be-compressed feature map data stream;

[0007] Identify the to-be-compressed feature map data block to obtain non-zero feature map data;

[0008] Encode the to-be-compressed feature map data block based on a preset rule to obtain a first encoding result;

[0009] Encode the non-zero feature map data based on a target encoding method to obtain a second encoding result; the target encoding method is obtained by looking up a first preset encoding table based on a target data type; the target data type is determined based on the continuous state of a preset value in the non-zero feature map data; the target encoding method indicates the target data type, the continuous state, and a target encoding length; the first preset encoding table includes at least two optional encoding modes; each optional encoding mode includes an optional data type and an optional encoding method; each optional encoding method includes an optional encoding length and an optional encoding value; the target encoding method is one of the optional encoding methods;

[0010] Merge the first encoding result and the second encoding result to obtain a compressed data packet.

[0011] In a possible implementation, the feature map data block to be compressed includes zero feature map data; the zero feature map data includes a plurality of zero data; the non-zero feature map data includes a plurality of non-zero data.

[0012] In a possible implementation, encoding the feature map data block to be compressed based on a preset rule to obtain a first encoding result includes:

[0013] Encoding a zero data into a first value for one zero data; or encoding a non-zero data into a second value for one non-zero data;

[0014] Using a plurality of the first values and a plurality of the second values as the first encoded data.

[0015] In a possible implementation, encoding non-zero feature map data based on a target encoding method to obtain a second encoding result includes:

[0016] For a group of non-zero data, the group of non-zero data includes a plurality of non-zero data;

[0017] Performing a difference process on each non-zero data to obtain a target difference sequence;

[0018] Transposing the target difference sequence to obtain a target transposed sequence;

[0019] Performing an exclusive OR process on the target transposed sequence to obtain a target exclusive OR sequence;

[0020] Determining the target data type of the target exclusive OR sequence;

[0021] Based on the target data type, looking up a first preset encoding table to obtain the target encoding method and the target encoding length;

[0022] Encoding a group of non-zero data based on the target encoding method and the target encoding length to obtain a plurality of non-zero encoded data.

[0023] In a possible implementation, L is an integer greater than or equal to 5 bit and less than or equal to 9 bit; L is the target encoding length.

[0024] In a possible implementation, determining the target data type of the target exclusive OR sequence includes:

[0025] When there are consecutive preset values in the target exclusive OR sequence, the target data type of the preset values is a first data type; the first data type is one of the optional data types; the target data type of the remaining target exclusive OR values in the target exclusive OR sequence is the second data type or the third data type; or

[0026] When there is only one said preset value in the said target exclusive-OR sequence, the said target data type of the said preset value is the second data type; the second data type is one of the said optional data types; the said target data type of the remaining said target exclusive-OR values in the said target exclusive-OR sequence is the third data type; or

[0027] When there are no consecutive said preset values in the said target exclusive-OR sequence and there are multiple said preset values, the said target data type of each said target exclusive-OR value is the third data type; the third data type is one of the said optional data types.

[0028] In one possible implementation manner, the finding the said target encoding method based on the said target data type includes:

[0029] When the said target data type of the said preset value is the first data type, encode the said target exclusive-OR value corresponding to the said preset value as a preset bit value;

[0030] Find a second preset encoding table based on the said preset bit value to obtain a consecutive quantity; the consecutive quantity is the quantity of consecutive said preset bit values;

[0031] Find a first preset encoding table based on the said first data type to obtain a first encoding method; the first encoding method is one of the said optional encoding methods;

[0032] Encode each said preset value based on the said first encoding method and the said consecutive quantity to obtain a plurality of non-zero encoded data; the non-zero encoded data corresponds to the said preset value one by one.

[0033] In one possible implementation manner, the finding a second preset encoding table based on the said preset bit value to obtain a consecutive quantity includes:

[0034] Divide a plurality of said preset bit values into two groups to obtain a first group of said preset bit values and a second group of said preset bit values; the first group of said preset bit values are the said preset bit values of the high bit positions; the second group of said preset bit values are the said preset bit values of the low bit positions;

[0035] Obtain a first consecutive quantity and a second consecutive quantity; the first consecutive quantity indicates the quantity of consecutive said preset bit values in the first group of said preset bit values; the second consecutive quantity indicates the quantity of consecutive said preset bit values in the second group of said preset bit values.

[0036] In a possible implementation, the step of looking up a second preset coding table based on the preset bit value to obtain a consecutive quantity further includes:

[0037] Obtaining a third consecutive quantity; the third consecutive quantity indicates a part of the preset bit values in a first group of the preset bit values and a part of the preset bit values in a second group of the preset bit values; a part of the preset bit values in the first group of the preset bit values and a part of the preset bit values in the second group of the preset bit values are consecutive;

[0038] In a possible implementation, the step of encoding each of the preset values based on the first coding method and the consecutive quantity to obtain a plurality of non-zero coded data includes:

[0039] Encoding each of the preset values of the first consecutive quantity based on the first coding method to obtain a plurality of the non-zero coded data; each of the non-zero coded data includes a first identification coding value and a first coding value; the first coding value indicates the first consecutive quantity; the first identification coding value indicates the first data type; or

[0040] Encoding each of the preset values of the second consecutive quantity based on the first coding method to obtain a plurality of the non-zero coded data; each of the non-zero coded data includes the second identification coding value and the second coding value; the second coding value indicates the second consecutive quantity; the second identification coding value indicates the first data type; or

[0041] Encoding each of the preset values of the third consecutive quantity based on the first coding method to obtain a plurality of the non-zero coded data; each of the non-zero coded data includes a third identification coding value and a third coding value; the third coding value indicates the third consecutive quantity; the third identification coding value indicates the first data type.

[0042] In a possible implementation, the step of looking up the first preset coding table based on the target data type to obtain the target coding method further includes:

[0043] When the target data type of the preset value is the second data type, looking up the first preset coding table based on the second data type to obtain a second coding method; the second coding method is one of the optional coding methods;

[0044] Encoding the preset value based on the second coding method to obtain the non-zero coded data; the non-zero coded data includes a fourth identification coding value and a fourth coding value; the fourth coding value indicates the position of the preset value in the target exclusive OR sequence.

[0045] In a possible implementation, the step of looking up the first preset coding table based on the target data type to obtain the target coding method further includes:

[0046] For a target XOR value, when the target data type of the target XOR value is the third data type, look up the first preset coding table based on the third data type to obtain a third coding method; the third coding method is one of the optional coding methods;

[0047] Encode the target XOR value based on the third coding method to obtain the non-zero coded data; the non-zero coded data includes a fifth identification coding value and a target XOR value.

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

[0049] If the actual size of the compressed data packet is greater than the initial size of the data block of the feature map to be compressed, then use the data block of the feature map to be compressed as the compressed data packet.

[0050] In a possible implementation, the compressed data packet further includes time data; the time data indicates the time for processing the data block of the feature map to be compressed; the time data is used to calculate the actual size of the compressed data packet.

[0051] In a possible implementation, the compressed data packet further includes identification data; the identification data indicates whether the compressed data packet has been compressed.

[0052] According to a second aspect of the embodiments of the present application, a data compression device is provided, and the device includes:

[0053] An acquisition module, configured to acquire a data block of a feature map to be compressed; the data block of the feature map to be compressed is a part of a data stream of the feature map to be compressed;

[0054] An identification module, configured to identify the data block of the feature map to be compressed to obtain non-zero feature map data;

[0055] A first coding module, configured to code the data block of the feature map to be compressed based on a preset rule to obtain a first coding result;

[0056] A second encoding module, configured to encode the non-zero feature map data based on a target encoding method to obtain a second encoding result; the target encoding method is obtained by looking up a first preset encoding table based on a target data type; the target data type is determined based on the continuous state of a preset value in the non-zero feature map data; the target encoding method indicates the target data type, the continuous state, and a target encoding length; the first preset encoding table includes at least two optional encoding modes; each of the optional encoding modes includes an optional data type and an optional encoding method; each of the optional encoding methods includes an optional encoding length and an optional encoding value; the target encoding method is one of the optional encoding methods;

[0057] A merging module, configured to merge the first encoding result and the second encoding result to obtain a compressed data packet.

[0058] According to a third aspect of the embodiments of the present application, there is provided a computer device, which includes a processor and a memory. The memory is used to store at least one segment of program, and the at least one segment of program is loaded and executed by the processor to perform a data compression method.

[0059] According to a fourth aspect of the embodiments of the present application, there is provided a computer-readable storage medium, in which at least one segment of program is stored, and the at least one segment of program is loaded and executed by a processor to perform a data compression method.

[0060] In the embodiments of the present application, the embodiments of the present application provide a data compression method, which divides a to-be-compressed feature map data stream into multiple to-be-compressed feature map data blocks, and compresses the multiple to-be-compressed feature map data blocks one by one, which is more beneficial to upper-layer applications. In addition, the embodiments of the present application encode non-zero feature map data based on a first preset encoding table. Compared with the related art, the number of optional encoding modes involved in the first preset encoding table of the present application is reduced, which facilitates the table lookup operation, is easy to meet the hardware timing, and is also convenient for the implementation of decompression. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0062] Figure 1 is a schematic diagram of an implementation environment provided according to an embodiment of the present application;

[0063] Figure 2 is an EBPC in the related art;

[0064] Figure 3 is a coding table in the related art;

[0065] Figure 4 is a schematic flowchart of a data compression method provided according to an embodiment of the present application;

[0066] Figure 5 is a schematic flowchart of step 404 provided according to an embodiment of the present application;

[0067] Figure 6 is a schematic diagram of a first preset coding table provided according to an embodiment of the present application;

[0068] Figure 7 is a schematic flowchart of step 4045 provided according to an embodiment of the present application;

[0069] Figure 8 is a schematic flowchart of step 40452 provided according to an embodiment of the present application;

[0070] Figure 9 is a schematic diagram of a second preset coding table provided according to an embodiment of the present application;

[0071] Figure 10 is a schematic diagram of the format of the first compressed data packet provided according to an embodiment of the present application;

[0072] Figure 11 is a schematic diagram of the format of the second compressed data packet provided according to an embodiment of the present application;

[0073] Figure 12 is a schematic diagram of the effect in the first application scenario provided according to an embodiment of the present application;

[0074] Figure 13 is a schematic diagram of the effect in the second application scenario provided according to an embodiment of the present application;

[0075] Figure 14 is a schematic structural diagram of a data compression device provided according to an embodiment of the present application;

[0076] Figure 15 is a schematic structural diagram of a terminal provided according to an embodiment of the present application;

[0077] Figure 16 is a schematic structural diagram of a server provided according to an embodiment of the present application. Detailed implementation manners

[0078] To make the objectives, technical solutions, and advantages of the present application clearer, the following will further describe the embodiments of the present application in detail with reference to the accompanying drawings.

[0079] Exemplary embodiments will be described in detail herein, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application.

[0080] In the present application, terms such as "first" and "second" are used to distinguish identical or similar items with basically the same functions. It should be understood that there is no logical or temporal dependency between "first", "second", and "nth", nor are the quantity and execution order limited. It should also be understood that although the following description uses terms such as first and second to describe various elements, these elements should not be limited by the terms.

[0081] These terms are only used to distinguish one element from another. For example, without departing from the scope of various examples, the first action can be called the second action, and similarly, the second action can also be called the first action. The first action and the second action can both be actions, and in some cases, they can be separate and different actions.

[0082] Among them, at least one means one or more than one. For example, at least one action can be one action, two actions, three actions, etc., any integer greater than or equal to one. And multiple means two or more than two. For example, multiple actions can be two actions, three actions, etc., any integer greater than or equal to two.

[0083] Figure 1 is a schematic diagram of an implementation environment provided according to an embodiment of the present application. The implementation environment may include a terminal 101 and a server 102.

[0084] In the terminal 101, a data compression device is provided. The data compression device is a hardware structure. The data compression device can be used to compress feature map data.

[0085] The terminal 101 can be a smartphone with a data compression device, a wearable device, a personal computer, a laptop computer, a tablet computer, a smart TV, a vehicle-mounted terminal, etc.

[0086] The server 102 can be a single server, a server cluster composed of multiple servers, or, alternatively, a cloud processing center.

[0087] The terminal 101 is connected to the server 102 through a wired or wireless network.

[0088] In some embodiments, a wireless network or a wired network uses standard communication technologies and / or protocols. The network is typically the Internet, but can also be any network, including but not limited to any combination of a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a private network or a virtual private network. In some embodiments, technologies and / or formats including Hyper Text Mark-up Language (HTML), Extensible Markup Language (XML), etc. are used to represent data exchanged through the network. Additionally, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Network (VPN), Internet Protocol Security (IPsec), etc. can be used to encrypt all or some of the links. In other embodiments, customized and / or proprietary data communication technologies can be used to replace or supplement the above data communication technologies.

[0089] Figure 2 is an EBPC in the related art.

[0090] Such as Figure 2 shown, the data stream of the feature map to be compressed is obtained, and the EBPC independently encodes zero data based on Zero-RLE (Zero Run Length Encoding). For non-zero data, after differential transposition, the obtained result is encoded. The compression results of the zero data and the non-zero data are used as compression data packets to obtain a compressed bitstream.

[0091] Figure 3 is a coding table in the related art.

[0092] Such as Figure 3 shown, when encoding non-zero data, multiple coding modes are used. For Figure 3The terms in [the above] are explained as follows: DBX represents the bit-plane value; DBP (data bit plane); bin (burst length - 1); BPC (Bit-Plane Encoder). m represents the bit width of non-zero data, and n represents the number of increments. "2-consec1s" indicates two consecutive 1s. "pos of first one" indicates the position where the first "1" appears.

[0093] In the related art, encoding in the form of an unlimited-length data stream is not conducive to upper-layer applications. There are too many encoding modes for non-zero data, resulting in high hardware power consumption, poor performance, and a large hardware area. In addition, after encoding is completed, the size of the compressed data packet may be larger than the size of the uncompressed data stream. That is, there is a problem of data expansion.

[0094] Embodiments of the present application provide a data compression method to solve the above technical problems.

[0095] Figure 4 is a schematic flowchart of a data compression method provided according to an embodiment of the present application. As Figure 4 shown, in the embodiments of the present application, it is described by taking an application to a terminal with a data compression device as an example. The method includes the following steps:

[0096] In step 401, the terminal acquires a to-be-compressed feature map data block.

[0097] Among them, the to-be-compressed feature map data block is a part of the to-be-compressed feature map data stream.

[0098] In some embodiments, during the process of compressing the to-be-compressed feature map data block, the terminal divides the to-be-compressed feature map data stream into multiple to-be-compressed feature map data blocks. Optionally, the terminal compresses one to-be-compressed feature map data block each time to obtain a compression result. This process continues until the last to-be-compressed feature map data block is compressed. This is more conducive to upper-layer applications. For example: the size of each to-be-compressed feature map data block is 1KB (1024B), where B represents a byte. It should be noted that each to-be-compressed feature map data block includes a packet header, and the size of the packet header is 8B. Therefore, the actual size of the data included in each to-be-compressed feature map data block is 1016B. When the size of the data in the last to-be-compressed feature map data block does not meet 1016B, it is filled with "1".

[0099] In some embodiments, each to-be-compressed feature map data block includes multiple non-zero data and multiple zero data. For example, the terminal acquires 64bit of data in each clock cycle. The size of each non-zero data is 8bit. The size of each zero data is also 8bit.

[0100] In step 402, the terminal identifies the feature map data block to be compressed and obtains non-zero feature map data.

[0101] In some embodiments, the feature map data block to be compressed includes zero feature map data; the zero feature map data includes a plurality of zero data; the non-zero feature map data includes a plurality of non-zero data. Optionally, each time the terminal obtains a data, it determines whether the data is non-zero data. If the data is non-zero data, the non-zero data is screened out. Thus, the non-zero feature map data is screened out from the feature map data block to be compressed, so as to facilitate subsequent compression of the non-zero feature map data alone.

[0102] In some embodiments, after the terminal obtains 64-bit data, it determines whether each data is all 0. If it is all 0, the data is regarded as zero data. Or if it is not all 0, the data is regarded as non-zero data. For example: "00000000" is a zero data; "01000100" is a non-zero data.

[0103] In step 403, the terminal encodes the feature map data block to be compressed based on a preset rule and obtains a first encoding result.

[0104] In some embodiments, the terminal compresses both non-zero data and zero data based on a preset rule, without distinguishing between non-zero data and zero data. Compared with the related art where only zero data is compressed, the embodiments of the present application can indicate the decoding process of the second encoding result obtained in step 404 through the compressed non-zero data in step 403, which is more convenient for decoding implementation.

[0105] In some embodiments, the above step 403 can be implemented by the following implementation manner:

[0106] For a zero data, the zero data is encoded as a first value; or for a non-zero data, the non-zero data is encoded as a second value; a plurality of first values and a plurality of second values are used as the first encoded data. Each data in the zero data is 0. There are non-zero data in the non-zero data. That is, the preset rule can be understood as encoding each zero data as a first value and each non-zero data as a second value. That is, in step 403, the terminal not only compresses non-zero data but also compresses zero data. For example: Use the ZVC (Zero-value compression) mode to compress non-zero data and zero data. ZVC is an encoding mode. It should be noted that in step 403, the non-zero data is compressed. It is to use the compressed non-zero data to indicate the decompression process of the compressed non-zero data in step 404 during the decompression process. The decompression process is not within the protection scope of the present application. Therefore, the decompression process will not be elaborated.

[0107] In one example, the terminal compresses multiple zero data in each clock cycle. For example, the size of each zero data is 8 bits. The size of each non-zero data is 8 bits. Each time, a 64-bit feature map data stream to be compressed is processed. That is, the terminal compresses 8 non-zero data in each clock cycle. Or the terminal compresses 8 zero data in each clock cycle. Or the sum of the number of non-zero data and the number of zero data compressed by the terminal in each clock cycle is 8. A zero data includes 8 "0"s. A non-zero data includes at least one "1".

[0108] In one example, when the terminal obtains a zero data, the zero data is encoded into a first value. The first value has only one bit. That is, the terminal encodes in units of bytes. Or when the terminal obtains a non-zero data, the non-zero data is encoded into a second value. The second value has only one bit. That is, whether it is zero data or non-zero data, it is compressed from 8 bits to 1 bit, thus achieving compression. For example: the first value is "1". The second value is "0".

[0109] It can be understood that the encoding length of the first encoding result is fixed.

[0110] In step 404, the terminal encodes the non-zero feature map data based on the target encoding method to obtain a second encoding result.

[0111] It should be noted that the embodiments of the present application do not limit the execution timing of step 404 and step 403.

[0112] In some embodiments, the target encoding method is obtained by looking up a first preset encoding table based on the target data type; the target data type is determined based on the continuous state of the preset value in the non-zero feature map data; the target encoding method indicates the target data type, continuous state, and target encoding length; the first preset encoding table includes at least two optional encoding modes; each optional encoding mode includes an optional data type and an optional encoding method; each optional encoding method includes an optional encoding length and an optional encoding value; the target encoding method is one of the optional encoding methods.

[0113] Figure 5 It is a schematic flowchart of step 404 provided according to the embodiments of the present application.

[0114] The following combines Figure 5 to give an exemplary description of step 404.

[0115] In some embodiments, the above step 404 includes the following steps 4041 to 4046:

[0116] In step 4041, the terminal targets a group of non-zero data, and a group of non-zero data includes multiple non-zero data.

[0117] In some embodiments, the terminal performs difference processing on each non-zero data to obtain a target difference sequence.

[0118] In one example, the terminal processes a group of non-zero data in each clock cycle. The group of non-zero data includes 8 non-zero data. The target difference sequence includes a plurality of target differences. The target differences correspond to the non-zero data one by one. The i-th target difference is the difference between the i-th non-zero data and the (i - 1)-th non-zero data; i is an integer greater than or equal to 1 and less than or equal to 7. It should be noted that if the last non-zero data in the last group of non-zero data in the to-be-compressed feature map data block is less than 8 bits, it is padded with "1". Optionally, if the group of non-zero data is the first group of non-zero data of the non-zero feature map data, the first target difference in the target difference sequence is the first non-zero data. That is, the non-zero feature map data is independent of each other, and the second coding results are independent of each other. The first non-zero data is "0". The second target difference is the difference between the second non-zero data and the first non-zero data. Thus, the target difference sequence is obtained. Optionally, if the group of non-zero data is not the first group of non-zero data of the non-zero feature map data, the first target difference in the target difference sequence is the difference between the first non-zero data and the last non-zero data of the previous group of non-zero data. Since the first non-zero data is "0", the first non-zero data is the last non-zero data of the previous group of non-zero data.

[0119] For example: If W[i] represents the i-th non-zero data, then a group of non-zero data can be expressed as:

[0120] {W[0], …… W[i], …… W[7]}.

[0121] If D[i] represents the i-th target difference, then a target difference sequence can be expressed as:

[0122] {D[0], …… D[i], …… D[7]}.

[0123] Wherein, when i > 0, D[i] = D[i] - D[i - 1]. When i = 0, D[0] = 0 or the last non-zero data in the previous group of non-zero data.

[0124] In step 4042, the terminal transposes the target difference sequence to obtain a target transposed sequence.

[0125] Wherein, the target transposed sequence includes 8 target transposes.

[0126] In one example, the explanation is given for the i-th target transposition. The i-th target transposition includes the product of each target difference and the (7 - i)-th target difference. For example, the i-th target transposition can be calculated by the following formula: DBP[i] = {D[0]D[7 - i], D[1]D[7 - i], …… D[7]D[7 - i]}. DBP[i] represents the i-th target transposition. A target transposition sequence can be expressed as: {DBP[0], …… DBP[i], …… DBP[7]}.

[0127] In step 4043, the terminal performs an exclusive OR operation on the target transposition sequence to obtain a target exclusive OR sequence.

[0128] Among them, the target exclusive OR sequence includes 8 target exclusive OR values.

[0129] In one example, the explanation is given for the i-th target exclusive OR value. The i-th target exclusive OR value is the result of the exclusive OR calculation between the i-th target transposition and the (i + 1)-th target transposition. For example, the i-th target exclusive OR can be calculated by the following formula: when i < 7, DBX[i] = DBP[i] ^ DBP[i + 1]. When i = 7, DBX[7] = DBP[7]. A target transposition sequence can be expressed as: {DBX[0], …… DBX[i], …… DBX[7]}. For example, DBX[i] is represented by 8 bits.

[0130] In step 4044, the terminal determines the target data type of the target exclusive OR sequence.

[0131] Figure 6 It is a schematic diagram of a first preset coding table provided according to an embodiment of the present application.

[0132] The following combines Figure 6 to give an exemplary illustration of step 4044.

[0133] In some embodiments, the first preset coding table includes 3 data types; each data type indicates a coding method. The coding method is used to determine the coding length of each DBX and the information represented by each bit; the information represented by each bit includes an identifier and data information.

[0134] In one example, L is an integer greater than or equal to 5 bits and less than or equal to 9 bits; L is the target coding length. For example: the target coding length corresponding to the first data type is 5 bits. Among them, 2 bits are used for identification, and the other 3 bits are used to represent the coding value. The target length corresponding to the second data type is 5 bits. Among them, 2 bits are used for identification, and the other 3 bits are used to represent the position of the preset value. The target coding length corresponding to the third data type is 9 bits. Among them, 1 bit is used for identification, and the other 8 bits are the target XOR value itself.

[0135] In some embodiments, the above step 4044 can be implemented in the following several implementation manners:

[0136] The first implementation manner: When there are consecutive preset values in the target XOR sequence, the target data type of the preset value is the first data type; the first data type is one of the optional data types. The target data types of the remaining target XOR values in the target XOR sequence are the second data type or the third data type. Optionally, the consecutive preset values in the target XOR sequence are encoded according to the first encoding method. Optionally, among the remaining target XOR values, if there is only one preset value, the preset value is encoded according to the second encoding method. Optionally, if there are at least two non-consecutive preset values among the remaining target XOR values, the remaining target XOR values are encoded according to the third encoding method. For example: When all 8 bits of DBX[i] are 0, then DBX[i] is a preset value. When both DBX[0] and DBX[1] in the target XOR sequence are preset values, the target data types of DBX[0] and DBX[1] are the first data type. That is, DBX[1]=DBX[0]=00000000. Or if there is only one preset value among DBX[2] to DBX[7], the preset value is encoded according to the second encoding method. Or if there are at least two non-consecutive preset values among DBX[2] to DBX[7], each target XOR value among DBX[2] to DBX[7] is encoded according to the third encoding method.

[0137] The second implementation manner: When there is only one preset value in the target XOR sequence, the target data type of the preset value is the second data type; the second data type is one of the optional data types. The target data types of the remaining target XOR values in the target XOR sequence are the third data type. That is, only one target XOR value in the target XOR sequence has all 8 bits equal to 0. For example: When in the target XOR sequence, only DBX[0] is a preset value, then DBX[0] is of the second data type. If there are at least two non-consecutive preset values among DBX[1] to DBX[7], each target XOR value among DBX[1] to DBX[7] is encoded according to the third encoding method.

[0138] The third implementation method: When there are no consecutive preset values in the target exclusive-OR sequence and there are multiple preset values, the target data type of each target exclusive-OR value is the third data type; the third data type is one of the optional data types. That is, there are no consecutive preset values in the target exclusive-OR sequence, and the 8 bits of at least two target exclusive-OR values are all 0.

[0139] In step 4045, the terminal looks up the first preset coding table based on the target data type to obtain the target coding method and the target coding length.

[0140] Figure 7 It is a flowchart of step 4045 provided according to an embodiment of the present application.

[0141] The following combines Figure 7 to give an exemplary description of step 4045.

[0142] In some embodiments, the above step 4045 can be implemented through the following steps 40451 to 40454:

[0143] In step 40451, when the target data type of the preset value is the first data type, the terminal encodes the target exclusive-OR value corresponding to the preset value into a preset bit value.

[0144] In some embodiments, when there are consecutive preset values in the target exclusive-OR sequence, the terminal determines that the target data type of each preset value is the first data type. Then each target exclusive-OR value is encoded into a preset bit value. For example: The preset bit value is represented by "1" or "0". The target exclusive-OR value with 8 bits all 0 is encoded as "1"; the target exclusive-OR value with 8 bits not all 0 is encoded as "0". Another example: A target exclusive-OR sequence can be represented as {1, 1, 0, 0, 0, 0, 0, 0} after encoding. Another example: A target exclusive-OR sequence can be represented as {1, 1, 0, 1, 0, 0, 1, 0} after encoding.

[0145] In step 40452, the terminal looks up the second preset coding table based on the preset bit value to obtain the consecutive quantity.

[0146] Wherein, the consecutive quantity is the quantity of consecutive preset bit values.

[0147] Figure 8 It is a flowchart of step 40452 provided according to an embodiment of the present application.

[0148] The following combines Figure 8 to give an exemplary description of step 40452.

[0149] In some embodiments, the above step 40452 includes the following steps 404521 and 404522:

[0150] In step 404521, the terminal divides a plurality of preset bit values into two groups to obtain a first group of preset bit values and a second group of preset bit values.

[0151] In some embodiments, the first group of preset bit values are the preset bit values of the high bit positions; the second group of preset bit values are the preset bit values of the low bit positions. For example: Divide {1, 1, 0, 1, 0, 0, 1, 0} into a first group of preset bit values and a second group of preset bit values. The first group of preset bit values {1, 1, 0, 1}. The second group of preset bit values is {0, 0, 1, 0}.

[0152] Figure 9 It is a schematic diagram of a second preset coding table provided according to an embodiment of the present application.

[0153] The following combines Figure 9 to give an exemplary description of the second preset coding table.

[0154] In step 404522, the terminal obtains a first consecutive quantity and a second consecutive quantity.

[0155] In some embodiments, the first consecutive quantity indicates the number of consecutive preset bit values in the first group of preset bit values; the second consecutive quantity indicates the number of consecutive preset bit values in the second group of preset bit values. For example: The first consecutive quantity corresponding to the first group of preset bit values {1, 1, 0, 1} is 2. The second consecutive quantity corresponding to the second group of preset bit values {0, 0, 1, 0} is 0.

[0156] In one example, the run-length encoding inside the BPC encoder is implemented by looking up a second preset coding table. Specifically, look up a second preset coding table based on the first group of preset bit values; at the same time, the terminal looks up another second preset coding table based on the second group of preset bit values. Figure 8 In, the leftmost first column of "=" is the input plurality of first group of preset bit values. The multiple arrays in the four columns on the right side of "=" are used to represent the lookup results, that is, the number of consecutive preset values. Each array on the right side of "=" corresponds to one bit position in the leftmost column of "=". For example, when the value of an array is 15, it means that the bit position in front of the corresponding bit position is consecutive and has been merged, and this bit position is an invalid bit. When the value of an array is 1, it means that the corresponding bit position is independent. If the value of an array is not 1 and 15, it means the number of consecutive preset values. For example: Take Figure 8Take the last line in [as an example]: The value of "4'b0100" on the right side of "=" is 4, indicating 4 consecutive preset values, and the following 3 "4'b1111" are all invalid bits. Therefore, "4'b1111" on the leftmost side of "=" indicates that the first consecutive quantity is 4.

[0157] In some embodiments, since there may also be consecutive preset values between the first set of preset bit values and the second set of preset bit values. To solve this problem, step 40452 above further includes: after checking the second preset coding table, the terminal obtains a third consecutive quantity; the third consecutive quantity indicates a part of the preset bit values in the first set of preset bit values and a part of the preset bit values in the second set of preset bit values; a part of the preset bit values in the first set of preset bit values and a part of the preset bit values in the second set of preset bit values are consecutive. Thus, the first consecutive quantity and the second consecutive quantity are corrected. For example: After looking up the second preset coding table for {1, 1, 0, 1, 1, 1, 0, 0}, the first consecutive quantity is 2, the second consecutive quantity is 0, and the third consecutive quantity is 2.

[0158] In step 40453, the terminal looks up the first preset coding table based on the first data type to obtain a first coding method.

[0159] Among them, the first coding method is one of the optional coding methods.

[0160] In step 40454, the terminal encodes each preset value based on the first coding method and the consecutive quantity to obtain a plurality of non-zero encoded data.

[0161] Among them, the non-zero encoded data corresponds to the preset value one by one.

[0162] In some embodiments, step 40454 above can be implemented by the following implementation methods:

[0163] The first implementation method: The terminal encodes each preset value of the first consecutive quantity based on the first coding method to obtain a plurality of non-zero encoded data; each non-zero encoded data includes a first identification coding value and a first coding value; the first coding value indicates the first consecutive quantity; the first identification coding value indicates the first data type. For example: The first consecutive quantity corresponding to the first set of preset bit values {1, 1, 0, 1} is 2. The second consecutive quantity corresponding to the second set of preset bit values {0, 0, 1, 0} is 0. Then, the two preset values are encoded according to the first coding method to obtain two non-zero encoded data. Each non-zero encoded data includes the data: first identification coding value + first coding value.

[0164] The second implementation method: The terminal encodes each preset value of the second consecutive quantity based on the first encoding method to obtain a plurality of non-zero encoded data. The non-zero encoded data includes a second identification encoded value and a second encoded value; the second encoded value indicates the second consecutive quantity; the second identification encoded value indicates the first data type. The first consecutive quantity corresponding to the first set of preset bit values {0, 0, 0, 1} is 0. The second consecutive quantity corresponding to the second set of preset bit values {0, 0, 1, 1} is 2. Then the non-zero encoded data only needs to indicate the first data type and the second consecutive quantity. It does not need to indicate the first consecutive quantity. That is, the non-encoded data includes: the second identification encoded value + the second encoded value.

[0165] The third implementation method: The terminal encodes each preset value of the third consecutive quantity based on the first encoding method to obtain a plurality of non-zero encoded data. The non-zero encoded data includes a third identification encoded value and a third encoded value; the third encoded value indicates the third consecutive quantity; the third identification encoded value indicates the first data type. The first consecutive quantity corresponding to the first set of preset bit values {0, 0, 0, 1} is 0. The second consecutive quantity corresponding to the second set of preset bit values {1, 0, 0, 0} is 0. The corresponding third consecutive quantity is 2. Then the non-zero encoded data only needs to indicate the first data type and the third consecutive quantity. It does not need to indicate the first consecutive quantity and the second consecutive quantity. That is, the non-encoded data includes: the third identification encoded value + the third encoded value.

[0166] In some embodiments, in the above step 4045, it further includes:

[0167] When the target data type of the preset value is the second data type, then look up the first preset encoding table based on the second data type to obtain the second encoding method; the second encoding method is one of the optional encoding methods; encode the preset value based on the second encoding method to obtain non-zero encoded data; the non-zero encoded data includes a fourth identification encoded value and a fourth encoded value; the fourth encoded value indicates the position of the preset value in the target exclusive-or sequence. For example: only the 8 bits of DBX[1] are all 0. The fourth encoded value indicates the second position.

[0168] In some embodiments, in the above step 4045, it further includes:

[0169] For one said target exclusive-or value, when the target data type of the target exclusive-or value is the third data type, then look up the first preset encoding table based on the third data type to obtain the third encoding method; the third encoding method is one of the optional encoding methods; encode the target exclusive-or value based on the third encoding method to obtain non-zero encoded data; each non-zero encoded data includes a fifth identification encoded value and a target exclusive-or value. The non-zero encoded data is the fifth identification encoded value + DBX[i].

[0170] In step 4046, the terminal encodes a set of non-zero data based on the target encoding method and the target encoding length to obtain multiple non-zero encoded data.

[0171] It can be understood that since the non-zero data is encoded based on the first preset encoding table, the lengths of the corresponding non-zero encoded data for different non-zero data may be different. For example: 5bit or 9bit. That is, the encoding length of the second encoding result is not fixed.

[0172] In step 405, the terminal combines the first encoding result and the second encoding result to obtain a compressed data packet.

[0173] In some embodiments, the terminal splices and encapsulates the first encoding result and the second encoding result corresponding to each data block of the feature map to be compressed together to obtain a compressed data packet.

[0174] In some embodiments, the method further includes: if the actual size of the compressed data packet is greater than the initial size of the data block of the feature map to be compressed, then use the data block of the feature map to be compressed as the compressed data packet.

[0175] In one example, during the process of compressing the data block of the feature map to be compressed, the terminal caches the data block of the feature map to be compressed. If the actual size of the compressed data packet is greater than the initial size of the data block of the feature map to be compressed, then the terminal obtains the data block of the feature map to be compressed from the cache and outputs the data block of the feature map to be compressed as the compressed data packet. Thus, the problem of compressed data expansion is solved.

[0176] It should be noted that the embodiments of the present application do not limit the size of the cache.

[0177] Figure 10 It is a schematic diagram of the format of the first compressed data packet provided according to the embodiments of the present application.

[0178] The following combines Figure 10 to give an exemplary description of the compressed data packet.

[0179] In some embodiments, the compressed data packet further includes time data; the time data indicates the time for processing the data block of the feature map to be compressed; the time data is used to calculate the actual size of the compressed data packet.

[0180] In one example, the time data includes the clock cycle when starting to process the data block of the feature map to be compressed and the clock cycle when ending to process the data block of the feature map to be compressed.

[0181] In some embodiments, the compressed data packet further includes identification data; the identification data indicates whether the compressed data packet has been compressed.

[0182] In one example, when the identification data indicates compression. The compressed data packet includes the offset address and length of the identification data. The compressed data packet also includes the offset address and length of the first coding result; and the offset and length of the second coding result. For example: the offset address of the identification data is "0" and the length is 1B. The offset address of the first coding result is "1" and the length is 127B. The offset address of the second coding result is "128" and the length is 8B to 896B. In addition, in the compressed data packet, there is also indication information. Indication information: when the seventh bit in the identification data is "0", it indicates compression; when it is "1", it indicates uncompressed. The 0th bit to the sixth bit in the identification data are time data. For the first coding result, when the bit value is "1", it represents non-zero data. When the bit value is "0", it represents zero data. For the second coding result, the length is dynamically variable, that is, not fixed.

[0183] Figure 11 It is a schematic diagram of the format of the second compressed data packet provided according to an embodiment of the present application.

[0184] The following combines Figure 11 to give an exemplary illustration of the compressed data packet.

[0185] In one example, when the identification data indicates uncompressed. The uncompressed compressed data packet includes the offset address and length of the identification data. The compressed data packet also includes the offset address and length of the zero feature map data; and the offset and length of the non-zero feature map data. For example: the offset address of the identification data is "0" and the length is 1B. The offset address of the first coding result is "1" and the length is 7B. The offset address of the second coding result is "8" and the length is 8B to 1016B. In addition, in the compressed data packet, there is also indication information. Specifically, when the seventh bit in the identification data is "0", it indicates compression; when it is "1", it indicates uncompressed. The 0th bit to the sixth bit in the identification data are time data. For the zero feature map data, all are "0". For the non-zero feature map data, only the length of the last feature map data block to be compressed may be less than 1016B.

[0186] Figure 12 It is a schematic diagram of the effect in the first application scenario provided according to an embodiment of the present application.

[0187] Figure 12 It is the compression effect of each layer of feature map in the yolov3 (You Only Look Once version 3) model.

[0188] Figure 13 It is a schematic diagram of the effect in the second application scenario provided according to an embodiment of the present application.

[0189] Figure 13It is the compression effect of the feature maps of each layer in the pmnp model. Among them, pmnp is an AI model.

[0190] Combined with Figure 11 and Figure 12 the compression effect, it can be known that in the embodiments of the present application, data compression can be performed in each clock cycle on the premise of meeting the compression ratio, realizing continuous compression and improving the compression efficiency.

[0191] In the embodiments of the present application, the data stream of the feature map to be compressed is divided into multiple data blocks of the feature map to be compressed, and the multiple data blocks of the feature map to be compressed are compressed one by one, which belongs to lightweight compression. The compression input has a full bandwidth of up to 6.4 GBps without wasting bandwidth; the compression speed is fast, the delay is less, and the performance is good, which is more conducive to upper-layer applications. In addition, the embodiments of the present application encode non-zero feature map data based on a first preset coding table. Compared with the related art, the number of optional coding modes involved in the first preset coding table of the present application is reduced, which facilitates the table lookup operation, is easy to meet the hardware timing, and is also convenient for the implementation of decompression.

[0192] Figure 14 FIG. 14 is a schematic structural diagram of a data compression device 1400 according to an embodiment of the present application. The device includes:

[0193] An acquisition module 1401, configured to acquire a data block of a feature map to be compressed; the data block of the feature map to be compressed is a part of the data stream of the feature map to be compressed.

[0194] An identification module 1402, configured to identify the data block of the feature map to be compressed to obtain non-zero feature map data.

[0195] A first encoding module 1403, configured to encode the data block of the feature map to be compressed based on a preset rule to obtain a first encoding result.

[0196] A second encoding module 1404, configured to encode the non-zero feature map data based on a target encoding method to obtain a second encoding result; the target encoding method is obtained by looking up a first preset coding table based on a target data type; the target data type is determined based on the continuous state of a preset value in the non-zero feature map data; the target encoding method indicates the target data type, the continuous state, and the target encoding length; the first preset coding table includes at least two optional coding modes; each optional coding mode includes an optional data type and an optional encoding method; each optional encoding method includes an optional encoding length and an optional encoding value; the target encoding method is one of the optional encoding methods.

[0197] A merging module 1405, configured to merge the first encoding result and the second encoding result to obtain a compressed data packet.

[0198] It should be noted that the acquisition module 1401, the recognition module 1402, the first encoding module 1403, the second encoding module 1404, and the merging module 1405 are all hardware.

[0199] In some embodiments, the feature map data block to be compressed includes zero feature map data; the zero feature map data includes a plurality of zero data; the non-zero feature map data includes a plurality of non-zero data.

[0200] In some embodiments, the apparatus is further configured to:

[0201] For a zero data, encode the zero data as a first value; or for a non-zero data, encode the non-zero data as a second value;

[0202] Use the plurality of first values and the plurality of second values as the first encoded data.

[0203] In some embodiments, the apparatus is further configured to:

[0204] For a group of non-zero data, the group of non-zero data includes a plurality of non-zero data;

[0205] Perform difference processing on each non-zero data to obtain a target difference sequence;

[0206] Transpose the target difference sequence to obtain a target transposed sequence;

[0207] Perform exclusive OR processing on the target transposed sequence to obtain a target exclusive OR sequence;

[0208] Determine the target data type of the target exclusive OR sequence;

[0209] Based on the target data type, look up a first preset encoding table to obtain a target encoding method and a target encoding length;

[0210] Encode the group of non-zero data based on the target encoding method and the target encoding length to obtain a plurality of non-zero encoded data.

[0211] In some embodiments, L is an integer greater than or equal to 5 bits and less than or equal to 9 bits; L is the target encoding length.

[0212] In some embodiments, the apparatus is further configured to:

[0213] When there are consecutive preset values in the target exclusive OR sequence, the target data type of the preset value is the first data type; the first data type is one of the optional data types; the target data type of the remaining target exclusive OR values in the target exclusive OR sequence is the second data type or the third data type; or

[0214] When there is only one preset value in the target exclusive - OR sequence, the target data type of the preset value is the second data type; the second data type is one of the optional data types; the target data type of the remaining target exclusive - OR values in the target exclusive - OR sequence is the third data type; or

[0215] When there are no consecutive preset values in the target exclusive - OR sequence and there are multiple preset values, the target data type of each target exclusive - OR value is the third data type; the third data type is one of the optional data types.

[0216] In some embodiments, the device is further configured to:

[0217] When the target data type of the preset value is the first data type, encode the target exclusive - OR value corresponding to the preset value into a preset bit value;

[0218] Search for a second preset coding table based on multiple preset bit values to obtain a consecutive quantity; the consecutive quantity is the number of consecutive preset bit values;

[0219] Search for a first preset coding table based on the first data type to obtain a first coding method; the first coding method is one of the optional coding methods;

[0220] Encode each preset value based on the first coding method and the consecutive quantity to obtain multiple non - zero coded data; the non - zero coded data corresponds to the preset value one by one.

[0221] In some embodiments, the device is further configured to:

[0222] Divide the multiple preset bit values into two groups to obtain a first group of preset bit values and a second group of preset bit values; the first group of preset bit values are the high - order preset bit values; the second group of preset bit values are the low - order preset bit values;

[0223] Obtain a first consecutive quantity and a second consecutive quantity; the first consecutive quantity indicates the number of consecutive preset bit values in the first group of preset bit values; the second consecutive quantity indicates the number of consecutive preset bit values in the second group of preset bit values.

[0224] In some embodiments, the device is further configured to:

[0225] Obtain a third consecutive quantity; the third consecutive quantity indicates a part of the preset bit values in the first group of preset bit values and a part of the preset bit values in the second group of preset bit values; a part of the preset bit values in the first group of preset bit values and a part of the preset bit values in the second group of preset bit values are consecutive;

[0226] In some embodiments, the device is further configured to:

[0227] Encode each preset value of the first consecutive quantity based on the first encoding method to obtain a plurality of non-zero encoded data; each non-zero encoded data includes a first identification encoded value and a first encoded value; the first encoded value indicates the first consecutive quantity; the first identification encoded value indicates the first data type; or

[0228] Encode each preset value of the second consecutive quantity based on the first encoding method to obtain a plurality of non-zero encoded data; each non-zero encoded data includes a second identification encoded value and a second encoded value; the second encoded value indicates the second consecutive quantity; the second identification encoded value indicates the first data type; or

[0229] Encode each preset value of the third consecutive quantity based on the first encoding method to obtain a plurality of non-zero encoded data; each non-zero encoded data includes a third identification encoded value and a third encoded value; the third encoded value indicates the third consecutive quantity; the third identification encoded value indicates the first data type.

[0230] In some embodiments, the device is further configured to:

[0231] When the target data type of the preset value is the second data type, look up the first preset encoding table based on the second data type to obtain a second encoding method; the second encoding method is one of the optional encoding methods;

[0232] Encode the preset value based on the second encoding method to obtain non-zero encoded data; the non-zero encoded data includes a fourth identification encoded value and a fourth encoded value; the fourth encoded value indicates the position of the preset value in the target exclusive OR sequence.

[0233] In some embodiments, the device is further configured to:

[0234] For a target exclusive OR value, when the target data type of the target exclusive OR value is the third data type, look up the first preset encoding table based on the third data type to obtain a third encoding method; the third encoding method is one of the optional encoding methods;

[0235] Encode the target exclusive OR value based on the third encoding method to obtain non-zero encoded data; the non-zero encoded data includes a fifth identification encoded value and a target exclusive OR value.

[0236] In some embodiments, the device is further configured to:

[0237] If the actual size of the compressed data packet is greater than the initial size of the data block of the feature map to be compressed, then use the data block of the feature map to be compressed as the compressed data packet.

[0238] In some embodiments, the compressed data packet further includes time data; the time data indicates the time for processing the data block of the feature map to be compressed; the time data is used to calculate the actual size of the compressed data packet.

[0239] In some embodiments, the compressed data packet further includes identification data; the identification data indicates whether the compressed data packet has been compressed.

[0240] It should be noted that when the data compression device provided in the above embodiments executes the corresponding steps, only the division of the above functional modules is used for illustration. In actual applications, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the data compression device provided in the above embodiments and the embodiments of the data compression method belong to the same concept. For the specific implementation process, please refer to the method embodiments and will not be elaborated here.

[0241] In the embodiments of the present application, the feature map data stream to be compressed is divided into multiple feature map data blocks to be compressed, and the multiple feature map data blocks to be compressed are compressed one by one, which is more beneficial to upper-layer applications. In addition, the embodiments of the present application encode non-zero feature map data based on a first preset coding table. Compared with the related art, the number of optional coding modes involved in the first preset coding table of the present application is reduced, which facilitates the table lookup operation, is easy to meet the hardware timing, and is also convenient for the implementation of decompression.

[0242] The embodiments of the present application also provide a computer device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the above method is implemented.

[0243] Taking the computer device as a terminal as an example, Figure 15 is a schematic structural diagram of a terminal provided by an embodiment of the present application. Refer to Figure 15 , the terminal 1500 may be: a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV) player, a notebook computer, or a desktop computer. The terminal 1500 may also be referred to by other names such as a user equipment, a portable terminal, a laptop terminal, a desktop terminal, etc.

[0244] Generally, the terminal 1500 includes: a processor 1501 and a memory 1502.

[0245] The processor 1501 may include one or more processing cores, such as a quad-core processor, a penta-core processor, etc. The processor 1501 may be implemented in at least one of the following hardware forms: DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 1501 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the wake state, also known as the CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1501 may be integrated with a GPU (Graphics Processing Unit), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1501 may further include an AI (Artificial Intelligence) processor, which is used to process computational operations related to machine learning.

[0246] The memory 1502 may include one or more computer-readable storage media, and the computer-readable storage media may be non-transitory. The memory 1502 may further include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash storage devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1502 is used to store at least one program code, and the at least one program code is used to be executed by the processor 1501 to implement the process executed by the terminal in the method provided in the method embodiments of the present application.

[0247] In some embodiments, the terminal 1500 may further optionally include: a peripheral device interface 1503 and at least one peripheral device. The processor 1501, the memory 1502, and the peripheral device interface 1503 may be connected through a bus or signal lines. Each peripheral device may be connected to the peripheral device interface 1503 through a bus, signal lines, or a circuit board. Specifically, the peripheral devices include at least one of the following: a display screen 1504, a camera assembly 1505, an audio circuit 1506, and a power supply 1507.

[0248] The peripheral device interface 1503 can be used to connect at least one I / O (Input / Output) related peripheral device to the processor 1501 and the memory 1502. In some embodiments, the processor 1501, the memory 1502, and the peripheral device interface 1503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1501, the memory 1502, and the peripheral device interface 1503 can be implemented on a separate chip or circuit board, and the embodiments of the present application do not limit this.

[0249] The display screen 1504 is used to display the UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1504 is a touch display screen, the display screen 1504 also has the ability to collect touch signals on or above the surface of the display screen 1504. The touch signals can be input to the processor 1501 as control signals for processing. At this time, the display screen 1504 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there can be one display screen 1504, which is set on the front panel of the terminal 1500; in some other embodiments, there can be at least two display screens 1504, which are respectively set on different surfaces of the terminal 1500 or are in a folding design; in some other embodiments, the display screen 1504 can be a flexible display screen, which is set on the curved surface or the folding surface of the terminal 1500. Even, the display screen 1504 can also be set as an irregular non-rectangular shape, that is, a special-shaped screen. The display screen 1504 can be prepared using materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).

[0250] The camera module 1505 is used to collect images or videos. In some embodiments, the camera module 1505 includes a front camera and a rear camera. Generally, the front camera is set on the front panel of the terminal, and the rear camera is set on the back of the terminal. In some embodiments, there are at least two rear cameras, which are respectively one of a main camera, a depth camera, a wide-angle camera, and a telephoto camera, so as to implement functions such as background blurring by fusing the main camera and the depth camera, panoramic shooting by fusing the main camera and the wide-angle camera, and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera module 1505 can also include a flash. The flash can be a single-color temperature flash or a two-color temperature flash. The two-color temperature flash refers to the combination of a warm light flash and a cold light flash, which can be used for light compensation under different color temperatures.

[0251] The audio circuit 1506 may include a microphone and a speaker. The microphone is used to collect sound waves of the user and the environment, and convert the sound waves into electrical signals for input to the processor 1501 for processing. For the purpose of stereo collection or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the terminal 1500. The microphone may also be an array microphone or an omnidirectional collection microphone. The speaker is used to convert the electrical signals from the processor 1501 into sound waves. The speaker may be a traditional thin film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert electrical signals into sound waves audible to humans, but also convert electrical signals into sound waves inaudible to humans for uses such as ranging. In some embodiments, the audio circuit 1506 may further include a headphone jack.

[0252] The power supply 1507 is used to supply power to each component in the terminal 1500. The power supply 1507 may be alternating current, direct current, a disposable battery or a rechargeable battery. When the power supply 1507 includes a rechargeable battery, the rechargeable battery may support wired charging or wireless charging. The rechargeable battery may also be used to support fast charging technology.

[0253] Those skilled in the art can understand that Figure 15 the structure shown in does not limit the terminal 1500, and may include more or fewer components than shown in the figure, or combine certain components, or adopt different component arrangements.

[0254] Taking a computer device as a server as an example, Figure 16 FIG. is a schematic structural diagram of a server provided by an embodiment of the present application. The server 1600 may vary greatly due to different configurations or performances, and may include one or more processors (Central Processing Units, CPUs) 1601 and one or more memories 1602. Among them, at least one computer program is stored in the one or more memories 1602, and the at least one computer program is loaded and executed by the one or more processors 1601 to implement the above data compression method. Of course, the server 1600 may also have components such as a wired or wireless network interface, a keyboard, and an input / output interface for input / output. The server 1600 may further include other components for implementing device functions, which will not be elaborated here.

[0255] Embodiments of the present application further provide a computer-readable storage medium. The computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the above method for generating an image processing model. Optionally, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, optical data storage device, etc.

[0256] Those of ordinary skill in the art can understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by a program instructing relevant hardware. The program can be stored in a computer-readable storage medium, and the above-mentioned storage medium can be a read-only memory, a magnetic disk, or an optical disc, etc.

[0257] The above are only optional embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included within the protection scope of the present application.

Claims

1. A data compression method, characterized in that: include: Obtaining a feature map data block to be compressed; The feature map data block to be compressed is a part of the feature map data stream to be compressed; Identifying the feature map data block to be compressed, and obtaining non-zero feature map data; Encoding the feature map data block to be compressed based on a preset rule to obtain a first encoding result; Encoding the non-zero feature map data based on a target encoding method to obtain a second encoding result; The target encoding method is obtained by searching a first preset encoding table based on the target data type; The target data type is determined based on a continuous state of a preset value in the non-zero feature map data; The target encoding mode indicates the target data type, the continuous state and the target encoding length; The first preset coding table includes at least two optional coding modes; each of the optional coding modes includes an optional data type and an optional coding method; each of the optional coding methods includes an optional coding length and an optional coding value; The target encoding mode is one of the optional encoding modes; The encoding of the non-zero feature map data based on the target encoding method to obtain a second encoding result includes: for a group of non-zero data, the group of non-zero data includes a plurality of the non-zero data; Performing difference processing on each of the non-zero data to obtain a target difference sequence; Transposing the target difference sequence to obtain a target transposed sequence; Performing XOR processing on the target transposed sequence to obtain a target XOR sequence; Determining the target data type of the target XOR sequence; Based on the target data type, searching the first preset coding table to obtain the target coding mode and target coding length; Encode a group of the non-zero data based on the target encoding mode and the target encoding length to obtain a plurality of non-zero encoded data; The determining the target data type of the target XOR sequence includes: When there are continuous preset values ​​in the target XOR sequence, the target data type of the preset values ​​is the first data type; the first data type is one of the optional data types; the target data type of the remaining target XOR values ​​in the target XOR sequence is the second data type or the third data type; or When there is only one preset value in the target XOR sequence, the target data type of the preset value is the second data type; the second data type is one of the optional data types; the target data types of the remaining target XOR values ​​in the target XOR sequence are the third data type; or When there are no consecutive preset values ​​in the target XOR sequence, and there are multiple preset values, the target data type of each target XOR value is the third data type; the third data type is one of the optional data types; The first encoding result and the second encoding result are combined to obtain a compressed data packet.

2. The method according to claim 1, characterized in that The feature map data block to be compressed includes zero feature map data; the zero feature map data includes multiple zero data; and the non-zero feature map data includes multiple non-zero data.

3. The method according to claim 2, characterized in that The step of encoding the feature map data block to be compressed based on a preset rule to obtain a first encoding result includes: For one of the zero data, encode the zero data as a first value; or for one of the non-zero data, encode the non-zero data as a second value; A plurality of the first values ​​and a plurality of the second values ​​are used as first encoded data.

4. The method according to claim 3, characterized in that L is an integer greater than or equal to 5 bits and less than or equal to 9 bits; L is the target coding length.

5. The method according to claim 1, characterized in that The step of searching the first preset coding table based on the target data type to obtain the target coding method includes: When the target data type of the preset value is the first data type, encoding the target XOR value corresponding to the preset value into a preset bit value; Searching a second preset coding table based on the preset bit value to obtain a continuous number; the continuous number is the number of consecutive preset bit values; Searching the first preset coding table based on the first data type to obtain a first coding method; the first coding method is one of the optional coding methods; Based on the first encoding method and the continuous number encoding each of the preset values, a plurality of non-zero encoded data are obtained; the non-zero encoded data correspond to the preset values ​​one by one.

6. The method according to claim 5, characterized in that The step of searching a second preset coding table based on the preset bit value to obtain a continuous number includes: Divide the plurality of preset bit values ​​into two groups to obtain a first group of preset bit values ​​and a second group of preset bit values; the first group of preset bit values ​​are the preset bit values ​​of the high bit positions; the second group of preset bit values ​​are the preset bit values ​​of the low bit positions; Obtain a first continuous number and a second continuous number; the first continuous number indicates the number of continuous preset bit values ​​in the first group of preset bit values; the second continuous number indicates the number of continuous preset bit values ​​in the second group of preset bit values.

7. The method according to claim 6, characterized in that The step of searching the second preset coding table based on the preset bit value to obtain the continuous number further includes: Obtain a third continuous number; the third continuous number indicates a part of the preset bit values ​​in the first group of preset bit values ​​and a part of the preset bit values ​​in the second group of preset bit values; a part of the preset bit values ​​in the first group of preset bit values ​​and a part of the preset bit values ​​in the second group of preset bit values ​​are continuous.

8. The method according to claim 7, characterized in that The step of encoding each of the preset values ​​based on the first encoding mode and the continuous number to obtain a plurality of non-zero encoded data includes: Based on the first encoding method, each of the preset values ​​of the first continuous number is encoded to obtain a plurality of the non-zero encoded data; each of the non-zero encoded data includes a first identification encoding value and a first encoding value; the first encoding value indicates the first continuous number; the first identification encoding value indicates the first data type; or Based on the first encoding method, each of the preset values ​​of the second continuous number is encoded to obtain a plurality of the non-zero encoded data; each of the non-zero encoded data includes a second identification encoding value and a second encoding value; the second encoding value indicates the second continuous number; the second identification encoding value indicates the first data type; or Based on the first encoding method, each preset value of the third continuous number is encoded to obtain a plurality of the non-zero encoded data; each of the non-zero encoded data includes a third identification encoding value and a third encoding value; the third encoding value indicates the third continuous number; the third identification encoding value indicates the first data type.

9. The method according to claim 1, characterized in that: The step of searching the first preset coding table based on the target data type to obtain the target coding method further includes: When the target data type of the preset value is the second data type, the first preset coding table is searched based on the second data type to obtain a second coding method; the second coding method is one of the optional coding methods; The preset value is encoded based on the second encoding method to obtain the non-zero encoded data; the non-zero encoded data includes a fourth identification encoding value and a fourth encoding value; the fourth encoding value indicates the position of the preset value in the target XOR sequence.

10. The method according to claim 1, characterized in that The step of searching the first preset coding table based on the target data type to obtain the target coding method further includes: For one of the target XOR values, when the target data type of the target XOR value is the third data type, searching the first preset coding table based on the third data type to obtain a third coding method; the third coding method is one of the optional coding methods; The target XOR value is encoded based on the third encoding method to obtain the non-zero encoded data; the non-zero encoded data includes a fifth identification encoding value and one of the target XOR values.

11. The method according to claim 1, characterized in that: The method further comprises: If the actual size of the compressed data packet is larger than the initial size of the feature map data block to be compressed, the feature map data block to be compressed is used as the compressed data packet.

12. The method according to claim 11, characterized in that The compressed data packet also includes time data; the time data indicates the time for processing the feature map data block to be compressed; the time data is used to calculate the actual size of the compressed data packet.

13. The method according to claim 1, characterized in that The compressed data packet further includes identification data; the identification data indicates whether the compressed data packet is compressed.

14. A data compression device, characterized in that: include: An acquisition module, used for acquiring a feature map data block to be compressed; The feature map data block to be compressed is a part of the feature map data stream to be compressed; An identification module, used for identifying the feature map data block to be compressed, and obtaining non-zero feature map data; A first encoding module, used for encoding the feature map data block to be compressed based on a preset rule to obtain a first encoding result; A second encoding module, used for encoding the non-zero feature map data based on a target encoding method to obtain a second encoding result; The target encoding method is obtained by searching a first preset encoding table based on the target data type; The target data type is determined based on a continuous state of a preset value in the non-zero feature map data; The target encoding mode indicates the target data type, the continuous state and the target encoding length; The first preset coding table includes at least two optional coding modes; each of the optional coding modes includes an optional data type and an optional coding method; each of the optional coding methods includes an optional coding length and an optional coding value; The target encoding mode is one of the optional encoding modes; The encoding of the non-zero feature map data based on the target encoding method to obtain a second encoding result includes: for a group of non-zero data, the group of non-zero data includes a plurality of the non-zero data; Performing difference processing on each of the non-zero data to obtain a target difference sequence; Transposing the target difference sequence to obtain a target transposed sequence; Performing XOR processing on the target transposed sequence to obtain a target XOR sequence; Determining the target data type of the target XOR sequence; Based on the target data type, searching the first preset coding table to obtain the target coding mode and target coding length; Encode a group of the non-zero data based on the target encoding mode and the target encoding length to obtain a plurality of non-zero encoded data; The determining the target data type of the target XOR sequence includes: When there are continuous preset values ​​in the target XOR sequence, the target data type of the preset values ​​is the first data type; the first data type is one of the optional data types; the target data type of the remaining target XOR values ​​in the target XOR sequence is the second data type or the third data type; or When there is only one preset value in the target XOR sequence, the target data type of the preset value is the second data type; the second data type is one of the optional data types; the target data types of the remaining target XOR values ​​in the target XOR sequence are the third data type; or When there are no consecutive preset values ​​in the target XOR sequence, and there are multiple preset values, the target data type of each target XOR value is the third data type; the third data type is one of the optional data types; A merging module is used to merge the first encoding result and the second encoding result to obtain a compressed data packet.

15. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory is used to store at least one program, and the at least one program is loaded by the processor and executes the data compression method according to any one of claims 1 to 13.

16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one program, and the at least one program is loaded and executed by a processor to implement the data compression method according to any one of claims 1 to 13.

Citation Information

Patent Citations

  • Neural network processing device and method, and storage medium

    CN117291238A