Bank card number identification method and related device

By embedding a self-attention mechanism into the YOLOv5 network model and optimizing the anchor box set, the problem of insufficient accuracy in bank card number recognition is solved, achieving efficient and accurate recognition in different scenarios, and applicable to mobile payment and online banking services.

CN119027931APending Publication Date: 2024-11-26中国农业银行股份有限公司宁波市分行
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411249586.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

Existing technologies for bank card number recognition in mobile payments and online banking services lack sufficient accuracy and are ill-suited to the recognition needs of different scenarios.

Method used

The YOLOv5 network model is used for bank card number recognition. By embedding a self-attention mechanism in the last layer of its backbone network and using the K-means clustering method based on dual genetic algorithm to optimize the anchor box set, the accuracy of feature extraction and recognition is improved.

Benefits of technology

It improves the accuracy and robustness of bank card number recognition, can adapt to recognition needs in different environments and backgrounds, simplifies user operation processes, and improves recognition efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119027931A_ABST
    Figure CN119027931A_ABST
Patent Text Reader

Abstract

The invention discloses a bank card number identification method and a related device, and relates to the technical field of software, a bank card number identification model is obtained by training a YOLOv5 network model, and a self-attention mechanism is embedded in the last layer of a backbone network of the YOLOv5 network model. On the basis, after the to-be-processed target image is acquired, the bank card number recognition model can be called, and the target image is input into the bank card number recognition model, so that a bank card number recognition result output by the bank card number recognition model is obtained. According to the invention, the self-attention mechanism is embedded in the last layer of the backbone network of the YOLOv5 network model, so that the feature extraction performance of the backbone network can be improved, the extraction of main information is enhanced, and the interference of useless information is reduced, thereby improving the recognition performance of the YOLOv5 network model, and improving the recognition efficiency of the YOLOv5 network model. Therefore, the identification of the bank card number identification model obtained by training based on the YOLOv5 network model is more accurate, so that the bank card number identification requirements in different scenes are met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software technology, and in particular to a bank card number recognition method and related devices. Background Art

[0002] At present, bank card numbers are widely used in scenarios such as mobile payment, online banking services, and identity verification. Taking mobile payment as an example, in mobile payment applications, users can identify bank card numbers by taking photos or scanning bank cards with their mobile phones to quickly bind bank cards for payment, thereby improving the convenience of payment.

[0003] Therefore, how to accurately identify bank card numbers to meet the bank card number recognition needs in different scenarios has become an urgent problem that needs to be solved at this stage. Summary of the invention

[0004] In view of the above problems, this application provides a bank card number recognition method and related devices to achieve the purpose of accurately identifying bank card numbers. The specific solution is as follows:

[0005] The first aspect of the present application provides a bank card number recognition method, the bank card number recognition method comprising:

[0006] Obtaining a target image to be processed;

[0007] Retrieving a trained bank card number recognition model, wherein the bank card number recognition model is obtained by training a YOLOv5 network model, wherein the last layer of the backbone network of the YOLOv5 network model is embedded with a self-attention mechanism;

[0008] The target image is input into the bank card number recognition model to obtain a bank card number recognition result output by the bank card number recognition model.

[0009] In a possible implementation, the process of obtaining the bank card number recognition model by training the YOLOv5 network model includes:

[0010] Get the bank card number image training set;

[0011] Using a K-means clustering method based on a dual genetic algorithm, anchor frame clustering is performed on the bank card number image training set to obtain an anchor frame set that characterizes the feature distribution of the bank card number image training set;

[0012] The anchor frame set is integrated into the predefined anchor frame of the YOLOv5 network model, and the YOLOv5 network model is trained using the bank card number image training set to obtain the bank card number recognition model.

[0013] In a possible implementation, the anchor frame clustering is performed on the bank card number image training set using a K-means clustering method based on a dual genetic algorithm to obtain an anchor frame set representing the feature distribution of the bank card number image training set, including:

[0014] Initializing the bank card number image training set to obtain a binary initial outer population and a decimal initial inner population;

[0015] Using the initial inner population as the current inner population;

[0016] Use K-means clustering method to calculate the first local optimal solution of the current inner population;

[0017] Using the first local optimal solution to update the current inner population, calculating the fitness of individuals in the updated current inner population, and recording the individual with the highest fitness in the first array;

[0018] A new generation of inner population is obtained by performing selection, crossover and mutation operations on individuals of the current inner population, the new generation of inner population is used as the current inner population, and the step of calculating the first local optimal solution of the current inner population by using the K-means clustering method is returned to be executed until the inner termination condition is met, the individual with the highest fitness in the first array is used as the anchor frame size, and the initial outer population is used as the current outer population;

[0019] Using the K-means clustering method to calculate the second local optimal solution of the current outer population;

[0020] The current outer population is updated with the second local optimal solution, the fitness of individuals in the updated current outer population is calculated, and the individual with the highest fitness is recorded in the second array;

[0021] A new generation outer population is obtained by performing selection, crossover and mutation operations on individuals of the current outer population, the new generation outer population is used as the current outer population, and the step of calculating the second local optimal solution of the current outer population using the K-means clustering method is returned to be executed until the outer termination condition is met, and the individuals with the highest fitness in the second array are used as the number of anchor boxes;

