Image processing and detecting system based on FPGA
By deploying image processing and convolutional neural networks on the FPGA platform, combined with improved mean filtering and parallel computing, the problems of low recognition rate and poor real-time performance of the convolutional neural network detection method are solved, and more efficient image detection is achieved.
Patent Information
- Application Number
- CN202410894485.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-01
AI Technical Summary
Existing convolutional neural network detection methods have low recognition rates and poor real-time performance, especially at the hardware implementation level. CPU, GPU and DSP platforms cannot give full play to their parallelism and computing advantages, resulting in performance bottlenecks in image processing and detection.
Design an FPGA-based image processing and detection system, including an image sensor module, a camera configuration module, an image data acquisition module, an image preprocessing module and a neural network acceleration module. Image acquisition, processing and the deployment of convolutional neural networks are implemented through FPGA. , using improved mean filtering and parallel calculation methods, combined with the ResNet18 residual network model, and quantified calculations as int8, using the parallelism and low latency of FPGA to improve detection accuracy and efficiency.
It improves the accuracy and real-time performance of image detection, reduces FPGA resource consumption, enables more efficient system deployment, and solves the problems of low recognition rate and poor real-time performance of convolutional neural networks on traditional platforms.
Smart Images

Figure CN118735764A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image detection, and in particular to an image processing and detection system based on FPGA. Background Art
[0002] The key technologies in image detection systems are mainly the extraction of image features and the discrimination of images through the designed core algorithms. Traditional image detection methods can be mainly divided into four types: structural method, statistical method, spectral method and model method. These methods rely on manual redesign of manual features for images of different products to detect images. Although they can achieve a certain level of performance, their detection process is relatively complicated, and the imaging process and feature extraction process have high requirements, and automatic threshold adjustment is not possible. In recent years, deep learning and neural network methods have become the main tools for image processing and detection. These methods perform complex classification and recognition tasks on images, such as facial recognition, object detection, etc. However, this method requires a large amount of data for training, and the complexity and computational requirements of the model are very high, so a suitable development platform is required.
[0003] Generally, convolutional neural networks are implemented using high-level programming languages, and most of them are compiled to the CPU (central processing unit) for calculation. Although CPU calculations have good portability, the CPU is executed sequentially. Even if multi-core processing is used, the parallel advantages of convolutional neural networks cannot be fully utilized. Of course, with the development of science and technology, researchers have also begun to use GPUs (graphics processing units) to calculate convolutional neural networks. Although the GPU platform can better realize the combination of software and hardware, the specific acceleration of convolutional neural networks is often limited by the underlying tools designed by GPU manufacturers, and GPUs have problems such as high power consumption and weak real-time performance, which greatly limits the scope of GPU use. At the hardware implementation level, dedicated DSP (digital signal processor) chips are mainly optimized for multiplication and addition operations. Although DSP is more suitable for some parallel computing operations, which coincides with convolutional neural networks, when faced with large-scale convolution operations and flexible changes in input data, DSP cannot fully play its advantages and still has the problem of insufficient real-time performance. Summary of the invention
[0004] The present invention aims to solve the technical problems of low recognition rate and poor real-time performance of existing convolutional neural network detection methods.
[0005] In order to solve the above technical problems, the present invention provides an image processing and detection system based on FPGA, comprising:
[0006] An image sensor module, used for collecting images;
[0007] A camera configuration module, used to control the image sensor module to collect images;
[0008] An image data acquisition module, used to acquire and store the image acquired by the image sensor module;
[0009] An image preprocessing module, used for performing mean filtering and feature enhancement on the image stored in the image data acquisition module to obtain an enhanced image;
[0010] A neural network acceleration module, used to perform feature detection on the enhanced image using a preset neural network model and output an image detection result;
[0011] The camera configuration module, the image data acquisition module, the image preprocessing module and the neural network acceleration module are implemented based on FPGA.
[0012] Furthermore, the image sensor module is implemented based on the OV5640 image sensor.
[0013] Furthermore, the image preprocessing module is specifically used for:
[0014] Based on the three-level pipeline, the data of the same pixel row in the image are arranged from large to small through the first-level pipeline; the minimum value is selected from the largest pixel column and the maximum value is selected from the smallest pixel column through the second-level pipeline; the average value of the eight pixels around a single pixel point P is calculated through the third-level pipeline.
[0015] Furthermore, in the image preprocessing module, the first-level pipeline, the second-level pipeline, and the third-level pipeline are all operated in parallel; wherein, when the second-level pipeline is operating, the third-level pipeline selects the maximum value from the largest pixel column and the minimum value from the smallest pixel column, and compares the value of the pixel point P with the maximum value and the minimum value in the entire window matrix through parallel processing. If they are equal, the average value of the eight pixel points around the pixel point P is assigned to the pixel point P through a multiplexer.
[0016] Furthermore, the preset neural network model is a ResNet18 residual network model.
[0017] Furthermore, the computation of the ResNet18 residual network model is quantized to int8.
[0018] Furthermore, the ResNet18 residual network model includes an input layer, a first convolutional layer, a pooling layer, multiple second convolutional layers, an averaging layer, a fully connected layer and an output layer.
[0019] Furthermore, the first convolution layer includes a boundary filling layer, a normalization layer, an activation function layer and a maximum pooling layer, and the boundary filling layer is implemented based on an FPGA finite state machine.
[0020] Furthermore, multiple of the second convolutional pooling layers are implemented through FPGA multiplexing.
[0021] The beneficial effect achieved by the present invention is that an FPGA-based image processing and detection system is proposed, which deploys image acquisition, image processing and convolutional neural network on FPGA to achieve acceleration, improves detection accuracy through an improved mean filtering method, reduces FPGA resource consumption through FPGA multiplexing and parallel computing design, and improves system deployment efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 It is a structural schematic diagram of an image processing and detection system based on FPGA provided by an embodiment of the present invention;
[0023] Figure 2 is a schematic diagram of the structure of an image sensor provided by an embodiment of the present invention;
[0024] Figure 3 is a schematic diagram of a mean filtering process provided by an embodiment of the present invention;
[0025] Figure 4 is a schematic diagram of implementing mean filtering provided by an embodiment of the present invention;
[0026] Figure 5 is a schematic diagram comparing the improved mean filtering provided by an embodiment of the present invention and the traditional mean filtering algorithm;
[0027] Figure 6 It is a schematic diagram of the structure of the ResNet18 residual network model provided in an embodiment of the present invention;
[0028] Figure 7 is a schematic diagram of border filling provided by an embodiment of the present invention;
[0029] Figure 8 is a schematic diagram of implementing border filling provided by an embodiment of the present invention;
[0030] Fig. 9 Schematic diagram of convolutional layer multiplexing provided by an embodiment of the present invention;
[0031] Fig.10 is a convolution schematic diagram provided by an embodiment of the present invention;
[0032] Fig.11 It is a schematic diagram of sequential reading of a convolution cache provided by an embodiment of the present invention;
[0033] Fig.12 is a schematic diagram of a convolution linear buffer provided by an embodiment of the present invention;
[0034] Fig.13 is a schematic diagram of a linear cache implementation provided by an embodiment of the present invention;
[0035] Fig.14 It is a schematic diagram of a first process flow of implementing linear cache provided by an embodiment of the present invention;
[0036] Fig.15 This is a schematic diagram of the second process flow of linear cache implementation provided by an embodiment of the present invention.
[0037] Fig.16 is a schematic diagram of an activation function image provided by an embodiment of the present invention;
[0038] Fig.17 is a schematic diagram of maximum pooling provided by an embodiment of the present invention;
[0039] Fig.18 This is a schematic diagram of maximum pooling values provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0040] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0041] Please refer to Figure 1 , Figure 1 : is a schematic diagram of the structure of the FPGA-based image processing and detection system provided by an embodiment of the present invention. FPGA is a reconfigurable chip with strong parallelism, low latency and low power consumption. The FPGA-based image processing and detection system includes:
[0042] An image sensor module, used for collecting images;
[0043] A camera configuration module, used to control the image sensor module to collect images;
[0044] An image data acquisition module, used to acquire and store the image acquired by the image sensor module;
[0045] An image preprocessing module, used for performing mean filtering and feature enhancement on the image stored in the image data acquisition module to obtain an enhanced image;
[0046] A neural network acceleration module, used to perform feature detection on the enhanced image using a preset neural network model and output an image detection result;
[0047] The camera configuration module, the image data acquisition module, the image preprocessing module and the neural network acceleration module are implemented based on FPGA.
[0048] Furthermore, the image sensor module is implemented based on the OV5640 image sensor. The structure of the OV5640 image sensor is as follows: Figure 2 shown.
[0049] The main idea of the mean filtering method is to replace the target pixel value with the average value of the target pixel and its neighboring pixels, which has the effect of smoothing the image. However, while removing noise, the traditional mean filtering also causes some damage to the details of the image, making the image blurry. Based on the mean filtering, the embodiment of the present invention proposes a selective mean filtering suitable for FPGA implementation. Based on the characteristic that noise points are generally extreme values of neighboring pixels, while edges are often not, a selective mean filtering is proposed. The specific method flow is as follows: Figure 3 As shown in the figure, the image is scanned line by line. When processing each pixel, it is determined whether the pixel is the maximum or minimum value of the pixels in the filter window. If so, conventional mean filtering is performed; otherwise, the pixel remains unchanged. This method can remove noise without affecting the edges, and is suitable for hardware implementation without adding additional delay.
[0050] Furthermore, the image preprocessing module is specifically used for:
[0051] Based on the three-stage pipeline, the first stage pipeline arranges the data of the same pixel row in the image from large to small; the second stage pipeline selects the minimum value from the largest pixel column and the maximum value from the smallest pixel column; the third stage pipeline calculates the single pixel point P 11 The average value of the eight surrounding pixels.
[0052] Furthermore, in the image preprocessing module, the first-stage pipeline, the second-stage pipeline, and the third-stage pipeline are all operated in parallel; wherein, when the second-stage pipeline is operated, the third-stage pipeline selects the maximum value from the largest pixel column and the minimum value from the smallest pixel column, and processes the pixel point P in parallel. 11 The value of is compared with the maximum and minimum values in the entire window matrix. If they are equal, the pixel point P is switched to 11 The average value of the eight surrounding pixels is assigned to the pixel P. 11 The process is as follows Figure 4 shown.
[0053] The comparison between the selective mean filtering method adapted to FPGA implementation provided by the embodiment of the present invention (hereinafter referred to as improved mean filtering) and the traditional mean filtering algorithm is as follows: Figure 5As shown, Figure 5 a in the figure is the original image. Figure 5 In the figure, b is the noise image, c is the image after traditional mean filtering, and d is the image after improved mean filtering. From the effect, both traditional mean filtering and improved mean filtering can remove the salt and pepper noise in the image very well, but the image processed by traditional mean filtering makes the image blurred, while the image processed by improved mean filtering is clearer, close to the original image, and the image details (such as hair) are better preserved.
[0054] Furthermore, the preset neural network model is a ResNet18 residual network model.
[0055] When training convolutional neural networks based on CPU or GPU platforms, in order to ensure high accuracy and the hardware platform's support for 32-bit floating-point calculations, 32-bit floating-point numbers are used for calculations when running convolutional neural networks on such platforms. However, when implementing convolutional neural networks on FPGAs, using 32-bit floating-point numbers for calculations will consume a lot of hardware resources and the cost of off-chip DDR and FPGA communication.
[0056] In the embodiment of the present invention, the calculation quantization of the ResNet18 residual network model is int8.
[0057] Model quantization can reduce network parameters, reduce computational complexity, and speed up model inference. The specific quantization calculation process is shown in Formula 1, which describes the calculation process of quantizing floating-point numbers to fixed-point numbers. Where q is the fixed-point value after quantization, r is the real floating-point number, z is the value of the fixed-point number corresponding to the floating-point number 0, and s is the minimum scale between quantized data. The calculation method of s is shown in Formula 2, and the calculation method of z is shown in Formula 3. Where rmax, rmin, qmax, and qmin are the maximum and minimum values of r and q, respectively.
[0058]
[0059] Furthermore, the ResNet18 residual network model includes an input layer, a first convolutional layer, a pooling layer, multiple second convolutional layers, an average layer, a fully connected layer and an output layer, such as Figure 6 shown.
[0060] Furthermore, the first convolution layer includes a boundary filling layer, a normalization layer, an activation function layer and a maximum pooling layer, and the boundary filling layer is implemented based on an FPGA finite state machine.
[0061] Furthermore, multiple of the second convolutional pooling layers are implemented through FPGA multiplexing.
[0062] Reference Figure 6, ResNet18 can be disassembled into non-repeating submodules. From top to bottom, first pass through a 7*7*64 first convolution layer, which contains a boundary padding layer (padding), a normalization (bn) layer, an activation function (relu) function, and a maximum pooling (max pool) calculation. Next, pass through four convolution blocks (second convolution layer). Each convolution block contains four convolution layers, such as the first convolution block is 4 3*3*64 convolution kernels. In this convolution layer, its operation only includes convolution calculation and bn calculation. It overlaps with the above module and does not need to be redesigned on FPGA. However, in the network, these four convolution layers operate in serial input and output. Then the idea of FPGA reuse can be used to reduce the consumption of FPGA resources. Take a 3*3*64 as a unit and use the cnn_control module to realize its repeated reuse four times. After the four convolution blocks are completed, the results are obtained through avg pool (average pooling) calculation and soft max calculation.
[0063] Padding operation is a very common operation in deep learning. In order to keep the image size unchanged after convolution, it is necessary to fill the borders of the original image with zeros. In the ResNet18 network, there is a padding layer before each convolution layer, where the padding is 1 (i.e. a layer of 0 is filled around the image), such as Figure 7 shown.
[0064] Assuming that the size of the original image to be filled is m*m, the filling process is as follows: after detecting the start signal, fill a row of (m+2) data zeros, then fill a data zero at the beginning of the next row, and then accept normal image data. After the end of this row of data, fill another data zero. This continues until a whole image is received, and finally fill a row of (m+2) data zeros.
[0065] The embodiment of the present invention implements the Padding operation through a finite state machine, which includes four states: Padding_wait (idle waiting state), Padding_row (filling a row of zero data), Padding_data (filling image data), and Count_row (filling row number counter). The state transition diagram is shown in FIG. Figure 8 shown.
[0066] The specific meanings of conditional jumps between states are as follows:
[0067] Condition A: When the start signal is detected, jump to the padding_row state.
[0068] Condition B: After the last row of data 0 is filled, jump to the Padding_wait state.
[0069] Condition C: After filling the first row of data 0, jump to the Padding_data state.
[0070] Condition D: After filling a row of image data, jump to Count_row state.
[0071] Condition E: The row counter is calculated. When the row counter is not equal to the number of rows of the original image plus 1 (including the first row of data 0 filled), it jumps to the Padding_data state.
[0072] Condition F: Row counter calculation. When the row counter is not equal to the number of rows of the original image plus 1 (including the first row of data 0 filled), jump to the padding_row state.
[0073] Convolution operation is the main operation in the convolutional neural network algorithm, accounting for more than 90% of the entire network's computing capacity. Therefore, the design of the accelerator should focus on the optimization of convolution calculation. Improving the speed of convolution calculation can effectively improve the overall computing speed of the network model.
[0074] From the network structure of ResNet18, we can see that each convolution block has repeated convolution layers. Taking the first convolution layer as an example, it contains four 3*3*64 convolution kernels. Using the FPGA reuse idea, we only need to design a 3*3*64 convolution kernel module, and then design a cnn_control module to realize its repeated four-time reuse, such as Fig. 9 As shown in the figure, the FPGA design is as follows: The cnn_control module has one input and two outputs. The cnn_control module contains a counter to calculate the number of times the 3*3*64 convolutional layer is reused. When the counter is less than 4, the result is transferred to the previous padding module. When it is greater than 4, it is transferred to the padding module of the second convolutional block. At the same time, the counter is reset to 0.
[0075] In ResNet18, M and N are respectively the output channel and input channel of the feature map. As the network deepens, M and N increase and become larger. The input channel of the first residual block is 64, and the output channel of the last residual block is 512. Therefore, the feature extraction is completed by traversing N input feature maps in a channel-parallel manner. The feature values of the same spatial position of the N input feature maps are simultaneously convolved with N different convolution kernels, and then accumulated to obtain the output feature values of the corresponding positions. Fig.10 As shown, Fig.10The topology diagram of the structure for parallel calculation of input channel N and output channel M. Each dotted box represents a data processing unit, which realizes parallel calculation between input channels. N input feature maps are convolved with N different convolution kernels respectively, and then the convolution results of N channels are accumulated through an addition tree to generate the output feature map of the same channel. Multiple dotted boxes, that is, multiple data processing units are executed simultaneously, to realize parallel calculation between output feature maps. M data processing units are executed simultaneously, and N*M different convolution kernels are required to generate M output feature maps.
[0076] Convolution calculation is the process of moving the convolution kernel on the input feature map to perform multiplication and accumulation calculations. When a single convolution kernel performs a convolution operation on a feature map, the data of the convolution kernel remains unchanged, while the value of the feature map corresponding to the convolution kernel changes as the convolution kernel moves, such as Fig.11 As shown in the figure, when the 3*3 convolution kernel moves on the feature map, the convolution window will overlap. When the step size is 1, the maximum overlap ratio reaches 66.7%. The linear cache module is designed to store the accessed data, so that when the pixel enters the convolution window for the second time, it can be directly read sequentially from the linear cache to realize data reuse, thus avoiding slow RAM access and greatly reducing data access latency, thereby increasing the overall computing speed.
[0077] The linear buffer design of convolution window data is as follows: Fig.12 As shown in the figure, the convolution window is a 3x3 register matrix, which is loaded data by data stream through two linear caches, namely linear cache 1 and linear cache 2. Assuming that the size of the feature map is k*k, because the padding before most convolutional layers of ResNet18 is 1, the size of the feature map after padding is (k+2)*(k+2), then the size of each linear cache is k-1.
[0078] The linear cache implements the convolution process as follows Fig.13 As shown, assuming that the feature map size is 7*7, a layer of 0 is padded on the top, bottom, left and right of the feature map, then the size of the linear buffer is 6. The convolution operation is performed on the feature map after padding. When the convolution window is just filled with data, the convolution window position is as follows Fig.13 The red box position, at which time the convolution calculation begins.
[0079] When the convolution window is at the end of a row (such as Fig.14 After the convolution window calculation is completed, the convolution window needs to be moved to the next line (as shown in the box). Fig.15 The data stream needs to move 3 positions in the convolution window and linear buffer to realize the convolution window line wrapping. And so on, until the feature extraction of the entire feature map is completed.
[0080] The Bn layer is located before the activation function relu. It first normalizes the data, then scales and translates it. It has three functions: speeding up the training and convergence of the network; controlling gradient explosion and preventing gradient disappearance; and preventing overfitting. Its formula is shown in Equation 4-7.
[0081]
[0082] After the network has trained the weights, the FPGA implementation only needs to implement the forward propagation process. For this formula, Formula 4 calculates the average value of the input data, Formula 5 calculates the variance of the input data, Formula 6 uses the mean and variance to normalize the data, and Formula 7 scales and shifts the normalized data. γ is the scaling factor, and β is the shifting factor. These two parameters can be learned and updated during the training process.
[0083] The activation function relu expression is shown in formula 8, and the function image is shown in Fig.16 As shown in the figure, when x is less than 0, y is 0. When x is greater than 0, y is the value of the input x. Because the output of the bn layer is the input of the relu layer, the relu function is designed together with the bn layer in the FPGA design. By setting a selector after the bn layer, if the output data signal of the bn layer is less than 0, the selector directly outputs 0; if the output data signal of the bn layer is greater than 0, the selector only needs to keep the data as it is, and no additional processing is required. This is equivalent to realizing the function of relu.
[0084] relu(x)=max(x,0)(8).
[0085] The maximum pooling operation in ResNet18 is to use a 3*3 fixed-size window to move with a step size of 2 on an image data, and take the maximum value in the window each time it moves, such as Fig.17 The maximum value is obtained as shown in Fig.17 As shown in the figure, the maximum value of each row is calculated first, and then these maximum values are compared to get the final result. The design of the avg pool (average pooling) module is similar to that of the max pool.
[0086] The beneficial effect achieved by the present invention is that an FPGA-based image processing and detection system is proposed, which deploys image acquisition, image processing and convolutional neural network on FPGA to achieve acceleration, improves detection accuracy through an improved mean filtering method, reduces FPGA resource consumption through FPGA multiplexing and parallel computing design, and improves system deployment efficiency.
[0087] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0088] The embodiments of the present invention are described above in conjunction with the accompanying drawings. What is disclosed is only the preferred embodiment of the present invention. However, the present invention is not limited to the above-mentioned specific implementation manner. The above-mentioned specific implementation manner is only illustrative rather than restrictive. Under the enlightenment of the present invention, ordinary technicians in this field can also make many forms and equivalent changes without departing from the scope of protection of the purpose of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. An image processing and detection system based on FPGA, It is characterized in that include: An image sensor module, used for collecting images; A camera configuration module, used to control the image sensor module to collect images; An image data acquisition module, used to acquire and store the image acquired by the image sensor module; An image preprocessing module, used for performing mean filtering and feature enhancement on the image stored in the image data acquisition module to obtain an enhanced image; A neural network acceleration module, used to perform feature detection on the enhanced image using a preset neural network model and output an image detection result; The camera configuration module, the image data acquisition module, the image preprocessing module and the neural network acceleration module are implemented based on FPGA.
2. The FPGA-based image processing and detection system according to claim 1, It is characterized in that The image sensor module is implemented based on the OV5640 image sensor.
3. The FPGA-based image processing and detection system according to claim 1, It is characterized in that The image preprocessing module is specifically used for: Based on the three-level pipeline, the data of the same pixel row in the image are arranged from large to small through the first-level pipeline; the minimum value is selected from the largest pixel column and the maximum value is selected from the smallest pixel column through the second-level pipeline; the average value of the eight pixels around a single pixel point P is calculated through the third-level pipeline.
4. The FPGA-based image processing and detection system according to claim 3, It is characterized in that In the image preprocessing module, the first-level pipeline, the second-level pipeline, and the third-level pipeline are all operated in parallel; wherein, when the second-level pipeline is operating, the third-level pipeline selects the maximum value from the largest pixel column and the minimum value from the smallest pixel column, and compares the value of the pixel point P with the maximum value and the minimum value in the entire window matrix in a parallel processing manner; if they are equal, the average value of the eight pixel points around the pixel point P is assigned to the pixel point P through a multiplexer.
5. The FPGA-based image processing and detection system according to claim 1, It is characterized in that The preset neural network model is the ResNet18 residual network model.
6. The FPGA-based image processing and detection system according to claim 5, It is characterized in that The computation of the ResNet18 residual network model is quantized to int8.
7. The FPGA-based image processing and detection system according to claim 5, It is characterized in that The ResNet18 residual network model includes an input layer, a first convolutional layer, a pooling layer, multiple second convolutional layers, an average layer, a fully connected layer and an output layer.
8. The FPGA-based image processing and detection system according to claim 7, It is characterized in that The first convolution layer includes a boundary filling layer, a normalization layer, an activation function layer and a maximum pooling layer, and the boundary filling layer is implemented based on an FPGA finite state machine.
9. The FPGA-based image processing and detection system according to claim 7, It is characterized in that Multiple of the second convolutional pooling layers are implemented through FPGA multiplexing.
Citation Information
Cited By
Image preprocessing method and system based on FPGA
CN120612250A
