Image Processing Method, Apparatus, Storage Medium, and Electronic Device
By determining the diagonal coordinates of the area to be calculated in the image processing, and using the pre-stored set of calculation results to find the calculation results of the sub-region, the problem of low image processing efficiency in the prior art is solved, and a more efficient calculation process is realized.
Patent Information
- Application Number
- CN202211697845.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-28
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-12-28
AI Technical Summary
In the prior art, the efficiency of image processing is low, mainly due to the high computation time complexity of the regionalized computing operator, which leads to traversing each element in the entire area to be calculated, increasing the calculation amount.
By obtaining the coordinates of a pair of diagonal points of the area to be calculated, N sub-regions corresponding to the area to be calculated are determined in the target image area, N calculation results corresponding to the N sub-regions in the pre-stored set of calculation results, and the target calculation results of the area to be calculated are determined based on these calculation results.
It avoids traversing every element of the entire area to be calculated, thereby reducing the amount of calculation and improving the efficiency of image processing.
Smart Images

Figure CN115880478B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the technical field of image processing. Specifically, the present invention relates to an image processing method, apparatus, storage medium, and electronic device. Background Art
[0002] In a neural network, there are many operators for performing regional calculations, such as convolution, pooling, normalization, etc. Each time, a calculation is performed on a specified region, and an output feature map is obtained through multiple regional calculations. These operators have a relatively high computational time complexity and account for the vast majority of the computational workload in the neural network. Currently, the source codes of major mainstream deep learning frameworks calculate the regional calculation method by continuously traversing each element within the region. The implementation of regional calculation starts from the boundary point. Each time, the next calculation region is determined by the step size and the region size, and then each element in this region is traversed and calculated as required. This value is used as an output, and then the above calculation process is repeated in the next region until the entire data block is traversed, which greatly increases the computational workload and results in low efficiency of image processing. Therefore, optimizing and accelerating the above-mentioned operators for regional calculation is the key to improving the inference efficiency of the neural network model.
[0003] In view of the problem of low efficiency of image processing in the related art, no effective solution has been proposed yet. Summary of the Invention
[0004] The embodiments of the present invention provide an image processing method, apparatus, storage medium, and electronic device to at least solve the problem of low efficiency of image processing in the related art.
[0005] According to an embodiment of the present invention, there is provided an image processing method, including: obtaining a first coordinate and a second coordinate of a region to be calculated, where the first coordinate and the second coordinate are respectively used to represent the positions of pixel points at a pair of diagonal points of the region to be calculated in a target image region, the target image region includes H*W pixel points, and both H and W are positive integers greater than or equal to 2; determining, according to the first coordinate and the second coordinate, N sub-regions corresponding to the region to be calculated in the target image region, where N is a positive integer greater than or equal to 2; searching for N calculation results respectively corresponding to the N sub-regions in a pre-stored calculation result set, where the calculation result set includes H*W calculation results calculated in advance, the H*W calculation results correspond one-to-one to H*W sub-regions in the target image region, the H*W sub-regions include sub-regions formed by taking the origin in the target image region and each of the H*W pixel points as diagonal vertices, and each of the H*W calculation results is a result determined according to data corresponding to each pixel point in the corresponding sub-region among the H*W sub-regions; and determining a target calculation result of the region to be calculated according to the N calculation results, where the target calculation result is used for a target neural network model to process the target image.
[0006] In an exemplary embodiment, the determining, according to the first coordinate and the second coordinate, N sub-regions corresponding to the region to be calculated in the target image region includes: when N = 4, determining a first sub-region, a second sub-region, a third sub-region, and a fourth sub-region, where the first sub-region, the second sub-region, the third sub-region, and the fourth sub-region are included in the H*W sub-regions, the row coordinate of the lower right corner of the first sub-region is equal to the row coordinate of the first coordinate minus 1, the column coordinate of the lower right corner of the first sub-region is equal to the column coordinate of the first coordinate minus 1, the row coordinate of the lower right corner of the second sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the second sub-region is equal to the column coordinate of the second coordinate, the row coordinate of the lower right corner of the third sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the third sub-region is equal to the column coordinate of the first coordinate minus 1, the row coordinate of the lower right corner of the fourth sub-region is equal to the row coordinate of the first coordinate minus 1, and the column coordinate of the lower right corner of the fourth sub-region is equal to the column coordinate of the second coordinate; the searching for N calculation results respectively corresponding to the N sub-regions in the pre-stored calculation result set includes: searching for a first calculation result, a second calculation result, a third calculation result, and a fourth calculation result respectively corresponding to the first sub-region, the second sub-region, the third sub-region, and the fourth sub-region in the calculation result set.
[0007] In an exemplary embodiment, determining the target calculation result of the area to be calculated according to the N calculation results includes: determining the target calculation result according to the following formula: V = D1 + D2 - D3 - D4, where V represents the target calculation result, D1 represents the first calculation result, D2 represents the second calculation result, D3 represents the third calculation result, and D4 represents the fourth calculation result.
[0008] In an exemplary embodiment, before looking up the N calculation results corresponding to the N sub-areas in the pre-stored calculation result set, the method further includes: obtaining an original data block, where the original data block includes pixel values of each pixel point P for representing the target image area, [i, j] represents the coordinates of the pixel point P, 0 ≤ i ≤ H - 1, 0 ≤ j ≤ W - 1; determining a fifth calculation result of the sub-area R included in the target image area according to the original data block to obtain the calculation result set, where the sub-area R represents a rectangular area formed by taking the pixel points P and P as diagonal points, and the H * W sub-areas include the sub-area R. [i,j] of which the pixel value, [i, j] represents the coordinates of the pixel point P [i,j] ; according to the original data block, determining a fifth calculation result of the sub-area R included in the target image area, to obtain the calculation result set, where the sub-area R [i,j] represents a rectangular area formed by taking the pixel points P [i,j] and P [0,0] as diagonal points, and the H * W sub-areas include the sub-area R [i,j] . [i,j] .
[0009] In an exemplary embodiment, determining the fifth calculation result of the sub-area R included in the target image area according to the original data block includes: according to D(0, 0) = input(0, 0), and performing recursion in the following manner to obtain the fifth calculation result D(i, j): D(i, j) = D(i, j - 1) + D(i - 1, j) - D(i - 1, j - 1) + input(i, j), where when (i - 1) is less than 0, D(i - 1, j) = 0, D(i - 1, j - 1) = 0, when (j - 1) is less than 0, D(i, j - 1) = 0, D(i - 1, j - 1) = 0, and input(i, j) represents the pixel value of the pixel point P [i,j] in the original data block. [i,j] .
[0010] In an exemplary embodiment, the method further includes: traversing all pixel points in the target image region to obtain the H*W calculation results, where D(i,j) represents the (i*j)-th calculation result among the H*W calculation results; storing the (i*j)-th calculation result D(i,j) in a specified area A(i,j) of the target memory, where the specified area A(i,j) represents the area in the target memory for storing the pixel value of the pixel point P [i,j] in the original data block when obtaining the original data block.
[0011] In an exemplary embodiment, each of the N calculation results includes one of the following: the result obtained by summing the pixel values of all pixel points included in the sub-region; the result obtained by calculating the sum of squares of the pixel values of all pixel points included in the sub-region.
[0012] In an exemplary embodiment, obtaining the first coordinate and the second coordinate of the region to be calculated includes: obtaining the first coordinate and the second coordinate of the region to be calculated through a target layer in the target neural network model; determining, according to the first coordinate and the second coordinate, N sub-regions corresponding to the region to be calculated in the target image region includes: determining, through the target layer, the N sub-regions corresponding to the region to be calculated in the target image region according to the first coordinate and the second coordinate; searching for the N calculation results respectively corresponding to the N sub-regions in a pre-stored calculation result set includes: searching, through the target layer, for the N calculation results respectively corresponding to the N sub-regions in the pre-stored calculation result set; determining the target calculation result of the region to be calculated according to the N calculation results includes: determining, through the target layer, the target calculation result of the region to be calculated according to the N calculation results; where the target layer includes at least one of the following: a pooling layer, a normalization layer.
[0013] According to another embodiment of the present invention, an image processing apparatus is further provided, including: a first acquisition module configured to acquire a first coordinate and a second coordinate of a region to be calculated, where the first coordinate and the second coordinate are respectively used to represent the positions of pixel points at a pair of diagonal points of the region to be calculated in a target image region, the target image region includes H*W pixel points, and both H and W are positive integers greater than or equal to 2; a first determination module configured to determine, according to the first coordinate and the second coordinate, N sub-regions corresponding to the region to be calculated in the target image region, where N is a positive integer greater than or equal to 2; a search module configured to search for N calculation results respectively corresponding to the N sub-regions in a pre-stored calculation result set, where the calculation result set includes H*W calculation results calculated in advance, the H*W calculation results correspond one-to-one to H*W sub-regions in the target image region, the H*W sub-regions include sub-regions formed by using the origin in the target image region and each of the H*W pixel points as diagonal vertices, and each of the H*W calculation results is a result determined according to data corresponding to each pixel point in the corresponding sub-region among the H*W sub-regions; a second determination module configured to determine a target calculation result of the region to be calculated according to the N calculation results, where the target calculation result is used for a target neural network model to process the target image.
[0014] According to still another embodiment of the present invention, a computer-readable storage medium is further provided, where a computer program is stored in the computer-readable storage medium, and the computer program is configured to execute the steps in any one of the above method embodiments when running.
[0015] According to still another embodiment of the present invention, an electronic device is further provided, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0016] According to the present invention, by obtaining the first coordinates and the second coordinates of a pair of diagonal points of the area to be calculated, N sub-areas corresponding to the area to be calculated are determined in the target image area according to the first coordinates and the second coordinates, and then N calculation results corresponding to the N sub-areas are searched in the pre-stored calculation result set. Among them, the calculation result set includes H*W calculation results calculated in advance, and the H*W calculation results correspond one-to-one with H*W sub-areas in the target image area. The H*W sub-areas include sub-areas formed by the origin in the target image area and each pixel point among the H*W pixel points in the target image area as diagonal vertices. Each calculation result among the H*W calculation results is a result determined according to the data corresponding to each pixel point in the corresponding sub-area among the H*W sub-areas; then the target calculation result of the area to be calculated is determined according to the N calculation results, and the target calculation result is used for the target neural network model to process the target image. That is, by determining N sub-areas corresponding to the area to be calculated and searching for N calculation results corresponding to the N sub-areas in the calculation result set, and then the target calculation result of the area to be calculated can be determined according to the N calculation results, avoiding the problem in the related art that when determining the calculation result of the area to be calculated, it is necessary to traverse each element of the entire area to be calculated, thereby greatly increasing the calculation amount and affecting the image processing efficiency. Therefore, the problem of low image processing efficiency in the related art is solved, and the effect of improving the image processing efficiency is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is the block diagram of the mobile terminal hardware structure of the image processing method according to the embodiment of the present invention;
[0018] Figure 2 is the flowchart of the image processing method according to the embodiment of the present invention;
[0019] Figure 3 is the schematic diagram of the regional optimization calculation process according to the embodiment of the present invention;
[0020] Figure 4 is the processing example diagram of the input data according to the embodiment of the present invention;
[0021] Figure 5 is the calculation example diagram of the regional mean according to the embodiment of the present invention;
[0022] Figure 6 is the block diagram of the image processing device according to the embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0023] In the following, embodiments of the present invention will be described in detail with reference to the drawings and in conjunction with the embodiments.
[0024] It should be noted that the terms "first", "second", etc. in the description, claims and above-mentioned drawings of the present invention are used to distinguish similar objects, and do not necessarily describe a specific order or sequence.
[0025] The method embodiments provided in the embodiments of the present application can be executed on a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 is a block diagram of the hardware structure of a mobile terminal for the image processing method of the embodiments of the present invention. As Figure 1 shown, the mobile terminal may include one or more ( Figure 1 only one is shown in the figure) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Among them, the above-mentioned mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those of ordinary skill in the art can understand that Figure 1 the structure shown is only schematic and does not limit the structure of the above-mentioned mobile terminal. For example, the mobile terminal may further include more or fewer components than Figure 1 shown in the figure, or have a different configuration from Figure 1 shown in the figure.
[0026] The memory 104 can be used to store computer programs. For example, software programs and modules of application software, such as the computer program corresponding to the image processing method in the embodiments of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, the above-mentioned method is implemented. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 104 may further include a memory remotely disposed relative to the processor 102, and these remote memories can be connected to the mobile terminal through a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0027] The transmission device 106 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wireless network provided by a communication provider of the mobile terminal. In one instance, the transmission device 106 includes a network adapter (abbreviated as NIC), which can be connected to other network devices through a base station and thus can communicate with the Internet. In one instance, the transmission device 106 may be a radio frequency (abbreviated as RF) module, which is used to communicate with the Internet wirelessly.
[0028] In this embodiment, an image processing method is provided. Figure 2 It is a flowchart of the image processing method according to the embodiment of the present invention. As Figure 2 shown, the process includes the following steps:
[0029] Step S202: Obtain the first coordinate and the second coordinate of the area to be calculated, where the first coordinate and the second coordinate are respectively used to represent the positions of the pixel points at a pair of diagonal points of the area to be calculated in the target image area, the target image area includes H*W pixel points, and both H and W are positive integers greater than or equal to 2;
[0030] Step S204: Determine N sub-areas corresponding to the area to be calculated in the target image area according to the first coordinate and the second coordinate, where N is a positive integer greater than or equal to 2;
[0031] Step S206: Search for N calculation results corresponding to the N sub-areas respectively in the pre-stored calculation result set, where the calculation result set includes H*W calculation results calculated in advance, the H*W calculation results correspond one-to-one to the H*W sub-areas in the target image area, the H*W sub-areas include the sub-areas formed by taking the origin in the target image area and each of the H*W pixel points as the diagonal vertices, and each of the H*W calculation results is a result determined according to the data corresponding to each pixel point in the corresponding sub-area in the H*W sub-areas;
[0032] Step S208: Determine the target calculation result of the area to be calculated according to the N calculation results, where the target calculation result is used for the target neural network model to process the target image.
[0033] Through the above steps, by obtaining the first coordinates and the second coordinates of a pair of diagonal points of the area to be calculated, N sub-areas corresponding to the area to be calculated are determined in the target image area according to the first coordinates and the second coordinates, and then N calculation results respectively corresponding to the N sub-areas are searched in the pre-stored calculation result set. Among them, the calculation result set includes H*W calculation results calculated in advance, and the H*W calculation results correspond one-to-one with H*W sub-areas in the target image area. The H*W sub-areas include sub-areas formed by the origin in the target image area and each of the H*W pixel points in the target image area as diagonal vertices. Each of the H*W calculation results is a result determined according to the data corresponding to each pixel point in the corresponding sub-area among the H*W sub-areas; then the target calculation result of the area to be calculated is determined according to the N calculation results, and the target calculation result is used for the target neural network model to process the target image. That is, by determining N sub-areas corresponding to the area to be calculated and searching for N calculation results respectively corresponding to the N sub-areas in the calculation result set, and then the target calculation result of the area to be calculated can be determined according to the N calculation results, avoiding the problem in the related technology that each element of the entire area to be calculated needs to be traversed when determining the calculation result of the area to be calculated, thereby greatly increasing the calculation amount and affecting the efficiency of image processing. Therefore, the problem of low efficiency of image processing in the related technology is solved, and the effect of improving the efficiency of image processing is achieved.
[0034] Among them, the execution subject of the above steps can be a terminal, or an image processing device, or an image processor, such as a neural network model in an image processor, or a processor with human-computer interaction capabilities configured on a storage device, or a processing device or processing unit with similar processing capabilities, etc., but not limited thereto.
[0035] In the above embodiments, the first coordinate and the second coordinate of the area to be calculated are obtained, where the first coordinate and the second coordinate are respectively used to represent the positions of the pixel points at a pair of diagonal points of the area to be calculated in the target image area. The target image area includes H*W pixel points, and both H and W are positive integers greater than or equal to 2. For example, the area to be calculated is any area in the target image area, such as a 3*3 or 5*5 or 6*6 area (or other A*B area). The above first coordinate and second coordinate can be the coordinates of the upper left vertex and the lower right vertex of the area to be calculated, or can also be the coordinates of the lower left vertex and the upper right vertex of the area to be calculated; according to the first coordinate and the second coordinate, N sub-areas corresponding to the area to be calculated are determined in the target image area, where N is a positive integer greater than or equal to 2. For example, the N sub-areas can be four sub-areas formed by the four vertices of the area to be calculated and the origin of the target image area respectively. The N sub-areas can also be other numbers of sub-areas, as long as the target calculation result of the area to be calculated can be obtained according to the operations of the N sub-areas. In this way, the target calculation result of the area to be calculated can be obtained according to the calculation results of the N sub-areas; the N calculation results corresponding to the N sub-areas are searched in the pre-stored calculation result set, where the calculation result set includes H*W calculation results calculated in advance, and the H*W calculation results correspond one by one to the H*W sub-areas in the target image area. Each sub-area in the H*W sub-areas is a sub-area formed by each pixel point in the H*W pixel points and the origin in the target image area as the diagonal vertices. Taking the [i,j]th pixel point P [i,j] as an example, this pixel point P [i,j] and the origin P [0,0]A sub-region is formed, so that there are H*W sub-regions corresponding to the H*W pixel points of the target image region. The upper left corner of each sub-region is the origin of the target image region. Each calculation result among the H*W calculation results is determined according to the data corresponding to each pixel point in the corresponding sub-region among the H*W sub-regions. For example, each calculation result can be the sum of the data corresponding to each pixel point in each sub-region, or the sum of the squares of the data corresponding to each pixel point, or the average value of the data corresponding to each pixel point, etc.; then, according to the N calculation results, the target calculation result of the region to be calculated is determined. In this way, the target calculation result can be used by the target neural network model to process the target image. That is, by determining the N sub-regions corresponding to the region to be calculated and finding the N calculation results corresponding to the N sub-regions respectively from the calculation result set, and then the target calculation result of the region to be calculated can be determined according to the N calculation results, avoiding the problem in the related art that when determining the calculation result of the region to be calculated, it is necessary to traverse each element of the entire region to be calculated, which greatly increases the calculation amount and affects the efficiency of image processing. Therefore, the problem of low efficiency of image processing in the related art is solved, and the effect of improving the efficiency of image processing is achieved.
[0036] In an optional embodiment, determining, according to the first coordinate and the second coordinate, N sub-regions corresponding to the region to be calculated in the target image region includes: when N = 4, determining a first sub-region, a second sub-region, a third sub-region, and a fourth sub-region, where the first sub-region, the second sub-region, the third sub-region, and the fourth sub-region are included in the H*W sub-regions, the row coordinate of the lower right corner of the first sub-region is equal to the row coordinate of the first coordinate minus 1, the column coordinate of the lower right corner of the first sub-region is equal to the column coordinate of the first coordinate minus 1, the row coordinate of the lower right corner of the second sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the second sub-region is equal to the column coordinate of the second coordinate, the row coordinate of the lower right corner of the third sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the third sub-region is equal to the column coordinate of the first coordinate minus 1, the row coordinate of the lower right corner of the fourth sub-region is equal to the row coordinate of the first coordinate minus 1, and the column coordinate of the lower right corner of the fourth sub-region is equal to the column coordinate of the second coordinate; searching for N calculation results corresponding to the N sub-regions respectively in the pre-stored calculation result set includes: searching for a first calculation result, a second calculation result, a third calculation result, and a fourth calculation result corresponding to the first sub-region, the second sub-region, the third sub-region, and the fourth sub-region respectively in the calculation result set.In this embodiment, taking N = 4 as an example, that is, 4 sub-regions corresponding to the region to be calculated are determined according to the first coordinate and the second coordinate. The above first coordinate may be the coordinate of the upper left corner vertex of the region to be calculated (such as the corresponding pixel point X0), and the second coordinate may be the coordinate of the lower right corner vertex of the region to be calculated (such as the corresponding pixel point Y0). Then, the row and column coordinates corresponding to the lower right corner vertex of the first sub-region (such as the corresponding pixel point X1) can be 1 less than the row and column coordinates of the pixel point X0. Thus, the region formed by the pixel point X1 and the origin (such as the pixel point O) is the first sub-region; the row and column coordinates corresponding to the lower right corner vertex of the second sub-region (such as the corresponding pixel point X2) can be equal to the row and column coordinates of the above second coordinate, that is, the pixel point X2 and the pixel point Y0 are the same pixel point, and thus the second sub-region can be obtained; the row coordinate corresponding to the lower right corner vertex of the third sub-region (such as the corresponding pixel point X3) can be equal to the row coordinate of the second coordinate, and the column coordinate corresponding to the lower right corner vertex of the third sub-region (such as the corresponding pixel point X3) can be 1 less than the column coordinate of the above first coordinate. Thus, the region formed by the pixel point X3 and the origin (such as the pixel point O) is the third sub-region; the row coordinate corresponding to the lower right corner vertex of the fourth sub-region (such as the corresponding pixel point X4) can be 1 less than the row coordinate of the above first coordinate, and the column coordinate corresponding to the lower right corner vertex of the fourth sub-region (such as the corresponding pixel point X4) can be equal to the column coordinate of the above second coordinate. Thus, the region formed by the pixel point X4 and the origin (such as the pixel point O) is the fourth sub-region; then, the first calculation result, the second calculation result, the third calculation result, and the fourth calculation result corresponding to the first sub-region, the second sub-region, the third sub-region, and the fourth sub-region are found according to the pre-calculated H*W calculation results (i.e., the calculation result set). Through this embodiment, the purpose of determining N sub-regions associated with the region to be calculated and finding N calculation results corresponding to the N sub-regions respectively from the calculation result set is achieved.
[0037] In an alternative embodiment, the determining the target calculation result of the region to be calculated according to the N calculation results includes: determining the target calculation result according to the following formula: V = D1 + D2 - D3 - D4, where V represents the target calculation result, D1 represents the first calculation result, D2 represents the second calculation result, D3 represents the third calculation result, and D4 represents the fourth calculation result. In this embodiment, after finding the 4 calculation results corresponding to the 4 sub-regions, the target calculation result of the region to be calculated can be determined according to V = D1 + D2 - D3 - D4. Through this embodiment, the purpose of determining the target calculation result of the region to be calculated according to the N calculation results corresponding to the N sub-regions is achieved, avoiding the problem in the related art that each element of the entire region to be calculated needs to be traversed, thus greatly increasing the amount of calculation.
[0038] In an optional embodiment, before looking up the N calculation results corresponding to the N sub-regions in the pre-stored set of calculation results, the method further includes: obtaining an original data block, where the original data block includes pixel values of each pixel point P for representing the target image region, [i, j] represents the coordinates of the pixel point P, 0 ≤ i ≤ H - 1, 0 ≤ j ≤ W - 1; determining a fifth calculation result of a sub-region R included in the target image region according to the original data block to obtain the set of calculation results, where the sub-region R represents a rectangular region formed by taking pixel points P and P as diagonal points, and the H * W sub-regions include the sub-region R. In this embodiment, by obtaining the original data block and then determining the calculation result (such as the above-mentioned fifth calculation result) of any sub-region R in the target image region according to the original data block, the calculation result of any sub-region can be calculated. For example, the calculation result can be the sum of data corresponding to each pixel point in any sub-region, or the sum of squares of data corresponding to each pixel point, or the mean value of data corresponding to each pixel point, etc.; according to the above method, the H * W calculation results corresponding to each of the H * W sub-regions can be calculated. [i,j] of the pixel value, [i, j] represents the pixel point P [i,j] of the coordinates, 0 ≤ i ≤ H - 1, 0 ≤ j ≤ W - 1; determining a fifth calculation result of a sub-region R included in the target image region according to the original data block, where the sub-region R [i,j] represents a rectangular region formed by taking pixel points P [i,j] and P [0,0] as diagonal points, and the H * W sub-regions include the sub-region R [i,j] formed by taking pixel points P [i,j] . In this embodiment, by obtaining the original data block and then determining the calculation result (such as the above-mentioned fifth calculation result) of any sub-region R in the target image region according to the original data block, the calculation result of any sub-region can be calculated. For example, the calculation result can be the sum of data corresponding to each pixel point in any sub-region, or the sum of squares of data corresponding to each pixel point, or the mean value of data corresponding to each pixel point, etc.; according to the above method, the H * W calculation results corresponding to each of the H * W sub-regions can be calculated. [i,j] In this embodiment, by obtaining the original data block and then determining the calculation result (such as the above-mentioned fifth calculation result) of any sub-region R in the target image region according to the original data block, the calculation result of any sub-region can be calculated. For example, the calculation result can be the sum of data corresponding to each pixel point in any sub-region, or the sum of squares of data corresponding to each pixel point, or the mean value of data corresponding to each pixel point, etc.; according to the above method, the H * W calculation results corresponding to each of the H * W sub-regions can be calculated.
[0039] In an optional embodiment, the determining a fifth calculation result of a sub-region R included in the target image region according to the original data block includes: according to D(0, 0) = input(0, 0), and performing recursion in the following manner to obtain the fifth calculation result D(i, j): D(i, j) = D(i, j - 1) + D(i - 1, j) - D(i - 1, j - 1) + input(i, j), where when (i - 1) is less than 0, D(i - 1, j) = 0, D(i - 1, j - 1) = 0, when (j - 1) is less than 0, D(i, j - 1) = 0, D(i - 1, j - 1) = 0, and input(i, j) represents the pixel value of the pixel point P [i,j] in the original data block. In this embodiment, when calculating the fifth calculation result of any sub-region R [i,j] in the original data block. In this embodiment, when calculating the fifth calculation result of any sub-region R [i,j]When calculating the result (i.e., the above fifth calculation result), it can be obtained by recursion according to the above formula D(i,j) = D(i,j - 1) + D(i - 1,j) - D(i - 1,j - 1) + input(i,j). For example, D(0,0) = input(0,0), and D(0,1) = D(0,0) + 0 - 0 + input(0,1) can be calculated, D(1,0) = 0 + D(0,0) - 0 + input(1,0). Then, taking the sub-region R [1,1] as an example, D(1,1) = D(1,0) + D(0,1) - D(0,0) + input(1,1), and so on. Only based on the three calculation results D(i,j - 1), D(i - 1,j), D(i - 1,j - 1) and input(i,j), the calculation result of any sub-region can be obtained without traversing all elements in that sub-region. According to the method of this embodiment, the calculation result of any sub-region can be calculated conveniently and quickly. In this way, when determining the calculation result of the region to be calculated, the calculation results of the sub-regions related to the region to be calculated can be searched, and then the calculation result of the region to be calculated can be quickly determined.
[0040] In an optional embodiment, the method further includes: traversing all pixel points of the target image region to obtain the H*W calculation results, where D(i,j) represents the (i*j)-th calculation result among the H*W calculation results; storing the (i*j)-th calculation result D(i,j) into the specified region A(i,j) of the target memory, where the specified region A(i,j) represents the region in the target memory for storing the pixel value of the pixel point P [i,j] when obtaining the original data block. In this embodiment, all pixel points of the entire target image region can be traversed according to the above method to obtain the H*W calculation results corresponding to each of the H*W sub-regions. In practical applications, the (i*j)-th calculation result D(i,j) can be stored into the specified region A(i,j) of the target memory, and the specified region A(i,j) is the region in the target memory for storing the pixel value of the pixel point P [i,j] when obtaining the original data block. In this way, there is no need to allocate additional temporary memory, and the value of D(i,j) can be used to overwrite the value of the original input(i,j) in the memory, avoiding the problem of wasting memory caused by the method of reallocating memory to store intermediate calculation results in the related art.
[0041] In an optional embodiment, each of the N calculation results includes one of the following: the result obtained by performing a sum calculation on the pixel values of each pixel point included in the sub-region; the result obtained by calculating the sum of squares of the pixel values of each pixel point included in the sub-region. In this embodiment, the calculation result for each sub-region may be the result obtained by performing a sum calculation on the pixel values of each pixel point included in the sub-region, or the result obtained by calculating the sum of squares of the pixel values of each pixel point included in the sub-region, or the result obtained by calculating the average value of the pixel values of each pixel point included in the sub-region.
[0042] In an optional embodiment, the obtaining of the first coordinate and the second coordinate of the region to be calculated includes: obtaining the first coordinate and the second coordinate of the region to be calculated through a target layer in the target neural network model; the determining of the N sub-regions corresponding to the region to be calculated in the target image region according to the first coordinate and the second coordinate includes: determining the N sub-regions corresponding to the region to be calculated in the target image region through the target layer according to the first coordinate and the second coordinate; the searching for the N calculation results respectively corresponding to the N sub-regions in a pre-stored calculation result set includes: searching for the N calculation results respectively corresponding to the N sub-regions in the pre-stored calculation result set through the target layer; the determining of the target calculation result of the region to be calculated according to the N calculation results includes: determining the target calculation result of the region to be calculated through the target layer according to the N calculation results; wherein, the target layer includes at least one of the following: a pooling layer, a normalization layer. In this embodiment, the above operation steps may be executed by a target layer in a target neural network. For example, the target layer may be a pooling layer (such as an average pooling layer), or a normalization layer. In the field of image processing, it is quite common to perform region calculations through a target layer of a target neural network model and then process the image according to the calculation results. For example, it is usually necessary to perform multiple region calculations to obtain an output feature map.
[0043] Obviously, the above-described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. The present invention will be specifically described in conjunction with the embodiments.
[0044] An embodiment of the present invention proposes a method for region optimization calculation. After obtaining an input data block, for several dimensions that need to perform region calculation, the corresponding data of these dimensions is taken out, and using the recursive idea, the sum of the region blocks with the point with coordinate 0 and each point under these dimensions as the diagonal (if performing region mean calculation or normalization, etc., it can also be expressed as the corresponding operation result) is calculated, and these results are used to replace the original data. Then, according to the corner coordinates of the region blocks obtained for calculation, and using the inference formula, the region calculation result is directly obtained through the processed data. The method of this embodiment is applicable to region calculation in any dimension.
[0045] Figure 3 It is a schematic diagram of the region optimization calculation process according to an embodiment of the present invention, and this process includes:
[0046] S302, obtain the input data and the dimensions that need to perform region calculation;
[0047] S304, process the input data;
[0048] S306, obtain the region corner coordinates according to the operator parameters (corresponding to the aforementioned first coordinate and second coordinate);
[0049] S308, directly obtain the sum of region elements or other forms of sum (corresponding to the aforementioned calculation result) according to the corner coordinates and the formula. For example, the sum of the squares of region elements, or the average value of region elements, etc.; the formula will be described later;
[0050] S310, process the result according to the operator function to obtain the final output result.
[0051] The following details some processes of the embodiment of the present invention:
[0052] 1. Process the input data
[0053] Taking two-dimensional average pooling as an example, if the data arrangement in the input data block is NCHW and the data block size is n*c*h*w, then the dimensions for performing region average calculation are HW. Use input(i,j) to represent the element value at the coordinate (i,j) under this HW, and d(i,j) to represent the sum of the elements in the rectangular region with the coordinates (0,0) and (i,j) as the diagonal. For example, Figure 4 the value of the element in the yellow region in is input(3,6), the sum of the elements in the blue region can be expressed as d(3,5), and the sum of the elements in the green region can be expressed as d(2,6).
[0054] For calculating the sum of elements within the red region, i.e., d(3, 6), it can be obtained by adding the input at its own position input(3, 6) to the sum of the blue region d(3, 5) with a width 1 less than it and the green region d(2, 6) with a height 1 less than it, and then subtracting their overlapping part, i.e., the purple region d(2, 5). And d(2, 6) and d(3, 5) have both been obtained previously according to the same method.
[0055] Then there is the following reasoning formula:
[0056] If i < 0 or j < 0: d(i, j) = 0;
[0057] Else: d(i, j) = d(i, j – 1) + d(i - 1, j) – d(i – 1, j - 1) + input(i, j);
[0058] Since i in the recurrence process ranges from 0 to h - 1 and j ranges from 0 to w - 1, in the program, the d array does not need to allocate additional temporary memory. The values in the original input memory can be used to overwrite itself, that is, use input to replace the d array, and the following replacement formula is obtained:
[0059] If i < 0 or j < 0: input(i, j) = 0;
[0060] Else: input(i, j) = input(i, j – 1) + input(i - 1, j) – input(i – 1, j - 1) + input(i, j);
[0061] This processing can be completed with a time complexity of O(hw).
[0062] 2. Obtain the calculation result according to the corner coordinates
[0063] Let v[(x1, y1)][(x2, y2)] represent the sum of elements within the rectangular region with the upper left corner at (x1, y1) and the lower right corner at (x2, y2) (corresponding to the aforementioned region to be calculated). Then Figure 5 The sum of elements within the red region in the figure can be expressed as v[(3, 5)][(4, 7)]. To obtain the sum of elements in the red region, it can be expressed as the sum of elements in the blue region minus the sum of elements in the green region and the orange region, and then plus the sum of elements in the brown region. The upper left coordinates of these four rectangular regions are all (0, 0), and for any (x, y), v[(0, 0)][(x, y)] = d(x, y).
[0064] So there is the following formula:
[0065] v[(x1,y1)][(x2,y2)] = d(x2,y2) - d(x1 - 1,y2) – d(x2,y1 - 1) + d(x1 - 1,y1 - 1)
[0066] Among them, d(x,y) is initialized in the previous step and can be directly used. Therefore, this calculation does not traverse all elements within the rectangular area from (x1,y1) to (x2,y2). Regardless of the size of the area, the result can be directly given according to the formula.
[0067] 3. Applicability of this method
[0068] Since this method involves cumulative calculation, it can only optimize the calculation of areas that do not involve maximum and minimum value calculations, and can effectively speed up operations such as finding the area sum, area mean, area sum of squares, and area normalization.
[0069] When there is no intersection between different regions, this method has no obvious advantage over the traditional method, but this situation hardly exists because the original data will be lost under such parameters. The larger the intersection between regions, the more obvious the performance improvement of this method.
[0070] This method is not only applicable to two-dimensional regions, but also applicable to any dimension. For three-dimensional region processing such as three-dimensional average pooling, the above inference formula changes from four terms to eight terms, and the initialization part is also extended accordingly.
[0071] This method can be applied to average pooling operators and regional normalization operators such as LRN in any dimension.
[0072] In the embodiments of the present invention, in the operators involving regional summation calculation, through the processing of the initial data, the calculation amount of repeated calculation between adjacent regions is avoided, and it is applicable to any dimension. The number of calculations is not affected by the size of the region, and the intermediate results do not need to be saved in temporary memory during the calculation process, improving the performance of the operator.
[0073] Through the embodiments of the present invention, the calculation amount of a single regional calculation is no longer the entire region, but after processing the original image data, the calculation result of the region is directly derived according to the corner coordinates of the region, and the single operation time is reduced to a constant level and is no longer affected by the size of the region. The method of the embodiments of the present invention does not involve any repeated calculation amount and is applicable to all network layers involving different types of summation calculations within the region.
[0074] Compared with the related art, the embodiments of the present invention have the following advantages: 1) There is no part of repeated calculation compared with the traditional method. Under the method proposed in this embodiment, the single calculations in different regions do not affect each other, and the processing of the original data is equivalent to replacing all repeated calculation amounts with a single processing in a different way; 2) The efficiency of a single calculation is not affected by the size of the region. In the prior art, all elements of the region for a single calculation need to be traversed, and the operation efficiency of operators with relatively large region length parameters is low. However, the method of this embodiment only needs to obtain region information (corner coordinates), and after processing the initial data, the result can be directly given, and the time consumed for processing the initial data can be almost ignored; 3) In the related art, it is necessary to apply for a temporary memory almost the same size as the input data to save the temporary feature map, and for region calculation in the traditional method, many temporary variables are also needed to save the values during the process of traversing the region; while this method does not require a lot of additional temporary memory and variables to store intermediate results, the data itself can be used to replace the processing process of the original data, and the result can be directly given without applying for additional variables and memory.
[0075] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such an understanding, the technical solution of the present invention, in essence, or the part that makes a contribution to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0076] In this embodiment, an image processing device is further provided. Figure 6 It is a structural block diagram of the image processing device according to the embodiment of the present invention, as Figure 6 shown. The device includes:
[0077] A first acquisition module 602, configured to acquire a first coordinate and a second coordinate of a region to be calculated, where the first coordinate and the second coordinate are respectively used to represent the positions of pixel points at a pair of diagonal points of the region to be calculated in a target image region, and the target image region includes H*W pixel points, and both H and W are positive integers greater than or equal to 2;
[0078] A first determination module 604, configured to determine N sub-regions corresponding to the region to be calculated in the target image region according to the first coordinate and the second coordinate, where N is a positive integer greater than or equal to 2;
[0079] A search module 606 is configured to search for N calculation results respectively corresponding to the N sub-regions in a pre-stored set of calculation results, where the set of calculation results includes H*W calculation results obtained by pre-calculation, the H*W calculation results correspond one-to-one to H*W sub-regions in the target image region, the H*W sub-regions include sub-regions formed by using the origin in the target image region and each of the H*W pixel points as diagonal vertices, and each of the H*W calculation results is a result determined according to data corresponding to each pixel point in the corresponding sub-region among the H*W sub-regions;
[0080] A second determination module 608 is configured to determine a target calculation result of the region to be calculated according to the N calculation results, where the target calculation result is used for a target neural network model to process the target image.
[0081] In an optional embodiment, the first determination module 604 includes: a first determination unit, configured to determine a first sub-region, a second sub-region, a third sub-region, and a fourth sub-region when N = 4, where the first sub-region, the second sub-region, the third sub-region, and the fourth sub-region are included in the H*W sub-regions, the row coordinate of the lower right corner of the first sub-region is equal to the row coordinate of the first coordinate minus 1, the column coordinate of the lower right corner of the first sub-region is equal to the column coordinate of the first coordinate minus 1, the row coordinate of the lower right corner of the second sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the second sub-region is equal to the column coordinate of the second coordinate, the row coordinate of the lower right corner of the third sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the third sub-region is equal to the column coordinate of the first coordinate minus 1, the row coordinate of the lower right corner of the fourth sub-region is equal to the row coordinate of the first coordinate minus 1, and the column coordinate of the lower right corner of the fourth sub-region is equal to the column coordinate of the second coordinate; the search module 606 includes: a search unit, configured to search for a first calculation result, a second calculation result, a third calculation result, and a fourth calculation result respectively corresponding to the first sub-region, the second sub-region, the third sub-region, and the fourth sub-region in the set of calculation results.
[0082] In an optional embodiment, the second determination module 608 includes: a second determination unit, configured to determine the target calculation result according to the following formula: V = D1 + D2 - D3 - D4, where V represents the target calculation result, D1 represents the first calculation result, D2 represents the second calculation result, D3 represents the third calculation result, and D4 represents the fourth calculation result.
[0083] In an alternative embodiment, the above-mentioned device further includes: a second acquisition module, configured to acquire an original data block before looking up N calculation results corresponding to the N sub-regions in a pre-stored set of calculation results, where the original data block includes pixel points P for representing the target image region [i,j] of the pixel values, [i, j] represents the coordinates of the pixel point P [i,j] ; a first acquisition module, configured to determine a fifth calculation result of a sub-region R included in the target image region according to the original data block, so as to obtain the set of calculation results, where the sub-region R [i,j] represents a rectangular region formed by taking pixel points P [i,j] and P [0,0] as diagonal points, and the H*W sub-regions include the sub-region R [i,j] . [i,j] .
[0084] In an alternative embodiment, the above-mentioned first acquisition module includes: an acquisition unit, configured to obtain the fifth calculation result D(i, j) according to D(0, 0) = input(0, 0) and perform recursion in the following manner: D(i, j) = D(i, j - 1) + D(i - 1, j) - D(i - 1, j - 1) + input(i, j), where when (i - 1) < 0, D(i - 1, j) = 0, D(i - 1, j - 1) = 0, when (j - 1) < 0, D(i, j - 1) = 0, D(i - 1, j - 1) = 0, and input(i, j) represents the pixel value of the pixel point P [i,j] in the original data block.
[0085] In an alternative embodiment, the above-mentioned device further includes: a second acquisition module, configured to traverse all pixel points of the target image region to obtain the H*W calculation results, where D(i, j) represents the (i*j)-th calculation result among the H*W calculation results; a storage module, configured to store the (i*j)-th calculation result D(i, j) in a specified area A(i, j) of a target memory, where the specified area A(i, j) represents an area in the target memory for storing the pixel value of the pixel point P [i,j] in the original data block when acquiring the original data block.
[0086] In an alternative embodiment, each of the N calculation results includes one of the following: a result obtained by performing a sum calculation on the pixel values of each pixel point included in the sub-region; a result obtained by performing a sum of squares calculation on the pixel values of each pixel point included in the sub-region.
[0087] In an alternative embodiment, the above-mentioned device is located in the target layer of the target neural network model, and the first coordinate and the second coordinate of the area to be calculated are obtained through the target layer in the target neural network model; the target layer determines the N sub-areas corresponding to the area to be calculated in the target image area according to the first coordinate and the second coordinate; the target layer searches for the N calculation results corresponding to the N sub-areas respectively in the pre-stored set of calculation results; the target layer determines the target calculation result of the area to be calculated according to the N calculation results; wherein, the target layer includes at least one of the following: a pooling layer, a normalization layer.
[0088] It should be noted that the above-mentioned modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to this: the above-mentioned modules are all located in the same processor; or, the above-mentioned modules are respectively located in different processors in any combination form.
[0089] An embodiment of the present invention also provides a computer-readable storage medium, in which a computer program is stored. Among them, the computer program is set to execute the steps in any one of the above method embodiments when running.
[0090] In an exemplary embodiment, the above-mentioned computer-readable storage medium may include, but is not limited to: various media such as a USB flash drive, a read-only memory (ROM for short), a random access memory (RAM for short), a mobile hard disk, a magnetic disk, or an optical disc that can store a computer program.
[0091] An embodiment of the present invention also provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is set to run the computer program to execute the steps in any one of the above method embodiments.
[0092] In an exemplary embodiment, the above-mentioned electronic device may further include a transmission device and an input / output device. Among them, the transmission device is connected to the above-mentioned processor, and the input / output device is connected to the above-mentioned processor.
[0093] The specific examples in this embodiment may refer to the examples described in the above embodiments and exemplary embodiments, and will not be repeated here.
[0094] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present invention can be implemented by a general-purpose computing device. They can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. They can be implemented by program codes executable by the computing device. Thus, they can be stored in a storage device and executed by the computing device. And in some cases, the steps shown or described can be executed in a sequence different from that here, or they can be separately fabricated into individual integrated circuit modules, or multiple modules or steps among them can be fabricated into a single integrated circuit module for implementation. In this way, the present invention is not limited to any specific combination of hardware and software.
[0095] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modifications, equivalent replacements, improvements, etc. made within the principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. An image processing method, characterized in that, including: obtaining a first coordinate and a second coordinate of a region to be calculated, where the first coordinate and the second coordinate are respectively used to represent the positions of pixel points at a pair of diagonal points of the region to be calculated in a target image region, the target image region includes H*W pixel points, and both H and W are positive integers greater than or equal to 2; determining N sub-regions corresponding to the region to be calculated in the target image region according to the first coordinate and the second coordinate, where N is a positive integer greater than or equal to 2; searching for N calculation results respectively corresponding to the N sub-regions in a pre-stored calculation result set, where the calculation result set includes H*W calculation results calculated in advance, the H*W calculation results correspond one-to-one to H*W sub-regions in the target image region, the H*W sub-regions include sub-regions formed by using the origin in the target image region and each of the H*W pixel points as diagonal vertices, and each of the H*W calculation results is a result determined according to data corresponding to each pixel point in the corresponding sub-region among the H*W sub-regions; determining a target calculation result of the region to be calculated according to the N calculation results, where the target calculation result is used for a target neural network model to process the target image.
2. The method according to claim 1, wherein the determining N sub-regions corresponding to the region to be calculated in the target image region according to the first coordinate and the second coordinate includes: in the case of N = 4, determining a first sub-region, a second sub-region, a third sub-region and a fourth sub-region, where the H*W sub-regions include the first sub-region, the second sub-region, the third sub-region and the fourth sub-region, the row coordinate of the lower right corner of the first sub-region is equal to the row coordinate of the first coordinate minus 1, the column coordinate of the lower right corner of the first sub-region is equal to the column coordinate of the first coordinate minus 1, the row coordinate of the lower right corner of the second sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the second sub-region is equal to the column coordinate of the second coordinate, the row coordinate of the lower right corner of the third sub-region is equal to the row coordinate of the second coordinate, the column coordinate of the lower right corner of the third sub-region is equal to the column coordinate of the first coordinate minus 1, and the row coordinate of the lower right corner of the fourth sub-region is equal to the row coordinate of the first coordinate minus 1, and the column coordinate of the lower right corner of the fourth sub-region is equal to the column coordinate of the second coordinate; the searching for N calculation results respectively corresponding to the N sub-regions in the pre-stored calculation result set includes: searching for a first calculation result, a second calculation result, a third calculation result and a fourth calculation result respectively corresponding to the first sub-region, the second sub-region, the third sub-region and the fourth sub-region in the calculation result set.
3. The method according to claim 2, wherein the determining the target calculation result of the region to be calculated according to the N calculation results includes: determining the target calculation result according to the following formula: V = D1 + D2 - D3 - D4, where V represents the target calculation result, D1 represents the first calculation result, D2 represents the second calculation result, D3 represents the third calculation result, and D4 represents the fourth calculation result.
4. The method according to claim 1, characterized in that, Before looking up the N calculation results corresponding to the N sub-regions in the pre-stored set of calculation results, the method further includes: Obtain the original data block, where each pixel point P for representing the target image region is included in the original data block [i,j] The pixel value of, [i, j] represents the pixel point P [i,j] The coordinates of, 0 ≤ i ≤ H - 1, 0 ≤ j ≤ W - 1; Determine sub-region R included in the target image region according to the original data block [i,j] of the fifth calculation result to obtain the set of calculation results, wherein the sub-region R [i,j] represents a rectangular region formed by taking pixel points P [0,0] and P [i,j] as diagonal points, and the H*W sub-regions include the sub-region R [i,j] .
5. The method according to claim 4, characterized in that, Determining a sub-region R included in the target image region according to the original data block [i,j] The fifth calculation result of which includes: According to D(0, 0) = input(0, 0), and performing recursion in the following manner to obtain the fifth calculation result D(i, j): D(i,j) = D(i,j - 1)+D(i - 1,j)-D(i - 1,j - 1)+input(i,j), where when (i - 1) is less than 0, D(i - 1,j)=0, D(i - 1,j - 1)=0, when (j - 1) is less than 0, D(i,j - 1)=0, D(i - 1,j - 1)=0, and input(i,j) represents the pixel value of the pixel point P [i,j] in the original data block.
6. The method according to claim 5, characterized in that, The method further includes: Traversing all pixel points in the target image region to obtain the H * W calculation results, where D(i, j) represents the (i * j)-th calculation result among the H * W calculation results; Store the (i*j)-th calculation result D(i,j) in the specified area A(i,j) of the target memory, where the specified area A(i,j) represents the area in the target memory for storing the pixel values of the pixel points P in the original data block when obtaining the original data block. [i,j] of the original data block.
7. The method according to any one of claims 1 to 6, wherein the obtaining of the first coordinate and the second coordinate of the region to be calculated includes: obtaining the first coordinate and the second coordinate of the region to be calculated through a target layer in the target neural network model; the determining, according to the first coordinate and the second coordinate, of the N sub-regions corresponding to the region to be calculated in the target image region includes: determining, through the target layer, the N sub-regions corresponding to the region to be calculated in the target image region according to the first coordinate and the second coordinate; the looking up, in the pre-stored set of calculation results, of the N calculation results corresponding to the N sub-regions respectively includes: looking up, through the target layer, the N calculation results corresponding to the N sub-regions respectively in the pre-stored set of calculation results; the determining, according to the N calculation results, of the target calculation result of the region to be calculated includes: determining, through the target layer, the target calculation result of the region to be calculated according to the N calculation results; wherein the target layer includes at least one of the following: a pooling layer, a normalization layer.
8. An image processing apparatus, characterized in that, including: a first obtaining module, configured to obtain a first coordinate and a second coordinate of a region to be calculated, where the first coordinate and the second coordinate are respectively used to represent the positions of pixel points at a pair of diagonal points of the region to be calculated in a target image region, and the target image region includes H * W pixel points, and both H and W are positive integers greater than or equal to 2; a first determining module, configured to determine, according to the first coordinate and the second coordinate, N sub-regions corresponding to the region to be calculated in the target image region, where N is a positive integer greater than or equal to 2; A search module, configured to search for N calculation results respectively corresponding to the N sub-regions in a pre-stored set of calculation results, where the set of calculation results includes H*W calculation results obtained by pre-calculation, the H*W calculation results correspond one-to-one to H*W sub-regions in the target image region, the H*W sub-regions include sub-regions formed by using the origin in the target image region and each of the H*W pixel points as diagonal vertices, and each of the H*W calculation results is a result determined according to data corresponding to each pixel point in the corresponding sub-region among the H*W sub-regions; A second determination module, configured to determine a target calculation result of the region to be calculated according to the N calculation results, where the target calculation result is used for a target neural network model to process the target image.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, where when the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.
10. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Electrical equipment fault diagnosis model implementation method based on graph calculation
CN114937142A
Image processing method and apparatus, and electronic device
WO2022237657A1