[0022] Output the anchor box size and the number of anchor boxes.

[0023] In a possible implementation, the process of obtaining the bank card number recognition model by training the YOLOv5 network model further includes:

[0024] Get the bank card number image test set;

[0025] Using the bank card number image test set to test the bank card number recognition model to obtain the accuracy of the bank card number recognition model;

[0026] Determining whether the accuracy rate is greater than a preset threshold;

[0027] If not, return to the step of obtaining the bank card number image training set;

[0028] If yes, the training ends.

[0029] A second aspect of the present application provides a bank card number recognition device, the bank card number recognition device comprising:

[0030] A model training module, used for obtaining a bank card number recognition model by training a YOLOv5 network model, wherein the last layer of the backbone network of the YOLOv5 network model is embedded with a self-attention mechanism;

[0031] The card number recognition module is used to obtain a target image to be processed; retrieve the bank card number recognition model; and input the target image into the bank card number recognition model to obtain a bank card number recognition result output by the bank card number recognition model.

[0032] In a possible implementation, the model training module is specifically used to:

[0033] A bank card number image training set is obtained; a K-means clustering method based on a dual genetic algorithm is used to perform anchor frame clustering on the bank card number image training set to obtain an anchor frame set that characterizes the feature distribution of the bank card number image training set; the anchor frame set is integrated into a predefined anchor frame of a YOLOv5 network model, and the bank card number image training set is used to train the YOLOv5 network model to obtain the bank card number recognition model.

[0034] In a possible implementation, the model training module is used to perform anchor frame clustering on the bank card number image training set using a K-means clustering method based on a dual genetic algorithm to obtain a set of anchor frames representing the feature distribution of the bank card number image training set, specifically for:

[0035] Initialize the bank card number image training set to obtain an initial outer population in binary and an initial inner population in decimal; use the initial inner population as the current inner population; use the K-means clustering method to calculate the first local optimal solution of the current inner population; update the current inner population with the first local optimal solution, calculate the fitness of individuals in the updated current inner population, and record the individual with the highest fitness in the first array; obtain a new generation of inner population by performing selection, crossover and mutation operations on individuals in the current inner population, use the new generation of inner population as the current inner population, and return to the step of using the K-means clustering method to calculate the first local optimal solution of the current inner population until the inner termination condition is met, use the individual with the highest fitness in the first array as the anchor box size, and use the initial outer population as the current outer population; use the K-means The clustering method is used to calculate the second local optimal solution of the current outer population; the current outer population is updated with the second local optimal solution, the fitness of individuals in the updated current outer population is calculated, and the individuals with the highest fitness are recorded in the second array; a new generation of outer population is obtained by performing selection, crossover and mutation operations on individuals of the current outer population, the new generation of outer population is used as the current outer population, and the step of calculating the second local optimal solution of the current outer population using the K-means clustering method is returned to execute until the outer termination condition is met, and the individuals with the highest fitness in the second array are used as the number of anchor boxes; the anchor box size and the number of anchor boxes are output.

[0036] The third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the bank card number recognition method of the first aspect or any implementation method of the first aspect.

[0037] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0038] The memory is used to store computer programs;

[0039] The processor is used to execute the computer program so that the electronic device can implement the bank card number recognition method of the above-mentioned first aspect or any implementation method of the first aspect.

[0040] The fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the bank card number recognition method of the above-mentioned first aspect or any implementation method of the first aspect.

[0041] By means of the above technical solution, a bank card number recognition method and related devices provided by the present application are obtained by training a YOLOv5 network model to obtain a bank card number recognition model, and the last layer of the backbone network of the YOLOv5 network model is embedded with a self-attention mechanism. Based on this, after obtaining the target image to be processed, the bank card number recognition model can be retrieved, and the target image can be input into the bank card number recognition model to obtain the bank card number recognition result output by the bank card number recognition model. The present application embeds a self-attention mechanism in the last layer of the backbone network of the YOLOv5 network model, which can improve the feature extraction performance of the backbone network, strengthen the extraction of main information, and reduce the interference of useless information, thereby improving the recognition performance of the YOLOv5 network model, which makes the recognition of the bank card number recognition model obtained by training based on the YOLOv5 network model more accurate, thereby adapting to the bank card number recognition needs in different scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0043] Figure 1 A method flow chart of a bank card number recognition method provided in an embodiment of the present application;

[0044] Figure 2 A schematic diagram of the structure of the backbone network of the YOLOv5 network model provided in an embodiment of the present application;

[0045] Figure 3 A partial method flow chart of a bank card number recognition method provided in an embodiment of the present application;

[0046] Figure 4 A flowchart of another part of a bank card number recognition method provided in an embodiment of the present application;

[0047] Figure 5 A bar chart comparing the performance of the models provided in the embodiments of the present application;

[0048] Figure 6 A comparison chart of the PR curves provided in the embodiments of the present application;

[0049] Figure 7 A schematic diagram of the structure of a bank card number recognition device provided in an embodiment of the present application;

[0050] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0052] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0053] The terms "first", "second" etc. in the specification of the application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable in appropriate circumstances, and this is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0054] To facilitate understanding of this application, the following first describes the relevant concepts involved in this application:

[0055] Target recognition: Accurate category and location recognition of objects in images.

[0056] Deep learning: is a machine learning method that can be divided into supervised, semi-supervised or unsupervised learning from the perspective of learning task structure.

[0057] YOLOv5: is a powerful target detection technology that can quickly and accurately identify target objects in images or videos. The model structure of YOLOv5 mainly includes the input end, Backbone network, Neck network and output end. The input end divides the image into grids of different sizes, each grid is called an anchor point, which is responsible for detecting a target object; the Backbone network is used as the backbone network, and CSPDarknet53 can be used, which has strong feature extraction capabilities and computational efficiency; the Neck network uses the FPN (Feature Pyramid Network) network to fuse information from different feature map levels; the output end uses the Focal Loss loss function and NMS (non-maximum suppression) to process overlapping target boxes to obtain the final detection results. YOLOv5 uses a series of convolution and pooling operations to extract features from the image, and then predicts the category and bounding box of the target object in each grid by classifying and regressing the feature map. YOLOv5 uses multi-scale prediction technology to better capture the optimal size of the object. The network will pre-select a path, such as the path from a smaller object to a larger object, to better grasp the object and more accurately calculate the size of the object. YOLOv5 uses a grid perspective to detect the position of an object from a specific perspective. Compared with other detection technologies, the grid perspective can identify objects more quickly and accurately, and capture the position of objects with higher accuracy.

[0058] K-means clustering: aims to divide a set into several clusters, trying to make the objects within the cluster highly similar, and the objects between clusters less similar. First, in a set, randomly select K points as cluster centers, then use the distance from all points to the center point as the division standard, assign each point to a cluster that is relatively close to the center point, and finally find the center point in the new cluster. Repeat this process until the center point is fixed or the clustering criterion function converges.

[0059] Genetic algorithm: It is a traversal search algorithm, usually used for model optimization and search problems. Traditional genetic algorithms can only obtain the optimal value of a certain variable. If a problem has more than one influencing factor, genetic algorithms need to be used multiple times.

[0060] Object detection is a basic task in the field of computer vision, which aims to identify objects in images and determine their locations. In the banking field, accurate bank card number recognition is of great significance for improving production efficiency and reducing costs. In order to solve the problems existing in the traditional bank card number recognition process, such as high error rate and low efficiency of manual input, as well as recognition difficulties caused by factors such as diverse bank card backgrounds, different card number printing methods, and wear and tear. This application adopts a bank card number recognition method based on deep learning, aiming to improve the recognition rate and accuracy of bank card numbers, simplify the user's operating process when binding bank cards, improve user experience, and be able to adapt to bank card recognition needs in different scenarios.

[0061] Based on this, this application achieves fast and accurate recognition of bank card numbers and robustness under different brightness and background conditions through the introduction of a deep learning model.

[0062] See also Figure 1 , Figure 1 A method flow chart of a bank card number recognition method provided in an embodiment of the present application. Figure 1 As shown, a bank card number recognition method provided in an embodiment of the present application may include steps S101 to S103, and these steps are described in detail below.

[0063] S101, obtaining a target image to be processed.

[0064] In the embodiment of the present application, the target image is an image to be used for bank card number recognition, which may be a captured image of scenes such as mobile payment, online banking services, and identity authentication, and the present application does not impose any limitation on this.

[0065] S102, retrieve the trained bank card number recognition model, the bank card number recognition model is obtained by training the YOLOv5 network model, and the last layer of the backbone network of the YOLOv5 network model is embedded with a self-attention mechanism.

[0066] The structure of the self-attention mechanism can record the positional relationship between information and measure the importance of each piece of information. In the embodiment of the present application, the structure of the self-attention mechanism is embedded in the last layer of the backbone network of the YOLOv5 network model to improve the feature extraction performance of the backbone network, strengthen the extraction of main information, and reduce the interference of useless information.

[0067] The self-attention mechanism can capture global dependencies in the feature map and enhance the YOLOv5 network model's understanding of the target context. The output of the self-attention mechanism is fused with the original feature map so that the enhanced feature information can be used in the subsequent detection head.

[0068] See also Figure 2 , Figure 2This is a schematic diagram of the backbone network structure of the YOLOv5 network model provided in the embodiment of the present application. Figure 2 As shown in the figure, the backbone network of the YOLOv5 network model is mainly composed of two modules: the C3 module and the SPP module. The main functions of the C3 module and the SPP module are as follows:

[0069] In the C3 module, the feature map of the base layer is first divided into two parts, and then merged using a cross-stage hierarchical network structure to achieve richer gradient combinations; the SPP module, also known as the spatial pyramid pooling network, originated from the SPPNet module proposed by He Kaiming. It splices feature maps of different scales through the method of k=(1x1, 5x5, 9x9, 13x13), integrates features of different scales, improves the receptive field, and extracts important features.

[0070] Continue to see Figure 2 This application improves the backbone network of the YOLOv5 network model, adds a self-attention mechanism to the last layer of the backbone network, that is, after the SPP module, associates it with the features of the bank card number, and updates the weight parameters so that the key information is strengthened and the useless information is weakened, making full use of the significant features in the image information, thereby improving the recognition performance of the YOLOv5 network model.

