Image classification method based on orthogonal sparse pruning capsule network

By using orthogonal sparse pruning technology in the capsule network to prune redundant capsules and orthogonalize the weight matrix, the problem of deep redundancy and dynamic routing complexity is solved, and the image classification performance and computing efficiency are improved.

CN118537701AInactive Publication Date: 2024-08-23HARBIN INSTITUTE OF TECHNOLOGY (SHENZHEN) (INSTITUTE OF SCIENCE AND TECHNOLOGY INNOVATION HARBIN INSTITUTE OF TECHNOLOGY SHENZHEN)

Patent Information

Application Number
CN202410643564.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-23
Publication Date
2024-08-23
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Redundant capsule problems exist in existing capsule networks, especially in deep capsule layers, resulting in a waste of computing resources and performance damage, and it is difficult for existing technologies to effectively solve the fully connected structure and iterative complexity problems in dynamic routing.

Method used

Adopt a method based on orthogonal sparse pruning, by initializing the pruning capsule layer, evaluating capsule contribution, calculating cosine similarity, pruning redundant capsules, using sparsemax attention routing, simplifying attention routing, orthogonalizing the weight matrix, and combining Householder orthogonal decomposition method reduces redundancy and computational complexity.

Benefits of technology

It effectively reduces deep redundant capsules, improves model performance, reduces computational complexity, avoids additional regularization terms, achieves strict matrix orthogonality, and improves image classification effects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118537701A
    Figure CN118537701A
Patent Text Reader

Abstract

The invention relates to an image classification method based on an orthogonal sparse pruning capsule network. The method comprises the following steps: S, initializing a pruning capsule layer in a densely connected main capsule layer; all the capsules in the capsule layer are subjected to importance sorting, and functionally overlapped or redundant capsules are identified; and according to a set similarity threshold, starting from the last sorted capsule, cutting off the capsules which are identified as overlapped or redundant capsules, generating an attention map by adopting attention routing based on sparsemax so as to optimize information flow among the capsules, and reducing calculation complexity and model parameters through simplified attention routing, so that the accuracy of the capsules is improved. According to parameter redundancy and model expressive power of the capsule network, a target matrix needing orthogonalization is determined, and orthogonalization is carried out on the target matrix through a House holder orthogonal decomposition method so as to introduce orthogonal constraints. According to the method, pruning, orthogonality and sparsity are combined to effectively reduce redundancy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to an image classification method based on an orthogonal sparse pruned capsule network, and belongs to the technical field of image classification. Background Art

[0002] Convolutional neural networks (CNNs) are good at handling computer vision tasks and are one of the most commonly used algorithms in the field of images. However, CNNs still have some shortcomings, such as information loss in the pooling layer, low robustness, and poor understanding of spatial features.

[0003] To solve these problems, some existing technologies have proposed capsule networks (CapsNet) and used capsule vectors instead of traditional neurons. In CapsNet, the length of each capsule vector represents the probability of existence of a specific entity in the input image, and the direction of the capsule represents the encoding of the specific features captured. Recent studies have mentioned that CapsNet contains redundant capsules. Specifically, 48.2% of capsule pairs have a cosine similarity higher than 0.65, which indicates that many capsules extract similar features, and even without these capsules, the model performance will not be greatly affected. Although some existing technologies have implemented pruning techniques in the main capsule layer, a large number of redundant capsules can still be observed in deeper capsule layers. This persistent redundancy mainly comes from dynamic routing. Specifically, it can be summarized into the following two points:

[0004] First, in dynamic routing, each high-level capsule is essentially a weighted sum of capsules in the lower layer, that is, the relationship between the lower layer and the higher layer is fully connected. This fully connected structure leads to the repeated introduction of potential redundant information, and dynamic routing requires multiple iterations to repeatedly update the coupling coefficient until convergence, which wastes computing resources to a certain extent. Although many studies have used attention strategies to improve dynamic routing, the problems of fully connected structure and redundancy remain unsolved. Some existing technologies incorporate attention into capsule routing through non-iterative feedforward operations. Other existing technologies introduce a parallel iterative routing that does not address the complexity of iteration requirements. In addition, many studies focus on pruning, but do not mention the new redundancy introduced by dynamic routing. For example, some existing technologies use encoding-based pruning algorithms to establish a ladder structure, some existing technologies create a pruning layer based on Taylor decomposition, and some existing technologies use LOBSTER to create a sparse tree.

