Image deduplication method and device based on deep residual network in combination with perceptual hash algorithm, electronic equipment and storage medium
By combining the deep residual network and the perceptual hashing algorithm, the problem of poor image deduplication robustness is solved, efficient deduplication of the same background or slightly shifted images is achieved, redundant data is reduced, and the deep learning model is improved. training efficiency.
Patent Information
- Application Number
- CN202410786782.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-09-06
AI Technical Summary
The existing technology has poor robustness in image deduplication, especially for pictures taken with the same background or slightly offset scenes. Deep learning methods cannot effectively remove the same pictures at different scales, and training is time-consuming. long.
An image deduplication method based on deep residual network combined with perceptual hashing algorithm is adopted. By combining the feature extraction network model and perceptual hashing algorithm, deep features and perceptual hash codes are used to judge the similarity of pixels and visual features to achieve image deduplication. Heavy.
It improves the accuracy and efficiency of image deduplication, reduces redundant data, and improves the data quality and efficiency of deep learning model training.
Smart Images

Figure CN118606507A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing, and more specifically, relates to an image deduplication method, system, electronic device and storage medium based on a deep residual network combined with a perceptual hash algorithm. Background Art
[0002] With the transformation of the global energy structure and the rapid development of renewable energy, the power industry is facing unprecedented challenges and opportunities. Artificial intelligence technology, especially computer vision and deep learning technology, has brought revolutionary changes to power inspection. Computer vision technology enables robots or drones to identify, track and record the status of power equipment, while deep learning technology can help robots or drones autonomously diagnose and predict faults.
[0003] To ensure the recognition accuracy of artificial intelligence inspections, it is necessary to collect a large amount of high-quality data for training deep learning models. Currently, most of the data collected during inspections is used directly. If the model is trained directly after data annotation without image deduplication, a large number of duplicate images will increase the computational complexity and time complexity of the algorithm when training the model, reducing the efficiency and accuracy of the algorithm; on the other hand, it will also increase the storage, transmission and human annotation costs, resulting in a waste of resources.
[0004] A good image deduplication algorithm is of great significance in substation AI inspection. It can improve data utilization and processing efficiency, promote the development of intelligent operation and maintenance, and ensure the safe and stable operation of the power system. Therefore, when developing substation AI inspection algorithms, full attention should be paid to the design and application of image deduplication algorithms.
[0005] The following problems may exist in current data collection, and the conventional image deduplication method has poor deduplication effect:
[0006] 1) There are a large number of pictures of the same target taken due to lens offset or slight adjustment. A large number of such pictures will increase the difficulty of identifying defect features, which will in turn affect the training effect and generalization ability of the model.
[0007] 2) The data returned by the inspection may contain the same image but different resolutions.
[0008] The current traditional image deduplication methods include grayscale histogram, optical flow method, support vector machine and other methods. The above methods have poor robustness and the degree of deduplication cannot be accurately measured. Deep learning deduplication uses convolutional neural network. Compared with traditional methods, deep learning methods have stronger generalization ability and higher deduplication accuracy, but deep learning methods have poor deduplication effect on the same images of different scales.
[0009] Chinese patent document CN113568571A discloses an image deduplication method based on residual neural network, which is applied to a server, including: receiving an upload request; performing similarity detection on the image to be processed in the database according to the first precise matching data and the first perceptual hash feature value; when a first image matching the image to be processed is detected in the database, comparing the image quality scores of the image to be processed and the first image; if the image quality score of the image to be processed is higher than the image quality score of the first image, sending an upload instruction to the client, and receiving the image to be processed uploaded by the client. The present invention can judge images with the same visual information as similar images by comparing the first precise matching data and the first perceptual hash feature value, and has good deduplication accuracy. In addition, by comparing the image quality of the image to be processed and the first image, and deleting redundant images with poor quality, a good deduplication effect can be obtained.
[0010] Chinese patent document CN117422866A discloses an image content forensics method based on a region candidate network and hash coding, including: constructing a feature extraction model based on a ResNet50 network and an FPN network, and constructing a region candidate model based on a region candidate network; for two images to be forensic, predicting and outputting a candidate feature map of each image based on the trained feature extraction model and the region candidate model, performing a region pooling operation on each candidate feature map to obtain a region feature map, and performing hash coding on each region feature map through a generator to obtain a corresponding hash code; for the two images to be forensic, comparing the hash codes corresponding to the two images through a discriminator to obtain a comparison label, and the comparison label is used to reflect whether the two images are similar content images or different content images.
[0011] In view of this, the present invention designs an image deduplication method based on a deep residual network combined with a perceptual hash algorithm. By combining a deep learning model with a traditional image processing method, the present invention solves the problems of poor deduplication robustness of existing traditional deduplication methods, poor deduplication effect for pictures with the same background or slight offset of continuous shots, inability of deep learning methods to remove the same pictures of different scales, and time-consuming training of methods such as twin networks. Summary of the invention
[0012] The present invention aims to overcome at least one defect of the above-mentioned prior art and provide an image deduplication method based on a deep residual network combined with a perceptual hash algorithm.
[0013] The present invention also discloses a device loaded with an image deduplication method based on a deep residual network combined with a perceptual hash algorithm.
[0014] The detailed technical scheme of the present invention is as follows:
[0015] An image deduplication method based on a deep residual network combined with a perceptual hashing algorithm, the method comprising:
[0016] S1. Obtain a dataset of images to be deduplicated, wherein the dataset contains M images to be deduplicated, where M is a positive integer.
[0017] S2. For the first image to be deduplicated, input it into the feature extraction network model to obtain its deep features, and use the perceptual hash algorithm to extract the perceptual hash code of the first image to be deduplicated, and store the deep features and perceptual hash code of the first image to be deduplicated into the feature library;
[0018] S3, for the mth image to be deduplicated, m is a positive integer and 2≤m≤M, input it into the feature extraction network model to obtain its depth feature, and use the perceptual hash algorithm to extract the perceptual hash code of the mth image to be deduplicated, and calculate the similarity between the depth feature of the mth image to be deduplicated and the depth features of the first m-1 images to be deduplicated stored in the feature library, and compare the calculated similarity with a preset threshold. If the similarity is greater than the preset threshold, it is determined that the images have similar pixel features. If the similarity is less than the preset threshold, execute step S4;
[0019] S4, comparing the perceptual hash code of the mth image to be deduplicated with the perceptual hash codes of the first m-1 images to be deduplicated stored in the feature library, and if they are consistent, determining that the images have similar visual features;
[0020] S5. Perform a deduplication operation on the to-be-deduplicated images in the to-be-deduplicated image data set based on the determination results of the pixel feature similarity and the visual feature similarity.
[0021] Preferably, according to the present invention, the method also includes: constructing a feature extraction network model based on a residual network and in combination with a coordinated attention mechanism, the residual network adopts a lightweight ResNet18 network model, which sequentially includes a 7*7 convolutional layer, a maximum pooling layer, multiple 3*3 convolutional layers and an average pooling layer; the coordinated attention mechanism is inserted into the residual network and constructed as a feature extraction network model for extracting deep features of each image to be deduplicated.
[0022] Preferably, according to the present invention, the perceptual hash algorithm includes a one-dimensional discrete cosine transform, and the one-dimensional discrete cosine transform is:
[0023]
[0024] In formulas (1) and (2), f(i) represents the original signal, that is, the value of the image to be deduplicated in the time domain, corresponding to the coordinate index i in the time domain or space domain. The discrete cosine transform is used to convert the original signal f(i) from the time domain to the frequency domain; F(u) represents the coefficient of the original one-dimensional signal after discrete cosine transform, u represents the frequency component in the one-dimensional discrete cosine transform; N represents the number of original signal points; c(u) represents the compensation coefficient.
[0025] Preferably, according to the present invention, the perceptual hash algorithm further includes a two-dimensional discrete cosine transform, and the two-dimensional discrete cosine transform is:
[0026]
[0027] In formulas (3) and (4), u and v represent the frequency components in the two-dimensional discrete cosine transform, F(u, v) represents the transformation result of the original two-dimensional signal on different frequency components (u, v); c(u) and c(v) are normalization factors, and the specific values of the normalization factors are related to the frequency components u and v; i and j represent the coordinate indexes of the original two-dimensional signal in the time domain or space domain.
[0028] Preferably, according to the present invention, the perceptual hash code of the image to be deduplicated is extracted by using a perceptual hash algorithm, specifically comprising:
[0029] Based on the perceptual hash algorithm, the corresponding value of each image to be deduplicated after discrete cosine transformation is calculated, and the average value of the corresponding values of all images to be deduplicated after discrete cosine transformation is calculated;
[0030] Compare the value corresponding to each image to be deduplicated after discrete cosine transform with the average value. If the value corresponding to each image to be deduplicated after discrete cosine transform is greater than or equal to the average value, output 1; if the value corresponding to each image to be deduplicated after discrete cosine transform is less than the average value, output 0, thereby generating a set of binary data;
[0031] The generated binary data is converted into a string of the set length, which is the perceptual hash code corresponding to each image to be deduplicated.
[0032] Preferably, in step S3, the cosine similarity algorithm is used to calculate the similarity between the depth feature of the mth image to be deduplicated and the depth features of the first m-1 images to be deduplicated stored in the feature library, that is,
[0033]
[0034] In formula (5), A and B correspond to the depth feature vector of the mth image to be deduplicated and the depth feature vector of one of the first m-1 images to be deduplicated, respectively, and k∈n represents the dimension of the depth feature vector.
[0035] Preferably, according to the present invention, in step S5, for the mth image to be deduplicated:
[0036] If it is determined that the image has similar pixel features to one of the previous m-1 images to be deduplicated, the mth image to be deduplicated is deleted from the image dataset to be deduplicated, and the deep features of the mth image to be deduplicated are stored in the feature library;
[0037] If it is determined that the image has similar visual features to one of the previous m-1 images to be deduplicated, the mth image to be deduplicated is deleted from the image dataset to be deduplicated, and its perceptual hash code is not stored;
[0038] If it is determined that there is no visual feature similarity between it and one of the previous m-1 images to be deduplicated, the mth image to be deduplicated is stored, and its perceptual hash code is stored in the feature library.
[0039] In another aspect of the present invention, a device for implementing an image deduplication method based on a deep residual network combined with a perceptual hashing algorithm is provided, the device comprising:
[0040] A data acquisition module is used to acquire a data set of images to be deduplicated, wherein the data set of images to be deduplicated includes M images to be deduplicated, where M is a positive integer;
[0041] A feature acquisition module, used to respectively acquire the depth features and the perceptual hash code of the first image to be deduplicated and store them in a feature library, and respectively acquire the depth features and the perceptual hash code of the mth image to be deduplicated, where m is a positive integer and 2≤m≤M;
[0042] The pixel feature judgment module is used to calculate the similarity between the depth feature of the mth image to be deduplicated and the depth feature of the first m-1 images to be deduplicated stored in the feature library, and compare the calculated similarity with a preset threshold. If the similarity is greater than the preset threshold, it is determined that the images have similar pixel features. If the similarity is less than the preset threshold, it enters the visual feature judgment module;
[0043] The visual feature judgment module is used to compare the perceptual hash code of the mth image to be deduplicated with the perceptual hash codes of the first m-1 images to be deduplicated stored in the feature library. If they are consistent, it is determined that the images have similar visual features.
[0044] The image deduplication module is used to perform a deduplication operation on the to-be-deduplicated images in the to-be-deduplicated image data set based on the determination results of the pixel feature similarity and the visual feature similarity.
[0045] In another aspect of the present invention, there is also provided an electronic device, comprising:
[0046] at least one processor; and
[0047] A memory storing instructions, which, when executed by the at least one processor, enables the at least one processor to perform the image deduplication method based on the deep residual network combined with the perceptual hashing algorithm as described above.
[0048] In another aspect of the present invention, a machine-readable storage medium is provided, which stores executable instructions, and when the instructions are executed, the machine executes the image deduplication method based on the deep residual network combined with the perceptual hashing algorithm as described above.
[0049] Compared with the prior art, the present invention has the following beneficial effects:
[0050] (1) The present invention provides an image deduplication method based on a deep residual network combined with a perceptual hashing algorithm. It solves the problem of poor image deduplication effect in specific situations by combining traditional image processing with deep learning. Compared with existing image deduplication methods, it has better effects and is more convenient to implement.
[0051] (2) The present invention adopts a multi-threading method during feature comparison to improve deduplication efficiency and save data processing time.
[0052] (3) The present invention performs targeted processing based on specific repetitive situations appearing in substation data. The processed data has less redundant data and higher image quality, which is conducive to the subsequent training of deep learning models. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 It is a flowchart of the image deduplication method based on the deep residual network combined with the perceptual hash algorithm described in the present invention.
[0054] Figure 2 It is an execution block diagram of the image deduplication method based on a deep residual network combined with a perceptual hash algorithm described in the present invention.
[0055] Figure 3 It is a structural schematic diagram of the feature extraction network model described in the present invention.
[0056] Figure 4 It is a structural diagram of the coordinated attention mechanism in the feature extraction network model described in the present invention.
[0057] Figure 5 This is the effect diagram of image deduplication using feature extraction network model.
[0058] Figure 6 This is the effect of using the feature extraction network model combined with the perceptual hashing algorithm to deduplicate images. DETAILED DESCRIPTION
[0059] The present disclosure is further described below in conjunction with the accompanying drawings and embodiments.
[0060] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present disclosure. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present disclosure belongs.
[0061] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present disclosure. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0062] In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments may be combined with each other.
[0063] In view of the shortcomings of the prior art, the present invention provides an image deduplication method based on a deep residual network combined with a perceptual hash algorithm. This method combines a deep learning model with a traditional image processing method to solve the problems of poor deduplication robustness of existing traditional deduplication methods, poor deduplication effect for pictures with the same background or slight offset of continuous shots, inability of deep learning methods to remove the same pictures of different scales, and time-consuming training of methods such as twin networks.
[0064] The present invention performs targeted processing based on specific repetitive situations appearing in substation data. The processed data has less redundant data and higher image quality, which is conducive to the subsequent training of deep learning models.
[0065] The following is a further description of the image deduplication method and device based on a deep residual network combined with a perceptual hash algorithm of the present invention in conjunction with specific embodiments.
[0066] Embodiment 1,
[0067] Ginseng Figure 1 This embodiment provides an image deduplication method based on a deep residual network combined with a perceptual hash algorithm, the method comprising:
[0068] S1. Obtain a dataset of images to be deduplicated, wherein the dataset contains M images to be deduplicated, where M is a positive integer.
[0069] Specifically, the image capture equipment installed at the substation site can be used to obtain video frame data from various shooting points. Generally, a site will have as few as a few to as many as hundreds or thousands of shooting points. The data from all the captured points are summarized, and first a manual frame extraction process is performed. Then the original image is extracted and summarized into the same folder as the image to be deduplicated, thus constructing a data set of images to be deduplicated.
[0070] The final constructed image dataset to be deduplicated contains M images to be deduplicated, where M is a positive integer.
[0071] S2. For the first image to be deduplicated, input it into the feature extraction network model to obtain its deep features, and use the perceptual hash algorithm to extract the perceptual hash code of the first image to be deduplicated, and store the deep features and perceptual hash code of the first image to be deduplicated into the feature library.
[0072] In this embodiment, a feature extraction network model is constructed based on a residual network and combined with a coordinated attention mechanism to extract deep features of the image to be deduplicated.
[0073] Specifically, in the process of constructing the feature extraction network model, it is necessary to first build a residual network model to extract the feature information of the image. Considering the feature extraction efficiency and time consumption, it is preferred to use a lightweight residual network ResNet18 to ensure the recognition effect while speeding up the deduplication speed as much as possible. At the same time, a coordinated attention mechanism is introduced, which can effectively obtain the attention information on the width and height of the image and accurately encode the position, thereby enhancing the expression ability of the model. The network structures of the residual network model and the coordinated attention mechanism are as follows: Figure 3 and Figure 4 shown.
[0074] Specifically, the input size of the ResNet18 network model is uniformly set to 224*224*3. After the first layer of 7*7 convolution and 64 convolution kernels, the feature map becomes 64*112*112. After the maximum pooling, the feature map becomes 64*56*56. After four layers of 3*3 convolution and two shortcut connections, the feature map size remains unchanged during this process, still 64*56*56. After another dimensionality reduction shortcut connection, the result is the same as the result after the next two layers of 3*3 convolution, and the feature map size becomes 128*28*28. Here, the dimensionality reduction is the dimensionality reduction in the spatial perspective. After two layers of 3*3 convolution and a shortcut connection, the feature map size remains unchanged in this process, all 128*28*28. Next, the last dimensionality reduction shortcut connection is performed, and the feature map becomes 512*7*7. The CA attention mechanism is added to the next layer of shortcut connection.
[0075] The CA attention mechanism can effectively obtain the attention information on the width and height of the image and accurately encode the position, thereby enhancing the expressiveness of the model. The obtained 512*7*7 feature map is used as input, i is the number of intermediate tensors, H is the height of the image, W is the width of the image, and C is the number of channels to enhance the expressiveness of the output. The process is as follows: ① After obtaining the feature map in the width and height direction, feature concatenation is performed, and then dimensionality reduction is performed; ② After the batch normalization layer and the Sigmoid activation function, the feature map f is obtained; ③ The dimension of the feature map f is restored, and after the Sigmoid activation function, the attention weights on the height H and width W are obtained; ④ After multiplication weighted Re-weight on the image to be deduplicated, the attention mechanism in the width W and height H directions can be realized, and the size of the feature map obtained is still 512*7*7.
[0076] The feature map can then be average-pooled by the ResNet18 network model to obtain its deep feature information.
[0077] Furthermore, the constructed feature extraction network model is trained. First, the model can be pre-trained using the ImageNet public dataset, and then the pre-trained model is fine-tuned using the image dataset to be deduplicated to enhance the model's feature extraction capability and ensure its deduplication effect. The model training process is a conventional technique and will not be described in detail here.
[0078] After training, the residual network model ResNet18 needs to remove the last fully connected layer and set it to evaluation mode.
[0079] After completing the construction and training of the feature extraction network model, the images to be deduplicated in the image dataset are input into the trained feature extraction network model in turn to obtain the deep features of each image to be deduplicated. The obtained deep feature information can be used to subsequently judge the pixel-level similarity between images.
[0080] Since the image depth features obtained using the above feature extraction network model are used to judge the pixel-level similarity between images rather than the similarity in visual features, this also leads to the problem of being unable to remove the same images of different scales, which requires further judgment.
[0081] In this embodiment, the perceptual hash algorithm is combined to determine the similarity of visual features between images, that is, the perceptual hash algorithm is used to extract the perceptual hash code of each image to be deduplicated in the image data set to be deduplicated in turn, and whether the image is a duplicate image is determined by comparing whether the perceptual hash codes between the images are consistent.
[0082] Perceptual hashing reduces the frequency of images through discrete cosine transform (DCT), which is more robust than other hashing algorithms. The discrete cosine transform process of perceptual hashing includes one-dimensional transform and two-dimensional transform, where the one-dimensional DCT transform is:
[0083]
[0084] In formulas (1) and (2), f(i) represents the original signal, that is, the value of the image to be deduplicated in the time domain, corresponding to the coordinate index i in the time domain or space domain. The purpose of DCT transform is to convert the original signal f(i) from the time domain to the frequency domain; F(u) represents the coefficient of the original one-dimensional signal after discrete cosine transform, u represents the frequency component in the one-dimensional DCT transform; N represents the number of original signal points; c(u) represents the compensation coefficient.
[0085] The two-dimensional DCT transform is:
[0086]
[0087] In formulas (3) and (4), u and v represent the frequency components in the two-dimensional DCT transform, F(u, v) represents the transform result of the original two-dimensional signal on different frequency components (u, v); c(u) and c(v) are normalization factors used to ensure the orthogonality of the DCT transform, and the specific values of the normalization factors are related to the frequency components u and v and help control the amplitude of the DCT coefficients; i and j represent the coordinate indexes of the original two-dimensional signal in the time domain or space domain.
[0088] In this embodiment, the steps of extracting the perceptual hash code include: 1) image scaling and grayscale; 2) calculating DCT (discrete cosine transform); 3) retaining low-frequency information and quantizing; 4) calculating the DCT mean; 5) hash calculation, that is, comparing each DCT value with the average value, if the DCT value ≥ the average value, then output 1; if the DCT value < the average value, then output 0. A 64-bit binary data is thus generated, which can be converted into a string of length 16 in groups of 4 characters, that is, the perceptual hash code of the image. This extraction process is a conventional technology and will not be repeated here.
[0089] Based on the above principle, the perceptual hashing algorithm can be used to extract the perceptual hash code of each image to be deduplicated in the image data set to be deduplicated in turn, and the obtained perceptual hash code can be used to subsequently judge the similarity of visual features between images.
[0090] In order to further speed up the deduplication process, a multi-threaded computing method is needed to be used when performing the above feature comparison to speed up the deduplication process.
[0091] In this embodiment, specific reference Figure 2, you can manually set the image batch size to be read at a time and the size of the similarity comparison threshold according to the actual situation of the image dataset to be deduplicated. The larger the image batch size is, the better the image deduplication effect will be, and the higher the requirements for the device hardware will be. The setting of the similarity comparison threshold needs to be based on the actual situation. The threshold range is preferably 0.90 to 1. When it is set to 1, completely duplicate images will be deleted. The lower the threshold, the smaller the similarity.
[0092] Furthermore, the batch size can be set to read 1000 images to be deduplicated at a time. Before inputting these images into the feature extraction network model, the read images to be deduplicated are first preprocessed, that is, the input image size is adjusted to (224, 224, 3) according to the model configuration requirements, and then the preprocessed images are sequentially input into the feature extraction network model for feature extraction.
[0093] For the first image to be deduplicated in the image data set to be deduplicated, it is input into the feature extraction network model to obtain its deep features. At the same time, the perceptual hashing algorithm is used to extract the perceptual hash code of the first image to be deduplicated, and the deep features and perceptual hash code of the first image to be deduplicated are stored in the feature library.
[0094] S3. For the mth image to be deduplicated, where m is a positive integer and 2≤m≤M, input it into the feature extraction network model to obtain its depth features. At the same time, use the perceptual hash algorithm to extract the perceptual hash code of the mth image to be deduplicated, and calculate the similarity between the depth features of the mth image to be deduplicated and the depth features of the first m-1 images to be deduplicated stored in the feature library. Compare the calculated similarity with a preset threshold. If the similarity is greater than the preset threshold, it is determined that the images have similar pixel features. If the similarity is less than the preset threshold, execute step S4.
[0095] In this step, excluding the first image to be deduplicated, the depth features of each subsequent image to be deduplicated will be respectively similarly calculated with the depth features of the image to be deduplicated previously stored in the feature library to determine whether there are similar pixel features.
[0096] For example, for the second image to be deduplicated (m=2), its depth features are extracted through the feature extraction network model, and the similarity between the depth features of the second image to be deduplicated and the depth features of the first image to be deduplicated that has been stored in the feature library is calculated. Then, the calculated similarity is compared with a preset threshold. If the similarity is greater than the preset threshold, it is determined that the two images to be deduplicated have similar pixel features. At this time, the second image to be deduplicated can be directly deleted from the image data set to be deduplicated, and the depth features of the second image to be deduplicated are stored in the feature library.
[0097] By analogy, for the mth image to be deduplicated (2<m≤M), its depth features are extracted through the feature extraction network model, and the similarities between the depth features of the mth image to be deduplicated and the depth features of the first m-1 images to be deduplicated that have been stored in the feature library are calculated respectively, and then the calculated similarities are compared with the preset threshold values respectively. If the similarity is greater than the preset threshold value, it is determined that the two images to be deduplicated have similar pixel features. At this time, the mth image to be deduplicated can be directly deleted from the image data set to be deduplicated, and the depth features of the mth image to be deduplicated are stored in the feature library.
[0098] If the similarity between the calculated depth features of the mth image to be deduplicated and the depth features of the image to be deduplicated previously stored in the feature library is less than a preset threshold, it is determined that there is no similarity in pixel features between the two images to be deduplicated. At this time, step S4 is executed to further determine whether there is similarity in visual features between the two images to be deduplicated.
[0099] Furthermore, in this embodiment, the cosine similarity algorithm can be used to calculate the similarity between the depth features of the two images to be deduplicated. The cosine similarity algorithm measures the difference between two individuals by the cosine value of the angle between two vectors in a vector space. The smaller the angle, the more similar they are, and vice versa. The calculation formula of cosine similarity is as follows:
[0100]
[0101] In formula (5), A and B correspond to the depth feature vector of the mth image to be deduplicated and the depth feature vector of one of the first m-1 images to be deduplicated, respectively, and k∈n represents the dimension of the depth feature vector.
[0102] S4. Compare the perceptual hash code of the mth image to be deduplicated with the perceptual hash codes of the first m-1 images to be deduplicated stored in the feature library. If they are consistent, it is determined that the images have similar visual features.
[0103] Continue to participate Figure 2 In the case where the similarity between the depth features of the mth image to be deduplicated calculated in step S3 and the depth features of the image to be deduplicated previously stored in the feature library is less than a preset threshold, the perceptual hash code is used in this embodiment to further determine whether there is similarity in visual features between the two images to be deduplicated.
[0104] The perceptual hashing algorithm can extract the key features of an image (such as edges, colors, textures, etc.) and convert these features into a shorter binary code or hash value. If the visual features of two images are exactly the same, their perceptual hash codes should also be exactly the same, thus eliminating the problem of the same images at different scales.
[0105] Based on this, in this embodiment, the perceptual hash code of the mth image to be deduplicated can be compared with the perceptual hash codes of the first m-1 images to be deduplicated that have been stored in the feature library. If they are consistent, it is determined that the two images to be deduplicated have similar visual features, that is, the images are repeated. At this time, the current mth image to be deduplicated can be directly deleted, and its hash code is not stored; otherwise, there is no duplication, the current mth image to be deduplicated is stored, and its perceptual hash code is stored in the feature library.
[0106] S5. Perform a deduplication operation on the to-be-deduplicated images in the to-be-deduplicated image data set based on the determination results of the pixel feature similarity and the visual feature similarity.
[0107] That is, the images that are determined to have similar pixel features and similar visual features are duplicate images. When storing images, for the first image to be deduplicated, the image and its depth features and perceptual hash code can be directly stored. For the subsequent m-th image to be deduplicated, if it is determined that it has similar pixel features with one of the previous m-1 images to be deduplicated, the m-th image to be deduplicated is deleted from the image data set to be deduplicated, and the depth features of the m-th image to be deduplicated are stored in the feature library; if it is determined that it has similar visual features with one of the previous m-1 images to be deduplicated, the m-th image to be deduplicated is deleted from the image data set to be deduplicated, and its perceptual hash code is not stored; if it is determined that it has no similar visual features with one of the previous m-1 images to be deduplicated, the m-th image to be deduplicated is stored, and its perceptual hash code is stored in the feature library.
[0108] In this way, the problem that the same target cannot be deduplicated due to slight lens offset or adjustment, or the same image of different scales, can be solved, and the result can be saved as a non-duplicate image. Figure 2 shown.
[0109] Furthermore, to verify the effectiveness of the present method, this embodiment compares the effect of image deduplication using a feature extraction network model and the effect of image deduplication using a feature extraction network model combined with a perceptual hashing algorithm.
[0110] Figure 5 The effect of image deduplication using only deep learning (feature extraction network model) is shown. Deep learning deduplication includes the following steps:
[0111] 1. Define the feature extraction network:
[0112] ① Initialization: When initializing the class, load the ResNet18 pre-trained model with the CA attention mechanism added, and remove its default last fully connected layer so that only features are extracted instead of classification. At the same time, the model is set to evaluation mode.
[0113] ② Preprocessing: Define the image preprocessing process, including resizing the image to 224x224 pixels, converting it to Tensor format, and normalizing the image to ensure that the input data meets the expected format of the ResNet18 model.
[0114] ③ Feature extraction: Read the image, then extract features through the ResNet model. Use the torch.no_grad() context manager to avoid unnecessary gradient calculations, and finally return the feature vector.
[0115] 2. Define auxiliary functions:
[0116] is_duplicate: Determines whether the cosine similarity between the new feature and any feature in the extracted feature list exceeds the threshold (default 0.92). If so, it is considered a duplicate image.
[0117] The deep learning model uses Resnet18 to remove the fully connected layer and combines it with the CA attention mechanism. The relevant parameter settings include the deduplication threshold: set above 0.9, input size: 224*224, and standardization processing: the mean of the RGB channel is usually set to (0.485, 0.456, 0.406), and the standard deviation is set to (0.229, 0.224, 0.225). Using only the deep learning algorithm for deduplication can remove images with slight lens offset through threshold setting, but the deduplication effect for different resolutions of the same image is relatively poor and cannot be completely removed. Therefore, it is necessary to combine traditional image processing methods (i.e., perceptual hashing algorithm) for deduplication.
[0118] Figure 6 The effect of image deduplication combined with the perceptual hash algorithm is shown. The perceptual hash deduplication includes the following steps:
[0119] Hash database storage: Create an empty dictionary to store the mapping between each unique image's hash value and its file name to identify duplicates.
[0120] Traverse and process images: Traverse all files in the specified image folder and display the processing progress. For each file name, try the following operations:
[0121] 1. Open and calculate the hash value: Use the PIL library to open the image file, and then calculate its perceptual hash value through the imagehash.phash() method, which is a hash algorithm that can reflect the visual similarity of images.
[0122] 2. Detect duplicates: Check whether the calculated hash value already exists in the hash value database. If it does, it means that the current image is very similar or identical to a previously processed image, and it is considered a duplicate image and deleted directly.
[0123] Record unique images: If the hash value has not appeared before, store it in hash_dict along with the current file name, marking it as a unique image that has been processed.
[0124] The above method can be used to remove the image with smaller resolution from two images that are exactly the same but have different resolutions.
[0125] In summary, the image deduplication method based on deep residual network combined with perceptual hash algorithm of the present invention performs image deduplication through a pre-built and pre-trained good deduplication model. Considering the feature extraction efficiency and time consumption, a lightweight residual network (ResNet18) is used to ensure the recognition effect while speeding up the deduplication speed as much as possible, and a coordinated attention mechanism is introduced to ensure the deduplication speed while ensuring the deduplication effect.
[0126] The present invention uses a deep learning model and traditional image processing methods to solve the problems of poor deduplication robustness of existing traditional deduplication methods, poor deduplication effect for pictures with the same background or slight offset of consecutive shots, inability of deep learning methods to remove the same pictures of different scales, and time-consuming training of methods such as twin networks.
[0127] Embodiment 2,
[0128] This embodiment provides a device for implementing an image deduplication method based on a deep residual network combined with a perceptual hash algorithm, the device comprising:
[0129] A data acquisition module is used to acquire a data set of images to be deduplicated, wherein the data set of images to be deduplicated includes M images to be deduplicated, where M is a positive integer;
[0130] A feature acquisition module, used to respectively acquire the depth features and the perceptual hash code of the first image to be deduplicated and store them in a feature library, and respectively acquire the depth features and the perceptual hash code of the mth image to be deduplicated, where m is a positive integer and 2≤m≤M;
[0131] The pixel feature judgment module is used to calculate the similarity between the depth feature of the mth image to be deduplicated and the depth feature of the first m-1 images to be deduplicated stored in the feature library, and compare the calculated similarity with a preset threshold. If the similarity is greater than the preset threshold, it is determined that the images have similar pixel features. If the similarity is less than the preset threshold, it enters the visual feature judgment module;
[0132] The visual feature judgment module is used to compare the perceptual hash code of the mth image to be deduplicated with the perceptual hash codes of the first m-1 images to be deduplicated stored in the feature library. If they are consistent, it is determined that the images have similar visual features.
[0133] The image deduplication module is used to perform a deduplication operation on the to-be-deduplicated images in the to-be-deduplicated image data set based on the determination results of the pixel feature similarity and the visual feature similarity.
[0134] Embodiment 3,
[0135] This embodiment also provides an electronic device, including:
[0136] at least one processor; and
[0137] A memory storing instructions, which, when executed by the at least one processor, enables the at least one processor to perform the image deduplication method based on the deep residual network combined with the perceptual hashing algorithm as described above.
[0138] In this embodiment, the electronic device may include, but is not limited to: personal computers, server computers, workstations, desktop computers, laptop computers, notebook computers, mobile computing devices, smart phones, tablet computers, cellular phones, personal digital assistants (PDAs), handheld devices, messaging devices, wearable computing devices, consumer electronic devices, and the like.
[0139] Embodiment 4,
[0140] This embodiment also provides a machine-readable storage medium storing executable instructions, which, when executed, enable the machine to perform the image deduplication method based on a deep residual network combined with a perceptual hash algorithm as described above.
[0141] Specifically, a system or device equipped with a readable storage medium can be provided, on which software program codes that implement the functions of any of the above-mentioned embodiments are stored, and a computer or processor of the system or device can read and execute instructions stored in the readable storage medium.
[0142] In this case, the program code itself read from the machine-readable medium can realize the function of any one of the above embodiments, and thus the machine-readable code and the machine-readable storage medium storing the machine-readable code constitute part of this specification.
[0143] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or a cloud via a communication network.
[0144] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0145] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0146] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0147] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0148] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution of the present invention, and are not intended to limit the specific implementation methods of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention shall be included in the protection scope of the claims of the present invention.
Claims
1. An image deduplication method based on a deep residual network combined with a perceptual hashing algorithm, characterized in that: The method comprises: S1. Obtain a dataset of images to be deduplicated, wherein the dataset contains M images to be deduplicated, where M is a positive integer. S2. For the first image to be deduplicated, input it into the feature extraction network model to obtain its deep features, and use the perceptual hash algorithm to extract the perceptual hash code of the first image to be deduplicated, and store the deep features and perceptual hash code of the first image to be deduplicated into the feature library; S3, for the mth image to be deduplicated, m is a positive integer and 2≤m≤M, input it into the feature extraction network model to obtain its depth feature, and use the perceptual hash algorithm to extract the perceptual hash code of the mth image to be deduplicated, and calculate the similarity between the depth feature of the mth image to be deduplicated and the depth features of the first m-1 images to be deduplicated stored in the feature library, and compare the calculated similarity with a preset threshold. If the similarity is greater than the preset threshold, it is determined that the images have similar pixel features. If the similarity is less than the preset threshold, execute step S4; S4, comparing the perceptual hash code of the mth image to be deduplicated with the perceptual hash codes of the first m-1 images to be deduplicated stored in the feature library, and if they are consistent, determining that the images have similar visual features; S5. Perform a deduplication operation on the to-be-deduplicated images in the to-be-deduplicated image data set based on the determination results of the pixel feature similarity and the visual feature similarity.
2. The image deduplication method based on deep residual network combined with perceptual hashing algorithm according to claim 1 is characterized in that: The method also includes: constructing a feature extraction network model based on a residual network and in combination with a coordinated attention mechanism, wherein the residual network adopts a lightweight ResNet18 network model, which sequentially includes a 7*7 convolutional layer, a maximum pooling layer, multiple 3*3 convolutional layers and an average pooling layer; the coordinated attention mechanism is inserted into the residual network and constructed as a feature extraction network model for extracting deep features of each image to be deduplicated.
3. The image deduplication method based on deep residual network combined with perceptual hash algorithm according to claim 1 is characterized in that: The perceptual hash algorithm includes a one-dimensional discrete cosine transform, which is: In formulas (1) and (2), f(i) represents the original signal, that is, the value of the image to be deduplicated in the time domain, corresponding to the coordinate index i in the time domain or space domain. The discrete cosine transform is used to convert the original signal f(i) from the time domain to the frequency domain; F(u) represents the coefficient of the original one-dimensional signal after discrete cosine transform, u represents the frequency component in the one-dimensional discrete cosine transform; N represents the number of original signal points; c(u) represents the compensation coefficient.
4. The image deduplication method based on deep residual network combined with perceptual hash algorithm according to claim 3 is characterized in that: The perceptual hash algorithm also includes a two-dimensional discrete cosine transform, which is: In formulas (3) and (4), u and v represent the frequency components in the two-dimensional discrete cosine transform, F(u, v) represents the transformation result of the original two-dimensional signal on different frequency components (u, v); c(u) and c(v) are normalization factors, and the specific values of the normalization factors are related to the frequency components u and v; i and j represent the coordinate indexes of the original two-dimensional signal in the time domain or space domain.
5. The image deduplication method based on deep residual network combined with perceptual hash algorithm according to claim 4 is characterized in that: Extracting the perceptual hash code of the image to be deduplicated using the perceptual hash algorithm specifically includes: Based on the perceptual hash algorithm, the corresponding value of each image to be deduplicated after discrete cosine transformation is calculated, and the average value of the corresponding values of all images to be deduplicated after discrete cosine transformation is calculated; Compare the value corresponding to each image to be deduplicated after discrete cosine transform with the average value. If the value corresponding to each image to be deduplicated after discrete cosine transform is greater than or equal to the average value, output 1; if the value corresponding to each image to be deduplicated after discrete cosine transform is less than the average value, output 0, thereby generating a set of binary data; The generated binary data is converted into a string of the set length, which is the perceptual hash code corresponding to each image to be deduplicated.
6. The image deduplication method based on deep residual network combined with perceptual hash algorithm according to claim 1 is characterized in that: In step S3, the cosine similarity algorithm is used to calculate the similarity between the depth feature of the mth image to be deduplicated and the depth features of the first m-1 images to be deduplicated stored in the feature library, that is, In formula (5), A and B correspond to the depth feature vector of the mth image to be deduplicated and the depth feature vector of one of the first m-1 images to be deduplicated, respectively, and k∈n represents the dimension of the depth feature vector.
7. The image deduplication method based on deep residual network combined with perceptual hash algorithm according to claim 1 is characterized in that: In step S5, for the mth image to be deduplicated: If it is determined that the image has similar pixel features to one of the previous m-1 images to be deduplicated, the mth image to be deduplicated is deleted from the image dataset to be deduplicated, and the deep features of the mth image to be deduplicated are stored in the feature library; If it is determined that the image has similar visual features to one of the previous m-1 images to be deduplicated, the mth image to be deduplicated is deleted from the image dataset to be deduplicated, and its perceptual hash code is not stored; If it is determined that there is no visual feature similarity between it and one of the previous m-1 images to be deduplicated, the mth image to be deduplicated is stored, and its perceptual hash code is stored in the feature library.
8. A device for implementing an image deduplication method based on a deep residual network combined with a perceptual hash algorithm, characterized in that: The device comprises: A data acquisition module is used to acquire a data set of images to be deduplicated, wherein the data set of images to be deduplicated includes M images to be deduplicated, where M is a positive integer; A feature acquisition module, used to respectively acquire the depth features and the perceptual hash code of the first image to be deduplicated and store them in a feature library, and respectively acquire the depth features and the perceptual hash code of the mth image to be deduplicated, where m is a positive integer and 2≤m≤M; The pixel feature judgment module is used to calculate the similarity between the depth feature of the mth image to be deduplicated and the depth feature of the first m-1 images to be deduplicated stored in the feature library, and compare the calculated similarity with a preset threshold. If the similarity is greater than the preset threshold, it is determined that the images have similar pixel features. If the similarity is less than the preset threshold, it enters the visual feature judgment module; The visual feature judgment module is used to compare the perceptual hash code of the mth image to be deduplicated with the perceptual hash codes of the first m-1 images to be deduplicated stored in the feature library. If they are consistent, it is determined that the images have similar visual features. The image deduplication module is used to perform a deduplication operation on the to-be-deduplicated images in the to-be-deduplicated image data set based on the determination results of the pixel feature similarity and the visual feature similarity.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and A memory storing instructions, which, when executed by the at least one processor, causes the at least one processor to perform the image deduplication method based on a deep residual network combined with a perceptual hashing algorithm as described in any one of claims 1 to 7.
10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores executable instructions, which, when executed, enable the machine to perform the image deduplication method based on a deep residual network combined with a perceptual hashing algorithm as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Image deduplication method based on residual neural network
CN113568571A
Image content evidence obtaining method based on regional candidate network and Hash coding
CN117422866A
Cited By
Credit material repeated detection method and device based on image fingerprints
CN120876079A
PPT static page detection method and system based on efficient compression and similarity judgment
CN121033460A
Image deduplication method and device, electronic equipment and storage medium
CN121388212A
Feature extraction method and electronic device
TWI940068B