[0071] In a possible implementation, in order to make the YOLOv5 network model better adapt to the actual distribution of the target, the embodiment of the present application uses a dual genetic algorithm to improve the K-means clustering method, clustering the target bounding boxes in the training data to determine the optimal anchor box set. Figure 3 , Figure 3 This is a partial method flow chart of a bank card number recognition method provided in an embodiment of the present application. Figure 3 As shown, a bank card number recognition method provided by an embodiment of the present application, wherein the process of obtaining a bank card number recognition model by training a YOLOv5 network model may include steps S201 to S203, and these steps are described in detail below.

[0072] S201, obtaining a bank card number image training set.

[0073] In an embodiment of the present application, a public image set containing bank card numbers can be obtained through a web crawler to ensure that the image set can cover various possible changes in the natural environment. For example, there are 2,400 valid images in the image set obtained through a web crawler, which can be divided into a bank card number image training set, a bank card number image test set, and a bank card number image verification set in an 8:1:1 manner after image compression, wherein the bank card number image training set contains 1,920 valid images, the bank card number image test set contains 240 valid images, and the bank card number image verification set contains 240 valid images.

[0074] In addition, necessary preprocessing can be performed on the obtained image set, such as contrast enhancement, brightness adjustment, rotation around the center, etc., to increase the number of images, improve the generalization ability of the model, and ensure the training effect. Continuing to use the bank card number image training set containing 1920 valid images as an example, the above preprocessing can be expanded to 9600 images, and finally a bank card number image training set containing 10080 valid images is obtained.

[0075] For the bank card number image training set, bank card number image test set, or bank card number image verification set, the bank card number area and card number content can be annotated by using existing annotation tools. Taking the bank card number image training set as an example, use LabelImg, which can directly generate .xml files, to annotate the images. First, set the save location of the .xml file to the desktop. Then set the category of the target and name the target box "bank". Then open the folder storing the bank card number image training set, select the corresponding image for card number annotation, and use "Create ReceBox" to start annotating the target bounding box. Finally, after completing the annotation of an image, click "Save" to save it. At this time, the automatically generated .xml file is saved in the corresponding folder to record the corresponding object location and category information. During the annotation process, it is necessary to ensure that the file name corresponds to the image name, and the annotation processing of the next image is carried out in sequence. After the .xml folder is constructed through the above annotation, the .xml file is converted into a .txt file through the python script, and the txt file and image file are placed in the corresponding folders respectively.

[0076] In practical applications, 1,600 images are randomly selected from the bank card number image training set, and statistical analysis is performed on the number of bank card numbers, the annotated target bounding boxes, positions, and sizes. There are nearly 10,000 bank cards, and the targets are mainly concentrated in the middle area of ​​the experimental result graph, which is conducive to the recognition of bank card numbers and determines that the image set obtained by the web crawler is reasonable.

[0077] S202, using a K-means clustering method based on a dual genetic algorithm to perform anchor box clustering on the bank card number image training set to obtain an anchor box set that characterizes the feature distribution of the bank card number image training set.

[0078] At present, the YOLOv5 network model uses the K-means clustering method, which clusters the height and width of all boxes contained in the training set, and then calculates the distance between each sample and K center points respectively, and assigns the sample to the center point closest to it. The distance calculation usually uses the Euclidean distance method.

[0079] The inventor studied the clustering anchor box method of the YOLOv5 network model and analyzed the characteristics of bank card number image data, and concluded that "there are two key factors that affect the clustering anchor box, namely the number of clustered anchor boxes and the size of the anchor box (the length and width of the rectangle), and directly affect the recognition effect of the bank card number." In order to improve the speed and accuracy of the clustering method, this application improves the clustering method and proposes a K-means clustering method based on a dual genetic algorithm (hereinafter referred to as the KDGA method) to find the number of anchor boxes and the size of the anchor boxes for the optimal clustering anchor box, thereby improving the training efficiency of the clustering method.

[0080] Compared with the K-means clustering method, the KDGA method can use the outer layer and the inner layer to iterate each other. It can not only use the outer layer genetic algorithm to change the number of clustering anchor boxes, but also use the inner layer genetic algorithm to optimize the size of the anchor boxes. After the outer layer and the inner layer are iterated each other, the KDGA method will find a better number and size of anchor boxes.

[0081] See also Figure 4 , Figure 4 Another method flow chart of a bank card number recognition method provided in an embodiment of the present application. Figure 4 As shown, a bank card number recognition method provided in an embodiment of the present application, wherein step S202 "using a K-means clustering method based on a dual genetic algorithm to perform anchor frame clustering on a bank card number image training set to obtain an anchor frame set that characterizes the feature distribution of the bank card number image training set" may include steps S2021 to S2029, and these steps are described in detail below.

[0082] S2021, initialize and configure the bank card number image training set to obtain an initial outer population of binary and an initial inner population of decimal.

[0083] In an embodiment of the present application, the initialization parameters of the inner population and the outer population can be configured based on the bank card number image training set; wherein the initialization parameters of the inner population may include the maximum number of iterations of the inner layer, the population size, the crossover method, the mutation method, the number of clusters, etc., and the initialization parameters of the outer population may include the maximum number of iterations of the outer layer, the population size, the crossover method, the mutation method, the number of clusters, etc.