[0005] Second, non-orthogonal weight matrices can increase capsule similarity in routing, which not only impairs routing performance, but also reintroduces redundancy in subsequent layers. The present invention solves this problem by orthogonalizing the weight matrix. There are many methods for introducing orthogonality into neural networks, which can be roughly divided into hard orthogonal and soft orthogonal. The hard orthogonal method can maintain the orthogonality of the matrix throughout the training process. For example, the weight matrix is ​​optimized on the Stiefel manifold, and a subset of the orthogonal matrix is ​​parameterized. However, these hard orthogonal methods will incur additional computational overhead and may cause gradients to vanish or explode. The soft orthogonal method adds a regularization term to the loss function to encourage orthogonality between the column vectors of the weight matrix without strict enforcement. However, if the degree of regularization is high, the loss function effect of the classification task will be deteriorated; if the degree of regularization is low, it is difficult to orthogonalize the weight matrix. Summary of the invention

[0006] The present invention provides an image classification method based on an orthogonal sparse pruned capsule network, aiming to solve at least one of the technical problems existing in the prior art.

[0007] The technical solution of the present invention relates to an image classification method, and the method according to the present invention comprises the following steps:

[0008] S100, in the densely connected main capsule layer, initialize a pruned capsule layer;

[0009] S200, evaluate the contribution of each capsule to the overall network output to rank the importance of all capsules in the capsule layer;

[0010] S300, calculating the cosine similarity between capsules to identify capsules that are functionally overlapping or redundant;

[0011] S400, according to the set similarity threshold, starting from the last capsule in the sorting, pruning the capsules identified as overlapping or redundant to retain the core valid capsules;

[0012] S500, using sparsemax-based attention routing to generate attention maps to optimize the information flow between capsules;

[0013] S600, reducing computational complexity and model parameters through simplified attention routing;

[0014] S700, determining a target matrix that needs to be orthogonalized according to parameter redundancy and model expressiveness of the capsule network;

[0015] S800. Orthogonalize the target matrix by using the Householder orthogonal decomposition method to introduce orthogonal constraints.

[0016] Furthermore, an efficient capsule pruning algorithm is adopted to place a capsule pruning layer after the main capsule layer, which includes the following steps:

[0017] Get the main capsule layer Capsules u∈R(B,n,d,W,H) and set the threshold to θ;

[0018] Calculate the L2 norm of each capsule, and then sort the capsules according to the L2 norm;

[0019] Initialize a matrix M with all 1s and calculate the cosine similarity between two capsules;

[0020] Update the M value by comparing the cosine similarity between capsules. If the similarity between two capsules exceeds the threshold θ, the corresponding position in M ​​is marked as 0.

[0021] Use the updated matrix M as the pruned capsule network and return the pruned capsule set.

[0022] Further, in step S300,

[0023] The cosine similarity of capsule angles is used to measure redundancy. The formula of cosine similarity is as follows:

[0024]

[0025] where u ordered,i ,u ordered,j They represent the dot product of the two capsule vectors whose cosine similarity needs to be calculated, |u ordered,i | and |u ordered,j |respectively represent the molds of the two capsules.

[0026] Further, the step S500 includes the following steps:

[0027] S510, using three weight matrices (prediction matrices) W Q ,W K ,W V ∈R d×d Come from u l,i Derive query Q, key K and value V; where,

[0028] u l,i represents the capsule of layer l;

[0029] Q=W Q ×u l,i , K=W K ×u l,i , V=W V ×u l,i , where W Q ,W K and WV is an orthogonal matrix, which can transform u l,i Project into a d-dimensional orthogonal subspace;

[0030] S520, generating coupling coefficient c through attention routing ij , where the coupling coefficient matrix C is derived from the attention graph generated by the dot product of Q and K, where

[0031]

[0032] In the formula, the dimension of each capsule is d, and the formula of α-Entmax is as follows:

[0033]

[0034] Where τ is an adaptive threshold and α is a hyperparameter that controls the sparsity of the attention map.

[0035] Further, in step S520,

[0036] In the voting matrix S i,j In the middle, the higher-level capsule v l+1,j Through the multi-head self-attention mechanism from voting s l+1,j The overall formula is as follows:

