Data compression method and device, equipment and storage medium
By simplifying the data compression method of non-zero data encoding, the problem of excessive hardware power consumption in the EBPC method is solved, and more efficient hardware implementation and performance improvement are achieved.
Patent Information
- Application Number
- CN202510272172.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-10
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2045-03-10
AI Technical Summary
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.
A data compression method is proposed, by obtaining the feature map data block to be compressed, identifying non-zero feature map data, and encoding it based on preset rules and target encoding methods, and combining the encoding results to generate a compressed data packet. This method simplifies the encoding process of non-zero data and reduces hardware power consumption.
By simplifying the encoding process of non-zero data, hardware power consumption is reduced, hardware implementation efficiency and performance are improved, and data bloat problem is avoided.
Smart Images

Figure CN119815032A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data compression method, device, equipment 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 continuity. It is a lightweight compression algorithm. It is currently mainly used to compress 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] The 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: According to a first aspect of an embodiment of the present application, a data compression method is provided, the method comprising: Acquire 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 to obtain a first encoding result; The non-zero feature map data is encoded 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 a 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 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; The first encoding result and the second encoding result are combined to obtain a compressed data packet.
[0005] In a possible implementation, 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.
[0006] In a possible implementation manner, 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 the first encoded data.
[0007] In a possible implementation, encoding the non-zero feature map data based on the target encoding mode to obtain a second encoding result includes: For a group of the non-zero data, the group of the 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; A group of the non-zero data is encoded based on the target encoding mode and the target encoding length to obtain a plurality of non-zero encoded data.
[0008] In a possible implementation, 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.
[0009] In a possible implementation manner, 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 type of the remaining target XOR values in the target XOR sequence is the third data type; or When there are no continuous 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; and the third data type is one of the optional data types.
[0010] In a possible implementation, 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.
[0011] In a possible implementation, 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.
[0012] In a possible implementation manner, searching a second preset coding table based on the preset bit value to obtain a continuous number further includes: Obtaining a third continuous number; the third continuous number indicates a portion of the preset bit values in the first group of preset bit values and a portion of the preset bit values in the second group of preset bit values; a portion of the preset bit values in the first group of preset bit values and a portion of the preset bit values in the second group of preset bit values are continuous; In a possible implementation, 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 Encode each of the preset values of the second continuous number based on the first encoding method to obtain a plurality of the non-zero encoded data; each of the non-zero encoded data includes the second identification encoding value and the 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.
[0013] In a possible implementation, 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, searching 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; 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 second encoding value indicates the position of the preset value in the target XOR sequence.
[0014] In a possible implementation, 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.
[0015] In a possible implementation, the method further includes: 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.
[0016] In a possible implementation, the compressed data packet further includes time data; the time data indicates the time for processing the feature map data block to be compressed; and the time data is used to calculate the actual size of the compressed data packet.
[0017] In a possible implementation, the compressed data packet further includes identification data; the identification data indicates whether the compressed data packet is compressed.
[0018] According to a second aspect of an embodiment of the present application, a data compression device is provided, the device comprising: 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 a 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 is used 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 searching a first preset encoding table based on a 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 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; A merging module is used to merge the first encoding result and the second encoding result to obtain a compressed data packet.
[0019] According to a third aspect of an embodiment of the present application, a computer device is provided, comprising 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 a data compression method.
[0020] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, in which at least one program is stored. The at least one program is loaded by a processor and executes a data compression method.
[0021] In an embodiment of the present application, an embodiment of the present application provides a data compression method, which divides a feature map data stream to be compressed into a plurality of feature map data blocks to be compressed, and compresses the plurality of feature map data blocks to be compressed one by one, which is more conducive to upper layer applications. In addition, an embodiment of the present application encodes 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, thereby facilitating table lookup operations, and thus easily meeting hardware timing, and also facilitating decompression. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 is a schematic diagram of an implementation environment provided according to an embodiment of the present application; Figure 2 It is a type of EBPC in the related art; Figure 3 It is a coding table in the related art; Figure 4 is a flow chart of a data compression method provided according to an embodiment of the present application; Figure 5 is a flow chart of step 404 provided according to an embodiment of the present application; Figure 6 is a schematic diagram of a first preset coding table provided according to an embodiment of the present application; Figure 7 is a flowchart of step 4045 provided according to an embodiment of the present application; Figure 8 is a flowchart of step 40452 provided according to an embodiment of the present application; Fig. 9 is a schematic diagram of a second preset coding table provided according to an embodiment of the present application; Fig.10 is a schematic diagram of the format of a first compressed data packet provided according to an embodiment of the present application; Fig.11 is a schematic diagram of the format of a second compressed data packet provided according to an embodiment of the present application; Fig.12 It is a schematic diagram of the effect in the first application scenario provided by the embodiment of the present application; Fig.13is a schematic diagram of the effect in the second application scenario provided by the embodiment of the present application; Fig.14 is a structural schematic diagram of a data compression device provided according to an embodiment of the present application; Fig.15 is a schematic diagram of the structure of a terminal provided according to an embodiment of the present application; Fig.16 It is a structural diagram of a server provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0025] Here, exemplary embodiments are described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application.
[0026] In this application, the terms "first", "second", etc. are used to distinguish between identical or similar items with substantially the same effects and functions. It should be understood that there is no logical or temporal dependency between "first", "second", and "nth", nor is there a limitation on the quantity and execution order. It should also be understood that although the following description uses the terms first, second, etc. to describe various elements, these elements should not be limited by the terms.
[0027] These terms are only used to distinguish one element from another element. For example, without departing from the scope of various examples, a first action can be referred to as a second action, and similarly, a second action can also be referred to as a first action. Both the first action and the second action can be actions, and in some cases, can be separate and different actions.
[0028] Here, at least one means one or more than one, for example, at least one action can be one action, two actions, three actions, or any other action that is an 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, or any other action that is an integer greater than or equal to two.
[0029] Figure 1 It is a schematic diagram of an implementation environment provided according to an embodiment of the present application, and the implementation environment may include a terminal 101 and a server 102.
[0030] The terminal 101 is provided with a data compression device. The data compression device is a hardware structure and can be used to compress feature map data.
[0031] The terminal 101 may be a smart phone 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.
[0032] The server 102 may be a single server, a server cluster consisting of multiple servers, or a cloud processing center.
[0033] The terminal 101 is connected to the server 102 via a wired or wireless network.
[0034] In some embodiments, the wireless network or wired network uses standard communication technology and / or protocol. The network is usually the Internet, but it can also be any network, including but not limited to any combination of local area network (LAN), metropolitan area network (MAN), wide area network (WAN), mobile, wired or wireless network, private network or virtual private network. In some embodiments, the data exchanged through the network is represented by technology and / or format including Hyper Text Mark-up Language (HTML), Extensible Markup Language (XML), etc. In addition, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Network (VPN), Internet Protocol Security (IPsec) can also be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technology can also be used to replace or supplement the above data communication technology.
[0035] Figure 2 It is a kind of EBPC in the related technology.
[0036] like Figure 2 As shown in the figure, the feature map data stream to be compressed is obtained, and EBPC independently encodes the zero data based on Zero-RLE (Zero Run Length Encoding). For the non-zero data, differential transposition is performed and the obtained result is encoded. The compression result of the zero data and the non-zero data is used as a compressed data packet to obtain a compressed bit stream.
[0037] Figure 3It is a coding table in the related technology.
[0038] like Figure 3 As shown in Figure 2, multiple encoding modes are used when encoding non-zero data. Figure 3 The terms in the table 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.
[0039] In the related art, encoding is performed in the form of a data stream of unlimited length, which is not conducive to upper-layer applications. There are too many encoding modes for non-zero data, which leads to high hardware power consumption, poor performance and large hardware area. In addition, after the 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.
[0040] In order to solve the above technical problems, an embodiment of the present application provides a data compression method.
[0041] Figure 4 is a flow chart of a data compression method provided according to an embodiment of the present application, such as Figure 4 As shown, in the embodiment of the present application, the application is described by taking the application on a terminal having a data compression device as an example. The method comprises the following steps: In step 401, the terminal obtains a feature map data block to be compressed.
[0042] The feature map data block to be compressed is a part of the feature map data stream to be compressed.
[0043] In some embodiments, the terminal divides the feature map data stream to be compressed into multiple feature map data blocks to be compressed during the process of compressing the feature map data block to be compressed. Optionally, the terminal compresses one feature map data block to be compressed each time to obtain a compression result. Until the last feature map data block to be compressed is compressed. This is more conducive to upper-layer applications. For example: the size of each feature map data block to be compressed is 1KB (1024B), where B represents bytes. It should be noted that each feature map data block to be compressed includes a header, and the size of the header is 8B. Therefore, the actual size of the data included in each feature map data block to be compressed is 1016B. When the size of the data in the last feature map data block to be compressed does not meet 1016B, it is supplemented with "1".
[0044] In some embodiments, each feature map data block to be compressed includes a plurality of non-zero data and a plurality of zero data. For example, the terminal obtains 64 bits of data in each clock cycle. The size of each non-zero data is 8 bits. The size of each zero data is also 8 bits.
[0045] In step 402, the terminal identifies the feature map data block to be compressed and obtains non-zero feature map data.
[0046] In some embodiments, the feature map data block to be compressed includes zero feature map data; zero feature map data includes multiple zero data; non-zero feature map data includes multiple non-zero data. Optionally, the terminal determines whether the data is non-zero data each time it obtains a data, and if the data is non-zero data, the non-zero data is filtered out. In this way, the non-zero feature map data is filtered out from the image data block to be compressed, so that the non-zero feature map data can be compressed separately later.
[0047] In some embodiments, after obtaining 64-bit data, the terminal determines whether each data is all 0. If all are 0, the data is regarded as zero data. Or if not all are 0, the data is regarded as non-zero data. For example, "00000000" is a zero data; "01000100" is a non-zero data.
[0048] In step 403, the terminal encodes the feature map data block to be compressed based on a preset rule to obtain a first encoding result.
[0049] 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, which only compresses zero data, 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.
[0050] In some embodiments, the above step 403 may be implemented as follows: 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; multiple first values and multiple second values are used as first encoded data. Among them, each data in the zero data is 0. There is non-0 data in the non-zero data. That is, the preset rule can be understood as encoding each zero data as a first value and encoding each non-zero data as a second value. That is, in step 403, the terminal not only compresses the non-zero data, but also compresses the zero data. For example: use the ZVC (Zero-value compression) mode to compress non-zero data and zero data. ZVC is a coding mode. It should be noted that in step 403, the non-zero data is compressed. This 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 scope of protection of this application. Therefore, the decompression process is not described in detail.
[0051] In one example, the terminal compresses multiple zero data per clock cycle. For example, the size of each zero data is 8 bits. The size of each non-zero data is 8 bits. A 64-bit feature map data stream to be compressed is processed each time. That is, the terminal compresses 8 non-zero data per clock cycle. Or the terminal compresses 8 zero data per clock cycle. Or the sum of the number of non-zero data and the number of zero data compressed by the terminal per clock cycle is 8. One zero data includes 8 "0s". One non-zero data includes at least one "1".
[0052] In one example, when a terminal obtains a zero data, the zero data is encoded as a first value. The first value has only one bit. That is, the terminal encodes in bytes. Or when a terminal obtains a non-zero data, the non-zero data is encoded as 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, thereby achieving compression. For example: the first value is "1". The second value is "0".
[0053] It can be understood that the encoding length of the first encoding result is fixed.
[0054] In step 404, the terminal encodes the non-zero feature map data based on the target encoding method to obtain a second encoding result.
[0055] It should be noted that the embodiments of the present application do not limit the execution sequence of step 404 and step 403.
[0056] In some embodiments, the target encoding method is obtained by searching the 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, the continuous state and the 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.
[0057] Figure 5 It is a flowchart of step 404 provided according to an embodiment of the present application.
[0058] Combine the following Figure 5 Step 404 is exemplarily described.
[0059] In some embodiments, the above step 404 includes the following steps 4041 to 4046: In step 4041, the terminal targets a group of non-zero data, where the group of non-zero data includes a plurality of non-zero data.
[0060] In some embodiments, the terminal performs difference processing on each non-zero data to obtain a target difference sequence.
[0061] In one example, the terminal processes a group of non-zero data per clock cycle. The group of non-zero data includes 8 non-zero data. The target difference sequence includes multiple target differences. The target difference corresponds 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 feature map data block to be compressed is less than 8 bits, it is supplemented with "1". Optionally, if the group of non-zero data is the first group of non-zero data of non-zero feature map data, the first target difference of the target difference sequence is the first non-zero data. That is, the non-zero feature map data are independent of each other, and the second encoding 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, a 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 value of the target difference value 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.
[0062] For example: W[i] represents the i-th non-zero data, then a set of non-zero data can be expressed as: {W[0],…W[i],…W[7]}.
[0063] D[i] represents the i-th target difference, so a target difference sequence can be expressed as: {D[0],…D[i],…D[7]}.
[0064] 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.
[0065] In step 4042, the terminal transposes the target difference sequence to obtain a target transposed sequence.
[0066] Among them, the target transposition sequence includes 8 target transpositions.
[0067] In one example, the i-th target transposition is explained. 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]}.
[0068] In step 4043, the terminal performs XOR processing on the target transposed sequence to obtain a target XOR sequence.
[0069] The target XOR sequence includes 8 target XOR values.
[0070] In an example, the i-th target XOR value is explained. The i-th target XOR value is the result of XOR calculation of each i-th target transposition and the i+1-th target transposition. For example: the i-th target XOR 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.
[0071] In step 4044, the terminal determines the target data type of the target XOR sequence.
[0072] Figure 6 It is a schematic diagram of a first preset coding table provided according to an embodiment of the present application.
[0073] Combine the following Figure 6 Step 4044 is exemplarily described.
[0074] In some embodiments, the first preset coding table includes three 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.
[0075] 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.
[0076] In some embodiments, the above step 4044 can be implemented in the following ways: The first implementation method: 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. Optionally, the continuous preset values in the target XOR sequence are encoded according to the first encoding method. Optionally, if there is only one preset value in the remaining target XOR values, the preset value is encoded according to the second encoding method. Optionally, if there are at least two discontinuous preset values in 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, DBX[i] is a preset value. When DBX[0] and DBX[1] in the target XOR sequence are both 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 in DBX[2] to DBX[7], the preset value is encoded according to the second encoding method. Or if there are at least two discontinuous preset values in DBX[2] to DBX[7], each target XOR value in DBX[2] to DBX[7] is encoded according to the third encoding method.
[0077] The second implementation method: 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 type of the remaining target XOR values in the target XOR sequence is the third data type. That is, only one target XOR value in the target XOR sequence has all 8 bits of 0. For example: When only DBX[0] is the preset value in the target XOR sequence, DBX[0] is the second data type. If there are at least two discontinuous preset values in DBX[1] to DBX[7], each target XOR value in DBX[1] to DBX[7] is encoded according to the third encoding method.
[0078] The third implementation method: 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. That is, there are no consecutive preset values in the target XOR sequence, and at least two target XOR values have 8 bits that are all 0.
[0079] In step 4045, the terminal searches the first preset coding table based on the target data type to obtain the target coding method and the target coding length.
[0080] Figure 7 It is a flowchart of step 4045 provided according to an embodiment of the present application.
[0081] Combine the following Figure 7 Step 4045 is exemplarily described.
[0082] In some embodiments, the above step 4045 can be implemented by the following steps 40451 to 40454: In step 40451, when the target data type of the preset value is the first data type, the terminal encodes the target XOR value corresponding to the preset value into a preset bit value.
[0083] In some embodiments, when there are continuous preset values in the target XOR sequence, the terminal determines that the target data type of each preset value is the first data type. Each target XOR value is then encoded as a preset bit value. For example: the preset bit value is represented by "1" or "0". The target XOR value of all 8 bits being 0 is encoded as "1"; the target XOR value of not all 8 bits being 0 is encoded as "0". For another example: a target XOR sequence can be represented as {1, 1, 0, 0, 0, 0, 0} after encoding. For another example: a target XOR sequence can be represented as {1, 1, 0, 1, 0, 0, 1, 0} after encoding.
[0084] In step 40452, the terminal searches the second preset coding table based on the preset bit value to obtain a continuous number.
[0085] The continuous number is the number of continuous preset bit values.
[0086] Figure 8 It is a flowchart of step 40452 provided according to an embodiment of the present application.
[0087] Combine the following Figure 8 Step 40452 is illustratively described.
[0088] In some embodiments, the above step 40452 includes the following steps 404521 and 404522: In step 404521, the terminal divides 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.
[0089] In some embodiments, the first group of preset bit values is a preset bit value of a high bit; the second group of preset bit values is a preset bit value of a low bit. For example, {1, 1, 0, 1, 0, 0, 1, 0} is divided into a first group of preset bit values and a second group of preset bit values. The first group of preset bit values is {1, 1, 0, 1}. The second group of preset bit values is {0, 0, 1, 0}.
[0090] Fig. 9 It is a schematic diagram of a second preset coding table provided according to an embodiment of the present application.
[0091] Combine the following Fig. 9 The second preset coding table is exemplified.
[0092] In step 404522, the terminal obtains the first continuous number and the second continuous number.
[0093] In some embodiments, the first continuous number indicates the number of continuous preset bit values in the first set of preset bit values; the second continuous number indicates the number of continuous preset bit values in the second set of preset bit values. For example, the first continuous number corresponding to the first set of preset bit values {1, 1, 0, 1} is 2. The second continuous number corresponding to the second set of preset bit values {0, 0, 1, 0} is 0.
[0094] In one example, the run-length coding in the BPC encoder is implemented by searching a second preset coding table. Specifically, a second preset coding table is searched based on the first set of preset bit values; and at the same time, the terminal searches another second preset coding table based on the second set of preset bit values. Figure 8In the figure, the first column on the left of “=” is the input of the first set of preset bit values. The multiple arrays in the four columns on the right of “=” are used to represent the search results, that is, the number of consecutive preset values. Each array on the right of “=” corresponds to a bit in the leftmost column of “=”. For example, when the value of an array is 15, it means that the bits in front of the corresponding bit are continuous and have been merged, and the bit is an invalid bit. When the value of an array is 1, it means that the corresponding bit is independent. If the value of an array is not 1 and 15, it indicates the number of consecutive preset values. For example: Figure 8 Take the last line in the 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 invalid bits. Therefore, the "4'b1111" on the left side of "=" indicates that the first consecutive number is 4.
[0095] In some embodiments, there may also be continuous preset values between the first set of preset bit values and the second set of preset bit values. In order to solve this problem, the above step 40452 also includes: after searching the second preset coding table, the terminal obtains a third continuous number; the third continuous number 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 continuous. Thereby, the first continuous number and the second continuous number are corrected. For example: {1, 1, 0, 1, 1, 1, 0, 0} After searching the second preset coding table, the first continuous number is 2, the second continuous number is 0, and the third continuous number is 2.
[0096] In step 40453, the terminal searches for a first preset coding table based on the first data type to obtain a first coding method.
[0097] The first encoding method is one of the optional encoding methods.
[0098] In step 40454, the terminal encodes each preset value based on the first encoding method and the continuous number to obtain multiple non-zero encoded data.
[0099] Among them, the non-zero coded data corresponds to the preset value one by one.
[0100] In some embodiments, the above step 40454 can be implemented as follows: The first implementation method: the terminal encodes each preset value of the first continuous number based on the first coding method to obtain multiple non-zero coded data; each non-zero coded data includes a first identification coding value and a first coding value; the first coding value indicates the first continuous number; the first identification coding value indicates the first data type. For example: the first continuous number corresponding to the first group of preset bit values {1, 1, 0, 1} is 2. The second continuous number corresponding to the second group 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 coded data. Each non-zero coded data includes data: the first identification coding value + the first coding value.
[0101] The second implementation method: The terminal encodes each preset value of the second continuous quantity based on the first encoding method to obtain multiple non-zero encoded data. The non-zero encoded data includes a second identification encoding value and a second encoding value; the second encoding value indicates the second continuous quantity; the second identification encoding value indicates the first data type. The first continuous quantity corresponding to the first group of preset bit values {0, 0, 0, 1} is 0. The second continuous quantity corresponding to the second group 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 continuous quantity. There is no need to indicate the first continuous quantity. That is, the non-encoded data includes: the second identification encoding value + the second encoding value.
[0102] The third implementation method: The terminal encodes each preset value of the third continuous quantity based on the first encoding method to obtain multiple non-zero encoded data. The non-zero encoded data includes a third identification encoding value and a third encoding value; the third encoding value indicates the third continuous quantity; the third identification encoding value indicates the first data type. The first continuous quantity corresponding to the first group of preset bit values {0, 0, 0, 1} is 0. The second continuous quantity corresponding to the second group of preset bit values {1, 0, 0, 0} is 0. The corresponding third continuous quantity is 2. Then the non-zero encoded data only needs to indicate the first data type and the third continuous quantity. There is no need to indicate the first continuous quantity and the second continuous quantity. That is, the non-encoded data includes: the third identification encoding value + the third encoding value.
[0103] In some embodiments, the above step 4045 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 coding method to obtain 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 XOR sequence. For example: only 8 bits of DBX[1] are all 0. The fourth coding value indicates the second position.
[0104] In some embodiments, the above step 4045 further includes: For a target XOR value, when the target data type of the target XOR value is the third data type, the first preset coding table is searched 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 coding method to obtain non-zero coded data; each non-zero coded data includes a fifth identification code value and a target XOR value. The non-zero coded data is the fifth identification code value+DBX[i].
[0105] In step 4046, the terminal encodes a group of non-zero data based on the target encoding method and the target encoding length to obtain multiple non-zero encoded data.
[0106] It is understandable that, since the non-zero data is encoded based on the first preset encoding table, the lengths of the non-zero encoded data corresponding to different non-zero data after encoding may be different, for example: 5 bits or 9 bits. That is, the encoding length of the second encoding result is not fixed.
[0107] In step 405, the terminal combines the first encoding result and the second encoding result to obtain a compressed data packet.
[0108] In some embodiments, the terminal concatenates and encapsulates the first encoding result and the second encoding result corresponding to each feature map data block to be compressed to obtain a compressed data packet.
[0109] In some embodiments, the method further includes: if the actual size of the compressed data packet is larger than the initial size of the feature map data block to be compressed, then using the feature map data block to be compressed as the compressed data packet.
[0110] In one example, when compressing a feature map data block to be compressed, the terminal caches the feature map data block to be compressed. 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 terminal obtains the feature map data block to be compressed from the cache and outputs the feature map data block to be compressed as a compressed data packet. This solves the problem of compressed data expansion.
[0111] It should be noted that the embodiments of the present application do not limit the size of the cache.
[0112] Fig.10 It is a schematic diagram of the format of the first compressed data packet provided according to an embodiment of the present application.
[0113] Combine the following Fig.10 An exemplary description is given of a compressed data packet.
[0114] In some embodiments, 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.
[0115] In one example, the time data includes a clock cycle for starting to process the feature map data block to be compressed and a clock cycle for ending to process the feature map data block to be compressed.
[0116] In some embodiments, the compressed data packet further includes identification data; the identification data indicates whether the compressed data packet is compressed.
[0117] 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 encoding result; and the offset and length of the second encoding result. For example: the offset address of the identification data is "0" and the length is 1B. The offset address of the first encoding result is "1" and the length is 127B. The offset address of the second encoding result is "128" and the length is 8B to 896B. In addition, the compressed data packet also includes 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 to sixth bits in the identification data are time data. For the first encoding result, when the bit value is "1", it indicates non-zero data. When the bit value is "0", it indicates zero data. For the second encoding result, the length changes dynamically, that is, it is not fixed.
[0118] Fig.11 It is a schematic diagram of the format of a second compressed data packet provided according to an embodiment of the present application.
[0119] Combine the following Fig.11 An exemplary description is given of a compressed data packet.
[0120] 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 encoding result is "1" and the length is 7B. The offset address of the second encoding result is "8" and the length is 8B to 1016B. In addition, the compressed data packet also includes 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 to the 6th bits in the identification data are time data. For zero feature map data, all are "0". For non-zero feature map data, only the length of the last feature map data block to be compressed may be less than 1016B.
[0121] Fig.12 It is a schematic diagram of the effect under the first application scenario provided according to the embodiment of the present application.
[0122] Fig.12 It is the compression effect of each layer of feature map in the yolov3 (You Only Look Once version 3) model.
[0123] Fig.13 It is a schematic diagram of the effect under the second application scenario provided according to the embodiment of the present application.
[0124] Fig.13 This is the compression effect of each layer of feature maps in the pmnp model, where pmnp is an AI model.
[0125] Combination Fig.11 as well as Fig.12 From the compression effect, it can be known that, under the premise of satisfying the compression rate, the embodiment of the present application can compress data in each clock cycle, thereby achieving continuous compression and improving the compression efficiency.
[0126] In the embodiment 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 belongs to lightweight compression. The compression input has a full bandwidth of up to 6.4GBps, and no bandwidth is wasted; the compression speed is fast, the delay is small, the performance is good, and it is more conducive to upper-layer applications. In addition, the embodiment of the present application encodes 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, and then it is easy to meet the hardware timing, and it is also convenient for decompression.
[0127] Fig.14 1 is a schematic diagram of a data compression device 1400 provided according to an embodiment of the present application, the device comprising: The acquisition module 1401 is used to acquire the 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.
[0128] The identification module 1402 is used to identify the feature map data block to be compressed and obtain non-zero feature map data.
[0129] The first encoding module 1403 is used to encode the feature map data block to be compressed based on a preset rule to obtain a first encoding result.
[0130] The second encoding module 1404 is used to encode the non-zero feature map data based on the target encoding method to obtain a second encoding result; the target encoding method is obtained by searching the 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, the continuous state and the 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.
[0131] The merging module 1405 is used to merge the first encoding result and the second encoding result to obtain a compressed data packet.
[0132] It should be noted that the acquisition module 1401 , the identification module 1402 , the first encoding module 1403 , the second encoding module 1404 and the merging module 1405 are all hardware.
[0133] In some embodiments, 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.
[0134] In some embodiments, the apparatus is further configured to: 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; A plurality of first values and a plurality of second values are used as first encoded data.
[0135] In some embodiments, the apparatus is further configured to: For a set of non-zero data, the set of non-zero data includes a plurality of non-zero data; Perform difference processing on each non-zero data to obtain the target difference sequence; Transpose the target difference sequence to obtain a target transposed sequence; Perform XOR processing on the target transposed sequence to obtain the target XOR sequence; Determine 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 the target coding length; A group of non-zero data is encoded based on a target encoding method and a target encoding length to obtain a plurality of non-zero encoded data.
[0136] 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 coding length.
[0137] In some embodiments, the apparatus is further configured to: 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 type of the remaining target XOR values in the target XOR sequence is the third data type; or When there are no continuous 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.
[0138] In some embodiments, the apparatus is further configured to: 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 the second preset coding table based on the multiple preset bit values to obtain a continuous number; the continuous number is the number of continuous preset bit values; Searching 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; Based on the first encoding method and the continuous number encoding each preset value, a plurality of non-zero encoded data are obtained; the non-zero encoded data correspond to the preset values one by one.
[0139] In some embodiments, the apparatus is further configured to: 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 preset bit values of high bits; the second group of preset bit values are preset bit values of low bits; A first continuous number and a second continuous number are obtained; 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.
[0140] In some embodiments, the apparatus is further configured to: Obtaining a third continuous number; the third continuous number indicates a portion of the preset bit values in the first group of preset bit values and a portion of the preset bit values in the second group of preset bit values; a portion of the preset bit values in the first group of preset bit values and a portion of the preset bit values in the second group of preset bit values are continuous; In some embodiments, the apparatus is further configured to: Encode each preset value of the first continuous number based on the first encoding method to obtain a plurality of non-zero encoded data; each 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 Encode each preset value of the second continuous number based on the first encoding method to obtain a plurality of non-zero encoded data; each non-zero encoded data includes a second identification encoding value and a second encoding value; the second encoding value indicates the second continuous number; and 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 multiple non-zero encoded data; each 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.
[0141] In some embodiments, the apparatus is further configured to: 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 non-zero encoded data; the non-zero encoded data includes a fourth identification encoding value and a fourth encoding value; the second encoding value indicates the position of the preset value in the target XOR sequence.
[0142] In some embodiments, the apparatus is further configured to: For a target XOR value, when the target data type of the target XOR value is a 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 non-zero encoded data; the non-zero encoded data includes the fifth identification encoding value and a target XOR value.
[0143] In some embodiments, the apparatus is further configured to: 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.
[0144] In some embodiments, 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.
[0145] In some embodiments, the compressed data packet further includes identification data; the identification data indicates whether the compressed data packet is compressed.
[0146] It should be noted that: when the data compression device provided in the above embodiment performs the corresponding steps, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, 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 embodiment and the data compression method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0147] In the embodiment of the present application, the feature map data stream to be compressed is divided into a plurality of feature map data blocks to be compressed, and the plurality of feature map data blocks to be compressed are compressed one by one, which is more conducive to upper layer applications. In addition, the embodiment of the present application encodes the non-zero feature map data based on the 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, thereby facilitating the table lookup operation, and thus easily meeting the hardware timing, and also facilitating the implementation of decompression.
[0148] An embodiment of the present application further provides a computer device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, and the processor implements the above method when executing the computer program.
[0149] Taking computer equipment as the terminal as an example, Fig.15 This is a schematic diagram of the structure of a terminal provided in an embodiment of the present application, see Fig.15 The terminal 1500 may be a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 player (Moving Picture Experts Group Audio Layer IV), a laptop computer, or a desktop computer. The terminal 1500 may also be called a user device, a portable terminal, a laptop terminal, a desktop terminal, or other names.
[0150] Typically, the terminal 1500 includes a processor 1501 and a memory 1502 .
[0151] The processor 1501 may include one or more processing cores, such as a 4-core processor, a 5-core processor, etc. The processor 1501 may be implemented in at least one hardware form of 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 awake state, also known as a 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), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1501 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0152] The memory 1502 may include one or more computer-readable storage media, which may be non-transitory. The memory 1502 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 1502 is used to store at least one program code, which is used to be executed by the processor 1501 to implement the process provided by the method embodiment of the present application for the terminal execution in the above method.
[0153] 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 via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 1503 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a display screen 1504, a camera assembly 1505, an audio circuit 1506 and a power supply 1507.
[0154] The peripheral device interface 1503 can be used to connect at least one peripheral device related to I / O (Input / Output) 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, which is not limited in the embodiments of the present application.
[0155] 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 the surface or above the surface of the display screen 1504. The touch signal can be input to the processor 1501 as a control signal for processing. At this time, the display screen 1504 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 1504 can be one, set on the front panel of the terminal 1500; in other embodiments, the display screen 1504 can be at least two, respectively set on different surfaces of the terminal 1500 or in a folding design; in other embodiments, the display screen 1504 can be a flexible display screen, set on the curved surface or folding surface of the terminal 1500. Even, the display screen 1504 can also be set as a non-rectangular irregular figure, that is, a special-shaped screen. The display screen 1504 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0156] The camera assembly 1505 is used to capture images or videos. In some embodiments, the camera assembly 1505 includes a front camera and a rear camera. Typically, the front camera is disposed on the front panel of the terminal, and the rear camera is disposed on the back of the terminal. In some embodiments, there are at least two rear cameras, which are one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 1505 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0157] The audio circuit 1506 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 1501 for processing. For the purpose of stereo acquisition 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 acquisition microphone. The speaker is used to convert the electrical signal from the processor 1501 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 1506 may also include a headphone jack.
[0158] The power supply 1507 is used to power various components in the terminal 1500. The power supply 1507 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 1507 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0159] Those skilled in the art will understand that Fig.15 The structure shown in the figure does not constitute a limitation on the terminal 1500, and the terminal 1500 may include more or less components than those shown in the figure, or combine some components, or adopt a different component arrangement.
[0160] Take the computer device as a server as an example. Fig.16 This is a schematic diagram of the structure of a server provided in an embodiment of the present application. The server 1600 may have relatively large differences due to different configurations or performances, and may include one or more processors (Central Processing Units, CPU) 1601 and one or more memories 1602, wherein the one or more memories 1602 store at least one computer program, 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 and output interface for input and output. The server 1600 may also include other components for implementing device functions, which will not be described in detail here.
[0161] The embodiment of the present application also provides a computer-readable storage medium, the computer-readable storage medium includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the above-mentioned method for generating an image processing model. Optionally, the computer-readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a compact disc (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, etc.
[0162] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0163] The above are only optional embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in 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 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 2, characterized in that: 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 the non-zero data, the group of the 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; A group of the non-zero data is encoded based on the target encoding mode and the target encoding length to obtain a plurality of non-zero encoded data.
5. The method according to claim 4, 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.
6. The method according to claim 4, characterized in that 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 continuous 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; and the third data type is one of the optional data types.
7. The method according to claim 6, 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.
8. The method according to claim 7, 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.
9. The method according to claim 8, 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.
10. The method according to claim 9, 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 Encode each of the preset values of the second continuous number based on the first encoding mode 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; and the second identification encoding value indicates the first data type; 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.
11. The method according to claim 6, 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, searching 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; 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 second encoding value indicates the position of the preset value in the target XOR sequence.
12. The method according to claim 6, 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.
13. 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.
14. The method according to claim 13, 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.
15. 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.
16. 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; A merging module is used to merge the first encoding result and the second encoding result to obtain a compressed data packet.
17. 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 15.
18. 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 15.
Citation Information
Patent Citations
Neural network processing device and method, and storage medium
CN117291238A
Method, device and equipment for decompressing data and method, device and equipment for compressing data
CN119582855A
Hierarchal encoding device and image decoding device
JP2005020384A
Method and apparatus for coding of spatial data
US20150078435A1
System and method for memory compression for deep learning networks
US20230131251A1