Image magnification method based on neural network, neural network accelerator and electronic device

By dividing the image into tiles and calculating and storing each tile separately, the problem of reduced computing performance and increased power consumption during image enlargement on traditional hardware platforms is solved, achieving more efficient memory utilization and computing performance. promote.

CN118505501BActive Publication Date: 2024-09-24REEXEN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410976370.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-20
Publication Date
2024-09-24
Estimated Expiration
2044-07-20

AI Technical Summary

Technical Problem

On traditional hardware platforms, neural networks need to calculate the entire image during the image enlargement process, resulting in reduced computing performance and increased power consumption, as well as increased memory data handling, making it difficult to deploy efficiently.

Method used

The image amplification method based on neural network is used to reduce the memory handling requirements by dividing the image into tiles and calculating and storing each tile separately. The nearest neighbor interpolation or bilinear interpolation algorithm is used to amplify the image and filter out redundant information. The information is not directly involved in the calculation.

Benefits of technology

The power consumption and computing performance of the neural network processing device are reduced, the memory handling required during image enlargement is reduced, and the computing performance is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118505501B
    Figure CN118505501B
Patent Text Reader

Abstract

The present invention discloses an image magnification method based on a neural network, a neural network accelerator and an electronic device, which relates to the field of neural network technology and solves the technical problem that memory data transfer is increased when the image is magnified, resulting in decreased computing performance and increased power consumption. The image magnification method comprises: selecting a tile from a preset tile to segment the original image, and indexing and marking each tile; calculating and storing the position information and cropping information of the tile at different segmentation positions, and associating them with the types in the alternative image magnification algorithm; obtaining multiple tile corresponding to the position of the area to be magnified, filtering the part of each tile that needs to be cropped after the image is magnified; and executing the target image magnification algorithm separately for each tile to magnify it by scale times. The present invention performs image magnification calculation based on tile, reduces memory transfer, improves computing performance, and reduces power consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of neural network technology, and in particular to a neural network-based image magnification method, a neural network accelerator and electronic equipment. Background Art

[0002] A Deep Neural Network (DNN) is a machine learning method based on the artificial neural network architecture. Artificial Neural Networks (ANN) use layers of interconnected nodes (called neurons) to process and learn input data. A Deep Neural Network is an artificial neural network with multiple layers, which are located between the input layer and the output layer. There are different types of neural networks, but they always consist of the same components: neurons, synapses, weights, biases, and functions. In practical applications, these components are usually called operators. Deep learning uses multiple layers to represent different levels of abstraction of data, thereby improving the accuracy and generalization ability of the model.

[0003] As the amount of data continues to accumulate, artificial intelligence technology with neural networks as the theme has been more and more widely used. Although neural networks have been proven to be able to successfully solve some practical problems, such as autonomous driving and face recognition. However, due to the limitations of computing performance on traditional hardware platforms, it is difficult to efficiently deploy neural networks on traditional hardware. Therefore, it has become an important thing to design a customized hardware platform specifically for neural network algorithms. The hardware platform designed and customized for neural network algorithms is called a neural network hardware accelerator, and its core is usually a set of dedicated integrated circuit chips. This chip is called a neural network hardware accelerator chip, also called a neural network accelerator.

[0004] Due to the considerations of area cost, performance and power consumption, neural network hardware accelerator chips need to reduce area cost and power consumption while maintaining specific performance. In neural networks applied to images, image magnification is an indispensable content, and generally uses algorithms such as bilinear interpolation and nearest neighbor interpolation. When executing the image magnification algorithm of the neural network, the entire image needs to be calculated, that is, the intermediate calculation results of the entire image are first stored in the memory, and then the calculation is started. This processing method will increase the memory data handling during the calculation process, resulting in a decrease in the computing performance and an increase in power consumption of the neural network processing device. Summary of the invention

[0005] The purpose of the present invention is to provide an image magnification method based on a neural network, a neural network accelerator and an electronic device to at least solve the above technical problems. The preferred technical solutions among the many technical solutions provided by the present invention can produce many technical effects as described below.