[0037]

[0038] In the formula, g represents the nonlinear activation function, v l+1,j Represents the capsule of the l+1th layer

[0039] Among them, voting l+1,j Calculated by multiplying V and C.

[0040] Further, in step S600,

[0041] Reduce the prediction matrix W from three to one and use u l,i Replace K, Q, V;

[0042] The coupling coefficient matrix C is obtained by using α-Entmax and dot product to produce the new vote s l+1,j , which is expressed as follows:

[0043]

[0044] In the formula, It is the lower capsule to the higher capsule v l+1,j prediction.

[0045] Among them, s l+1,j Through the nonlinear function g to generate v l+1,j .

[0046] Further, in step S700,

[0047] For the matrix W Q ,W K , and W V Orthogonalization is performed, where the calculation of the coupling coefficient matrix C is expressed as follows:

[0048]

[0049] Where U l Represents a capsule of layer l.

[0050] Further, the step S800 includes:

[0051] S810, an orthogonal matrix W∈R d×d The structure is:

[0052] W=H0H1…H d-1

[0053] Where W is the weight matrix to be orthogonalized, and each H i represents a Householder transformation, H i Defined as:

[0054]

[0055] In the formula, a i is a unit column vector

[0056] S810, use a set of randomly generated column vectors {b_i|i=0,…,d-1} to replace a i To construct H i , then the orthogonal matrix W is expressed as follows:

[0057]

[0058] Among them, during the training process, b i Optimization via gradient backpropagation

[0059] The technical solution of the present invention also relates to a computer-readable storage medium on which program instructions are stored, and the above-mentioned method is implemented when the program instructions are executed by a processor.

[0060] The technical solution of the present invention also relates to an image classification system based on an orthogonal sparse pruned capsule network, wherein the system comprises a computer device, and the computer device comprises the above-mentioned computer-readable storage medium.

[0061] The beneficial effects of the present invention are as follows:

[0062] The image classification method based on orthogonal sparse pruned capsule network of the present invention solves the deep redundancy problem of capsules for the first time. It implements a novel pruning strategy to reduce capsule redundancy and proposes an orthogonal sparse attention routing mechanism to replace dynamic routing, which combines pruning, orthogonality and sparsity to effectively reduce redundancy.

[0063] The present invention is the first to use Householder orthogonal decomposition to enforce orthogonality in CapsNet, where this simple, penalty-free orthogonalization method is also applicable to other neural networks. The present invention solves the fully connected structure and iteration problems of dynamic routing through OrthCaps, thereby avoiding the increase of deep capsule similarity and reducing redundant capsules. The present invention uses Householder orthogonal decomposition to achieve strict matrix orthogonality, minimize computational complexity and avoid additional regularization terms. The present invention solves the fully connected structure and iteration problems of dynamic routing through OrthCaps, thereby avoiding the increase of deep capsule similarity and reducing redundant capsules. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 is a basic flow chart of the method according to the present invention.

[0065] Figure 2 Schematic diagram of the structure of the lightweight OrthCaps-Shallow according to the method of the present invention.

[0066] Figure 3 Schematic diagram of the structure of the lightweight OrthCaps-Deep according to the method of the present invention.

[0067] Figure 4 is a flowchart of the steps of attention graph routing according to the method of the present invention.

[0068] Figure 5 is a flowchart of the steps of simplified attention graph routing according to the method of the present invention.

[0069] Figure 6 It is a flow chart of the steps of constructing an orthogonal matrix according to the method of the present invention. DETAILED DESCRIPTION

[0070] The concept, specific structure and technical effects of the present invention will be clearly and completely described below in combination with the embodiments and drawings to fully understand the purpose, scheme and effect of the present invention.

[0071] It should be noted that, unless otherwise specified, when a feature is referred to as being "fixed" or "connected" to another feature, it may be directly fixed or connected to another feature, or it may be indirectly fixed or connected to another feature. The singular forms "a", "said" and "the" used herein are also intended to include the plural forms, unless the context clearly indicates otherwise. In addition, unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art. The terms used in this specification are intended only to describe specific embodiments and are not intended to limit the invention. The term "and / or" used herein includes any combination of one or more of the related listed items.