[0084] Based on the initialization parameters of the inner population, samples can be randomly selected from the bank card number image training set according to their cluster numbers, and chromosome encoding can be performed, and this can be repeated multiple times according to the population size to form a binary initial outer population. Similarly, based on the initialization parameters of the outer population, samples can be randomly selected from the bank card number image training set according to their cluster numbers, and chromosome encoding can be performed, and this can be repeated multiple times according to the population size to form a decimal initial inner population.

[0085] S2022, using the initial inner population as the current inner population.

[0086] S2023, using the K-means clustering method to calculate the first local optimal solution of the current inner population.

[0087] In the embodiment of the present application, when the inner population is initially iterated, the initial inner population is used as the current inner population. For the current inner population, the K-means clustering method can be used to calculate its local optimal solution, that is, the first local optimal solution.

[0088] S2024, updating the current inner population with the first local optimal solution, calculating the fitness of individuals in the updated current inner population, and recording the individual with the highest fitness into the first array.

[0089] In an embodiment of the present application, according to the first local optimal solution, the allocation information of individuals and cluster centers in the current inner population is updated, and the fitness of different individuals in the updated current inner population is calculated in combination with the fitness function of the inner population, and the individual with the highest fitness is selected and its identification is recorded in the first array.

[0090] S2025, obtain a new generation of inner population by performing selection, crossover and mutation operations on individuals of the current inner population, use the new generation of inner population as the current inner population, and return to execute the step of using the K-means clustering method to calculate the first local optimal solution of the current inner population, until the inner termination condition is met, use the individual with the highest fitness in the first array as the anchor box size, and use the initial outer population as the current outer population.

[0091] In the embodiment of the present application, it is determined whether the inner termination condition is currently met. For example, if the number of iterations exceeds the maximum number of iterations, or the number of times the K-means clustering method obtains the same first local optimal solution exceeds a given threshold, then the inner termination condition is considered to be met.

[0092] If the inner layer termination condition is not met at present, individuals in the current inner layer population are selected according to their fitness, and the crossover probability and mutation probability of the selected individuals are calculated respectively. The crossover and mutation operations are performed according to the crossover method and mutation method to generate a new generation of inner layer population; if the inner layer termination condition is met at present, the individual with the highest fitness in the first array is used as the anchor frame size, and the iteration of the outer layer population is entered, and the initial outer layer population is used as the current outer layer population.

[0093] S2026, using the K-means clustering method to calculate the second local optimal solution of the current outer population.

[0094] In the embodiment of the present application, when the outer population is initially iterated, the initial outer population is used as the current outer population. For the current inner population, the K-means clustering method can be used to calculate its local optimal solution, that is, the second local optimal solution.

[0095] S2027, updating the current outer population with the second local optimal solution, calculating the fitness of individuals in the updated current outer population, and recording the individual with the highest fitness in the second array.

[0096] In an embodiment of the present application, according to the second local optimal solution, the allocation information of individuals and cluster centers in the current outer population is updated, and the fitness of different individuals in the updated current outer population is calculated in combination with the fitness function of the outer population, and the individual with the highest fitness is selected and its identification is recorded in the second array.

[0097] S2028, obtain a new generation of outer population by performing selection, crossover and mutation operations on individuals of the current outer population, use the new generation of outer population as the current outer population, and return to execute the step of using the K-means clustering method to calculate the second local optimal solution of the current outer population, until the outer termination condition is met, and use the individual with the highest fitness in the second array as the number of anchor boxes.

[0098] In the embodiment of the present application, it is determined whether the outer termination condition is currently met. For example, if the number of iterations exceeds the maximum number of iterations, or the number of times the K-means clustering method obtains the same second local optimal solution exceeds a given threshold, then the outer termination condition is considered to be met.

[0099] If the outer termination condition is not met at present, individuals in the current outer population are selected according to their fitness, and the crossover probability and mutation probability of the selected individuals are calculated respectively. The crossover and mutation operations are performed according to the crossover method and mutation method to generate a new generation of outer population; if the outer termination condition is met at present, the individual with the highest fitness in the second array is used as the number of anchor frames.

[0100] S2029, output the anchor box size and the number of anchor boxes.

[0101] S203, integrating the anchor frame set into the predefined anchor frame of the YOLOv5 network model, and using the bank card number image training set to train the YOLOv5 network model to obtain a bank card number recognition model.

[0102] In the embodiment of the present application, after obtaining the optimal number and size of anchor boxes, they can be integrated into the predefined anchor boxes of the YOLOv5 network model as an anchor box set to adjust the weights and biases of the YOLOv5 network model. Based on the existing deep learning model training process, the YOLOv5 network model can be trained using the bank card number image training set to ultimately obtain a bank card number recognition model. After the bank card number recognition model training is completed, cluster analysis can be further used to optimize the parameters of non-maximum suppression (NMS) to improve the accuracy of detection.