[0006] To achieve the above object, the present invention provides the following technical solutions:

[0007] The present invention provides a neural network-based image magnification method, which is used for magnifying an image in a neural network vector processing, and includes the following steps: S100: the input layer of the neural network obtains the height information, width information and channel number information of the original image; S200: based on the height information, width information and channel number information of the original image, selects a tile from a preset tile to segment the original image, obtains the total number of segments, and indexes each tile based on the total number of segments and the segmentation position of the tile; S300: based on the magnification scale and at least one type of alternative image magnification algorithm, calculates and stores the position information and cropping information of the tile at different segmentation positions , and associate the position information and cropping information with the type in the candidate image magnification algorithm; S400: select a type from the candidate image magnification algorithm as the target image magnification algorithm, based on the area to be magnified of the original image, obtain multiple tiles corresponding to the position of the area to be magnified, and based on the type of the target image magnification algorithm and the stored position information and cropping information of the multiple tiles, filter the part that needs to be cropped of each tile after the image is magnified; S500: the vector processor of the neural network executes the target image magnification algorithm on each tile after the filtering operation separately and sends it to the memory, magnifies the area to be magnified of the original image by scale times, and the output layer of the neural network outputs the magnified image information.

[0008] Preferably, steps S200 to S400 are replaced by: S200': based on the height information, width information, channel number information of the original image and the area to be enlarged, select tiles from preset tiles to segment the image of the area to be enlarged, obtain the total number of segments, and index each tile based on the total number of segments and the segmentation position of each tile; S300': based on the magnification scale and at least one type of alternative image enlargement algorithm, calculate and store the position information and cropping information of tiles at different segmentation positions, and associate the position information and cropping information with the type in the alternative image enlargement algorithm; S400': select a type from the alternative image enlargement algorithm as the target image enlargement algorithm, and based on the type of the target image enlargement algorithm and the position information and cropping information of the stored multiple tiles, filter the part of each tile that needs to be cropped after the image is enlarged.

[0009] Preferably, tiles of different sizes are obtained according to height information, width information and channel number information of different acquired original images, and the preset tile is obtained based on a set of multiple tiles of different sizes.

[0010] Preferably, when segmenting, the original image or the area to be enlarged of the original image is segmented from top to bottom along the longitudinal direction by tiles, and the tiles are indexed starting from 0.

[0011] Preferably, the cropping information of different segmentation positions is stored through the cropping function T[a,b,0,0], wherein a and b represent the cropping sizes corresponding to the results of filtering out the tile in the upper and lower directions, respectively, and the third parameter 0 and the fourth parameter 0 in the cropping function T represent that the tile does not need to be cropped in the left and right directions, respectively; when processing the first tile, the values ​​of a and b in the cropping function T are 0 and x, respectively; when processing the last tile, the values ​​of a and b in the cropping function T are x and 0, respectively; when processing tiles other than the first and last, the values ​​of a and b in the cropping function T are x and x, respectively.

[0012] Preferably, the image magnification algorithm adopts a nearest neighbor interpolation algorithm and / or a bilinear interpolation algorithm; if the nearest neighbor interpolation algorithm is adopted, x in the cropping function T is equal to the magnification scale; if the bilinear interpolation algorithm is adopted, x in the cropping function T is equal to 2.

[0013] Preferably, when calculating the cropping information of the tile, the portion of the tile to be cropped is adapted to the interpolation of a fixed size, and the points after the interpolation of the nearest neighbor interpolation algorithm and / or the bilinear interpolation algorithm are identified.

[0014] Preferably, the position information of the tile is stored by the position function A[e, f, g], where e, f, and g represent the tile index mark information, tile width information, and tile channel quantity information of the tile respectively; when processing the first or last tile, the value of e in the position function A is h-scale; when processing tiles other than the first and last tile, the value of e in the position function A is h-2scale; where h is the index mark number of the tile.