[0072] It should be understood that, although the term first, second, third etc. may be adopted to describe various elements in the present disclosure, these elements should not be limited to these terms. These terms are only used to distinguish the same type of elements from each other. For example, without departing from the scope of the present disclosure, the first element may also be referred to as the second element, and similarly, the second element may also be referred to as the first element. The use of any and all examples or exemplary language ("for example", "such as" etc.) provided herein is only intended to better illustrate embodiments of the present invention, and unless otherwise required, the scope of the present invention will not be limited.

[0073] Reference Figures 1 to 6 In some embodiments, the image classification method based on the orthogonal sparse pruned capsule network according to the present invention comprises at least the following steps:

[0074] S100, in the densely connected main capsule layer, initialize a pruned capsule layer;

[0075] S200, evaluate the contribution of each capsule to the overall network output to rank the importance of all capsules in the capsule layer;

[0076] S300, calculating the cosine similarity between capsules to identify capsules that are functionally overlapping or redundant;

[0077] S400, according to the set similarity threshold, starting from the last capsule in the sorting, pruning the capsules identified as overlapping or redundant to retain the core valid capsules;

[0078] S500, using sparsemax-based attention routing to generate attention maps to optimize the information flow between capsules;

[0079] S600, reducing computational complexity and model parameters through simplified attention routing;

[0080] S700, determining a target matrix that needs to be orthogonalized according to parameter redundancy and model expressiveness of the capsule network;

[0081] S800. Orthogonalize the target matrix by using the Householder orthogonal decomposition method to introduce orthogonal constraints.

[0082] In order to reduce capsule redundancy and improve model classification effect, this paper proposes an orthogonal capsule network (OrthCaps). OrthCaps includes two versions, namely lightweight OrthCaps-Shallow (OrthCaps-S) and OrthCaps-Deep (OrthCaps-D). Figure 1 and Figure 2 shown.

[0083] Specific implementation of steps S100 to S400

[0084] The present invention first initializes the capsule network structure. The generation of capsules begins at the main capsule layer, and a pruned capsule layer is initialized in the densely connected main capsule layer to prepare for subsequent simplification and optimization. The present invention generates capsules with low correlation in the initial stage, which is conducive to ensuring efficient feature representation and reducing feature overlap in subsequent layers. Specifically, the present invention places a capsule pruning layer after the main capsule layer, and its algorithm is expressed as follows:

[0085]

[0086] In the above-mentioned efficient capsule pruning algorithm of the present invention, the main capsule Capsules u∈R(B,n,d,W,H) is set and the threshold is θ. First, the L2 norm of each capsule is calculated: ||u flat ||2, and then sort the capsules according to this L2 norm. Next, initialize a matrix M with all 1s and use the cosine_similarity function to calculate the two capsule vectors (u ordered,i and u ordered,j ), and then update the M value by comparing the cosine similarity between capsules. If the similarity between two capsules exceeds the threshold θ, the corresponding position in M ​​is marked as 0 to remove the connection during pruning. Finally, the matrix M is used as the pruned capsule network and the pruned capsule set is returned.

[0087] In some embodiments, the present invention ranks all capsules in the capsule layer by importance and evaluates the contribution of each capsule to the overall network output. Specifically, for redundant capsule pairs, random pruning may result in the loss of capsules that are critical to accurate classification, and in order to ensure a high similarity between a pair of capsules, it is necessary to first prune the less important capsules. Therefore, the present invention calculates the importance based on the L2 norm of the capsule, ranks all capsules in the capsule layer by importance, and evaluates the contribution of each capsule to the overall network output.

[0088] Specifically, the L2 norm is used to calculate the length of the capsule vector, and the length of the capsule encodes the probability of the existence of the entity feature in the image, which shows the activity of the capsule. Therefore, the larger the L2 norm of the capsule, the more important the capsule can be considered. Therefore, the importance of the capsule can be judged according to the size of the L2 norm of the capsule, and the capsules can be reordered according to their importance. The sorted capsules are represented by u ordered express.

[0089] In some embodiments, the present invention calculates the cosine similarity between capsules to identify capsules that overlap or are redundant in function. Specifically, based on the fact that redundancy occurs when two capsules capture the same or similar features, and based on the fact that the direction of each capsule vector encodes a specific feature, capsules with closer directions (or angles) indicate that they capture similar features and entities, and the cosine similarity of capsule angles is used to measure redundancy, thereby obtaining capsules that overlap or are redundant in function.

