A multi-classification sensitive image detection method
By constructing a lightweight convolutional neural network model, combining the SE channel attention mechanism and HardSwish activation function, the problem of insufficient detection efficiency and accuracy of sensitive images in the existing technology is solved, and efficient sensitive image recognition is achieved.
Patent Information
- Application Number
- CN202310023144.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-09
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2043-01-09
AI Technical Summary
The existing technology cannot efficiently complete the detection task of sensitive images under the huge data flow of the Internet, especially the identification accuracy and speed of pornographic, political and terrorist information are difficult to take into account.
Build a lightweight convolutional neural network model, feature extraction is performed through the SE channel attention mechanism and Ghost Module, and combine the HardSwish activation function and model pruning to optimize the model structure to improve detection efficiency and accuracy.
On the premise of ensuring high accuracy, the number of model parameters is significantly reduced and the detection speed is improved, and the efficient recognition of sensitive images is achieved, with the detection accuracy reaching 94.46%, and the detection time of a single image is shortened to 6.37ms.
Smart Images

Figure CN116342926B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of multimedia content security, and in particular to a multi-classification sensitive image detection method. Background Art
[0002] With the rapid development of internet technology in recent years, multimedia content has also shown an exponential growth trend. However, this growth has brought with it regulatory pressure. This multimedia content includes content related to pornography, politics, and terrorism. Without oversight, this information can have a significant negative impact on the physical and mental health of young people and social stability. Reliably and efficiently preventing the spread of sensitive information through images, protecting the physical and mental health of minors, and maintaining social stability are urgent issues that need to be addressed.
[0003] In early studies, many researchers tended to use traditional machine learning to solve the classification problem of sensitive images. Most of these methods are based on low-level features. They first extract vectors of feature information such as texture, color, contour and relative size of the image area, then use genetic algorithms to find the category of each area, and finally accumulate the object category to which the image belongs to calculate the probability that the image belongs to a certain category.
[0004] With the outstanding performance of deep learning in computer vision in recent years, many researchers have been inclined to apply deep learning methods to the recognition of sensitive images. These methods are mainly based on the powerful feature extraction capabilities of CNNs, which can effectively identify discriminative deep features and thus achieve classification of sensitive images.
[0005] However, in recent years, research on sensitive image detection tasks has ignored actual application scenarios and focused on the extraction and detection of image features, which has failed to complete the task of detecting sensitive images under the huge data flow of the Internet. Summary of the Invention
[0006] The purpose of the present invention is to address the shortcomings of the existing technology and provide a multi-classification sensitive image detection method, build and train a convolutional neural network model, and improve the detection accuracy of sensitive information based on the trained convolutional neural network model.
[0007] The technical solution adopted by the present invention to solve the above technical problems is: a multi-classification sensitive image detection method, characterized in that it includes the following steps:
[0008] Step 1: Use Python code to extract public datasets from the Internet and perform unified image transformation processing to obtain sensitive image datasets;
[0009] Step 2: Build a lightweight convolutional neural network model and train it using the sensitive image dataset to obtain a trained convolutional neural network model;
[0010] Step 3: Obtain the image to be detected, normalize it, and input it into the trained lightweight convolutional neural network model to obtain the detection result of the image.
[0011] Preferably, step 1 comprises the following steps in order:
[0012] Step 1a: Obtain various public datasets through Kaggle official website and GitHub;
[0013] Step 1b: Write a Python program to classify and label the dataset and perform image processing to ensure that it can be used during model training.
[0014] Preferably, the sensitive image dataset in step 1 includes four types: pornography, terrorism, politics, and normal.
[0015] Preferably, the lightweight convolutional neural network model in step 2 includes ten layers from input to output, namely:
[0016] The first layer is the Ghost Module and SE channel attention mechanism, which contains 8 ordinary convolution kernels and 8 group convolution kernels. The convolution kernel size is 3×3, the stride is 1, and 16 feature maps are generated.
[0017] The second layer is a convolution module, which contains 16 convolution kernels, a pooling kernel of 3×3, and a stride of 2;
[0018] The third layer is the MBConv module, which contains 16 convolution kernels, a pooling kernel of 3×3, a stride of 1, and a convolution kernel expansion amplitude of 1;
[0019] The fourth layer is the MBConv module, which contains 32 convolution kernels, a pooling kernel of 3×3, a stride of 2, and a convolution kernel expansion amplitude of 6;
[0020] The fifth layer is the MBConv module, which contains 64 convolution kernels, a pooling kernel of 5×5, a stride of 2, a convolution kernel expansion amplitude of 6, and a cycle of 2 times, with a second step of 1;
[0021] The sixth layer is the MBConv module, which contains 80 convolution kernels, a pooling kernel of 3×3, a stride of 2, a convolution kernel expansion amplitude of 6, and a cycle of 2 times, with a second step of 1;
[0022] The seventh layer is the MBConv module, which contains 119 convolution kernels, a pooling kernel of 5×5, a stride of 1, a convolution kernel expansion amplitude of 6, and 2 cycles;
[0023] The eighth layer is the MBConv module, which contains 160 convolution kernels, a pooling kernel of 5×5, a stride of 2, and a convolution kernel expansion amplitude of 6;
[0024] The ninth layer is the MBConv module, which contains 320 convolution kernels, a pooling kernel of 3×3, a stride of 1, and a convolution kernel expansion amplitude of 6;
[0025] The tenth layer is the classification module, which contains 1280 convolution kernels, a pooling kernel of 1×1, a stride of 1, and uses global average pooling and a fully connected layer to implement index classification.
[0026] Preferably, the lightweight convolutional neural network model training step includes:
[0027] Step 2a: Use the transforms.Resize function of the torchvision library to resize the image to 224×224 and randomly invert it for data augmentation. The ratio of the training set to the test set is 8:2.
[0028] Step 2b: Use Python to extract relevant images from multiple Kaggle datasets and NSFM public datasets to create a dataset;
[0029] Step 2c: Train the convolutional neural network model using the created data set to obtain the trained convolutional neural network model.
[0030] Preferably, the convolutional neural network model training optimization parameters are: selecting the cross entropy cost function as the loss function, selecting AdamW as the optimizer during training; selecting the learning rate as 0.0005 and gradually decaying with the learning rounds; and the batch size of samples is 64.
[0031] Preferably, the training process in step 2 includes data normalization and data enhancement.
[0032] According to the above technical solution, the beneficial effects of the present invention are:
[0033] This detection method builds and trains a convolutional neural network model. Based on the trained convolutional neural network model, the accuracy of sensitive information detection reaches 94.46%, which is higher than that of similar algorithms. This method prunes the model through ablation experiments and replaces the activation function with HardSwish, reducing the original model parameters by 54.67%. While ensuring accuracy, the single image detection time is shortened from 8.88ms to 6.37ms. Multiple experimental results show that the proposed method effectively improves the recognition accuracy of multi-class sensitive images, significantly reduces the number of model parameters, and achieves an accuracy that is superior to similar algorithms based on a more lightweight model design.
[0034] In terms of model accuracy, the model enhances feature extraction by introducing the Ghost-Module with the SE channel attention mechanism, so that the model can better reduce the feature loss of the model for sensitive images; in terms of model detection speed, the model parameters are reduced by using model pruning operations and the performance is optimized by introducing the HardSwish activation function, thereby improving the model's detection efficiency for sensitive images; by comparing multiple lightweight models, the experimental results show that in the task of detecting sensitive images, the model of the present invention can achieve very excellent detection speed while ensuring an accuracy rate higher than that of similar lightweight network models. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 is a schematic diagram of a network structure in an embodiment of the present invention;
[0036] Figure 2 is a distribution diagram of the number of data set categories in an embodiment of the present invention;
[0037] Figure 3 This is a curve chart showing changes in the accuracy of the validation set during the training process of the present invention;
[0038] Figure 4 is the confusion matrix of the present invention in the case of multiple classifications;
[0039] Figure 5 This is a model attention visualization effect diagram displayed by the present invention using the class activation map visualization method. DETAILED DESCRIPTION
[0040] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0041] The structures, proportions, sizes, etc. depicted in the drawings of this specification are only used to match the contents disclosed in the specification so as to facilitate understanding and reading by persons familiar with this technology. They are not intended to limit the conditions under which the present invention can be implemented and therefore have no substantive technical significance. Any structural modifications, changes in proportional relationships, or adjustments in size should still fall within the scope of the technical contents disclosed in the present invention without affecting the efficacy and objectives that can be achieved by the present invention.
[0042] The present invention provides a multi-classification sensitive image detection method based on a lightweight convolutional neural network, including: collecting data and performing classification processing, inputting the sensitive image to be identified into a trained convolutional neural network model, and obtaining the classification detection results of the sensitive image. A specific embodiment is now given.
[0043] The dataset used in this example includes 14,575 images involving pornography, politics, terrorism, and normal images. Among them, there are 3,016 pornographic images, 2,433 political images, 3,325 terrorism images, and 5,801 normal images. 20% of them are taken as the test set, and the rest are used as the training set. The data distribution is as follows Figure 2 shown.
[0044] The experimental environment used in this study was Python 3.6. The open-source Python machine learning library Pytorch 1.10.0 was used with CUDA 11.3 for training. All experiments were trained using the Adamw
[29] optimizer with the same experimental batches and rounds. The initial learning rate was 0.0005, and the warmup method was used to increase the learning rate to 0.005 in the first round and then continuously decay the learning rate. The cross-entropy loss was used as the loss function.
[0045] Training hardware conditions: GPU model is RTX 3080, video memory 10GB; CPU model is 12-core Intel(R) Xeon(R) Platinum 8255.
[0046] Then, a lightweight convolutional neural network model is constructed for multi-classification sensitive image detection. It includes ten layers from input to output, namely:
[0047] The first layer is the Ghost Module and SE channel attention mechanism, which contains 8 ordinary convolution kernels and 8 group convolution kernels. The convolution kernel size is 3×3, the stride is 1, and 16 feature maps are generated.
[0048] The second layer is a convolution module, which contains 16 convolution kernels, a pooling kernel of 3×3, and a stride of 2;
[0049] The third layer is the MBConv module, which contains 16 convolution kernels, a pooling kernel of 3×3, a stride of 1, and a convolution kernel expansion amplitude of 1;
[0050] The fourth layer is the MBConv module, which contains 32 convolution kernels, a pooling kernel of 3×3, a stride of 2, and a convolution kernel expansion amplitude of 6;
[0051] The fifth layer is the MBConv module, which contains 64 convolution kernels, a pooling kernel of 5×5, a stride of 2, a convolution kernel expansion amplitude of 6, and a cycle of 2 times, with a second step of 1;
[0052] The sixth layer is the MBConv module, which contains 80 convolution kernels, a pooling kernel of 3×3, a stride of 2, a convolution kernel expansion amplitude of 6, and a cycle of 2 times, with a second step of 1;
[0053] The seventh layer is the MBConv module, which contains 119 convolution kernels, a pooling kernel of 5×5, a stride of 1, a convolution kernel expansion amplitude of 6, and 2 cycles;
[0054] The eighth layer is the MBConv module, which contains 160 convolution kernels, a pooling kernel of 5×5, a stride of 2, and a convolution kernel expansion amplitude of 6;
[0055] The ninth layer is the MBConv module, which contains 320 convolution kernels, a pooling kernel of 3×3, a stride of 1, and a convolution kernel expansion amplitude of 6;
[0056] The tenth layer is the classification module, which contains 1280 convolution kernels, a 1×1 pooling kernel, and a stride of 1. It then uses global average pooling and a fully connected layer to implement index classification.
[0057] The first nine modules all include normalization processing and HardSwish activation processing. Table 1 is the model network structure table of this embodiment.
[0058]
[0059] Table 1
[0060] like Figure 1 As shown in the figure, Conv represents the convolution kernel; MBConv represents the lightweight flip bottleneck convolution kernel; AvgPool represents the adaptive average pooling; FC represents the fully connected layer; BN represents the batch normalization; HardSwish represents the piecewise linear activation function; C represents the number of input channels; C1 represents the number of output channels; H represents the feature map height; W represents the feature map width; Concat represents the channel stacking of the feature map obtained by ordinary convolution and the feature map directly connected through grouped convolution; ⊕ represents channel-level addition, and each directly connected branch represents the fusion of the input feature map with the feature map obtained by convolution and other operations.
[0061] In order to comprehensively compare the various effects of the model, the experiment uses accuracy, F1 value, parameter amount Params and detection speed.
[0062] The Accuracy calculation formula is as follows:
[0063]
[0064] Where PC represents the number of samples whose sensitive image categories are correctly predicted, and PALL represents the total number of samples in the sensitive image test set.
[0065] In order to evaluate the pros and cons of different algorithms, the experiment introduces the concept of F1 value to compare models, and uses F1 value to evaluate the accuracy (Precision) and recall (Recall) as a whole. The definition of F1 is as follows:
[0066]
[0067]
[0068]
[0069] Among them, TP represents the number of correctly predicted positive samples, FP represents the number of incorrectly predicted samples, and FN represents the number of positive samples predicted as negative by the model. Combining the above three formulas, the F1 value can more comprehensively demonstrate the prediction effect of the model.
[0070] The model speed test selected 4980 sensitive images and set the model detection batch size to 1 to test the time consumption of the model when detecting a single image. To eliminate interference factors, the first detection speed of this test is not included in the calculation, and the detection speeds of the remaining batches are accumulated and averaged. The calculation formula is as follows:
[0071] Where n represents the number of predicted sensitive images, t i,start , t i,end Respectively represent the start and end time of the i-th picture, in seconds.
[0072] When the number of parameters is limited to 1.5M or 2.5M and the accuracy is similar to that of other models, the patented model is significantly ahead in both parameter number and inference speed, as shown in Table 2 (GPU inference speed is measured on GTX 1650). Figure 4 、 5 , it can also be clearly seen that the patented model is effective in sensitive image detection.
[0073]
[0074] Table 2
[0075] It should be noted that the parts not described in detail in this application are all prior art.
[0076] The above description is merely a preferred embodiment of the present invention and does not constitute any form of limitation to the present invention. Although the present invention has been disclosed as a preferred embodiment, it is not intended to limit the present invention. Any technician familiar with the present profession can make slight changes or modifications to equivalent embodiments using the technical contents disclosed above without departing from the scope of the technical solution of the present invention. However, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention should be covered by the protection scope of the present invention.
Claims
1. A multi-classification sensitive image detection method, characterized by: The steps include: Step 1: Use Python code to extract public datasets from the Internet and perform unified image transformation processing to obtain a sensitive image dataset; Step 2: Build a lightweight convolutional neural network model and train it using the sensitive image dataset to obtain a trained convolutional neural network model; Step 3: Obtain the image to be detected, perform normalization processing, and input it into the trained lightweight convolutional neural network model to obtain the detection result of the image; The lightweight convolutional neural network model in step 2 includes ten layers from input to output, namely: the first layer is GhostModule and SE channel attention mechanism, which contains 8 ordinary convolution kernels and 8 group convolution kernels, the convolution kernel size is 3×3, the step size is 1, and 16 feature maps are generated; The second layer is a convolution module, which contains 16 convolution kernels, a pooling kernel of 3×3, and a stride of 2; The third layer is the MBConv module, which contains 16 convolution kernels, a pooling kernel of 3×3, a stride of 1, and a convolution kernel expansion amplitude of 1; The fourth layer is the MBConv module, which contains 32 convolution kernels, a pooling kernel of 3×3, a stride of 2, and a convolution kernel expansion amplitude of 6; The fifth layer is the MBConv module, which contains 64 convolution kernels, a pooling kernel of 5×5, a stride of 2, a convolution kernel expansion amplitude of 6, and a cycle of 2 times, with a second step of 1; The sixth layer is the MBConv module, which contains 80 convolution kernels, a pooling kernel of 3×3, a stride of 2, a convolution kernel expansion amplitude of 6, and a cycle of 2 times, with a second step of 1; The seventh layer is the MBConv module, which contains 119 convolution kernels, a pooling kernel of 5×5, a stride of 1, a convolution kernel expansion amplitude of 6, and 2 cycles; The eighth layer is the MBConv module, which contains 160 convolution kernels, a pooling kernel of 5×5, a stride of 2, and a convolution kernel expansion amplitude of 6; The ninth layer is the MBConv module, which contains 320 convolution kernels, a pooling kernel of 3×3, a stride of 1, and a convolution kernel expansion amplitude of 6; The tenth layer is the classification module, which contains 1280 convolution kernels, a pooling kernel of 1×1, a stride of 1, and uses global average pooling and a fully connected layer to implement index classification.
2. The multi-classification sensitive image detection method according to claim 1, characterized in that: The step 1 comprises the following steps in order: Step 1a: Obtain various public datasets through Kaggle official website and GitHub; Step 1b: Write a Python program to classify and label the dataset and perform image processing to ensure that it can be used during model training.
3. The multi-classification sensitive image detection method according to claim 1, characterized in that: The sensitive image dataset in step 1 includes four types: pornography, terrorism, politics, and normal.
4. The multi-classification sensitive image detection method according to claim 1, characterized in that: The lightweight convolutional neural network model training steps include: Step 2a: Use the transforms.Resize function of the torchvision library to resize the image to 224×224 and randomly invert it for data augmentation. The ratio of the training set to the test set is 8:
2. Step 2b: Use Python to extract relevant images from multiple Kaggle datasets and NSFM public datasets to create a dataset; Step 2c: Train the convolutional neural network model using the created data set to obtain the trained convolutional neural network model.
5. The multi-classification sensitive image detection method according to claim 1, characterized in that: The convolutional neural network model training optimization parameters are as follows: the cross entropy cost function is selected as the loss function, AdamW is selected as the optimizer during training; the learning rate is selected as 0.0005 and gradually decays with the learning rounds; the batch size is 64.
6. The multi-classification sensitive image detection method according to claim 1, characterized in that: The training process in step 2 includes data normalization and data enhancement.
Citation Information
Patent Citations
Sensitive image identification method based on depth learning
CN106682694A
Lightweight crop disease identification method based on SK-EfficientNet
CN113627281A