An image classification method, device and computer equipment for industrial detection
By expanding the angle between initial vectors in the angle space and using the cross-entropy loss function to calculate similarity, the problem of low accuracy of deep learning image classification models when image differences are small is solved, and more accurate image classification is achieved.
Patent Information
- Application Number
- CN202210857094.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-20
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2042-07-20
AI Technical Summary
Deep learning-based image classification models struggle to achieve fine-grained classification and detection when image differences are small, resulting in low classification and detection accuracy.
By expanding the angle between initial vectors in the angle space, the cosine value of the angle between target vectors is calculated, and the similarity is calculated using the cross-entropy loss function to determine the image category and strengthen the separation boundary between category images.
It achieves accurate classification of image data in the angular classification space, improves the compactness of intra-class distances and the separability of inter-class distances, and enhances the accuracy of classification results.
Smart Images

Figure CN114972335B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of deep learning, in particular to an image classification method and device for industrial detection and a computer device. BACKGROUND
[0002] Image classification technology based on deep learning has become a research hotspot in the field of artificial intelligence. Deep learning models can automatically learn image features and are applied to traditional multi-class image classification tasks, achieving good classification detection results.
[0003] However, for fine-grained classification detection applications with high similarity of image features, image classification models based on deep learning have the problem of inaccurate image classification, which cannot meet the detection requirements. Fine-grained classification detection is a more detailed sub-class division based on distinguishing basic categories. Due to the more similar appearance and features between images, as well as the influence of posture, angle, light, occlusion, background interference, etc. in the sampling, the images exhibit the characteristics of large inter-class difference and small intra-class difference.
[0004] Although the algorithm based on deep learning technology is much better than traditional methods, when the image difference is small, it is still relatively difficult for image classification models based on deep learning to reclassify images, and there is a problem of low classification detection accuracy. SUMMARY
[0005] In order to solve the problem of low classification detection accuracy when performing more detailed sub-class division on images due to small image difference, the present application provides an image classification method, device and computer equipment for industrial detection.
[0006] Embodiments of the present application are implemented as follows:
[0007] The present application provides an image classification method for industrial detection, which comprises:
[0008] Obtaining a feature vector of a first training image and inputting the feature vector into a weight matrix with multiple category vectors, the category vectors being set according to image classification requirements;
[0009] Expanding the angle of each initial vector in the angle space to obtain a cosine value corresponding to the target vector angle, the initial vector angle being the angle between the feature vector and each category vector; wherein the cosine value is used to determine the similarity, and the angle space is a classification space converted based on the weight matrix;
[0010] According to the corresponding threshold interval where the similarity is located, a first category corresponding to the first training image is determined.
[0011] In some embodiments, the method further comprises:
[0012] setting a separation angle interval;
[0013] calculating a sum or a product of the separation angle interval and the initial vector angle to obtain a target vector angle;
[0014] calculating a cosine value of the target vector angle.
[0015] In some embodiments, the method further comprises:
[0016] calculating a dot product of each of the category vectors in the weight matrix and the feature vector;
[0017] calculating the initial vector angle between the feature vector and each of the category vectors based on the dot product, the initial vector angle being a one-dimensional vector with a size of n, the n representing a number of categories of the category vectors.
[0018] In some embodiments, the method further comprises:
[0019] calculating the similarity by a cross-entropy loss function, the similarity representing a degree of similarity between the cosine value and the category vector.
[0020] In some embodiments, the angle space is a classification space transformed based on the weight matrix, the method further comprising:
[0021] calculating a feature vector norm and a row parameter norm of the weight matrix;
[0022] calculating a ratio of the feature vector to the feature vector norm and a ratio of the row parameter of the weight matrix to the row parameter norm, and calculating a product of the two ratios as an angle cosine value;
[0023] transforming the weight matrix to the angle space by an inverse cosine calculation based on the angle cosine value.
[0024] In some embodiments, the method further comprises:
[0025] extracting the feature vector from the first training image by a backbone model, the feature vector being a one-dimensional vector with a size of the n.
[0026] In some embodiments, after the inputting the feature vector into the weight matrix with the plurality of category vectors, the method further comprises:
[0027] The category vector is divided into a current index bit category and other index bit categories according to a category to which the current index bit is directed, wherein the current index bit category is represented as 1, and the other index bit categories are represented as 0.
[0028] Yet another embodiment of the present application provides an image classification device for industrial detection, comprising:
[0029] The acquisition module is configured to acquire a feature vector of a first training image and input the feature vector into a weight matrix having a plurality of category vectors, the category vectors being set according to image classification requirements.
[0030] The expansion module is configured to expand each initial vector angle in an angle space to obtain a cosine value corresponding to a target vector angle, the initial vector angle being an angle between the feature vector and each category vector; wherein the cosine value is used to determine a similarity, and the angle space is a classification space converted based on the weight matrix.
[0031] The determination module is configured to determine a first category corresponding to the first training image according to a corresponding threshold interval in which the similarity is located.
[0032] In some embodiments, the expansion module comprises:
[0033] The setting unit is configured to set a separation angle interval.
[0034] The first calculation unit is configured to obtain a sum or a product of the separation angle interval and the initial vector angle to obtain the target vector angle.
[0035] The second calculation unit is configured to calculate a cosine value of the target vector angle.
[0036] Yet another embodiment of the present application provides a computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements steps of the image classification method for industrial detection when executing the computer program.
[0037] The present application has the following beneficial effects: by expanding each initial vector angle in an angle space, the separation boundary between different category images is strengthened, so that the intra-class distance of image features is more compact, and the inter-class distance is more separated, and the effect that all image data can be correctly classified in an angle classification space can be achieved; further, the similarity is calculated based on a cross-entropy loss function, the smaller the cross-entropy loss function, the higher the similarity, and the better the fitting degree between the feature vector and the category vector, and the more accurate the classification result obtained. BRIEF DESCRIPTION OF DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0039] Figure 1 The flow chart of the image classification method for industrial detection provided by the embodiments of the present application;
[0040] Figure 2 The flow chart of the method for calculating the enhanced angle cosine value provided by the embodiments of the present application;
[0041] Figure 3 The angle classification space schematic diagram before and after adding the separation angle interval provided by the embodiments of the present application;
[0042] Figure 4 The structural block diagram of the image classification device for industrial detection provided by the embodiments of the present application. DETAILED DESCRIPTION
[0043] In order to make the purpose, implementation and advantages of the present application more clear, the following will combine the drawings in the exemplary embodiments of the present application to clearly and completely describe the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only some of the embodiments of the present application, but not all the embodiments.
[0044] Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments in the present application without creative labor are within the scope of protection of the present application.
[0045] Based on the exemplary embodiments described in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the appended claims of the present application. In addition, although the disclosure in the present application is introduced according to exemplary one or more examples, it should be understood that each aspect of these disclosures can also constitute a complete embodiment independently.
[0046] It should be noted that the brief description of the terms in the present application is only for the convenience of understanding the following described embodiments, and is not intended to limit the embodiments of the present application. Unless otherwise specified, these terms should be understood according to their ordinary and general meanings.
[0047] The implementation of the present application will be specifically described below in combination with the technical solutions of the present application.
[0048] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, and machine learning / deep learning.
[0049] In the embodiments of the present invention, the main focus is on machine learning. Machine learning and deep learning generally include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and self-learning techniques.
[0050] The image classification method proposed in the embodiment of the present invention can be divided into two parts, including a training part and an image classification part; wherein the training part involves the technical field of machine learning.
[0051] In some embodiments, image classification is to find a label from an existing label set for an input image and assign it to the image.
[0052] Image classification models are usually used for image classification. Image classification models are generally divided into four parts: input image, backbone model, classifier, and output prediction probability.
[0053] The input image is a set of N images, each of which is marked with a classification label;
[0054] The backbone model is used to extract image features from the image, the classifier is used to map the image features to category scores, and the classifier predicts the classification labels of unseen images and outputs the predicted probabilities.
[0055] When the classification label predicted by the classifier is consistent with the true classification label of the image, the prediction probability is high.
[0056] This application transforms the linear classification space into the angular space and adds a separation angle interval to allow the image classification model to learn clearer classification boundaries, making the intra-class distance of features more compact and the inter-class distance more separated.
[0057] Figure 1 The flowchart of the image classification method for industrial detection provided by the embodiment of the present application is shown as an example. Figure 1 As shown, an image classification method for industrial inspection provided in an embodiment of the present application includes the following steps:
[0058] In step 110, a feature vector of a first training image is obtained, and the feature vector is input into a weight matrix with a plurality of category vectors, the category vectors being set according to image classification requirements.
[0059] The training image refers to an image of an object such as a display screen or an industrial part. It should be noted that the training image can be a local image pre-stored in the terminal device, or can be transmitted to the terminal device by another terminal in communication connection with the terminal device, or can be an image collected by a designated camera, or can be a video frame extracted from a designated video. The specific source and image form of the training image are not limited herein.
[0060] The weight matrix is composed of n rows and d columns, where n is the number of categories of classification, which is set according to the actual classification requirements of industrial detection. For example, when the classification is pass and fail, n represents 2; when the classification is excellent, pass and fail, n represents 3.
[0061] In some embodiments, the category vectors are divided into a current index bit category and other index bit categories according to the category to which the current index bit is directed, where the current index bit category is represented as 1 and the other index bit categories are represented as 0.
[0062] The d in the weight matrix represents the size of the feature vector, and each row in the weight matrix is used to represent the parameters of the current category in the angle space, i.e., the row parameters.
[0063] Of course, different feature vectors can be set in different application fields. For example, in display screen defect detection, the feature vectors include mean gray value, perimeter, area, perimeter-to-area ratio, compactness, and ellipticity, etc.
[0064] In step 120, the angle between the initial vectors in the angle space is expanded to obtain a cosine value corresponding to the target vector angle, the initial vector angle being the angle between the feature vector and each category vector;
[0065] The cosine value is used to determine the similarity, and the angle space is a classification space converted based on the weight matrix.
[0066] The angle space is one of decision spaces, and the decision space is an abstract data space in which image feature data extracted by a backbone model is mapped.
[0067] In step 130, a first category corresponding to the first training image is determined according to the corresponding threshold interval in which the similarity lies.
[0068] The greater the cosine value corresponding to the target vector angle is, the smaller the angle between the category vector and the feature vector is, and the more similar the category vector and the feature vector are. When the similarity of the category vector and the feature vector satisfies a corresponding threshold interval, the feature vector belongs to the category corresponding to the category vector.
[0069] In some embodiments, the initial vector angle in step 120 is calculated by the following steps:
[0070] calculating the dot product of each category vector in the weight matrix and the feature vector;
[0071] based on the dot product, calculating the initial vector angle between the feature vector and each category vector, the initial vector angle being a one-dimensional vector with a size of n, n representing the number of categories of the category vector.
[0072] Figure 2 A flowchart of a method for calculating the enhanced angle cosine value is provided in the embodiments of the present application, as shown in Figure 2 The above-mentioned step 120 of expanding the initial vector angle in the angle space to obtain the cosine value corresponding to the target vector angle in the embodiments is implemented by the following steps:
[0073] In step 121, a separation angle interval is set. The size of the separation angle interval is set according to the similarity between image features.
[0074] In step 122, the sum or product of the separation angle interval and the initial vector angle is calculated to obtain the target vector angle.
[0075] In step 123, the cosine value of the target vector angle is calculated.
[0076] It should be noted that expanding the initial vector angle includes increasing the additive separation angle interval or increasing the multiplicative separation angle interval, which is respectively represented by the following formulas:
[0077] cos(θ1+m)-cos(θ2)=0
[0078] cos(m*θ1)-cos(θ2)=0
[0079] wherein θ1 and θ2 are the angles of image categories 1 and 2 respectively, and m is the separation angle interval.
[0080] By expanding the initial vector angle, the inter-class separability is improved, and the inter-class compactness is also enhanced.
[0081] As shown in Figure 3 the angle classification space diagram before and after adding the separation angle interval, Figure 3 (a) is an angle classification space diagram without adding a separation angle interval;Figure 3 The angle classification space in (b) is divided by the separation angle interval.
[0082] Compared with Figure 3 The angle classification space in (a) is divided by the separation angle interval. Figure 3 The boundary between the classes in the angle classification space in (b) with the separation angle interval is better separable.
[0083] In some embodiments, the method for determining the similarity includes: calculating the similarity by using a cross-entropy loss function, the similarity being used to represent the degree of similarity between the cosine value and the category vector.
[0084] The cross-entropy is used as the loss function of the classifier, and is used to measure the similarity between two variables.
[0085] For example, given two probability distributions p and q, the cross-entropy of p with respect to q is the difficulty of expressing the probability distribution p by using the probability distribution q, where p represents the correct answer and q represents the predicted value. The smaller the cross-entropy, the closer the two probability distributions are, and the more similar the two variables are.
[0086] The loss function is used to measure the difference between the predicted value of the model and the true value in a sample.
[0087] For example, for a sample (a i , b i ), where bi is the true value, and f(a i ) is the predicted value.
[0088] The loss function L(f(a i )b i ) is used to represent the difference between the true value and the predicted value. The smaller the difference, the better. The most ideal case is that the predicted value is exactly equal to the true value, and the difference is 0.
[0089] Since the cross-entropy is used to evaluate the distance between two sample distributions, the cross-entropy can be used to evaluate the difference between the probability distribution obtained by the current training and the true distribution. That is, the cross-entropy loss function is used to describe the distance between the actual output (probability) and the expected output (probability). The smaller the cross-entropy value, the closer the two probability distributions are.
[0090] In some embodiments, the angle space is a classification space obtained by weight matrix transformation or mapping. The angle space is obtained by weight matrix transformation or mapping, including the following steps:
[0091] Calculate the feature vector module and the row parameter module of the weight matrix.
[0092] The vector is a quantity with size and direction, the size of the vector becomes the module of the vector, that is, the size of the eigenvector is the eigenvector module, and the size of the parameter vector of each row in the weight matrix is the row parameter module;
[0093] The ratio of the eigenvector to the eigenvector module and the ratio of the row parameter of the weight matrix to the row parameter module are calculated, the product of the two ratios is the cosine value of the angle, and the angle is calculated by the inverse cosine of the cosine value to realize the conversion of the weight matrix to the angle space.
[0094] The cosine value of the angle is expressed by the formula:
[0095] cosθ=(W j / ||W j ||)·(x / ||x||)
[0096] Wherein, Wj represents the row parameter of the weight matrix, x represents the eigenvector of the training image, |W j | represents the row parameter module of the weight matrix, |x| represents the eigenvector module, and the right side of the equation represents the normalization of the current class vector of the decision space and the feature x of the training image.
[0097] In some embodiments, the eigenvector of the first training image is obtained, which can be realized by the following method:
[0098] The eigenvector is extracted from the first training image by the backbone model, and the eigenvector is a one-dimensional vector with a size of n. The image features extracted by the backbone model include color features, texture features, shape features and spatial relationship features. The more the number of extracted eigenvectors, the more accurate the description of the image, and the higher the accuracy of the retrieval.
[0099] It should be noted that the color feature is a global feature, which describes the surface properties of the scene corresponding to the image or image region. Generally, the color feature is a pixel-based feature, at this time all the pixels belonging to the image or image region have their own contribution;
[0100] For texture images with large differences in thickness, density and other aspects, using texture features is an effective method, but when the differences between the easily distinguishable information of the texture are not large, the general texture features are difficult to accurately reflect the differences between the textures with different visual feelings of people.
[0101] There are two types of shape features, one is contour feature, and the other is region feature.
[0102] The contour feature of the image is mainly for the outer boundary of the object, and the region feature of the image is related to the entire shape region.
[0103] The spatial relationship refers to the mutual spatial position or relative direction relationship between multiple targets segmented in the image. The relationship can be classified into connection / adjacency relationship, intersection / overlap relationship, and inclusion / containment relationship.
[0104] Generally, the spatial position information can be classified into two categories: relative spatial position information and absolute spatial position information. The former emphasizes the relative situation between targets, such as up-down and left-right relationship, and the latter emphasizes the distance and direction between targets. The use of spatial relationship features can enhance the description and differentiation ability of image content.
[0105] In the above embodiment, the feature vector corresponding to the image can also be extracted by the convolutional neural network. The convolutional neural network is the most commonly used and effective model in computer vision at present. The convolutional neural network only includes multiple convolutional layers. The image to be processed is input into the convolutional neural network for feature extraction to obtain the feature vector of the image.
[0106] In some embodiments, in order to enhance the diversity of the training image, before obtaining the feature vector of the first training image, the training image is further subjected to a wide range of processing, such as horizontal and vertical direction flipping and brightness enhancement, to obtain more image data.
[0107] Based on the image classification method of the above embodiment, the image to be detected is input into the classifier established based on the above embodiment, and the output data is the category of the image to be detected.
[0108] The present application strengthens the separation boundary between images of different categories by expanding the angle of each initial vector in the angle space, so that the intra-class distance of image features is more compact and the inter-class distance is more separated, and all image data can be correctly classified in the angle classification space. Further, the similarity is calculated based on the cross-entropy loss function. The smaller the cross-entropy loss function, the higher the similarity, which indicates that the fitting degree between the feature vector and the category vector is better, and the classification result obtained is more accurate.
[0109] Figure 4 A structural block diagram of an image classification device for industrial detection provided by an embodiment of the present application is shown in FIG. 1. As shown in the figure, the image classification device for industrial detection provided in the embodiment of the present application comprises: Figure 4
[0110] The acquisition module 401 is configured to acquire the feature vector of the first training image and input the feature vector into a weight matrix having multiple category vectors, wherein the category vectors are set according to the image classification requirement.
[0111] The expanding module 402 is configured to expand each initial vector included angle in an angle space to obtain a cosine value corresponding to a target vector included angle, the initial vector included angle being an angle between a feature vector and a category vector; and the cosine value is used to determine the similarity, and the angle space is a classification space obtained based on a weight matrix.
[0112] The determining module 403 is configured to determine a first category corresponding to the first training image according to a corresponding threshold interval in which the similarity is located.
[0113] In some embodiments, the expanding module 402 includes a setting unit, a first calculating unit and a second calculating unit.
[0114] The setting unit is configured to set a separation angle interval.
[0115] The first calculating unit is configured to obtain a sum or a product of the separation angle interval and the initial vector included angle to obtain the target vector included angle.
[0116] The second calculating unit is configured to calculate the cosine value of the target vector included angle.
[0117] The above image classification apparatus and each module in the image classification apparatus can be realized by software, hardware or a combination thereof. The above modules can be embedded in or independent of a processor of a computer device in a hardware form, or stored in a memory of the computer device in a software form, so as to be called and executed by the processor to perform operations corresponding to the above modules.
[0118] The image classification apparatus provided by the embodiments of the present application has similar implementation principles and technical effects to the above method embodiments, and thus will not be described here.
[0119] The embodiments of the present application further provide a computer device including a memory and a processor, the memory storing a computer program, and the processor implementing steps in the image classification method for industrial detection when executing the computer program.
[0120] The computer device provided by the embodiments of the present application has similar implementation principles and technical effects to the above method embodiments, and thus will not be described here.
[0121] In the embodiments of the present application, a computer readable storage medium is also provided, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to implement the steps in the image classification method for industrial detection. The computer readable storage medium provided in the embodiments of the present application has similar implementation principles and technical effects to the above method embodiments, and will not be described here. The computer readable storage medium includes, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0122] The algorithms and displays presented herein are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems can be used with these teachings, depending on the implementation and the desires of the user. As will be apparent to those of ordinary skill in the art, the structures required to construct such systems are within the scope of the present application. In addition, the present application is not described with reference to any particular programming language. It will be appreciated that a variety of programming languages can be used to implement the teachings of the present application as described herein, and any oblique descriptions of a specific language are used only for the purpose of clarity.
[0123] In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the application can be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been described in detail in order to not obscure the understanding of this description.
[0124] Similarly, it is to be understood that the above description is one example of inventive aspects of the present application and that not all of the features would necessarily be included in all embodiments of the application. In some instances, features have been described generally in terms of their functionality without describing the specifics of the feature because it is contemplated that the one skilled in the art would be able to determine such specific details in view of the disclosure herein. Additionally, it is contemplated that various features of the application described can be implemented in various embodiments of the application and that such described features can be combined in various permutations and combinations.
[0125] Those skilled in the art will appreciate that the modules in the apparatuses in the embodiments can be adapted and placed in one or more apparatuses other than that of the embodiments. The modules or units or components in the embodiments can be combined into one module or unit or component, and furthermore can be split into multiple sub-modules or sub-units or sub-components. Any combination of all the features disclosed in the present specification (including the accompanying claims, abstract and drawings), and any method or process of any combination of the features disclosed in the present specification (including the accompanying claims, abstract and drawings) can be adopted unless expressly stated otherwise. Each feature disclosed in the present specification (including the accompanying claims, abstract and drawings) can be replaced by alternative features providing the same, equivalent or similar function unless expressly stated otherwise.
[0126] Furthermore, those skilled in the art will appreciate that the features of the different embodiments can be combined in any combination, meaning that the scope of the application is intended to cover any possible combination of the individual features disclosed or suggested in the present specification (including the accompanying claims, abstract and drawings). For example, in the claims below any of the claimed embodiments can be used in any combination.
Claims
1. An image classification method for industrial inspection, characterized in that, The method comprises: obtaining a feature vector of a first training image and inputting the feature vector into a weight matrix with a plurality of category vectors, the category vectors being set according to image classification requirements, comprising: extracting the feature vector from the first training image by a backbone model, the feature vector being a one-dimensional vector with a size of n; dividing the category vectors into a current index bit category and other index bit categories according to the category to which the current index bit is directed, wherein the current index bit category is represented as 1 and the other index bit categories are represented as 0; widening each initial vector angle in an angle space to obtain a cosine value corresponding to a target vector angle, the initial vector angle being an angle between the feature vector and each category vector, comprising: setting a separation angle interval; obtaining a sum or product of the separation angle interval and the initial vector angle to obtain a target vector angle; calculating the cosine value of the target vector angle; wherein the cosine value is used to determine a similarity, and the angle space is a classification space converted based on the weight matrix; the separation angle interval is set according to a similarity between image features of the first training image, the image features including color features, texture features, shape features and spatial relationship features; determining a first category corresponding to the first training image according to a corresponding threshold interval in which the similarity is located.
2. The image classification method for industrial inspection of claim 1, wherein, The calculation of the initial vector angle further comprises: calculating a dot product of each category vector in the weight matrix and the feature vector; based on the dot product, calculating the initial vector angle between the feature vector and each category vector, the initial vector angle being a one-dimensional vector with a size of n, wherein n represents the number of categories of the category vector.
3. The image classification method for industrial inspection of claim 2, wherein, The determination of the similarity further comprises: calculating the similarity by a cross-entropy loss function, the similarity being used to represent a similarity degree between the cosine value and the category vector.
4. The image classification method for industrial inspection of claim 3, wherein, The angle space is a classification space converted based on the weight matrix, further comprising: calculating a feature vector module and a row parameter module of the weight matrix; calculating a ratio of the feature vector to the feature vector module and a ratio of a row parameter of the weight matrix to the row parameter module, and obtaining a product of the two ratios as an angle cosine value; obtaining an angle by arccosine calculation of the angle cosine value, to realize conversion of the weight matrix to the angle space.
5. An image classification apparatus for industrial inspection, characterized by comprising: comprises: an obtaining module, configured to obtain a feature vector of a first training image and input the feature vector into a weight matrix with a plurality of category vectors, the category vectors being set according to image classification requirements, comprising: extracting the feature vector from the first training image by a backbone model, the feature vector being a one-dimensional vector with a size of n; and after inputting the feature vector into the weight matrix with the plurality of category vectors, dividing the category vectors into a current index bit category and other index bit categories according to the category to which the current index bit is directed, wherein the current index bit category is represented as 1 and the other index bit categories are represented as 0; An expanding module is configured to expand an initial vector angle between a feature vector and a category vector to obtain a target vector angle, and to obtain a cosine value corresponding to the target vector angle, wherein the initial vector angle is an angle between the feature vector and the category vector, the cosine value is used to determine a similarity, and the angle space is a classification space transformed based on the weight matrix; the expanding module comprises: a setting unit configured to set a separation angle interval; a first calculation unit configured to obtain a sum or a product of the separation angle interval and the initial vector angle to obtain the target vector angle; and a second calculation unit configured to calculate the cosine value of the target vector angle, wherein the separation angle interval is set according to a similarity between image features of the first training image, and the image features comprise color features, texture features, shape features and spatial relationship features. A determining module is configured to determine a first category corresponding to the first training image according to a corresponding threshold interval in which the similarity is located. 6.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-5 when the computer program is executed by the processor. The processor executes the computer program to implement the steps of the method in any one of claims 1 to 4.