[0090] The formula for the cosine similarity of capsule angles is as follows:

[0091]

[0092] where u ordered,i ,u ordered,j Represents the two capsule vectors for which cosine similarity needs to be calculated, u ordered,i ·u ordered,j is the dot product of two capsule vectors, |u ordered,i | and |u ordered,j |These are the molds of two capsules respectively.

[0093] In some embodiments, the present invention starts from the last capsule in the sorting process and removes the capsules identified as redundant based on a pre-set similarity threshold, retaining the core valid capsules. Specifically, after re-sorting by importance, a mask matrix M∈R with all 1s is initialized. (1,n,1) Starting from the capsule with the lowest activity, that is, the capsule with the smallest L2 norm, the process calculates the capsule u with lower activity ordered,i With more active capsules u ordered,jWhen the similarity exceeds the threshold θ, it corresponds to u ordered,i The mask column of is set to 0, indicating that the capsules with low activity are pruned. In this way, only capsules with high activity are always kept. The last step is to apply M to u ordered , generate pruned capsule u pruned . Where n′ is the number of remaining capsules after pruning.

[0094] Specific implementation of step S500

[0095] The present invention uses attention routing based on sparsemax (an activation function in deep learning) to replace traditional dynamic routing, and optimizes the information flow between capsules by generating an attention graph. Specifically, the present invention uses the attention mechanism to replace dynamic routing, so that the coupling coefficient between low-level capsules and high-level capsules can be obtained without iteration, and sparsity is used to reduce the transmission of redundant features.

[0096] Specifically, let u l,i and v l+1,j Represent the capsules of the lth layer and the l+1th layer respectively, and the dimension of each capsule is d. Three weight matrices W are used Q ,W K ,W V ∈R d×d Come from u l,i Derive query Q, key K and value V, that is, Q = W Q ×u l,i , K=W K ×u l,i , V=W V ×u l,i Among them, W Q ,W K and W V is an orthogonal matrix, and they can transform u l,i Projected into a d-dimensional orthogonal subspace.

[0097] See also Figure 3 , generating a coupling coefficient c through attention routing ij , as the weight in the routing process from low-level capsules to high-level capsules. The coupling coefficient matrix C is derived through the attention map generated by the dot product of Q and K, that is, The softmax function in the original attention mechanism is replaced by α-Entmax to enhance the sparsity of the attention graph. α-Entmax adaptively sets small c_{ij} to zero, thereby encouraging the router to prioritize more important capsules while minimizing the transmission of irrelevant information. The formula of α-Entmax is as follows:

[0098]

[0099] Where τ is an adaptive threshold and α is a hyperparameter that controls the sparsity of the attention map. l+1,j It is calculated by multiplying V and C. In the voting matrix S i,j In the middle, the higher-level capsule v l+1,j Through the multi-head self-attention mechanism from s l+1,j The overall formula is as follows:

[0100]

[0101] The nonlinear activation function is represented by g.

[0102] Specific implementation of step S600

[0103] This paper aims to simplify the capsule network structure and designs a simplified attention routing to reduce the computational complexity and model parameters. Figure 4 The simplified attention routing of the present invention reduces the prediction matrix W from three to one and uses u l,i Replace K,Q,V. It is the lower capsule to the higher capsule v l+1,j The coupling coefficient matrix C derived from the attention map is obtained by using α-Entmax and dot product to produce the new vote s l+1,j ,

[0104]

[0105] Among them, s l+1,j Through the nonlinear function g to generate v l+1,j It is worth noting that the standard convolution is replaced by the depthwise convolution to reduce the number of parameters. The attention routing of the present invention does not have any iterations, which can reduce the computational complexity.

[0106] Specific implementation of step S700

[0107] In order to reduce the parameter redundancy of the capsule network and improve the model expressiveness, the present invention introduces the orthogonality constraint. After a series of analyses, it is determined that the target matrix to be orthogonalized is W Q ,W K , and W V According to the orthogonalization goal of maintaining low similarity between high-level capsules, the present invention represents high-level capsules by matrix multiplication according to step S500 and step S600:

[0108] V l+1 =g(S l )=g(CV)=g[(C×W V ) l ]