[0015] A neural network accelerator is used to run any of the neural network-based image enlargement methods described above.

[0016] An electronic device comprises the neural network accelerator described above.

[0017] Implementing one of the above technical solutions of the present invention has the following advantages or beneficial effects:

[0018] The present invention is a tile-based image magnification algorithm, which only needs to use a part of the original image for calculation each time, specifically, a tile is magnified separately and the calculation result is sent to the memory, instead of the existing image magnification calculation of the entire magnified area of ​​the original image, which reduces the memory handling requirements required in the calculation process, thereby reducing the power consumption of the neural network processing device. At the same time, the present invention filters and excludes the redundant information generated by each tile when executing the magnification algorithm, and does not directly participate in the final image magnification calculation. This processing method further reduces the memory handling required in the image magnification calculation process, improves the computing performance, and further reduces the power consumption of the neural network processing device. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. It is obvious that the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0020] Figure 1 The process of the image magnification method based on neural network in the first embodiment of the present invention is as follows Figure 1 ;

[0021] Figure 2 The process of the image magnification method based on neural network in the first embodiment of the present invention is as follows Figure 2 ;

[0022] Figure 3 is an operation diagram of a neural network-based image magnification method according to a first embodiment of the present invention;

[0023] Figure 4 Schematic diagram of a neural network accelerator according to Embodiment 2 of the present invention. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical solutions and advantages of the present invention clearer, the various exemplary embodiments to be described below will refer to the corresponding drawings, which constitute a part of the exemplary embodiments, wherein various exemplary embodiments that may be used to implement the present invention are described. Unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation methods described in the following exemplary embodiments do not represent all implementation methods consistent with the present disclosure. It should be understood that they are only examples of processes, methods, devices, etc. that are consistent with some aspects of the present disclosure as detailed in the attached claims, and other embodiments may also be used, or the embodiments listed herein may be modified in structure and function without departing from the scope and essence of the present invention.

[0025] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", etc. indicate the orientation or positional relationship based on the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the elements referred to must have a specific orientation, be constructed and operated in a specific orientation. The terms "first", "second", etc. are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. The term "multiple" means two or more. The terms "connected" and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, an integral connection, a mechanical connection, an electrical connection, a communication connection, a direct connection, an indirect connection through an intermediate medium, and can be the internal connection of two elements or the interaction relationship between two elements. The term "and / or" includes any and all combinations of one or more related listed items. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to the specific circumstances.

[0026] In order to illustrate the technical solution of the present invention, a specific embodiment is used below for description, and only the parts related to the embodiment of the present invention are shown.

[0027] Embodiment 1:

[0028] like Figure 1As shown, the present invention provides an image magnification algorithm based on a neural network, which is used to magnify the image in the neural network vector processing, including the following steps. S100: The input layer of the neural network obtains the height information (pixels in the height direction), width information (pixels in the width direction) and channel number information (generally RGB red, green and blue three channels) of the original image, so as to facilitate the corresponding processing and magnification calculation of the original image. Specifically, the height information, width information and channel number information of the original image are required to segment the original image by tiles. S200: Based on the height information, width information and channel number information of the original image, these information are required to segment the original image, and tiles are selected from preset tiles to segment the original image. The size of the tile can be set as needed to better adapt to the height and width of the original image, and the total number of segments is obtained. The tile is indexed and marked based on the total number of segments and the segmentation position of the tile, so as to quickly confirm the corresponding tile according to the position of the image magnification. S300: Based on the magnification scale (the magnification scale is preferably a positive integer power of 2, such as 2, 4, 8, etc., which is convenient for rapid calculation), and at least one type of alternative image magnification algorithm, the alternative image magnification algorithm includes multiple types of magnification algorithms, such as the nearest neighbor interpolation algorithm, the bilinear interpolation algorithm, etc., so as to facilitate the selection of the most suitable magnification algorithm according to needs, and improve the applicability of the present invention. The position information and cropping information of the tiles at different segmentation positions are calculated and stored, and the position information and cropping information are associated with the types in the alternative image magnification algorithm, that is, the position information and cropping information corresponding to different types of image magnification algorithms are different, so as to facilitate filtering of redundant information of image magnification. S400: Select a type from the alternative image magnification algorithm as the target image magnification algorithm, based on the area to be magnified of the original image, obtain multiple tiles corresponding to the position of the area to be magnified, and filter the part to be cropped of each tile after the image is magnified based on the type of the target image magnification algorithm, as well as the stored position information (used to locate the specific tile) and cropping information (used to obtain the part to be cropped). S500: The vector processor of the neural network executes the target image magnification algorithm on each tile after the filtering operation and sends it to the memory, that is, each tile is calculated separately and sent to the memory, rather than calculating the entire magnified area as a whole and moving the whole data in the memory, so that it is not easy to exceed the memory capacity, and the memory data moving volume can be greatly reduced, thereby reducing the power consumption caused by it, and the area to be magnified of the original image is scaled up, and then the output layer of the neural network outputs the amplified image information.The image magnification algorithm can be selected according to the usage scenario, and the calculation results are sent to the memory. After the results of executing the magnification algorithm on all tiles are spliced ​​according to the index mark information of the tile tiles, the magnification area of ​​the original image is magnified by scale times. The present invention is an image magnification algorithm based on tile tiles. Only a part of the original image needs to be calculated each time. Specifically, a tile tile is magnified separately and the calculation result is sent to the memory, which replaces the existing image magnification calculation of the entire magnified area of ​​the original image, reducing the memory handling requirements required in the calculation process, thereby reducing the power consumption of the neural network processing device. At the same time, the present invention filters and excludes the redundant information generated by each tile when executing the magnification algorithm, and does not directly participate in the final image magnification calculation. This processing method further reduces the memory handling required in the image magnification calculation process, improves the computing performance, and thus reduces the power consumption of the neural network processing device.

[0029] As an optional implementation, Figure 2As shown, steps S200~S400 are replaced by: S200': Based on the area to be enlarged of the original image, select tiles from the preset tiles to segment the image of the area to be enlarged, obtain the total number of segments, and index and mark each tile based on the total number of segments and the segmentation position of each tile. S300': Based on the magnification scale and at least one type of alternative image enlargement algorithm, the alternative image enlargement algorithm includes multiple types of enlargement algorithms, such as the nearest neighbor interpolation algorithm, the bilinear interpolation algorithm, etc., so as to facilitate the selection of the most suitable enlargement algorithm according to needs, thereby improving the applicability of the present invention. The position information and cropping information of tiles at different segmentation positions are calculated and stored, and the position information and cropping information are associated with the type in the alternative image enlargement algorithm, that is, the position information and cropping information of different types of image enlargement algorithms are different, and the mutual association facilitates the rapid subsequent operation. S400': Select a type from the candidate image magnification algorithms as the target image magnification algorithm, and based on the type of the target image magnification algorithm and the position information and cropping information of the stored multiple tile tiles, filter the portion of each tile tile that needs to be cropped after the image is magnified. In this method, tile segmentation is performed only on the magnified area of ​​the original image, and tile segmentation is not performed on the entire original image, that is, there is no need to segment the area outside the magnified area of ​​the original image, thereby reducing the memory requirement during the image magnification process (storage of index marks for each tile tile, etc. requires memory resources), and can further reduce the amount of calculation required for image magnification (calculating the total number of tile segmentations, indexing each tile tile, etc. requires computing resources), thereby improving computing performance and reducing power consumption of the neural network processing device.