[0103] This application uses a dual genetic algorithm to improve the K-means method, which can perform cluster analysis on the target bounding boxes in the image training set, optimize the selection of the initial anchor box, and find a set of anchor boxes that is more suitable for the feature distribution of the image training set through the selection, crossover and mutation operations of the genetic algorithm. The anchor box set is integrated into the predefined anchor box of the YOLOv5 network model so that the YOLOv5 network model can better adapt to the actual size and shape of the target. This application has the following advantages:

[0104] 1) Improve detection accuracy: By optimizing anchor boxes and feature representations, the accuracy of target detection can be improved; 2) Enhance model generalization ability: Using a dual genetic algorithm to improve the K-means clustering method can better handle the problem of category imbalance and improve the model's detection ability for rare categories; 3) Automated optimization: The global search capability of the genetic algorithm can automatically discover the optimal parameters, reducing the need for manual adjustment.

[0105] In a possible implementation, the bank card number recognition model can also be tested to ensure the accuracy of the bank card number recognition model. In this regard, the embodiment of the present application provides a bank card number recognition method, wherein the process of obtaining the bank card number recognition model by training the YOLOv5 network model also includes the following steps:

[0106] Obtain a bank card number image test set; use the bank card number image test set to test the bank card number recognition model to obtain the accuracy of the bank card number recognition model; determine whether the accuracy is greater than a preset threshold; if not, return to execute step S201; if so, end the training.

[0107] In an embodiment of the present application, a bank card number image test set can be obtained, and the images in the bank card number image test set can be input into a bank card number recognition model to obtain the bank card number recognition results of the bank card recognition model for the images in the bank card number image test set. By comparing the annotations of the images, it can be determined whether the bank card recognition model accurately recognizes the images, thereby obtaining the accuracy of recognizing the bank card number image test set.

[0108] If the accuracy is not greater than the preset threshold, the process returns to step S201 for training. Otherwise, if the accuracy is not greater than the threshold, the training is terminated to obtain the final bank card number recognition model.

[0109] S103, inputting the target image into a bank card number recognition model to obtain a bank card number recognition result output by the bank card number recognition model.

[0110] In an embodiment of the present application, the target image is input into a bank card number recognition model, and the bank card number recognition result of the target image, that is, the position and content of the bank card number in the target image, can be obtained through the bank card number recognition model.

[0111] To verify the application effect of this application, the self-attention mechanism and the traditional convolution layer are applied in parallel in the detection head of the YOLOv5 network model to enhance the feature expression ability while maintaining the model speed. Ensure that the self-attention mechanism can be inserted into different layers of YOLOv5 as an independent structure to facilitate the expansion and maintenance of the model.

[0112] The following Table 1 is a performance comparison analysis result of the traditional YOLOv5 network model and the improved YOLOv5 (ie, YOLOv5-ALL) network model of this application. Figure 5 , Figure 5 This is a bar chart comparing the performance of the models provided in the embodiments of the present application. Figure 5 (a) is a bar graph comparing precision. Figure 5 (b) is the recall comparison bar graph, Figure 5 (c) is the mAP@.5 comparison bar chart, Figure 5 (d) is a bar chart comparing mAP@.5:.95.

[0113]

[0114] Table 1

[0115] Analysis Table 1 and Figure 4 It can be seen that the mAP@.5 of the YOLOv5 network model is 85.90%, and the mAP@.5 of the YOLOv5-ALL network model is 90.20%, which is an increase of 4.3%, and the mAP@.5:.95 is increased by 3.8%, which is a significant improvement. In addition, compared with the YOLOv5 network model, the Precision of the YOLOv5-ALL network model is increased by 4.6%, and the Recall is increased by 5.11%.

[0116] In addition, the present application draws a PR (Recall-Precision) curve based on the image set obtained by the web crawler. Figure 6 , Figure 6 This is a PR curve comparison diagram provided in the embodiment of the present application. Figure 6 As shown, curve 1 is the PR curve of the YOLOv5-ALL network model, and curve 2 is the PR curve of the YOLOv5 network model.

[0117] analyze Figure 5 It can be seen that the area enclosed by the PR curve of the YOLOv5-ALL network model is larger than the area enclosed by the PR curve of the YOLOv5 network model, that is, the mAP (mean Average Precision) of the YOLOv5-ALL network model is higher.

[0118] Based on the above description, the bank card number recognition method provided by the embodiment of the present application has the following advantages:

[0119] 1) High-accuracy recognition. The YOLOv5 network model is an optimized target detection model with high accuracy and speed. Using the YOLOv5 network model as the core algorithm for bank card number recognition can accurately identify bank card numbers in images, including effective recognition of features such as the size of bank cards.

[0120] 2) Real-time detection capability. The YOLOv5 network model is designed with emphasis on real-time performance, which enables fast detection while maintaining high accuracy. This method can achieve real-time detection of bank card numbers in practical applications and is suitable for application scenarios that require fast feedback, such as automated identification and system entry.

[0121] 3) Good generalization performance. By training the YOLOv5 network model on a variety of data sets, the model can learn the characteristics of bank cards in different environments. The model has good generalization ability and can recognize bank card numbers in a variety of different environments and conditions, reducing the impact of environmental changes on recognition results.

[0122] 4) Dealing with occlusion and similarity issues. The YOLOv5 network model was designed with target occlusion and shape diversity in mind. This method can effectively deal with the occlusion problem of bank card numbers and improve recognition accuracy and robustness.