[0109] In the formula, S l represents the voting matrix; U l Represents a capsule of layer l.

[0110] Since the activation function g in CapsNet can maintain the direction of the capsule vector, we only need to ensure that C and W V The orthogonality of C can maintain low similarity. However, it is difficult to directly orthogonalize C, so the present invention obtains an alternative solution based on the calculation process of C. Specifically:

[0111]

[0112] According to the more detailed calculation formula of C in the above formula, the present invention obtains a new method of orthogonalizing C by analyzing this formula. Among them, since d is a constant, d does not need additional analysis. Step S400 reduces the The effect of orthogonalization C, pruning removes capsules with short length and high cosine similarity, so that the remaining capsules are updated to capsules with approximately unit length and low correlation, which is similar to the standard orthogonal basis. Then, as the network is trained, Gradually become more orthogonal, minimizing its impact on the orthogonality of C. Among them, although α-Entmax is a nonlinear function and may not maintain the orthogonality of the input, it makes C sparse. This sparsity effectively guides low-level capsules toward their respective high-level goals, reduces interference in the routing process, and encourages high-level capsules to maintain a relatively low similarity. Orthogonalization can make C as orthogonal as possible. Therefore, the optimization goal of the present invention is W Q ,W K , and W V , that is, for the target matrix W Q ,W K , and W V Orthogonal.

[0113] Specific implementation of step S800

[0114] The present invention orthogonalizes the target matrix by Householder orthogonal decomposition method (a matrix orthogonalization method). Specifically, let W be the weight matrix to be orthogonalized. The present invention uses Householder orthogonal decomposition theorem to construct an endogenously optimizable orthogonal matrix, as shown in Figure 5. According to the essence of Householder orthogonal decomposition method, any orthogonal n×n matrix is ​​the product of at most n orthogonal Householder transformations. The present invention converts an orthogonal matrix W∈R d×d The structure is:

[0115] W=H0H1…H d-1

[0116] Among them, each H i represents a Householder transformation, H i Defined as:

[0117]

[0118] In the formula, a i is a unit column vector.

[0119] Furthermore, the present invention uses a set of randomly generated column vectors {b_i|i=0,…,d-1} to replace a i To construct H i ,

[0120]

[0121] During the training process, b i Optimization is performed by gradient backpropagation. W inherently maintains its orthogonality during training. Thus W Q , W K and W v It can be easily orthogonalized. The present invention adopts Householder orthogonalization, which can efficiently convert any coefficient matrix into an orthogonal matrix without any additional penalty term in the loss function.

[0122] A specific embodiment is described below.

[0123] The simulation scenario for image classification of the present invention is set as follows: The present invention is developed on Python 3.9 PyTorch 1.12.1, and the training process is accelerated by using four GTX-3090 GPUs. Its model uses the AdamW optimizer, with a cosine annealing learning rate scheduler and a linear warm-up of 5 cycles. The learning rate is set to 5e-3, the weight decay is set to 5e-4, and the batch size is set to 512. The image classification task of OrthCaps-S is performed on four classic image classification datasets, SVHN, smallNORB, CIFAR10, and MNIST, and OrthCaps-D is performed on CIFAR10, CIFAR100, Fashion-MNIST, and MNIST. The image size of the SmallNORB dataset is adjusted from 96×96 to 64×64 and cropped to 48×48. The images of other datasets retain their original sizes.

[0124] For OrthCaps-S, it is compared with Efficient-Caps, CapsNet, Matrix-CapsNet with EM routing, AR-CapsNet, AA-CapsNet, DA-CapsNet, CapProNet, and a standard 7-layer CNN. OrthCaps-D is compared with CapsNet (7 ensembles), AR-CapsNet (7 ensembles), RS-CapsNet, InvertedDot-Product, DeepCaps, ResNet-18, and VGG-16. All CapsNet variants use a backbone network with 4 convolutional layers and are trained for 500 epochs. The results are obtained by running the official code using hyperparameters.

[0125] The following table shows the classification performance of OrthCaps-S and OrthCaps-D, with model size represented by Param and computational requirements represented by FLOPS[M]. Param and FLOPS[M] in each table are tested on MNIST and CIFAR10 respectively. * means there is no official code to run, so the results are directly compared with the results of this invention.