[0030] As an optional implementation, tiles of different sizes are obtained according to the height information, width information and channel number information of different original images, that is, different original images have different height information, width information and channel number information, the height information and width information correspond to the size of the original image, that is, the resolution size, the number of channels of the original image is generally RGB red, green and blue, usually the number of channels corresponds to the display mode of the image, and it is obvious that the tile can only be matched and segmented when the number of channels of the image is consistent. In the actual image processing scenario, when the channel number information is consistent, original images of different sizes have the most matching tile size, and the size of the tile is also the pixel size, such as 64*64 pixels, 128*128 pixels, 256*256 pixels, 64*1 pixels, 128*1 pixels, 256*1 pixels, 1*64 pixels, 1*128 pixels, 1*256 pixels, etc. Of course, it can also be set to other sizes of tile values ​​according to the common picture ratio and the specific application field of image magnification by neural network vector processing. The preset tile is obtained based on a set of multiple tiles of different sizes. Preferably, the larger the image, the larger the tile. The image pixels correspond to a tile of a specific size within a certain range, forming a correspondence between the image pixel size and the tile. This correspondence can achieve rapid segmentation of the image and improve the processing speed of image enlargement. For example, when the image is smaller, the tile can be set to a smaller value. A preset tile is obtained based on a set of multiple tile sizes. Then, a suitable tile is selected from the set of tile as the preset tile, and the original image or the enlarged area of ​​the original image is segmented. This can improve the computational efficiency of image enlargement and further enhance the computing performance, thereby reducing the power consumption of the neural network processing device. At the same time, when selecting a tile from the preset tile, matching is performed based on the computing power, memory capacity, and cache capacity of the vector processor, so that hardware adaptation of different vector processors can be achieved. During the matching process, the computing power of the vector processor, that is, the calculation speed of the vector processor, is preferably a memory capacity that can process more than one tile at a time, and the cache capacity can store intermediate data in the calculation process, so that after matching, the calculation potential of the vector processor can be maximized, the memory data handling in the image magnification calculation process can be reduced, and the calculation power consumption of the vector processor can be reduced. Furthermore, when matching tiles of different sizes, the image magnification can also be considered. In the specific application of image magnification by some neural network vector processing, the image magnification is relatively fixed. When the magnification is high, a smaller tile is matched, and when the magnification is low, a larger tile is matched, so that the calculation efficiency of image magnification can be further improved and power consumption can be reduced.

[0031] As an optional implementation, when segmenting, the original image or the enlarged area of ​​the original image is segmented from top to bottom along the longitudinal direction by tiles, so as to facilitate vector calculation by neural network vector processing, and the tiles are indexed and marked starting from 0, so as to facilitate rapid acquisition of the position information of each tile. That is, the original image or the area to be enlarged of the original image is segmented into multiple rows, each row is a tile, and the width of the tile is equal to the width of the original image. Preferably, the original image or the enlarged area of ​​the original image is segmented uniformly (when the number of tiles is n, the height of each tile is one-nth of the height of the original image or the enlarged area of ​​the original image) for the convenience of calculation, and the tiles are indexed and marked starting from 0 from top to bottom, so as to facilitate rapid acquisition of tiles corresponding to different enlarged positions. Of course, the original image or the enlarged area of ​​the original image can also be divided in the horizontal direction (in this case, the height of the tile is equal to the height of the original image or the enlarged area of ​​the original image) or in a combination of the horizontal and vertical directions (such as dividing the original image or the enlarged area of ​​the original image into four-grids, nine-grids, sixteen-grids, etc.) as needed to adapt to different image enlargement scenarios.

[0032] As an optional implementation, the cropping information of different segmentation positions is stored through the cropping function T[a,b,0,0], where a and b represent the cropping size corresponding to the result of filtering out the tile in the upper and lower directions, respectively. Obviously, the values ​​of a and b are both natural numbers. When segmenting, the tile is segmented along the longitudinal direction, and there is no segmentation in the left and right directions, so no cropping is required. That is, the third parameter 0 and the fourth parameter 0 in the cropping function T respectively indicate that the tile does not need to be cropped in the left and right directions. If a and b are both 0, the cropping function T[0,0,0,0] at this time indicates that no cropping is required in all directions. When processing the first tile, the values ​​of a and b in the cropping function T are 0 and x, respectively, that is, the x rows below the first tile need to be cropped and filtered. When processing the last tile, the values ​​of a and b in the cropping function T are x and 0, respectively, that is, the x rows above the last tile need to be cropped and filtered. When processing tiles other than the first and last tiles, that is, when processing the middle tiles, the values ​​of a and b in the cropping function T are x and x respectively, that is, the upper and lower sides of the processed tile need to be cropped and filtered by x rows, where x is a natural number. By limiting the cropping parameters of tiles at different positions, it is convenient to quickly crop and filter irrelevant parts of the image, reducing the computational complexity, thereby making more efficient use of the computing power and cache of the device, which can greatly reduce the memory handling when the image is enlarged and reduce computing power consumption.