[0123] 5) Computational resource optimization. Compared with other deep learning models, the YOLOv5 network model reduces the demand for computing resources while maintaining performance. This method can run with lower computing resources and is suitable for deployment on resource-constrained devices, such as mobile devices or embedded systems.

[0124] 6) Easy to integrate and expand. The YOLOv5 network model has a good modular design, which is easy to integrate with other systems or algorithms. This method can be easily integrated with other bank management systems or automation equipment to realize the automation and intelligence of bank card number recognition, and can also be expanded as needed.

[0125] Through the above reasoning, this application improves the YOLOv5 network model and has the advantages of high accuracy, real-time detection capability, good generalization performance, effective handling of occlusion and similarity problems, optimization of computing resources, and easy integration and expansion in bank card number recognition. These characteristics make it very suitable for application in the banking and financial industry to improve production efficiency and product quality.

[0126] A bank card number recognition method provided in an embodiment of the present application is introduced above, and a device for executing the bank card number recognition method is introduced below.

[0127] See also Figure 7 , Figure 7 This is a schematic diagram of the structure of a bank card number recognition device provided in an embodiment of the present application. Figure 7 As shown, the bank card number recognition device comprises:

[0128] The model training module 10 is used to obtain a bank card number recognition model by training a YOLOv5 network model, wherein the last layer of the backbone network of the YOLOv5 network model is embedded with a self-attention mechanism;

[0129] The card number recognition module 20 is used to obtain a target image to be processed; retrieve a bank card number recognition model; and input the target image into the bank card number recognition model to obtain a bank card number recognition result output by the bank card number recognition model.

[0130] In a possible implementation, the model training module 10 is specifically used to:

[0131] Obtain a bank card number image training set; use the K-means clustering method based on the dual genetic algorithm to perform anchor box clustering on the bank card number image training set to obtain an anchor box set that characterizes the feature distribution of the bank card number image training set; integrate the anchor box set into the predefined anchor box of the YOLOv5 network model, and use the bank card number image training set to train the YOLOv5 network model to obtain a bank card number recognition model.

[0132] In a possible implementation, the model training module 10 is used to perform anchor frame clustering on the bank card number image training set using a K-means clustering method based on a dual genetic algorithm to obtain a set of anchor frames representing the feature distribution of the bank card number image training set, and is specifically used to:

[0133] Initialize the bank card number image training set to obtain the initial binary outer population and the decimal initial inner population; use the initial inner population as the current inner population; use the K-means clustering method to calculate the first local optimal solution of the current inner population; update the current inner population with the first local optimal solution, calculate the fitness of the individuals in the updated current inner population, and record the individual with the highest fitness in the first array; obtain a new generation of inner population by performing selection, crossover and mutation operations on the individuals of the current inner population, use the new generation of inner population as the current inner population, and return to the step of using the K-means clustering method to calculate the first local optimal solution of the current inner population until the inner termination condition is met, use the individual with the highest fitness in the first array as the anchor box size, and use the initial outer population as the current outer population; use K-means The clustering method is used to calculate the second local optimal solution of the current outer population; the current outer population is updated with the second local optimal solution, the fitness of the individuals in the updated current outer population is calculated, and the individuals with the highest fitness are recorded in the second array; a new generation of outer population is obtained by performing selection, crossover and mutation operations on the individuals of the current outer population, the new generation of outer population is used as the current outer population, and the step of calculating the second local optimal solution of the current outer population using the K-means clustering method is returned to execute until the outer termination condition is met, and the individuals with the highest fitness in the second array are used as the number of anchor boxes; the anchor box size and the number of anchor boxes are output.

[0134] In a possible implementation, the model training module 10 is further used to:

[0135] Obtain a bank card number image test set; use the bank card number image test set to test the bank card number recognition model to obtain the accuracy of the bank card number recognition model; determine whether the accuracy is greater than a preset threshold; if not, return to the step of obtaining a bank card number image training set; if yes, end the training.

[0136] It should be noted that the detailed functions of each module in the embodiment of the present application can be found in the corresponding public part of the above-mentioned bank card number recognition embodiment, and will not be repeated here.

[0137] The present application also provides an electronic device in an embodiment. Figure 8 , Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 8 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0138] like Figure 8 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 to a random access memory (RAM) 803. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 803. The processing device 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0139] Typically, the following devices may be connected to the I / O interface 805: input devices 806 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 808 including, for example, a memory card, a hard disk, etc.; and communication devices 809. The communication device 809 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 8 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0140] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any one of the bank card number recognition methods provided in the embodiments of the present application.

[0141] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any bank card number recognition method provided in the embodiment of the present application.

[0142] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0143] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0144] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0145] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A bank card number recognition method, characterized in that: The bank card number recognition method comprises: Obtaining a target image to be processed; Retrieving a trained bank card number recognition model, wherein the bank card number recognition model is obtained by training a YOLOv5 network model, wherein the last layer of the backbone network of the YOLOv5 network model is embedded with a self-attention mechanism; The target image is input into the bank card number recognition model to obtain a bank card number recognition result output by the bank card number recognition model.