[0126]

[0127] As shown in Table (a), OrthCaps-S achieves excellent efficiency with only 105.5K parameters, surpassing CNN, CapsNet and many variants. For example, the EfficientCaps model, which optimizes efficiency, has about 50% more parameters than OrthCaps-S. In addition, OrthCaps-S performs well on all four datasets. On SVHN and CIFAR10, OrthCaps-S achieved accuracies of 96.26% and 86.84%, respectively, surpassing CapsNet, which has 80 times the number of parameters. The computational requirement is 673.1M FLOPS, slightly higher than EfficientCaps. The slight increase in FLOPS is due to the additional calculations caused by pruning capsule layers and orthogonal transformations. It is understandable that this slight increase in FLOPS trade-off is acceptable, considering that the present invention achieves a significant reduction in the number of parameters and an improvement in accuracy.

[0128] As for OrthCaps-D, as shown in Table (b), it shows competitive performance on complex datasets with fewer parameters than complex models. Although convolution-based networks such as ResNet-18 and VGG-16 perform well on CIFAR10 and CIFAR100, OrthCaps-D uses only 1.41% and 0.11% of their parameters and only 56% and 20.8% of their FLOPS. Compared with DeepCaps, the efficiency of OrthCaps is more obvious. Although DeepCaps achieves an accuracy of 91.01% on CIFAR10, its parameter count is 13.42M, which is 23.4 times that of OrthCaps-D. Both OrthCaps variants maintain high performance with fewer parameters.

[0129] It should be appreciated that the method steps in the embodiments of the present invention can be implemented or implemented by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory computer readable memory. The method can use standard programming techniques. Each program can be implemented in a high-level process or object-oriented programming language to communicate with a computer system. However, if necessary, the program can be implemented in an assembly or machine language. In any case, the language can be a compiled or interpreted language. In addition, the program can be run on a programmed ASIC for this purpose.

[0130] Furthermore, the operations of the processes described herein may be performed in any suitable order unless otherwise indicated herein or otherwise clearly contradicted by context. The processes described herein (or variations and / or combinations thereof) may be performed under the control of one or more computer systems configured with executable instructions, and may be implemented as code (e.g., executable instructions, one or more computer programs, or one or more applications) that is executed collectively on one or more processors, by hardware, or a combination thereof. The computer program includes a plurality of instructions that may be executed by one or more processors.

[0131] Further, the method can be implemented in any type of computing platform that is operably connected to a suitable computer, including but not limited to a personal computer, a minicomputer, a mainframe, a workstation, a network or distributed computing environment, a separate or integrated computer platform, or in communication with a charged particle tool or other imaging device, etc. Various aspects of the present invention can be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into a computing platform, such as a hard disk, an optical read and / or write storage medium, an RSM, a ROM, etc., so that it can be read by a programmable computer, and when the storage medium or device is read by the computer, it can be used to configure and operate the computer to perform the process described herein. In addition, the machine-readable code, or portions thereof, can be transmitted via a wired or wireless network. When such media includes instructions or programs that implement the steps described above in conjunction with a microprocessor or other data processor, the invention described herein includes these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques of the present invention, the present invention can also include the computer itself.

[0132] The computer program can be applied to input data to perform the functions described herein, thereby converting the input data to generate output data stored in a non-volatile memory. The output information can also be applied to one or more output devices such as a display. In a preferred embodiment of the present invention, the converted data represents physical and tangible objects, including specific visual depictions of physical and tangible objects produced on the display.

[0133] The above is only a preferred embodiment of the present invention. The present invention is not limited to the above implementation. As long as the technical effect of the present invention is achieved by the same means, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of protection of the present invention. Within the scope of protection of the present invention, its technical scheme and / or implementation method may have various modifications and changes.

Claims

1. An image classification method, characterized in that: The method comprises the following steps: S100, in the densely connected main capsule layer, initialize a pruned capsule layer; S200, evaluate the contribution of each capsule to the overall network output to rank the importance of all capsules in the capsule layer; S300, calculating the cosine similarity between capsules to identify capsules that are functionally overlapping or redundant; S400, according to the set similarity threshold, starting from the last capsule in the sorting, pruning the capsules identified as overlapping or redundant to retain the core valid capsules; S500, using sparsemax-based attention routing to generate attention maps to optimize the information flow between capsules; S600, reducing computational complexity and model parameters through simplified attention routing; S700, determining a target matrix that needs to be orthogonalized according to parameter redundancy and model expressiveness of the capsule network; S800. Orthogonalize the target matrix by using the Householder orthogonal decomposition method to introduce orthogonal constraints.