[0033] As an optional implementation, the image magnification algorithm uses the nearest neighbor interpolation algorithm and / or the bilinear interpolation algorithm. The nearest neighbor interpolation algorithm is a very intuitive and simple image interpolation method with the fastest calculation speed. For each pixel coordinate in the target image, the closest pixel coordinate corresponding to it in the source image is calculated, which is usually obtained by dividing the target pixel coordinate by the scaling factor and then rounding down. The bilinear interpolation algorithm uses 4 (2*2) points in the original image to calculate 1 point in the new image. The effect is slightly inferior to the bicubic interpolation, but the speed is faster than the bicubic interpolation. It is the default algorithm in many frameworks and is a method of linear interpolation in two dimensions at the same time. If the nearest neighbor interpolation algorithm is used, the pixel point is obtained from the closest coordinate position in the original image. Therefore, the x in the cropping function T is equal to the magnification scale, that is, only the scale row needs to be cropped when the image is enlarged. If the bilinear interpolation algorithm is used, x in the cropping function T is equal to 2. Since the 2*2 points in the original image are calculated as 1 point in the new image, two rows are cropped.

[0034] As an optional implementation, the position information of the tile is stored through the position function A[e, f, g], where e, f, and g represent the tile index mark information, tile width information, and tile channel number information of the tile respectively. When vertical segmentation is performed, the tile width information is the width of the original image or the area to be enlarged of the original image. In the tile channel number information, such as the three RGB channels, the position information of each channel needs to be stored separately. When processing the first or last tile, the value of e in the position function A is h-scale, and the enlargement operation is performed on the top or bottom of the tile; when processing tiles other than the first and last, the enlargement operation is performed on the top and bottom of the tile, and the value of e in the position function A is h-2scale; where h is the index mark number of the tile, which is a natural number.

