Image contrast clustering method based on sparse representation
By employing a sparse representation-based image contrast clustering method and optimizing it with multiple loss functions, this approach addresses the problem of neglecting semantic information differences in existing technologies, thereby improving clustering accuracy and robustness and achieving better feature representation and clustering results.
Patent Information
- Application Number
- CN202411936197.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2026-02-13
AI Technical Summary
Existing contrastive clustering methods ignore the semantic information differences between samples when extracting low-dimensional spatial feature representations suitable for clustering, resulting in insufficient clustering accuracy and robustness.
An image contrast clustering method based on sparse representation is adopted. Through data augmentation, weight-sharing convolutional neural networks, decoder reconstruction and multiple loss function optimization, positive and negative sample pairs are constructed, reconstruction and contrast loss are calculated, network parameters are updated, and soft labels are generated for cluster assignment.
It significantly improves the robustness and clustering accuracy of the model, can more accurately preserve and recover the semantic information of the input data, and enhances the discriminative ability and clustering effect of features.
Smart Images

Figure CN121527461A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of image clustering methods, specifically relating to an image contrastive clustering method based on sparse representation. Background Technology
[0002] Clustering is an important task in unsupervised learning, aiming to reveal the inherent structure of data by grouping similar samples into categories, thus helping to understand and analyze the distribution and characteristics of the data. Unlike supervised learning, clustering does not rely on label information but classifies samples based on similarity or distance. Clustering algorithms are widely used in many fields, such as automatically classifying documents by topic in information retrieval to improve search efficiency; in medical diagnosis, clustering patient data helps identify potential disease patterns; in social network analysis, clustering can discover user communities and promote targeted marketing; and in image segmentation, clustering helps divide images into different regions based on pixel similarity, applicable to tasks such as object recognition. Clustering has become one of the core technologies in machine learning.
[0003] With the rapid development of image processing, natural language processing, and other fields, deep learning, especially contrastive learning, has made significant progress in data representation learning. In clustering tasks, deep neural networks combined with contrastive learning can automatically extract discriminative features from large amounts of unlabeled data and perform efficient clustering based on these features. Through optimized training on positive and negative sample pairs, these methods can make the feature vectors of samples of the same class more similar and the feature vectors of samples of different classes more separated, thus demonstrating powerful capabilities in clustering tasks. Especially when dealing with large-scale datasets, deep learning methods can effectively avoid the tedious process of manual feature extraction and improve the efficiency and accuracy of clustering.
[0004] Image clustering methods based on contrastive learning have received widespread attention in the field of computer vision in recent years. Contrastive learning extracts more discriminative features by learning the similarities and differences between samples, thereby effectively improving clustering performance. In image clustering tasks, contrastive learning clustering automatically learns more robust and discriminative feature representations by maximizing the similarity between images of the same class while minimizing the distance between images of different classes. Existing contrastive clustering methods are insufficient in extracting low-dimensional spatial feature representations suitable for clustering, failing to fully preserve key information in the original data and ignoring semantic differences between samples. Therefore, how to perform effective low-dimensional feature learning while preserving the original features of the data has become a key problem that urgently needs to be solved to improve the accuracy and robustness of clustering. Summary of the Invention
[0005] The purpose of this invention is to provide an image contrastive clustering method based on sparse representation, which solves the problem that existing contrastive clustering methods ignore the semantic information differences between samples when extracting low-dimensional spatial feature representations suitable for clustering.
[0006] The technical solution adopted in this invention is an image contrast clustering method based on sparse representation, which is implemented according to the following steps:
[0007] Step 1: Preprocess the sample dataset, and then generate two diverse augmented samples through two data augmentation operations;
[0008] Step 2: Input the two enhanced samples generated in Step 1 into a weight-sharing convolutional neural network to extract the embedding features of the samples respectively;
[0009] Step 3: Construct sample pairs and obtain reconstructed samples;
[0010] Step 4: Calculate the reconstruction loss and the dual contrast loss;
[0011] Step 5: Update network parameters and calculate cluster assignments.
[0012] The invention is further characterized by:
[0013] Step 1 is implemented in the following steps:
[0014] Step 1.1: Perform comprehensive preprocessing on the sample dataset, including data cleaning, denoising, and standardization, to ensure data quality, eliminate noise, and make the data comparable on a uniform scale, thereby improving the training efficiency and performance of the model;
[0015] Step 1.2: The preprocessed sample X is augmented twice to generate two diversified augmented samples X. a and X b The enhancement methods include rotation, cropping, and translation, which further increase the diversity of samples and improve the model's generalization ability and robustness.
[0016] Step 2 specifically involves inputting the two augmented samples generated in Step 1 into a shared-weight encoder, which extracts the embedding features of each sample. Since shared weights are used, the feature extraction process for the two samples is the same, which helps to enhance the model's generalization ability to different augmentation perspectives. Through this process, the network can learn more robust and discriminative feature representations, laying the foundation for subsequent contrastive learning and clustering tasks.
[0017] In step 3, positive and negative sample pairs for contrastive learning are constructed, and the extracted features are embedded back into the original data space using a decoder to generate reconstructed samples.
[0018] Step 3 is implemented in the following steps:
[0019] Step 3.1: Treat the data in a mini-batch of samples as a dictionary, and use the enhanced sample features X extracted in Step 2. a The sparse coefficient matrix is solved using the orthogonal matching pursuit algorithm with the data in the sample set. Then, the eigenvector Y' corresponding to the largest coefficient is extracted from the sparse coefficient matrix. The eigenvector Y' and the augmented sample vector X are then compared. a The characteristics that have the highest correlation among them;
[0020] Step 3.2: Combine the feature vector Y' extracted in Step 2 with another enhanced sample feature vector X. b Through two independent fully connected layers and The process yields a high-level feature representation z with discriminative power. a z b and y a y b Then z a With z b As a positive pair, we perform instance-level comparisons to optimize the similarity of similar samples, while also adjusting y a and y b Perform cluster-level comparisons to promote the clustering of samples of the same type in the feature space, thereby improving the clustering effect and the model's recognition ability;
[0021] Step 3.3: Input the feature vector Y and feature vector Y' from Step 2 into the convolutional neural network decoder with shared weights. The decoder converts these features into reconstructed image features X through a reverse mapping process. a' and X b' This effectively preserves key information from the samples, thereby improving the quality of reconstruction.
[0022] In step 4, the reconstruction loss is calculated to measure the difference between the original sample and the reconstructed sample, ensuring that the model can accurately recover the key information of the sample. At the same time, instance-level and cluster-level contrastive losses are calculated to optimize the feature representations of similar samples, making them closer in the embedding space; and to increase the feature distance between samples of different categories, thereby improving the model's discriminative ability.
[0023] Step 4 is implemented in the following steps:
[0024] Step 4.1: Calculate the reconstruction loss, which measures the difference between the original sample and the reconstructed sample. The reconstruction loss evaluates the similarity between the original sample and the sample reconstructed by the decoder in the feature space. The smaller the loss value, the better the model can recover the original information of the sample. The calculation formula is:
[0025]
[0026] Where N is the number of mini-batch samples, and the reconstruction loss of two augmented samples is calculated using mean squared error (MSE).
[0027] Step 4.2: Instance representation loss. Features are associated with the sample set through sparse representation, and the sample feature corresponding to the maximum value is selected from the obtained sparse matrix. This feature is then paired with another enhancement feature to form a positive sample pair. To reduce information loss caused by contrastive loss, it is non-linearly mapped to the probability distribution space as the feature representation of the instance. Cosine similarity is used to evaluate the consistency of the distribution of positive sample pairs, as shown in the following formula:
[0028]
[0029] Where i,j∈[1,N], according to InfoNCE loss, the instance-level loss can be defined as:
[0030]
[0031] Where τ>0 is an instance-level temperature parameter. To identify all pairs in the dataset, an instance-level contrastive loss is calculated on each augmented sample, i.e.:
[0032]
[0033] Step 4.3: Cluster representation loss,
[0034] When the original data is projected onto a subspace with dimension equal to the number of clusters, the i-th element of its feature vector represents the probability that the sample belongs to the i-th cluster. That is, the feature vector corresponds to its cluster assignment probability. The last layer generates soft labels through a Softmax operation, mapping the output features to a probability distribution. The Softmax function transforms the score for each category into a probability value between 0 and 1. These probabilities reflect the relative likelihood of a sample belonging to each category. Assuming the target number of clusters is M, two layers are used. Project the features onto a dimensional space M, denoted as Y∈R. N×M The probability matrix for clustering the original samples within a batch after one enhancement is given, where N is the number of sample data.
[0035] For clarity, we define associating features with the sample set through sparse representation, selecting the sample feature corresponding to the maximum value from the resulting sparse matrix, and then pairing it with another enhanced feature to form a positive cluster pair. The rest are negative cluster pairs. We also use cosine distance to measure the similarity between clusters, as shown in the following formula:
[0036]
[0037] Correspondingly, for i,j∈[1,M], according to InfoNCE loss, the clustering level loss can be defined as:
[0038]
[0039] By traversing all clusters, the final cluster-level contrastive loss is calculated as follows:
[0040]
[0041] in, This represents the entropy value that indicates the probability of cluster assignment after each data augmentation. This entropy helps to prevent most samples from being simply assigned to the same cluster.
[0042] In step 5, by minimizing the total loss, the gradient is calculated and the network parameters are updated using the backpropagation algorithm. After optimization, the feature representation of each sample is obtained through the trained network, and soft labels are generated through fully connected layers. The soft labels represent the probability distribution of each sample belonging to each category. Finally, the category is assigned according to the maximum probability, thereby obtaining the predicted category of the sample.
[0043] Step 5 is implemented in the following steps:
[0044] Step 5.1: By minimizing the total loss function, the backpropagation algorithm is used to calculate the gradient and update the network parameters. The backpropagation process gradually adjusts the network parameters by passing the error from the output layer back to each layer to optimize the model performance.
[0045] Step 5.2: After optimizing the network parameters, obtain the feature representation U' of the samples through the trained network, and then pass these features through... The process generates soft labels, which represent the probability distribution of each sample belonging to each category. The category with the highest probability is the predicted category of that sample.
[0046] The beneficial effects of this invention are
[0047] 1) This invention, based on a sparse representation-based image contrastive clustering method, introduces a decoder and a reconstruction loss function, which not only enhances the model's robustness in handling complex tasks but also significantly improves its ability to discriminate sample features. By integrating the reconstruction loss function into the training process, the model can more accurately preserve and recover the semantic information of the input data, thereby ensuring that the core structure of the data is maintained during feature extraction. This effectively improves the model's generative ability, enhances its understanding and representation of input samples, and further optimizes the overall performance of the model.
[0048] 2) This invention treats the data in a mini-batch of samples as a dictionary and uses the Orthogonal Matching Pursuit (OMP) algorithm to calculate the sparse coefficient matrix between the features of one augmented sample and the data in the sample set. Then, it extracts the feature vector corresponding to the largest coefficient from the sparse coefficient matrix, thereby finding the closest sample in the support set for each sample and pairing it with the features of another augmented sample. This method effectively improves the expressive power of the neural network, enhances the model's discriminative power among diverse samples, and thus improves the accuracy of feature learning and clustering. Attached Figure Description
[0049] Figure 1 This is a flowchart illustrating the image contrast clustering method based on sparse representation of the present invention.
[0050] Figure 2 This is a model diagram of the image contrast clustering method based on sparse representation of the present invention. Detailed Implementation
[0051] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.
[0052] Example 1
[0053] This invention provides an image contrastive clustering method based on sparse representation, such as... Figure 1-2 As shown, please follow these steps:
[0054] Step 1, Sample Data Preprocessing and Augmentation
[0055] The sample dataset is preprocessed, and then two diverse augmented samples are generated through two data augmentation processes.
[0056] Step 2: Feature extraction using a convolutional neural network
[0057] The two enhanced samples generated in step 1 are input into a weight-shared convolutional neural network to extract the embedding features of the samples respectively.
[0058] Step 3: Construct sample pairs and obtain reconstructed samples;
[0059] Construct positive and negative sample pairs for contrastive learning, and use the decoder to embed the extracted features back into the original data space to generate reconstructed samples. In this way, the model can learn how to recover the original samples from the feature space.
[0060] Step 4: Calculate the reconstruction loss and the dual contrast loss;
[0061] Step 5: Update network parameters and calculate cluster assignments.
[0062] Example 2
[0063] The image contrastive clustering method based on sparse representation, wherein step 1 is specifically implemented according to the following steps:
[0064] Step 1.1: Perform comprehensive preprocessing on the sample dataset, including data cleaning, denoising, and standardization, to ensure data quality, eliminate noise, and make the data comparable on a uniform scale, thereby improving the training efficiency and performance of the model;
[0065] Data cleaning corrects missing values, outliers, and other invalid data, ensuring the integrity and accuracy of the dataset. Denoising removes random noise from the data using filtering or other methods, making the data smoother and preventing noise from interfering with model training. Preprocessed data is more suitable for subsequent model training, improving training efficiency and performance, and reducing training difficulties caused by data inconsistencies or noise. Preprocessed datasets better reflect the true relationships between samples, helping the model learn more effective feature representations.
[0066] Step 1.2: The preprocessed sample X is augmented twice to generate two diversified augmented samples X. a and X b The enhancement methods include rotation, cropping, and translation, which further increase the diversity of samples and improve the model's generalization ability and robustness.
[0067] Data augmentation employs basic transformation operations such as rotation, cropping, and translation. These operations not only alter the geometry of the samples but also simulate different perspectives and scene changes, effectively increasing sample diversity. In this way, the samples become spatially richer, helping the model adapt to different input patterns and improving its robustness and generalization ability. Furthermore, data augmentation can expand the size of the training set, mitigating overfitting, especially when the dataset is small. By introducing augmented samples from different angles, the model can learn more diverse features, thus better handling complex changes and unknown scenarios in real-world applications, improving model stability and performance.
[0068] Example 3
[0069] The image contrastive clustering method based on sparse representation involves step 2, where the two augmented samples generated in step 1 are input into a shared-weight encoder to extract the embedding features of each sample. Because shared weights are used, the feature extraction process for both samples is identical, ensuring the network learns consistent feature representations across different viewpoints or augmentation transformations. This shared-weight approach not only reduces the number of model parameters but also enhances the model's adaptability to data diversity and augmentation viewpoints, improving generalization ability. Through this process, the network generates more robust and discriminative feature representations, laying a solid foundation for subsequent contrastive learning and clustering tasks, thereby effectively improving the model's learning performance and accuracy.
[0070] Example 4
[0071] The image contrastive clustering method based on sparse representation, wherein step 3 is specifically implemented according to the following steps:
[0072] Step 3.1: Treat the data in a mini-batch of samples as a dictionary, and use the enhanced sample features X extracted in Step 2. a The sparse coefficient matrix is solved using the Orthogonal Matching Pursuit (OMP) algorithm with the data in the sample set. Then, the eigenvector Y' corresponding to the largest coefficient is extracted from the sparse coefficient matrix. The eigenvector Y' and the augmented sample vector X are then compared. a The characteristics that have the highest correlation among them;
[0073] Step 3.2: Combine the feature vector Y' extracted in Step 2 with another enhanced sample feature vector X. b Through two independent fully connected layers and The process yields a high-level feature representation z with discriminative power. a z b and y a y b Then z a With z b As a positive pair, we perform instance-level comparisons to optimize the similarity of similar samples, while also adjusting y a and y b Perform cluster-level comparisons to promote the clustering of samples of the same type in the feature space, thereby improving the clustering effect and the model's recognition ability;
[0074] Step 3.3: Input the feature vector Y and feature vector Y' from Step 2 into the convolutional neural network decoder with shared weights. The decoder converts these features into reconstructed image features X through a reverse mapping process. a' and X b' This effectively preserves key information from the samples, thereby improving the quality of reconstruction.
[0075] Step 3 consists of two parts: constructing sample pairs and obtaining reconstructed samples.
[0076] First, treat a small batch of sample data as a dictionary, and then use the Orthogonal Matching Pursuit (OMP) algorithm to enhance the sample features X extracted in step 2. a The sparse coefficient matrix is solved by matching it with data in the sample set. Then, the eigenvector Y' corresponding to the largest coefficient is extracted from the sparse coefficient matrix. The eigenvector Y' is then compared with the augmented sample vector X. a The samples exhibit the highest correlation, reflecting their similarity in the feature space. This process accurately captures the potential relationship between the enhanced and original samples, providing high-quality features for subsequent pairing construction.
[0077] Then, the feature vector Y' extracted in step 2 is compared with the feature vector X of another enhanced sample. b Through two independent fully connected layers and The process yields a higher-level feature representation z with greater discriminative power. a z b and y a y b Then, z a With z b As a positive pair, instance-level comparison is performed to optimize the similarity of similar samples in the embedding space, ensuring that the features of similar samples are more closely related; at the same time, y a With y b Cluster-level comparisons are performed to encourage samples of the same category to cluster together in the feature space, enhancing clustering performance and improving the model's discriminative ability. In this way, the model can effectively learn more discriminative feature representations, further improving the accuracy of clustering and classification.
[0078] The feature vectors Y and Y' from step 2 are simultaneously input into the convolutional neural network decoder with shared weights. The decoder transforms these features into reconstructed image features X through an inverse mapping process. a' and X b' This effectively restores the semantic information of the image, ensuring that the key features of the sample are fully preserved. Through the reconstruction process, the model can improve the expressive power of the features, ensuring that the learned features not only have high discriminative power but also accurately reconstruct the input data, thereby improving the overall performance and robustness of the model.
[0079] Example 5
[0080] In the image contrastive clustering method based on sparse representation, step 4 calculates the reconstruction loss to measure the difference between the original sample and the reconstructed sample, ensuring that the model can accurately recover the key information of the sample. Simultaneously, instance-level and cluster-level contrastive losses are calculated to optimize the feature representations of similar samples, making them closer in the embedding space; at the same time, the feature distance between samples of different categories is increased, thereby improving the model's discriminative ability.
[0081] Step 4 is implemented in the following steps:
[0082] Step 4.1: Calculate the reconstruction loss, which measures the difference between the original sample and the reconstructed sample. The reconstruction loss evaluates the similarity between the original sample and the sample reconstructed by the decoder in the feature space. The smaller the loss value, the better the model can recover the original information of the sample. The calculation formula is:
[0083]
[0084] Where N is the number of mini-batch samples, and the reconstruction loss of two augmented samples is calculated using mean squared error (MSE).
[0085] Step 4.2: Instance representation loss. Features are associated with the sample set through sparse representation, and the sample feature corresponding to the maximum value is selected from the obtained sparse matrix. This feature is then paired with another enhancement feature to form a positive sample pair. To reduce information loss caused by contrastive loss, it is non-linearly mapped to the probability distribution space as the feature representation of the instance. Cosine similarity is used to evaluate the consistency of the distribution of positive sample pairs, as shown in the following formula:
[0086]
[0087] Where i,j∈[1,N], according to InfoNCE loss, the instance-level loss can be defined as:
[0088]
[0089] Where τ>0 is an instance-level temperature parameter. To identify all pairs in the dataset, an instance-level contrastive loss is calculated on each augmented sample, i.e.:
[0090]
[0091] Step 4.3: Cluster representation loss,
[0092] When the original data is projected onto a subspace with dimension equal to the number of clusters, the i-th element of its feature vector represents the probability that the sample belongs to the i-th cluster. That is, the feature vector corresponds to its cluster assignment probability. The last layer generates soft labels through a Softmax operation, mapping the output features to a probability distribution. The Softmax function transforms the score for each category into a probability value between 0 and 1. These probabilities reflect the relative likelihood of a sample belonging to each category. Assuming the target number of clusters is M, two layers are used. Project the features onto a dimensional space M, denoted as Y∈R. N×M The probability matrix for clustering the original samples within a batch after one enhancement is given, where N is the number of sample data.
[0093] For clarity, we define associating features with the sample set through sparse representation, selecting the sample feature corresponding to the maximum value from the resulting sparse matrix, and then pairing it with another enhanced feature to form a positive cluster pair. The rest are negative cluster pairs. We also use cosine distance to measure the similarity between clusters, as shown in the following formula:
[0094]
[0095] Correspondingly, for i,j∈[1,M], according to InfoNCE loss, the clustering level loss can be defined as:
[0096]
[0097] By traversing all clusters, the final cluster-level contrastive loss is calculated as follows:
[0098]
[0099] in, This represents the entropy value that indicates the probability of cluster assignment after each data augmentation. This entropy helps to prevent most samples from being simply assigned to the same cluster.
[0100] Step 4 consists of two parts: calculating the reconstruction loss and the dual contrast loss.
[0101] Reconstruction loss: This measures the difference between the original sample and the reconstructed sample. It assesses the similarity in feature space by comparing the original sample and the sample reconstructed by the decoder. A smaller loss value indicates that the model can more accurately recover the original information of the sample. Mean squared error (MSE) is used to calculate the reconstruction loss between two augmented samples, further enhancing the model's robustness and ability to recover sample details.
[0102] Instance-level representation loss: Features are associated with data in the sample set through sparse representation, and the feature vector corresponding to the largest coefficient is selected from the resulting sparse matrix. This feature is then paired with a feature from another augmented sample to form a positive sample pair. To reduce information loss caused by contrastive loss, the features output by the neural network are not used directly, but rather transformed into feature representations in the probability distribution space through a nonlinear mapping. This mapping better represents the position of the sample in the high-dimensional space. To evaluate the distributional consistency between positive sample pairs, this invention uses a cosine similarity metric.
[0103] Cluster-level representation loss: When the original data is projected to a subspace with a dimension equal to the number of clusters, each element of the feature vector represents the probability that the sample belongs to a specific cluster. Fully connected layers map the output features onto a probability distribution, thus generating soft labels. The Softmax function transforms the score for each class into a probability value between 0 and 1, reflecting the relative likelihood of a sample belonging to each class. Assuming the target number of clusters is M, similar to instance-level comparison, two fully connected layers are used to project the features into an M-dimensional space, obtaining the probability matrix of sample allocation in the cluster space.
[0104] To further improve clustering performance, a method is defined that associates features with the sample set through sparse representation. The feature corresponding to the sample with the largest coefficient is extracted from the sparse matrix and then paired with the feature of another enhanced sample to form a positive cluster pair; the rest are negative cluster pairs. In this way, positive cluster pairs have higher similarity, while negative cluster pairs are relatively more distant. To measure the similarity between clusters, a cosine distance metric is used, and the InfoNCE loss is used to calculate the cluster-level loss. Furthermore, an entropy term for cluster assignment probabilities is introduced to avoid simply assigning most samples to the same cluster. This entropy term helps maintain the diversity of the clustering process, ensuring a more uniform distribution of samples in each cluster, thereby improving the clustering performance and the model's generalization ability.
[0105] Example 6
[0106] In the image contrast clustering method based on sparse representation, step 5 involves minimizing the total loss, calculating the gradient using the backpropagation algorithm, updating the network parameters, optimizing the network, obtaining the feature representation of each sample through the trained network, and generating soft labels through fully connected layers. The soft labels represent the probability distribution of each sample belonging to each category. Finally, the category is assigned according to the maximum probability to obtain the predicted category of the sample.
[0107] Step 5 is implemented in the following steps:
[0108] Step 5.1: By minimizing the total loss function, the backpropagation algorithm is used to calculate the gradient and update the network parameters. The backpropagation process gradually adjusts the network parameters by passing the error from the output layer back to each layer to optimize the model performance.
[0109] Step 5.2: After optimizing the network parameters, obtain the feature representation U' of the samples through the trained network, and then pass these features through... The process generates soft labels, which represent the probability distribution of each sample belonging to each category. The category with the highest probability is the predicted category of that sample.
[0110] Step 5 consists of two parts: updating network parameters and calculating cluster assignments.
[0111] First, by minimizing the total loss function, the gradient is calculated using the backpropagation algorithm to update the network parameters. Next, after optimizing the network parameters, the feature representations of the samples are obtained through the trained network. Finally, through... The fully connected layer converts these features into soft labels. The generated soft labels represent the probability distribution of each sample belonging to each class. The Softmax function outputs the probability of the sample in each class based on the score of each class, and the class corresponding to the highest probability is the predicted class of the sample.
[0112] This invention presents an image contrastive clustering method based on sparse representation. It utilizes data augmentation to construct positive and negative pairs for instance-level and cluster-level contrastive learning. By jointly optimizing the reconstruction loss of the autoencoder and the constraints of sparse representation, the model retains more original sample features, obtains richer semantic information, and further improves the clustering quality.
Claims
1. An image contrastive clustering method based on sparse representation, characterized in that, The specific steps are as follows: Step 1: Preprocess the sample dataset, and then generate two diverse augmented samples through two data augmentation operations; Step 2: Input the two enhanced samples generated in Step 1 into a weight-sharing convolutional neural network to extract the embedding features of the samples respectively; Step 3: Construct sample pairs and obtain reconstructed samples; Step 4: Calculate the reconstruction loss and the dual contrast loss; Step 5: Update network parameters and calculate cluster assignments.
2. The image contrast clustering method based on sparse representation according to claim 1, characterized in that, Step 1 is implemented in the following steps: Step 1.1: Perform comprehensive preprocessing on the sample dataset, including data cleaning, denoising, and standardization, to ensure data quality, eliminate noise, and make the data comparable on a uniform scale, thereby improving the training efficiency and performance of the model; Step 1.2: The preprocessed sample X is augmented twice to generate two diversified augmented samples X. a and X b The enhancement methods include rotation, cropping, and translation, which further increase the diversity of samples and improve the model's generalization ability and robustness.
3. The image contrast clustering method based on sparse representation according to claim 1, characterized in that, Step 2 specifically involves inputting the two augmented samples generated in step 1 into a shared-weight encoder, which extracts the embedding features of each sample. Since shared weights are used, the feature extraction process for the two samples is the same, which helps to enhance the model's generalization ability to different augmentation perspectives. Through this process, the network can learn more robust and discriminative feature representations, laying the foundation for subsequent comparative learning and clustering tasks.
4. The image contrast clustering method based on sparse representation according to claim 1, characterized in that, In step 3, positive and negative sample pairs for contrastive learning are constructed, and the extracted features are embedded back into the original data space using a decoder to generate reconstructed samples.
5. The image contrast clustering method based on sparse representation according to claim 4, characterized in that, Step 3 is implemented in the following steps: Step 3.1: Treat the data in a small batch of samples as a dictionary, and solve the sparse coefficient matrix by using the orthogonal matching pursuit algorithm with the enhanced sample feature Xa extracted in Step 2 and the data in the sample set. Then extract the feature vector Y' corresponding to the largest coefficient from the sparse coefficient matrix. The feature vector Y' has the highest correlation with the enhanced sample vector Xa. Step 3.2: Combine the feature vector Y' extracted in Step 2 with another enhanced sample feature vector X. b Through two independent fully connected layers and The process yields a high-level feature representation z with discriminative power. a z b and y a y b Then z a With z b As a positive pair, we perform instance-level comparisons to optimize the similarity of similar samples, while also adjusting y a and y b Perform cluster-level comparisons to promote the clustering of samples of the same type in the feature space, thereby improving the clustering effect and the model's recognition ability; Step 3.3: Input the feature vector Y and feature vector Y' from step 2 into the convolutional neural network decoder with shared weights. The decoder converts these features into image reconstruction features Xa' and Xb' through a reverse mapping process, effectively preserving the key information of the sample and thus improving the reconstruction quality.
6. The image contrast clustering method based on sparse representation according to claim 1, characterized in that, In step 4, the reconstruction loss is calculated to measure the difference between the original sample and the reconstructed sample, ensuring that the model can accurately recover the key information of the sample. At the same time, the instance-level and cluster-level contrastive losses are calculated to optimize the feature representation of similar samples, making them closer in the embedding space. Meanwhile, the feature distance between samples of different categories is increased, thereby improving the model's discriminative ability.
7. The image contrast clustering method based on sparse representation according to claim 6, characterized in that, Step 4 is implemented in the following steps: Step 4.1: Calculate the reconstruction loss, which measures the difference between the original sample and the reconstructed sample. The reconstruction loss evaluates the similarity between the original sample and the sample reconstructed by the decoder in the feature space. The smaller the loss value, the better the model can recover the original information of the sample. The calculation formula is: Where N is the number of mini-batch samples, and the reconstruction loss of two augmented samples is calculated using mean squared error (MSE); Step 4.2: Instance representation loss. Features are associated with the sample set through sparse representation, and the sample feature corresponding to the maximum value is selected from the obtained sparse matrix. This feature is then paired with another enhancement feature to form a positive sample pair. To reduce information loss caused by contrastive loss, it is non-linearly mapped to the probability distribution space as the feature representation of the instance. Cosine similarity is used to evaluate the consistency of the distribution of positive sample pairs, as shown in the following formula: Where i,j∈[1,N], according to InfoNCE loss, the instance-level loss can be defined as: Where τ>0 is an instance-level temperature parameter. To identify all pairs in the dataset, an instance-level contrastive loss is calculated on each augmented sample, i.e.: Step 4.3: Clustering Representation Loss. When the original data is projected onto a subspace with dimension equal to the number of clusters, the i-th element of its feature vector represents the probability that the sample belongs to the i-th cluster. That is, the feature vector corresponds to its cluster assignment probability. The last layer generates soft labels through the Softmax operation, mapping the output features onto the probability distribution. The Softmax function transforms the score of each category into a probability value between 0 and 1. These probabilities reflect the relative likelihood of a sample belonging to each category. Assuming the target number of clusters is M, two layers are used. Project the features onto a dimensional space M, denoted as Y∈R. N×M The probability matrix for clustering the original samples within a batch after one enhancement is given, where N is the number of sample data. For clarity, we define associating features with the sample set through sparse representation, selecting the sample feature corresponding to the maximum value from the resulting sparse matrix, and then pairing it with another enhanced feature to form a positive cluster pair. The rest are negative cluster pairs. We also use cosine distance to measure the similarity between clusters, as shown in the following formula: Correspondingly, for i,j∈[1,M], according to InfoNCE loss, the clustering level loss can be defined as: By traversing all clusters, the final cluster-level contrastive loss is calculated as follows: in, This represents the entropy value that indicates the probability of cluster assignment after each data augmentation. This entropy helps to prevent most samples from being simply assigned to the same cluster.
8. The image contrast clustering method based on sparse representation according to claim 1, characterized in that, In step 5, by minimizing the total loss, the gradient is calculated and the network parameters are updated using the backpropagation algorithm. After optimization, the feature representation of each sample is obtained through the trained network, and soft labels are generated through fully connected layers. The soft labels represent the probability distribution of each sample belonging to each category. Finally, the category is assigned according to the maximum probability, thereby obtaining the predicted category of the sample.
9. The image contrast clustering method based on sparse representation according to claim 8, characterized in that, Step 5 is implemented in the following steps: Step 5.1: By minimizing the total loss function, the backpropagation algorithm is used to calculate the gradient and update the network parameters. The backpropagation process gradually adjusts the network parameters by passing the error from the output layer back to each layer to optimize the model performance. Step 5.2: After optimizing the network parameters, obtain the feature representation U' of the samples through the trained network, and then pass these features through... The process generates soft labels, which represent the probability distribution of each sample belonging to each category. The category with the highest probability is the predicted category of that sample.