2. The method according to claim 1, characterized in that in, An efficient capsule pruning algorithm is used to place a capsule pruning layer after the main capsule layer, which includes the following steps: Get the main capsule layer Capsules u∈R(B,n,d,W,H) and set the threshold to θ; Calculate the L2 norm of each capsule, and then sort the capsules according to the L2 norm; Initialize a matrix M with all 1s and calculate the cosine similarity between two capsules; Update the M value by comparing the cosine similarity between capsules. If the similarity between two capsules exceeds the threshold θ, the corresponding position in M ​​is marked as 0. Use the updated matrix M as the pruned capsule network and return the pruned capsule set.

3. The method according to claim 2, characterized in that In the step S300, The cosine similarity of capsule angles is used to measure redundancy. The formula of cosine similarity is as follows: where u ordered,i ,u ordered,j They represent the dot product of the two capsule vectors whose cosine similarity needs to be calculated, |u ordered,i | and |u ordered,j |respectively represent the molds of the two capsules.

4. The method according to claim 1, characterized in that: The step S500 includes the following steps: S510, using three weight matrices (prediction matrices) W Q ,W K ,W V ∈R d×d Come from u l,i Derive query Q, key K and value V; where, u l,i represents the l-th layer capsule; Q=W Q ×u l,i , K=W K ×u l,i , V=W V ×u l,i , where W Q ,W K and W V is an orthogonal matrix, which can transform u l,i Project into a d-dimensional orthogonal subspace; S520, generating coupling coefficient c through attention routing ij , where the coupling coefficient matrix C is derived from the attention graph generated by the dot product of Q and K, where In the formula, the dimension of each capsule is d, and the formula of α-Entmax is as follows: Where τ is an adaptive threshold and α is a hyperparameter that controls the sparsity of the attention map.

5. The method according to claim 4, characterized in that In the step S520, In the voting matrix S i,j In the middle, the higher-level capsule v l+1,j Through the multi-head self-attention mechanism from voting s l+1,j The overall formula is as follows: In the formula, g represents the nonlinear activation function, v l+1,j Represents the capsule of the l+1th layer Among them, voting l+1,j Calculated by multiplying V and C.

6. The method according to claim 5, characterized in that In step S600, Reduce the prediction matrix W from three to one and use u l,i Replace K, Q, V; The coupling coefficient matrix C is obtained by using α-Entmax and dot product to produce the new vote s l+1,j , which is expressed as follows: In the formula, It is the lower capsule to the higher capsule v l+1,j prediction. Among them, s l+1,j Through the nonlinear function g to generate v l+1,j .

7. The method according to claim 6, characterized in that In the step S700, For the matrix W Q ,W K , and W V Orthogonalization is performed, where the calculation of the coupling coefficient matrix C is expressed as follows: Where U l Represents a capsule of layer l.

8. The method according to claim 7, characterized in that The step S800 includes: S810, an orthogonal matrix W∈R d×d The structure is: W=H0H1…H d-1 Where W is the weight matrix to be orthogonalized, and each H i represents a Householder transformation, H i Defined as: In the formula, a i is a unit column vector S810, use a set of randomly generated column vectors {b_i|i=0,…,d-1} to replace a i To construct H i , then the orthogonal matrix W is expressed as follows: Among them, during the training process, b i Optimization is performed via gradient backpropagation. 9 . A computer-readable storage medium having program instructions stored thereon, wherein the program instructions, when executed by a processor, implement the method according to any one of claims 1 to 8.

10. An image classification system based on orthogonal sparse pruned capsule network, characterized in that: include: A computer device comprising a computer readable storage medium according to claim 9.

Citation Information

Patent Citations

  • Image classification method based on improved capsule network

    CN116246110A

  • Pruning-based lightweight network structure image classification method

    CN117197524A

Cited By

  • Dynamic layer cutting system and method for large language model

    CN120181137A

  • Document image correction method and system based on space-channel sparse attention

    CN122510134A