Real data often follows a long-tailed distribution, with the head class dominating the training and the tail class having only a small number of samples, which is a major challenge in the field of image classification. The existing methods either use manually balanced datasets (such as ImageNet) or develop more robust algorithms to process data, such as class rebalancing strategies and network module improvements.
Although the above methods are effective for long-tailed distribution datasets, they sacrifice the performance of the header class at different levels. To address these limitations, researchers have turned to exploring new network architecture training paradigms. Long-tailed classification models typically include two key parts: feature extractors and classifiers. For each component, there are corresponding methods, either designing better classifiers [
37,
55], or learning reliable representations [
56,
57]. In terms of the new training framework, existing work attempts to divide one stage of training into two stages. For example, the learning process of decoupling training method [
58] is decoupled into representation learning and classifier training. In addition, the Ensemble learning scheme [
52] [
54] first learns multiple experts with different data subsets, and then combines them to deal with the long-tailed distribution image classification problem. However, these methods all use a limited set of predefined labels to train the model, ignoring the availability of semantic feature information in the original label text of the image. After research, it was found that previous work was almost limited to a predetermined approach when dealing with imbalanced datasets, which relied entirely on visual models and completely ignored the semantic features of the original label text rich in the image itself. This may be a promising solution to impose additional supervision on insufficient data sources.
The large-scale visual-language pre-training model provides a new approach for image classification. Through open vocabulary supervision, pre trained visual-language models can learn powerful multimodal representations (input information can be expressed in multiple ways). Utilize semantic similarity between visual input and text input to transform visual recognition into a visual-language matching problem. Comparative visual language models such as CLIP [
59] and ALIGN [
60] provide new ideas for long-tailed classification tasks. The feature extractors of these models integrate image and text modalities, focusing on learning feature matching between different modalities. They have strong robustness, but lack the ability to model complex interactions between images and text.
Due to the significant difference in classification accuracy between majority and minority classes in commonly used long tail classification algorithms, the failure to utilize the semantic features of the original image label text, and the inability of existing contrastive visual-language models to model complex interactions between images and text, this paper proposes an enhanced contrastive visual language long-tailed image classification algorithm (ECVL). The algorithm uses a two-stage training method, designs the Loss function for text and image retrieval respectively, uses enhanced momentum to compare the Loss function to measure the learning degree of samples, and applies random enhancement to the categories with insufficient learning degree to further strengthen the learning of the model for minority samples.
3.2. Contrasting Visual-Language Pre-Training Model
Compare visual language models with a dual encoder architecture, including a language encoder
and a visual encoder
. Given an input image
, use
extracts the visual features of image
using the formula shown in (1). Similarly, use
encodes the input text sequence
as its corresponding text feature, as shown in the formula (2).
After extracting the features of each modality, use two transformation matrices
and
project the original visual and textual features into a shared embedding space, where v and u are d-dimensional normalized vectors, as shown in formula (3).
In the pre-training stage, for text-image pairs in a batch, the training goal is to shorten the distance between the same category and different categories,
for text retrieval,
for image retrieval, where
Indicates that the temperature exceeds the parameter,
represents the number of text image pairs in a batch.
and
as shown in formulas (4) and (5).
By converting the category labels of an image into a text sequence of "A photo of a {Class}", the matching score between the target image and the text sequence of all categories can be obtained. The category with the highest score is selected as the final predicted category. The normalized test image features are represented as
, and the normalized text features are represented as
. Therefore, the category probability of the test image is shown in formula (5.6). Where
represents the probability of class
, and
represents the total number of candidate classes. Finally, the text label with the highest probability will be selected as the prediction result.
3.3. Balanced Linear Adapter
The performance of contrastive visual-language models on the head and tail classes is balanced, while traditional contrastive learning methods such as PaCo [
61] have lower performance on the tail classes due to a lack of training samples. Inspired by the zero-shot classification ability of visual-language comparison models, improvements were made on the basis of CLIP. The training of long tail data is divided into two stages. The first stage fully utilizes existing training data and ensures the performance of most categories, while the second stage focuses on improving the learning ability of a few categories. These two stages aim at the long-tailed and balance training samples respectively, and refine the comparison Loss function.
According to the research results proposed by Gururangan et al. [
62] in Phase I, model pre-training with domain adaptation and task adaptation can greatly improve the performance of the target NLP task. Similarly, this applies equally to image classification tasks. In stage one, pre-training using the contrastive visual-language backbone model on the long-tailed target dataset is also beneficial for learning most class samples, making full use of available training data. Since the input of the model in Phase I is to process image category labels into text sequences, the comparison loss function used in the pre training is formula (4). The parameters of the text encoder and image encoder are updated instantly during training. After stage one training, most classes usually achieve good results, while minority class samples require stage two balance training. The processing process of the stage model is shown in
Figure 2.
Due to the insufficient sample size and limited data for the tail category, direct training on the backbone in Phrase Ⅱ will result in overfitting. Therefore, in this stage, pre training is not conducted on the backbone, but instead, linear adapters and enhancements are used to optimize the visual language representation of a few category samples for momentum contrast loss. As shown in
Figure 3, the processing of the semantic features of the original label text is the same as that of Stage Ⅰ. Assuming the original image feature is
, the weight matrix of the linear adapter is
The offset is
, and the processed image features can be expressed as formula (7).
Among , the residual factor is used to dynamically combine the image features after fine-tuning in the second stage with the original image features in the first stage.
The enhanced momentum comparison loss function is used to measure the learning of the model for samples. Assuming
is the training sample on the long tail dataset,
The comparison loss is expressed as
.
represents the tracking loss value
among
Epochs. Based on this, define the moving average momentum loss, as shown in formula (8).
The
is a hyperparameter that represents the smoothness of the loss. After training
Epochs using the above moving average momentum loss, the set of momentum losses for each sample can be obtained as
, where N is the number of training samples in the dataset. Finally, the definition of momentum loss is normalized as follows, as shown in formula (9):
Among them
represents the average momentum loss of the
Epoch. The range of
normalized values is
, with an average value of 0.5, reflecting the model's level of sample memory. To promote model learning, use
to control the occurrence and intensity of enhancement indicators. The specific approach follows RandAugment [
63], randomly selecting
types of enhancements and using probability
and intensity
apply each enhancement. Assuming that the enhancement set defined by RandAugment is
, where
is the enhancement amount, k enhancements are applied in each step. On this basis, define a memory enhancement function, as shown in formula (10).
Among
sampling from uniformly distributed
.
represent
undergoes the j enhancement with a strength of
. Apply the selected
enhancements in sequence in
. For simplicity, use
to represent
. In this paper, the enhanced momentum loss function is shown in Formula (11).
Where represents , and represents two views of a sample, is a view of other samples. Intuitively, the enhanced momentum contrast Loss function is used to measure the memory of the model for the samples, and adaptively allocate appropriate enhanced strength for the samples with insufficient memory.
In the training process of stage 2, to avoid the model deviating from the head class, a class balance sampling strategy [
8] is still used to construct a balanced training sample set. Assuming there are
classes in the target dataset to form a total of
training samples. The number of training samples for class
is expressed as
. Then use formula (12) to represent
.
Assuming that classes are sorted in descending order, the long- tailed distribution means (< and ). For class balanced sampling, the probability of sampling each data point from class is defined as . In other words, to construct a balanced training sample set, first select a class from candidate objects, and then sample a data point from the selected class. Finally, through stage two, use Fine tune the balanced training data.
3.4. Algorithm Description
Based on the introduction of the ECVL long tail image classification algorithm in the previous text, this section mainly introduces the training process of the long tail image classification algorithm based on enhanced contrastive visual language in two different stages: stage one and stage two, as shown in algorithm 1 and algorithm 2.

Algorithm 1 is the training process for model stage one, which simultaneously trains the visual and language branches of the visual language model. In each Epoch, it is preferred to input images and corresponding category text information; Afterwards, the visual features of the image and the semantic features of the original label text are extracted using formulas (1) and (2), respectively; And then use Perform text retrieval using Perform image retrieval to obtain associated image and text information; Finally, use formula (6) to predict the image category, and evaluate the prediction results using evaluation indicators after the classification is completed.
Algorithm 2 is the training process for model stage 2. The model first balances a few types of samples, and then fine tunes the linear adapter. After fine tuning, it uses the enhanced momentum Loss function described according to formula (11) to evaluate the sample learning situation. For samples with insufficient representation of learning features, RA random enhancement is used. Finally, the features learned in these two stages are dynamically fused and output.