[0035] The specific operation steps of the present invention are as follows: Taking the operation method of S200~S400 as an example, Figure 3 As shown, (1) first extract the height h, width W and number of channels C of the original image. (2) Initialize a list of cropping information to store the number of rows that need to be cropped for the corresponding tile, where the cropping function T[a,b,0,0] of the cropping information corresponds to the length of the output result that needs to be filtered out on the top, bottom, left and right. Figure 3The cropped part corresponds to the tile position of the first row. (3) According to the value of the index position when the image is split in the vertical direction, the function updates the cropping information according to the calculation rules. (4) The updated position information and cropping information are returned, and the hardware of the neural network filters the calculation results according to the value corresponding to the cropping information. (5) The image magnification algorithm is executed separately for each tile, and the calculation results are sent to the memory to magnify the magnified area of ​​the original image by scale times. Specifically, when the nearest neighbor interpolation algorithm is executed, ① coordinate mapping, for each pixel coordinate (i', j') in the target magnified image corresponding to each tile, calculate the closest pixel coordinate (i, j) corresponding to it in the tile. Usually, this is obtained by dividing the target pixel coordinate by the magnification factor scale and then rounding down, i=int(i' / scale_factor_width), j=int(j' / scale_factor_height). ② pixel replication, the pixel at the coordinate (i, j) in the tile is directly assigned to the pixel at the coordinate (i', j') of the target image. ③ Traverse all target pixels in each tile, and repeat the above process for each pixel in the target image until all pixels are filled. When executing the bilinear interpolation algorithm, ① determine the position of the point to be interpolated for each tile. Assuming that the size of the original tile is W*H, enlarge it by k1 times and k2 times (horizontally and vertically, usually the values ​​of k1 and k2 are the same). The size of the enlarged image will be (int(W*k1))x(int(H*k2)). For each pixel (i',j') in the enlarged image of each tile, find its corresponding coordinates (i,j) in the original tile. These two coordinates are often floating point numbers. ② Find the nearest neighbor pixels and find the four nearest neighbor pixels around the point to be interpolated in the original tile. Their coordinates are (i,j), (i+1,j), (i,j+1) and (i+1,j+1). Among them, (i,j) is actually converted from (i' / k1,j' / k2) and rounded down. ③ Calculate the weight, calculate the distance ratio (that is, weight) of the interpolation point (i', j') from the center of the four neighboring pixels: in the horizontal direction, the weight u is (i'%k1) / k1; in the vertical direction, the weight v is (j'%k2) / k2.④ Perform interpolation calculation, use the grayscale values ​​or color values ​​of these four neighboring pixels for bilinear interpolation calculation: f(i',j')=(1-u)*(1-v)*f(int(i),int(j))+(1-u)*v*f(int(i),int(j)+1)+u*(1-v)*f(int(i)+1,int(j))+u*v*f(int(i)+1,int(j)+1), where f(i,j) represents the pixel value at the coordinate (i,j) in the original tile. In this way, each pixel value in the new image after each tile is enlarged is the weighted average of the four pixel values ​​around the original tile, so that each tile generates an enlarged image with smooth transition and better visual effect, and finally obtains the enlarged image corresponding to the enlarged area of ​​the original image.

[0036] The embodiment is only a specific example and does not represent only one implementation mode of the present invention.

[0037] Embodiment 2:

[0038] A neural network accelerator is used to run the neural network-based image magnification method in Example 1. The neural network accelerator (i.e., NPU, such as Figure 4 As shown, the NPU includes functional modules such as an in-memory computing matrix, a vector processor, and a compiler for performing neural network calculations). Of course, the present invention can also be a chip, an IP core (a circuit module with independent functions), and can be applied to other chip design projects that include the circuit module. When it is a chip, each module in the chip can be implemented in whole or in part by software, hardware, and a combination thereof. The above modules can be embedded in or independent of the processor in the computing device in the form of hardware, or can be stored in the memory of the computing device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0039] The invention can be used in fields requiring high-precision, high-reliability, low-power consumption, and low-area cost computing power, such as artificial intelligence and the metaverse, artificial intelligence training or reasoning chip products, autonomous driving chips, VR chips, robot built-in chips, wearable smart chips, and deep learning applications of parallel computing.

[0040] Embodiment three:

[0041] An electronic device includes the neural network accelerator in the second embodiment. The present invention can be applied to electronic devices related to computing centers, computing devices, edge computing, autonomous driving, AR, VR, laser radar, etc., smart phones, tablet computers, wearable electronic equipment, smart home electronic products, industrial or medical or battery-powered electronic devices, as well as speech recognition processing electronic devices, video processing electronic devices, large model processing electronic devices, etc. including neural network accelerators.

[0042] The above description is only the preferred embodiment of the present invention. It is known to those skilled in the art that various changes or equivalent substitutions may be made to these features and embodiments without departing from the spirit and scope of the present invention. In addition, under the teachings of the present invention, these features and embodiments may be modified to adapt to specific circumstances and materials without departing from the spirit and scope of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application belong to the protection scope of the present invention.

Claims

