Binary neural network pruning compression and deployment optimization system and method
By introducing a regularization term with a decay factor and dynamic pruning, combined with a segmented PopCount lookup table and binary convolution max pooling fusion, the efficiency and stability issues in the deployment of binary neural networks are solved, achieving high efficiency in resource-constrained device adaptability and inference efficiency.
Patent Information
- Application Number
- CN202510758550.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-09
- Publication Date
- 2025-11-18
AI Technical Summary
In existing binary neural network deployment technologies, the software implementation efficiency of PopCount calculation is not high, it fails to effectively integrate binary max pooling and binary convolutional layers, the pruning rate improvement guided by the loss function leads to instability in the training process, and it depends on specific hardware during inference.
Training is performed using a regularization module with a decay factor, combined with runtime dynamic pruning and a segmented PopCount lookup table, and the binary convolution and max pooling calculations are integrated to optimize the deployment of the binary neural network.
It improves training stability and inference efficiency, adapts to resource-constrained devices, reduces redundant computation, supports multiple microcontrollers, and is compatible with binary neural network models of different structures.
Smart Images

Figure CN120975162A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of binary neural network optimization technology, and particularly relates to a binary neural network pruning, compression and deployment optimization system and method. Background Technology
[0002] With the development of artificial intelligence, deep neural networks (DNNs) have been widely used due to their superior performance in image classification, object detection, and other fields. However, deep learning models have high requirements for computing resources and storage space, limiting their application in resource-constrained scenarios. Existing technologies use quantization techniques to compress DNN models to reduce storage requirements. Binary Neural Networks (BNNs) are highly quantized network structures that achieve significant optimization effects by quantizing weights and intermediate activation values to +1 or -1. Their advantages are twofold: First, this network uses a 1-bit width representation, achieving up to 32 times the storage compression compared to full-precision networks using 32-bit floating-point numbers; second, since both weights and activation values are quantized to +1 or -1, the traditional 32-bit floating-point multiply-accumulate (MAC) operation can be replaced by efficient bitwise operations.
[0003] Since most deep learning models are implemented using Python training environments, and Python cannot support storing data in binary format or performing bitwise operations like C / C++, the binary weights in binary neural network models exported from Python, although numerically +1 or -1, are in float32 format, meaning each value still occupies 32 bits of space. In this case, the binary neural network does not truly store the weight parameters in binary format, nor can it perform binary matrix multiplication using bitwise operations in convolutional and fully connected layers, thus failing to fully realize the performance potential of binary neural networks.
[0004] To improve the performance of binary neural network models, some existing binary neural network deployment frameworks employ the bitpack method to compress weights and activation values. For example, they encode floating-point numbers of +1 or -1 as 0 or 1, and then pack every 32 encoded values into an int32 type data. Based on this, binary convolution calculations can be implemented using XOR operations and PopCount operations. PopCount, as a core component of binary convolution calculations, relies on the GCC compiler's built-in function __builtin_popcount to count the number of "1"s in the binary representation. When the hardware supports the PopCount instruction, such as on ARMv8-A architecture processors, __builtin_popcount directly maps to the hardware-level "cnt" and "addv" instructions, achieving efficient computation. When the hardware does not support the PopCount instruction, it degenerates into a compiler software implementation, resulting in lower computational efficiency. However, resource-constrained edge processors, such as the Cortex-M series, typically do not support the hardware PopCount instruction, limiting the practicality of binary neural networks in resource-constrained scenarios.
[0005] Full-precision neural networks use max pooling or average pooling operations to reduce feature map size. Binary neural networks, using only +1 and -1 (encoded as 0 and 1), are unsuitable for average pooling and typically use max pooling to reduce feature map size. However, max pooling in binary data degenerates into a simple "presence of 1" detection. For example, for a binary input window [1, -1, 1, 1], the max pooling result is 1. In existing technologies, before performing binary max pooling calculations, padding may cause coordinates to exceed limits, requiring boundary processing to ensure the filter does not exceed the input boundaries, leading to increased latency.
[0006] Furthermore, each convolutional or fully connected layer in a binary neural network is immediately followed by a batch normalization layer. When this is followed by a sign activation function, forming a structure of "binary convolutional layer - batch normalization layer - sign activation," the computation of this batch normalization layer can be simplified to a channel-by-channel threshold comparison operation. The multiplicative sum obtained from the binary convolution is compared with this threshold to determine the output value as +1 or -1. The multiplication and accumulation are performed incrementally; once the accumulation reaches a point where the output value can be determined, subsequent operations are unnecessary as they do not affect the output value. At this point, the related subsequent operations are redundant and can be pruned. By controlling the threshold to increase or decrease, the output value can be determined earlier, resulting in a higher pruning rate. Some studies have used specific loss functions to guide the network to update parameters in a direction that is conducive to improving the pruning rate; however, the introduction of regularization terms in these loss functions can cause instability in the training process, and the pruning operation during inference depends on specific hardware. Summary of the Invention
[0007] The purpose of this invention is to provide a binary neural network pruning compression and deployment optimization system and method to solve the technical problems of low software implementation efficiency of PopCount calculation in existing binary neural network deployment technologies, lack of consideration for the fusion of binary max pooling and binary convolutional layers, instability of the training process caused by existing loss functions that guide the improvement of pruning rate, and reliance on custom hardware implementation for pruning operations during inference.
[0008] To address the aforementioned technical problems, the specific technical solution of the binary neural network pruning, compression, and deployment optimization system and method of the present invention is as follows:
[0009] A binary neural network pruning, compression, and deployment optimization system includes a regularization module with a decay factor during training, a binary convolution runtime pruning module, a PopCount lookup table module, and a binary convolution and binary max pooling fusion calculation module during deployment and inference. The regularization module with the decay factor is used for binary neural network pruning training; the binary convolution runtime pruning module is used for binary neural network inference on the edge computing device; the PopCount lookup table module is used for binary neural network inference on the edge computing device; and the binary convolution and binary max pooling fusion calculation module is used for binary neural network inference on the edge computing device.
[0010] This invention also discloses an optimization method for a binary neural network pruning, compression, and deployment optimization system, comprising the following steps:
[0011] Step 1: Perform binary neural network pruning training using a regularization term with a decay factor;
[0012] Step 2: Use a binary convolution optimization method based on runtime dynamic pruning for inference in the binary neural network on the edge computing device;
[0013] Step 3: Use the Popcount calculation method based on a segmented lookup table to perform binary neural network inference in the edge computing device;
[0014] Step 4: Use binary convolution and binary max pooling to fuse the padding information of binary max pooling into the data output stage of binary convolution for binary neural network inference in the edge computing device, reduce boundary checks and judgments, and improve computational efficiency.
[0015] Furthermore, step 1 includes the following steps:
[0016] The formula for calculating the regularization term is as follows:
[0017]
[0018] The above formula illustrates the calculation process of the regularization term for a single binary convolutional layer. The overall regularization term is obtained by accumulating the regularization terms of each binary convolutional layer, where y... i T i These are the convolutional sum and the threshold, respectively. N = oH × oW × channel_out, representing the sum and number of output sums, oH and oW are the height and width of the output feature map, and channel_out is the number of output channels. L = kH × kW × channel_in, representing the length of the accumulation vector, kH and kW are the height and width of the convolutional kernel, and channel_in is the number of input channels. The output sum reaches its maximum value, i.e., the upper limit L, when all elements in the sum and number of output sums are 1.
[0019] Where λ is the dynamic decay factor, and the formula is as follows:
[0020] λ=λ0×Max{0,tanh(-50(vv max ))}
[0021] λ is the product of an initial scalar value λ0 and a piecewise function constructed with a Max term, where tanh in the Max term is a nonlinear function used to calculate the product of v and v. max The difference is adjusted by the regularization coefficient. As training progresses, the threshold distribution moves closer to both sides of the interval [0, L], and the value of v gradually increases. When v exceeds the preset hyperparameter v max When the tanh term is negative, the Max term is 0, λ equals 0, and the regularization term is invalid.
[0022] Where v is a statistical indicator used to measure the distribution of thresholds, and the calculation formula is as follows:
[0023]
[0024] By introducing a regularization term into the original network's loss function, a new loss function is obtained as shown in the formula:
[0025] loss = loss network +R threshold .
[0026] Furthermore, the calculation method for dynamic pruning during binary convolution in step 2 includes:
[0027] Step 2.1: Initialize convolution parameters;
[0028] Step 2.2: Construct a seven-level nested loop structure;
[0029] Step 2.3: Perform dynamic pruning in the innermost loop of the channel dimension;
[0030] Step 2.4: Generate a binary output based on the final accumulated value.
[0031] Furthermore, the convolution parameters in step 2.1 include:
[0032] Input feature maps in batches (batches), height (input_h), width (input_w), and number of channels (packed_input_c);
[0033] The number of convolutional kernels (filter_n), height (filter_h), width (filter_w), and number of channels (packed_filter_c); the dimension parameters of the output feature map (output_h, output_w, packed_output_c);
[0034] The convolution stride lengths stride_h and stride_w, and the threshold array thresholds.
[0035] Furthermore, the seven-level nested loop structure in step 2.2 includes:
[0036] The outer loop iterates through the batch, outputs the height out_h and the width out_w;
[0037] The middle loop iterates through the output channel out_ch and the convolution kernel spatial positions filt_h, filt_w;
[0038] The inner loop iterates through the input channel packed_in_c.
[0039] Furthermore, step 2.3 includes the following steps:
[0040] The XOR logical operation and PopCount operation are used to calculate the accumulated value accum in the current step; a two-condition pruning mechanism is used to simultaneously detect both "threshold exceeded" and "threshold cannot be exceeded" cases; early exit is triggered when any of the following conditions are met:
[0041] a) accum > thresholds[out_ch]
[0042] b)accum + maximum possible remaining increment ≤ thresholds[out_ch].
[0043] Furthermore, step 2.4 includes the following steps:
[0044] Set the corresponding bit when accum > thresholds[out_ch];
[0045] Each 32 channels are packaged into an int32 output.
[0046] Furthermore, step 3 includes the following steps:
[0047] Step 3.1: Method for generating the lookup table in the offline stage:
[0048] Step 3.1.1: Initialize an unsigned character array containing 256 elements as a lookup table container;
[0049] Step 3.1.2: For each possible 8-bit unsigned integer value i, 0 ≤ i ≤ 255, perform the following operation:
[0050] 1) Calculate the number of set bits "1" in the binary representation of i;
[0051] 2) Store the quantity in the i-th index position of the lookup table;
[0052] Step 3.1.3: Store the generated lookup table in the on-chip Flash memory of the microcontroller;
[0053] Step 3.1.4: During system initialization, load the lookup table into the microcontroller's on-chip SRAM;
[0054] Step 3.2: Calculating PopCount using a lookup table during the online phase:
[0055] Step 3.2.1: Receive a 32-bit integer input num;
[0056] Step 3.2.2: Divide the num into four 8-bit segments:
[0057] a) Least significant byte (num & 0xFF);
[0058] b) The second least significant byte ((num>>8)&0xFF);
[0059] c) The second most significant byte ((num>>16)&0xFF);
[0060] d) The most significant byte ((num>>24)&0xFF);
[0061] Step 3.2.3: Obtain the number of set bits corresponding to each byte from the lookup table pre-computed in the offline stage; Step 3.2.4: Perform an addition operation on the four lookup table results to obtain the final PopCount value. Further, the fusion calculation of binary convolution and binary max pooling in step 4 includes the following steps:
[0062] Step 4.1: Derive the required output size of the convolutional layer in reverse based on the pooling parameters stride, filter, and padding to ensure that its output data can be directly processed by the pooling layer;
[0063] Step 4.2: Remove the boundary checks of the binary max pooling layer and retain only the core bitwise AND operation; Step 4.3: Implement two versions of binary convolution and select the corresponding version based on whether padding is required for pooling.
[0064] The binary neural network pruning, compression, and deployment optimization system and method of the present invention have the following advantages:
[0065] 1. Dynamic decay factor improves training stability
[0066] By introducing a regularization term with a decay factor, the system can dynamically adjust the regularization strength according to changes in the threshold distribution during training. When the threshold distribution tends to stabilize, the regularization term automatically weakens or becomes ineffective, avoiding over-suppression and significantly improving the model's training stability and accuracy preservation capabilities.
[0067] 2. Runtime dynamic pruning optimizes inference efficiency
[0068] In edge computing devices, a dual-condition pruning mechanism ("threshold exceeded" and "threshold cannot be exceeded") is used to terminate redundant calculations early, reducing unnecessary computation. This optimization significantly improves the computational efficiency of binary neural network inference, and is particularly suitable for resource-constrained embedded devices.
[0069] 3. Efficient PopCount Calculation
[0070] By generating a segmented lookup table offline and quickly calculating PopCount during the online phase, this method addresses the efficiency bottleneck when the hardware does not support the PopCount instruction. This approach enables efficient bit counting operations on resource-constrained devices such as microcontrollers, further improving the computation speed of binary convolution.
[0071] 4. Fusion computing reduces boundary checks
[0072] By fusing binary convolution with binary max pooling, and by inversely deriving the convolution output size and removing boundary checks from the pooling layer, redundant judgments and computational steps are reduced. This optimization significantly reduces latency and improves overall inference efficiency.
[0073] 5. End-side deployment adaptability
[0074] The system optimizes weight storage (Flash loading to SRAM) and computation process (such as 32-bit packaged output) for the characteristics of edge devices such as microcontrollers, ensuring the efficient deployment and operation of binary neural networks in resource-constrained environments.
[0075] 6. Universality and compatibility
[0076] It supports a variety of Cortex-M series microcontrollers, does not rely on specific hardware acceleration instructions, and has broad applicability. Furthermore, through dynamic pruning and fusion computation, it is compatible with binary neural network models of different architectures.
[0077] In summary, this invention has significant advantages in terms of training stability, inference efficiency, resource consumption, and deployment adaptability, providing an efficient and stable solution for the application of binary neural networks on edge devices. Attached Figure Description
[0078] Figure 1 This is an overall flowchart of the binary neural network pruning, compression, and deployment optimization method of the present invention;
[0079] Figure 2 This is a flowchart of the pruning decision-making process of the present invention;
[0080] Figure 3 This is a flowchart of the offline runtime algorithm for the PopCount lookup table of the present invention.
[0081] Figure 4 This is a flowchart of the PopCount lookup table algorithm during the online phase of this invention.
[0082] Figure 5 This is a flowchart of the fusion calculation of binary convolution and binary max pooling in this invention. Detailed Implementation
[0083] To better understand the purpose, structure, and function of this invention, the following detailed description of a binary neural network pruning, compression, and deployment optimization system and method is provided in conjunction with the accompanying drawings.
[0084] This invention discloses a binary neural network pruning, compression, and deployment optimization system, comprising a regularization module with a decay factor during training, a binary convolution runtime pruning module, a PopCount lookup table module, and a binary convolution and binary max pooling fusion calculation module during deployment and inference. The regularization module with a decay factor is used for binary neural network pruning training; the binary convolution runtime pruning module is used for binary neural network inference on the edge computing device; the PopCount lookup table module is used for binary neural network inference on the edge computing device; and the binary convolution and binary max pooling fusion calculation module is used for binary neural network inference on the edge computing device.
[0085] like Figure 1 As shown, the present invention provides a binary neural network pruning, compression, and deployment optimization method, which includes the following steps:
[0086] Step 1: Perform binary neural network pruning training using a regularization term with a decay factor;
[0087] The regularization term calculation formula proposed in this invention is as follows:
[0088]
[0089] The above formula illustrates the calculation process of the regularization term for a single binary convolutional layer. The overall regularization term is obtained by accumulating the regularization terms of each binary convolutional layer. Where y... i T i These are the convolutional summation and the threshold, respectively. N = oH × oW × channel_out, representing the sum and number of output summations, where oH and oW are the height and width of the output feature map, and channel_out is the number of output channels. L = kH × kW × channel_in, representing the length of the accumulation vector, where kH and kW are the height and width of the convolutional kernel, and channel_in is the number of input channels. The output summation reaches its maximum value, i.e., the upper limit L, when all elements in the sum of the output summations are 1.
[0090] Where λ is the dynamic decay factor, and the formula is as follows:
[0091] λ=λ0×Max{0,tanh(-50(vv max ))}
[0092] λ is the product of an initial scalar value λ0 and a piecewise function constructed with a Max term. The tanh term in the Max term is a nonlinear function used to calculate the product of v and v0. max The difference is used to adjust the regularization coefficient. As training progresses, the threshold distribution moves closer to both sides of the interval [0, L], and the value of v gradually increases. When v exceeds the preset hyperparameter v max The tanh term is negative, the Max term is 0, λ equals 0, and the regularization term is invalid.
[0093] Where v is a statistical indicator used to measure the distribution of thresholds, and the calculation formula is as follows:
[0094]
[0095] By introducing the regularization term of this invention into the loss function of the original network, a new loss function is obtained as shown in the formula:
[0096] loss = loss network +R threshold
[0097] This invention introduces a dynamic decay factor into the regularization term of the loss function, equipping each layer's regularization term with an independent adjustment coefficient. These adjustment coefficients are automatically updated based on changes in the threshold distribution of each layer. This dynamic adjustment method effectively avoids over-suppression of the regularization term due to excessive training epochs, leading to a more reasonable pruning rate for each layer and significantly improving the model's training stability and accuracy retention.
[0098] Step 2: Use a binary convolution optimization method based on runtime dynamic pruning for inference in the binary neural network on the edge computing device;
[0099] like Figure 2 As shown, the calculation method for dynamic pruning during binary convolution includes:
[0100] Step 2.1: Initialize the convolution parameters, including:
[0101] The batch size, height (input_h), width (input_w), and number of channels (packed_input_c) of the input feature map.
[0102] The number of convolutional kernels (filter_n), height (filter_h), width (filter_w), and number of channels (packed_filter_c)
[0103] The dimensional parameters of the output feature map (output_h, output_w, packed_output_c)
[0104] Convolution stride (stride_h, stride_w) and threshold array (thresholds)
[0105] Step 2.2: Construct a seven-level nested loop structure:
[0106] The outer loop iterates through the batch, outputs the height (out_h) and width (out_w).
[0107] The middle layer loop iterates through the output channels (out_ch) and the convolution kernel spatial locations (filt_h, filt_w).
[0108] The inner loop iterates through the input channels (packed_in_c).
[0109] Step 2.3: Perform dynamic pruning in the innermost loop of the channel dimension:
[0110] Using XOR logic and the PopCount operation, calculate the cumulative value (accum) for the current step. A two-condition pruning mechanism is used: simultaneously detecting both "threshold exceeded" and "threshold cannot be exceeded". Early exit is triggered when either of the following conditions is met:
[0111] a) accum > thresholds[out_ch]
[0112] b) accum + maximum possible remaining increment ≤ thresholds[out_ch]
[0113] Step 2.4: Generate a binary output based on the final accumulated value:
[0114] Set the corresponding bit when accum > thresholds[out_ch].
[0115] Pack each 32 channels into an int32 array for output. Algorithm framework pseudocode:
[0116]
[0117] Pseudocode for the core pruning process:
[0118]
[0119] Step 3: Use the Popcount calculation method based on a segmented lookup table to perform binary neural network inference in the edge computing device;
[0120] The PopCount lookup table module proposed in this invention is divided into two parts: lookup table generation in the offline stage and PopCount calculation in the online stage.
[0121] Step 3.1: As Figure 3 As shown, the method for generating a lookup table in the offline stage includes the following steps:
[0122] Step 3.1.1: Initialize an unsigned character array containing 256 elements as a lookup table container;
[0123] Step 3.1.2: For each possible 8-bit unsigned integer value i (0 ≤ i ≤ 255), perform the following operation:
[0124] 1) Calculate the number of set bits "1" in the binary representation of i;
[0125] 2) Store the quantity in the i-th index position of the lookup table;
[0126] Step 3.1.3: Store the generated lookup table in the on-chip Flash memory of the microcontroller;
[0127] Step 3.1.4: During system initialization, load the lookup table into the microcontroller's on-chip SRAM.
[0128] Step 3.2: As Figure 4 As shown, the method for calculating PopCount using a lookup table in the online phase includes the following steps:
[0129] Step 3.2.1: Receive a 32-bit integer input num;
[0130] Step 3.2.2: Divide the num into four 8-bit segments:
[0131] a) Least significant byte (num & 0xFF)
[0132] b) Second least significant byte ((num>>8)&0xFF)
[0133] c) Second most significant byte ((num>>16)&0xFF)
[0134] d) Most significant byte ((num>>24)&0xFF)
[0135] Step 3.2.3: Obtain the number of set bits corresponding to each byte from the lookup table pre-calculated in the offline stage;
[0136] Step 3.2.4: Perform an addition operation on the four lookup results to obtain the final PopCount value;
[0137] Step 4: Use binary convolution and binary max pooling to fuse the padding information of binary max pooling into the data output stage of binary convolution for binary neural network inference in the edge computing device, reduce boundary checks and judgments, and improve computational efficiency.
[0138] like Figure 5 As shown, the fusion calculation of binary convolution and binary max pooling includes the following steps:
[0139] Step 4.1: Derive the required output size of the convolutional layer in reverse based on the pooling parameters (stride, filter, padding) to ensure that its output data can be directly processed by the pooling layer.
[0140] Step 4.2: Remove boundary checks from the binary max pooling layer, keeping only the core bitwise AND operations.
[0141] Step 4.3: Implement two versions of binary convolution, and select the corresponding version based on whether padding is required during pooling.
[0142] This invention is based on deep learning, and therefore consists of two stages: training and inference.
[0143] Training phase:
[0144] Repeat the following training steps multiple times until convergence is achieved.
[0145] 1) Prepare data
[0146] Given a batch of RGB images and a corresponding batch of image category labels;
[0147] 2) Forward computation of neural networks
[0148] Perform a forward computation based on a given set of images.
[0149] Calculate threshold distribution index
[0150] Calculate the dynamic attenuation factor λ=λ0×Max{0,tanh(-50(vv) max ))}
[0151] Calculate the regularization term
[0152] 3) Loss function calculation
[0153] Calculate the cross-entropy as the network's loss term. network
[0154] Calculate the overall loss function: loss = loss network +R threshold
[0155] 4) Parameter update
[0156] Update the network parameters based on the gradient of the loss function with respect to the network parameters.
[0157] Reasoning stage:
[0158] 1) Given an RGB image;
[0159] 2) Extract the weight parameters from the training phase and convert the neural network model into a deployment form;
[0160] 3) Perform forward computation of the neural network on the microcontroller and obtain the image category based on the computation result.
[0161] Example:
[0162] The training environment uses the binary neural network framework Larq and the publicly available dataset CIFAR-10, which contains 60,000 images. 50,000 images are used for training, and the remaining 10,000 are used for testing. The input images are horizontally flipped and randomly cropped as data augmentation.
[0163] The VGG-Small convolutional neural network is used as the model. The first convolutional layer performs binary quantization of the weights, and the other convolutional layers perform binary quantization of both the activation values and weights.
[0164] The model was trained for 300 epochs using the Adam optimizer. The learning rate was decreased from 1e-2 to 1e-4, adjusted by decreasing it by a factor of 0.1 every 100 epochs.
[0165] The deployment platform uses a microcontroller with a Cortex-M0 / 3 / 4 / 7 main core. The weights are stored in non-volatile Flash memory. During system initialization, the weights are loaded into the faster SRAM to execute the inference of the binary neural network.
[0166] It is understood that the present invention has been described through some embodiments, and those skilled in the art will recognize that various changes or equivalent substitutions can be made to these features and embodiments without departing from the spirit and scope of the invention. Furthermore, under the teachings of the present invention, these features and embodiments can be modified to adapt to specific situations and materials without departing from the spirit and scope of the invention. Therefore, the present invention is not limited to the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application are within the protection scope of the present invention.
Claims
1. A binary neural network pruning, compression, and deployment optimization system, characterized in that, The system includes a regularization module with a decay factor during training, a binary convolution runtime pruning module, a PopCount lookup table module, and a binary convolution and binary max pooling fusion calculation module during deployment and inference. The regularization module with a decay factor is used for binary neural network pruning training; the binary convolution runtime pruning module is used for binary neural network inference on the edge computing device; the PopCount lookup table module is used for binary neural network inference on the edge computing device; and the binary convolution and binary max pooling fusion calculation module is used for binary neural network inference on the edge computing device.
2. An optimization method for the binary neural network pruning, compression, and deployment optimization system as described in claim 1, characterized in that, Includes the following steps: Step 1: Perform binary neural network pruning training using a regularization term with a decay factor; Step 2: Use a binary convolution optimization method based on runtime dynamic pruning for inference in the binary neural network on the edge computing device; Step 3: Use the Popcount calculation method based on a segmented lookup table to perform binary neural network inference in the edge computing device; Step 4: Use binary convolution and binary max pooling to fuse the padding information of binary max pooling into the data output stage of binary convolution for binary neural network inference in the edge computing device, reduce boundary checks and judgments, and improve computational efficiency.
3. The optimization method according to claim 2, characterized in that, Step 1 includes the following steps: The formula for calculating the regularization term is as follows: The above formula illustrates the calculation process of the regularization term for a single binary convolutional layer. The overall regularization term is obtained by accumulating the regularization terms of each binary convolutional layer, where y... i T i These are the convolutional sum and the threshold, respectively. N = oH × oW × channel_out, representing the sum and number of output sums, oH and oW are the height and width of the output feature map, and channel_out is the number of output channels. L = kH × kW × channel_in, representing the length of the accumulation vector, kH and kW are the height and width of the convolutional kernel, and channel_in is the number of input channels. The output sum reaches its maximum value, i.e., the upper limit L, when all elements in the sum and number of output sums are 1. Where λ is the dynamic decay factor, and the formula is as follows: λ=λ0×Max{0,tanh(-50(vv max ))} λ is the product of an initial scalar value λ0 and a piecewise function constructed with a Max term, where tanh in the Max term is a nonlinear function used to calculate the product of v and v. max The difference is adjusted by the regularization coefficient. As training progresses, the threshold distribution moves closer to both sides of the interval [0, L], and the value of v gradually increases. When v exceeds the preset hyperparameter v max When the tanh term is negative, the Max term is 0, λ equals 0, and the regularization term is invalid. Where v is a statistical indicator used to measure the distribution of thresholds, and the calculation formula is as follows: By introducing a regularization term into the original network's loss function, a new loss function is obtained as shown in the formula: loss=loss network +R threshold 。 4. The optimization method according to claim 2, characterized in that, The calculation method for dynamic pruning during binary convolution in step 2 includes: Step 2.1: Initialize convolution parameters; Step 2.2: Construct a seven-level nested loop structure; Step 2.3: Perform dynamic pruning in the innermost loop of the channel dimension; Step 2.4: Generate a binary output based on the final accumulated value.
5. The optimization method according to claim 4, characterized in that, The convolution parameters in step 2.1 include: Input feature maps in batches (batches), height (input_h), width (input_w), and number of channels (packed_input_c); The number of convolutional kernels (filter_n), height (filter_h), width (filter_w), and number of channels (packed_filter_c); The dimension parameters of the output feature map are output_h, output_w, and packed_output_c. The convolution stride lengths stride_h and stride_w, and the threshold array thresholds.
6. The optimization method according to claim 4, characterized in that, The seven-level nested loop structure in step 2.2 includes: The outer loop iterates through the batch, outputs the height out_h and the width out_w; The middle loop iterates through the output channel out_ch and the convolution kernel spatial positions filt_h, filt_w; The inner loop iterates through the input channel packed_in_c.
7. The optimization method according to claim 4, characterized in that, Step 2.3 includes the following steps: Use the XOR logical operation and the PopCount operation to calculate the accumulated value accum in the current step; Two-condition pruning mechanism: simultaneously detects both "threshold exceeded" and "threshold cannot be exceeded" conditions; Early exit is triggered when any of the following conditions are met: a) accum > thresholds[out_ch] b)accum + maximum possible remaining increment ≤ thresholds[out_ch].
8. The optimization method according to claim 4, characterized in that, Step 2.4 includes the following steps: Set the corresponding bit when accum > thresholds[out_ch]; Each 32 channels are packaged into an int32 output.
9. The optimization method according to claim 2, characterized in that, Step 3 includes the following steps: Step 3.1: Method for generating the lookup table in the offline stage: Step 3.1.1: Initialize an unsigned character array containing 256 elements as a lookup table container; Step 3.1.2: For each possible 8-bit unsigned integer value i, 0 ≤ i ≤ 255, perform the following operation: 1) Calculate the number of set bits "1" in the binary representation of i; 2) Store the quantity in the i-th index position of the lookup table; Step 3.1.3: Store the generated lookup table in the on-chip Flash memory of the microcontroller; Step 3.1.4: During system initialization, load the lookup table into the microcontroller's on-chip SRAM; Step 3.2: Calculating PopCount using a lookup table during the online phase: Step 3.2.1: Receive a 32-bit integer input num; Step 3.2.2: Divide the num into four 8-bit segments: a) Least significant byte (num & 0xFF); b) The second least significant byte ((num>>8)&0xFF); c) The second most significant byte ((num>>16)&0xFF); d) The most significant byte ((num>>24)&0xFF); Step 3.2.3: Obtain the number of set bits corresponding to each byte from the lookup table pre-calculated in the offline stage; Step 3.2.4: Perform an addition operation on the four lookup results to obtain the final PopCount value.
10. The optimization method according to claim 2, characterized in that, The fusion calculation of binary convolution and binary max pooling in step 4 includes the following steps: Step 4.1: Derive the required output size of the convolutional layer in reverse based on the pooling parameters stride, filter, and padding to ensure that its output data can be directly processed by the pooling layer; Step 4.2: Remove the boundary checks of the binary max pooling layer and retain only the core bitwise AND operation; Step 4.3: Implement two versions of binary convolution and select the corresponding version based on whether padding is required for pooling.