2. The bank card number recognition method according to claim 1, characterized in that: The process of obtaining the bank card number recognition model by training the YOLOv5 network model includes: Get the bank card number image training set; Using a K-means clustering method based on a dual genetic algorithm, anchor frame clustering is performed on the bank card number image training set to obtain an anchor frame set that characterizes the feature distribution of the bank card number image training set; The anchor frame set is integrated into the predefined anchor frame of the YOLOv5 network model, and the YOLOv5 network model is trained using the bank card number image training set to obtain the bank card number recognition model.

3. The bank card number recognition method according to claim 2, characterized in that: The method of using a K-means clustering method based on a dual genetic algorithm to perform anchor frame clustering on the bank card number image training set to obtain an anchor frame set that characterizes the feature distribution of the bank card number image training set includes: Initializing the bank card number image training set to obtain a binary initial outer population and a decimal initial inner population; Using the initial inner population as the current inner population; Use K-means clustering method to calculate the first local optimal solution of the current inner population; Using the first local optimal solution to update the current inner population, calculating the fitness of individuals in the updated current inner population, and recording the individual with the highest fitness in the first array; A new generation of inner population is obtained by performing selection, crossover and mutation operations on individuals of the current inner population, the new generation of inner population is used as the current inner population, and the step of calculating the first local optimal solution of the current inner population by using the K-means clustering method is returned to be executed until the inner termination condition is met, the individual with the highest fitness in the first array is used as the anchor frame size, and the initial outer population is used as the current outer population; Using the K-means clustering method to calculate the second local optimal solution of the current outer population; The current outer population is updated with the second local optimal solution, the fitness of individuals in the updated current outer population is calculated, and the individual with the highest fitness is recorded in the second array; A new generation outer population is obtained by performing selection, crossover and mutation operations on individuals of the current outer population, the new generation outer population is used as the current outer population, and the step of calculating the second local optimal solution of the current outer population using the K-means clustering method is returned to be executed until the outer termination condition is met, and the individuals with the highest fitness in the second array are used as the number of anchor boxes; Output the anchor box size and the number of anchor boxes.

4. The bank card number recognition method according to claim 2, characterized in that: The process of obtaining the bank card number recognition model by training the YOLOv5 network model also includes: Get the bank card number image test set; Using the bank card number image test set to test the bank card number recognition model to obtain the accuracy of the bank card number recognition model; Determining whether the accuracy rate is greater than a preset threshold; If not, return to the step of obtaining the bank card number image training set; If yes, the training ends.

5. A bank card number recognition device, characterized in that: The bank card number recognition device comprises: A model training module, used for obtaining a bank card number recognition model by training a YOLOv5 network model, wherein the last layer of the backbone network of the YOLOv5 network model is embedded with a self-attention mechanism; The card number recognition module is used to obtain a target image to be processed; retrieve the bank card number recognition model; and input the target image into the bank card number recognition model to obtain a bank card number recognition result output by the bank card number recognition model.

6. The bank card number recognition device according to claim 5, characterized in that: The model training module is specifically used for: A bank card number image training set is obtained; a K-means clustering method based on a dual genetic algorithm is used to perform anchor frame clustering on the bank card number image training set to obtain an anchor frame set that characterizes the feature distribution of the bank card number image training set; the anchor frame set is integrated into a predefined anchor frame of a YOLOv5 network model, and the bank card number image training set is used to train the YOLOv5 network model to obtain the bank card number recognition model.

7. The bank card number recognition device according to claim 6, characterized in that: The model training module is used to perform anchor frame clustering on the bank card number image training set using a K-means clustering method based on a dual genetic algorithm to obtain an anchor frame set that characterizes the feature distribution of the bank card number image training set, specifically for: Initialize the bank card number image training set to obtain an initial outer population in binary and an initial inner population in decimal; use the initial inner population as the current inner population; use the K-means clustering method to calculate the first local optimal solution of the current inner population; update the current inner population with the first local optimal solution, calculate the fitness of individuals in the updated current inner population, and record the individual with the highest fitness in the first array; obtain a new generation of inner population by performing selection, crossover and mutation operations on individuals in the current inner population, use the new generation of inner population as the current inner population, and return to the step of using the K-means clustering method to calculate the first local optimal solution of the current inner population until the inner termination condition is met, use the individual with the highest fitness in the first array as the anchor box size, and use the initial outer population as the current outer population; use the K-means The clustering method is used to calculate the second local optimal solution of the current outer population; the current outer population is updated with the second local optimal solution, the fitness of individuals in the updated current outer population is calculated, and the individuals with the highest fitness are recorded in the second array; a new generation of outer population is obtained by performing selection, crossover and mutation operations on individuals of the current outer population, the new generation of outer population is used as the current outer population, and the step of calculating the second local optimal solution of the current outer population using the K-means clustering method is returned to execute until the outer termination condition is met, and the individuals with the highest fitness in the second array are used as the number of anchor boxes; the anchor box size and the number of anchor boxes are output.

8. A computer program product, characterized in that It includes computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the bank card number recognition method as described in any one of claims 1 to 4.

9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the bank card number recognition method as described in any one of claims 1 to 4.

10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the bank card number recognition method as described in any one of claims 1 to 4.