1. A neural network-based image magnification method, characterized in that: The method is used to enlarge the image in the neural network vector processing, including the following steps: S100: The input layer of the neural network obtains the height information, width information and channel number information of the original image; S200: based on the height information, width information and channel number information of the original image, select a tile from the preset tile to segment the original image, obtain the total number of segments, and index each tile based on the total number of segments and the segmentation position of the tile; S300: Calculate and store position information and cropping information of tiles at different segmentation positions based on the magnification scale and at least one type of candidate image magnification algorithm, and associate the position information and cropping information with the type of the candidate image magnification algorithm; S400: selecting a type from the candidate image magnification algorithms as a target image magnification algorithm, acquiring a plurality of tiles corresponding to the position of the region to be magnified based on the region to be magnified of the original image, and filtering a portion of each tile to be cropped after the image is magnified based on the type of the target image magnification algorithm and the position information and cropping information of the plurality of tiles stored; S500: The vector processor of the neural network executes the target image magnification algorithm on each tile after the filtering operation and sends it to the memory, and magnifies the area to be magnified by scale times of the original image. The output layer of the neural network outputs the magnified image information.

2. The neural network-based image magnification method according to claim 1, characterized in that: Steps S200~S400 are replaced by: S200': based on the height information, width information, channel number information of the original image and the area to be enlarged, select tiles from preset tiles to segment the image of the area to be enlarged, obtain the total number of segments, and index each tile based on the total number of segments and the segmentation position of each tile; S300': based on the magnification scale and at least one type of candidate image magnification algorithm, calculate and store the position information and cropping information of tiles at different segmentation positions, and associate the position information and cropping information with the type in the candidate image magnification algorithm; S400': selecting a type from the candidate image magnification algorithms as the target image magnification algorithm, and filtering the portion of each tile that needs to be cropped after the image is magnified based on the type of the target image magnification algorithm and the stored position information and cropping information of the plurality of tiles.

3. The neural network-based image magnification method according to claim 1 or 2, characterized in that: According to the acquired height information, width information and channel number information of different original images, tiles of different sizes are obtained, and the preset tile is obtained based on a set of multiple tiles of different sizes.

4. The neural network-based image magnification method according to claim 1 or 2, characterized in that: When segmenting, the original image or the area to be enlarged of the original image is segmented from top to bottom along the longitudinal direction by tiles, and the tiles are indexed starting from 0.

5. The neural network-based image magnification method according to claim 4, characterized in that: The cropping information of different segmentation positions is stored through the cropping function T[a,b,0,0], where a and b represent the cropping sizes corresponding to the results of filtering out the tile in the upper and lower directions, respectively. The third parameter 0 and the fourth parameter 0 in the cropping function T represent that the tile does not need to be cropped in the left and right directions, respectively. When processing the first tile, the values ​​of a and b in the cropping function T are 0 and x, respectively. When processing the last tile, the values ​​of a and b in the cropping function T are x and 0, respectively. When processing tiles other than the first and last tiles, the values ​​of a and b in the cropping function T are x and x, respectively.

6. The neural network-based image magnification method according to claim 5, characterized in that: The image magnification algorithm adopts the nearest neighbor interpolation algorithm and / or the bilinear interpolation algorithm; if the nearest neighbor interpolation algorithm is adopted, x in the cropping function T is equal to the magnification scale; if the bilinear interpolation algorithm is adopted, x in the cropping function T is equal to 2.

7. The neural network-based image magnification method according to claim 6, characterized in that: When calculating the clipping information of the tile, the portion of the tile that needs to be clipped is adapted to the fixed-size interpolation, and the points after the nearest neighbor interpolation algorithm and / or the bilinear interpolation algorithm are identified.

8. The neural network-based image magnification method according to claim 5, characterized in that: The position information of the tile is stored through the position function A[e, f, g], where e, f, and g represent the tile index mark information, tile width information, and tile channel number information of the tile respectively; when processing the first or last tile, the value of e in the position function A is h-scale; when processing tiles other than the first and last, the value of e in the position function A is h-2scale; where h is the index mark number of the tile.

9. A neural network accelerator, characterized in that: Used to run the neural network-based image enlargement method described in any one of claims 1-8.

10. An electronic device, characterized in that: Including the neural network accelerator described in claim 9.