scieee AI-readable full text Open interactive document viewer

Exploring multi-subset learning techniques for fine-grained food image classification

Villacorta Benito, Pablo

Abstract

Fine-grained image recognition (FGIR) is a fundamental and challenging problem within the field of computer vision that involves analyzing visual objects from subordinate categories, such as bird species or car models. The applications of FGIR are plentiful in both industry and research, ranging from automatic biodiversity monitoring to intelligent transportation. Recent advances in deep learning have paved the way for significant progress in this field. A recently proposed method is FGFR, a food-centered fine-grained recognition method that leverages a multitask architecture in which different heads or tasks specialize in discriminating between classes of automatically detected subsets of hard-to-distinguish classes. In this work, we provide an in-depth analysis of the behavior of FGFR and propose an improved version, FGFR+, which builds on top of the limitations we identify from our study of the original method. While we prove that FGFR is capable of generalizing to other non-food domains and different types of backbone architectures, we also observe that the method is not taking full advantage of its specialized multi-head structure. We find that, by implementing a series of conceptually simple modifications, the performance of the method can be significantly boosted, capitalizing on the fine-grained knowledge provided by the heads. FGFR+ achieves 94.2% top-1 validation accuracy on the Food-101 dataset, virtually ranking third in its corresponding benchmark. Being compatible with a wide range of deep learning computer vision backbone architectures, FGFR+ could have the potential of boosting the performance of many computer vision classification tasks.

Full text

Master’s Thesis Master in Artificial Intelligence Facultat d’Informàtica de Barcelona (FIB) Facultat de Matemàtiques (UB) Escola Tècnica Superior d’Enginyeria (URV) Exploring Multi-Subset Learning Techniques for Fine-Grained Food Image Classification Author: Pablo Villacorta Benito Advisor: Dr. Petia Radeva Dept. Matemàtiques i Informàtica (UB) Co-advisor: Javier Ródenas Cumplido Date of defense: January 25, 2023 Abstract Fine-grained image recognition (FGIR) is a fundamental and challenging problem within the field of computer vision that involves analyzing visual objects from subordinate categories, such as bird species or car models. The applications of FGIR are plentiful in both industry and research, ranging from automatic biodiversity monitoring to intelligent transportation. Recent advances in deep learning have paved the way for significant progress in this field. A recently proposed method is FGFR [51], a food-centered fine-grained recognition method that leverages a multitask architecture in which different heads or tasks specialize in discriminating between classes of automatically detected subsets of hard-to-distinguish classes. In this work, we provide an in-depth analysis of the behavior of FGFR and propose an improved version, FGFR+, which builds on top of the limitations we identify from our study of the original method. While we prove that FGFR is capable of generalizing to other non-food domains and different types of backbone architectures, we also observe that the method is not taking full advantage of its specialized multi-head structure. We find that, by implementing a series of conceptually simple modifications, the performance of the method can be significantly boosted, capitalizing on the finegrained knowledge provided by the heads. FGFR+ achieves 94.2% top-1 validation accuracy on the Food-101 dataset, virtually ranking third in its corresponding benchmark. Being compatible with a wide range of deep learning computer vision backbone architectures, FGFR+ could have the potential of boosting the performance of many computer vision classification tasks. Keywords Fine-grained recognition, subsets of classes, multi-task learning iii Contents 1 Introduction 1 1.1 Objectives......................................... 2 1.2 Contributions....................................... 2 1.3 DocumentStructure ................................... 3 2 State of the Art 5 2.1 Fine-Grained Image Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.1 Fine-Grained Image Recognition Based on Subset Learning . . . . . . . . . 7 2.2 Multi-TaskLearning ................................... 8 3 Methodology 11 3.1 TheOriginalFGFRMethod............................... 11 3.1.1 Step 1: Baseline Training and Multi-Subsets Extraction . . . . . . . . . . . 12 3.1.2 Step 2: Specialization Step . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.1.3 Step 3: Aggregation Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.2 Baseline Model Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.3 Multi-Task Learning Loss Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.3.1 LossWeighting.................................. 16 3.4 Self-Attention....................................... 17 3.5 FocalLoss......................................... 18 4 Proposed Method: FGFR+ 21 4.1 TheFGFR+Method................................... 21 4.1.1 Our Proposal for the Aggregation Step . . . . . . . . . . . . . . . . . . . . . 22 4.1.2 Our Proposal for the Specialization Step . . . . . . . . . . . . . . . . . . . . 23 5 Evaluation 25 5.1 Datasets and Experimental Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.1.1 Datasets...................................... 25 5.1.2 FrameworkandTools .............................. 27 5.1.3 BaselineModels ................................. 27 5.1.4 Training Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5.1.5 DataAugmentation ............................... 30 5.2 Exploring the Original FGFR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.2.1 Study of the Classes Subset Extraction . . . . . . . . . . . . . . . . . . . . 30 v 5.2.2 Study of the Specialization Step . . . . . . . . . . . . . . . . . . . . . . . . 32 5.2.3 Study of the Aggregation Step . . . . . . . . . . . . . . . . . . . . . . . . . 35 5.2.4 Limitations of the Original FGFR . . . . . . . . . . . . . . . . . . . . . . . 40 5.3 ResultsofFGFR+ .................................... 40 5.3.1 Comparison with Other Methods . . . . . . . . . . . . . . . . . . . . . . . . 41 5.4 AnalysisofFGFR+ ................................... 42 5.4.1 Effect of Combining Head Embeddings for the Aggregation Step . . . . . . 42 5.4.2 Effect of Self-Attention in the Aggregation Step . . . . . . . . . . . . . . . . 46 5.4.3 Effect of Multi-Task Loss Functions for the Specialization Step . . . . . . . 53 5.4.4 Exploring Other Loss Functions . . . . . . . . . . . . . . . . . . . . . . . . . 55 5.4.5 LimitationsofFGFR+.............................. 56 6 Conclusions and Future Work 57 6.1 FutureWork ....................................... 58 vi MASTER’S THESIS Chapter 1 Introduction Fine-grained image recognition constitutes a fundamental problem within the field of computer vision. Recent breakthroughs in computer-based image analysis have demonstrated that machines can outperform human capabilities on tasks that rely on visual data, especially when dealing with coarse-grained objects. However, addressing fine-grained visual objects still remains a difficult problem. While the average human might effortlessly notice that a bronzed cowbird can be distinguished form a shiny cowbird by the color of its eyes, teaching machines to locate and emphasize on such specific discriminative regions of an image still remains an open challenge. As a consequence, significant progress has been done in recent years in the field of fine-grained image recognition, in an attempt of improving machines’ capabilities to differentiate between hard- to-distinguish classes. Different strategies have been proposed to tackle this problem, such as using a two-step method that first localizes the informative regions and then makes a prediction based on them. Other modern approaches try to learn how to effectively encode the important discriminative information into image features. A particularly challenging domain within the field of fine-grained image analysis, and computer vision in general, is food. Food dishes are inherently unstructured objects that can present large intra-class variations which can make a single type of dish have many different visual appearances. Another common, well-known issue is the difficulty of properly annotating food images, as a single dish may belong to many different classes (different ingredients) and some ingredients may present a hierarchical structure (having classes such as spaghetti and pasta) that may not always be reflected in the annotations. In this work, we focus on a recently published method for Fine-Grained Food Recognition (FGFR) that was proposed in [51]. This work introduces a novel multi-step approach for performing finegrained food image classification, leveraging a multi-task architecture. FGFR is capable of automatically identifying subsets of classes that are hard to distinguish, and builds a multi-head model where each head specializes in discriminating between the classes within its corresponding subset. Using this approach, the authors of [51] managed to outperform multiple state-of-the-art approaches for different fine-grained food datasets. 1 1. INTRODUCTION The method, however, was introduced as a preliminar approach that was only evaluated on a limited set of datasets, all of them belonging to the food domain. Thus, in this work, we aim at both evaluating the generalization ability of FGFR to different visual domains and model architectures, as well as providing a more insightful understanding of its behavior. Based on our analysis, we also identify potential areas of improvement for the original method, and we propose a series of upgrades based on them, introducing the method which we refer to as FGFR+. We evaluate the extended method against the original one, and demonstrate its superiority in a variety of domains, achieving a performance that is competitive with current state-of-the-art approaches for at least one of our evaluation datasets. 1.1 Objectives The primary objectives of our project can be outlined as follows: •Objective 1: perform an extensive study of the original FGFR, analyzing each of its steps individually and assessing its ability to generalize to different domains and model architectures. •Objective 2: based on the analysis of the original method, identify potential limitations or areas of improvement and propose modifications that alleviate them. •Objective 3: provide a detailed analysis of the behavior of each of the proposed modifications to determine their contribution to the performance of the method. 1.2 Contributions The contributions of our work are summarized as follows: 1. We demonstrate that the original FGFR is capable of generalizing to different domains (i.e., birds, cars and food), as well as to different backbone architectures (i.e., EfficientNet [55] and CSWin Transformer [13]). 2. We provide an in-depth analysis of the behavior of the original FGFR, carefully evaluating the results obtained after each of its steps and identifying potential areas of improvement. 3. We propose a series of improvement proposals based on our study of the original method, under the name of FGFR+, which allow to fully unlock the potential of the multi-head model. 4. We show the ineffectiveness of integrating some seemingly reasonable approaches into the FGFR method, namely the use of self-attention as a way of combining the multi-head outputs. 5. We demonstrate that FGFR+ consistently outperforms the original FGFR in a variety of dataset domains and backbone architectures. Our proposed method managed to achieve a top-1 validation accuracy of 94.2% for the Food-101 dataset [6], which, to our best knowledge, would rank in third place for the Food-101 fine-grained image classification benchmark, among those methods that do not use additional training data. 2 MASTER’S THESIS 1.3 Document Structure This document is organized in the following way. Chapter 2 provides an overview of the most relevant related work to our project within the fields of fine-grained image recognition and multitask learning. Chapter 3 describes in more detail both the original FGFR, as well as some other complementary techniques that were used throughout the development of our work. Our proposal for FGFR+ is introduced in Chapter 4. Chapter 5 reports the evaluation process and results of both the original and the FGFR+ methods. More concretely, this chapter includes a description of the evaluation strategy and settings followed, a report of the study of the original FGFR, the results obtained using FGFR+, and an analysis of some of the most relevant aspects we experimented with while developing our proposal. Finally, in Chapter 6, we gather the conclusions we reached during the development of our project and discuss some other relevant aspects of it, while also pointing out some promising lines of future work. 3 2. STATE OF THE ART 10 MASTER’S THESIS Chapter 3 Methodology In this chapter, we explain in more detail the most relevant methods or techniques we used during the development of our project. In particular, we start by thoroughly describing the original FGFR as it was introduced in [51], and we continue by explaining some relevant models, methods and techniques that played an important role during our work, including the backbone architectures we used [55, 13], several multi-task loss functions [32, 36], self-attention [59] and focal loss [37]. 3.1 The Original FGFR Method This part of the document aims at introducing the fine-grained food recognition method proposed in [51], FGFR. The goal of the method is to improve the ability of an image classification model to correctly identify fine-grained classes. FGFR is conceptually based on building on top of an already trained image classification model (the baseline) and applying a classes subsets extraction procedure to identify groups of classes that the baseline classifier tends to confuse with one another. Note that each of these subsets constitutes a fine-grained recognition problem of its own. Then, the original baseline is extended, replicating the last block of the original architecture (the head) as many times as there are subsets, and each replicated head will specialize in distinguishing the classes within its corresponding subset. The expanded model is trained in a multi-task way (where each subset has its own associated classification task), allowing each head to specialize in its subset. After the training of the heads, a fully connected (FC) layer is trained, to aggregate the predictions made by each of the heads (including the head of the original baseline) and generate a final prediction. Figure 3.1 illustrates the proposed scheme. FGFR consists of three well-defined steps: 1. Baseline training and multi-subsets extraction. 2. Specialization step. 3. Aggregation step. 11 3. METHODOLOGY Figure 3.1: Diagram illustrating the complete model architecture during the aggregation step. The outputs of all heads are concatenated and passed to the final FC layer, which will aggregate all predictions and make the final classification. In the original FGFR, only the final FC layer (in red) is trained during this step. Each of them will now be explained individually in more detail. 3.1.1 Step 1: Baseline Training and Multi-Subsets Extraction The method starts with the training of a standard image classification model, as seen in Figure 3.2, the baseline. In order to extract the subsets of classes, a hierarchical clustering procedure is applied based on the confusion matrix obtained from the baseline model. The authors transform the confusion matrix into a distance matrix using the following formula, which defines the distance dbetween two classes ciand cjas: d(ci, cj)=1−1 2(Mij +Mji),(3.1) where Mrepresents the confusion matrix generated by the model. The authors normalize the confusion matrix so that the resulting distances are bound between 0 and 1. Once the distance between all pairs of classes is computed, an agglomerative clustering method is applied in order to obtain a hierarchy of class similarities. This dendrogram is then cut by applying a threshold value, in order to obtain the final clusters of classes. The hierarchical clustering is generated using single linkage, and the dendrogram threshold value is automatically calculated as the midpoint of the largest vertical difference between nodes. 3.1.2 Step 2: Specialization Step After the multi-subsets extraction, the model needs to be extended so that it can have multiple parallel heads, each specializing in a different subset. In order to build the expanded model, the original baseline model needs to be split into two parts: the backbone and the head. The backbone will act as a generic feature extractor that will be shared by all the heads. The splitting point between the backbone and the head can be arbitrarily set, always assuming that the size of the head will be relatively small compared to that of the backbone. For instance, in the example 12 MASTER’S THESIS Figure 3.2: Diagram illustrating the different blocks that constitute a CSWin Transformer model, plus the final FC layer that performs the classification. Although here the example of CSWin is used, any other backbone architecture can be used, as long as it allows for a split between backbone and head. used in the original paper [51], out of the four main transformer blocks that constitute the CSWin Transformer, the first three blocks are taken as the backbone, whereas the last remaining block is considered to be the head. The head part of the model will be then replicated in parallel as many times as there are clusters. The final classification FC layer of each specialized head will be adapted so that it has as many outputs as there are classes in its corresponding cluster. Additionally, the classifiers of all heads (except for the original baseline head, which remains intact) will predict an additional class, ‘others’. This class includes all the classes that do not belong to the specific subset, so that the classifier of a head learns to discriminate between the classes in its cluster and the rest of classes in the dataset. The result of this process is illustrated in Figure 3.3. Figure 3.3: The multi-head CSWin model used for the specialization step. The shape of the classifier FC layer of each head is adapted to predict all classes in its subset plus the ‘others’ class. Only the specialized heads (in orange) are trained during the specialization step. 13 3. METHODOLOGY To train the second step of the pipeline, the specialization step, the authors propose keeping the weights of the baseline frozen (that is, the shared backbone and the original, generic head that makes predictions for all classes in the dataset), and only training the replicated specialized heads in a multi-task way, where each of the heads constitutes a task of its own. The multi-task training is simply performed by computing the cross-entropy loss of each head separately, and then averaging the loss of all heads to obtain a final loss value: CEi(y, ˆy) = − Nsubseti X j=1 yjlog(ˆyj),L=1 Nsubsets + 1 Nsubsets+1 X i=1 CEi,(3.2) where yjis the ground truth, ˆyjis the corresponding classifier prediction, CEiis the cross-entropy of head i,CE0is the cross-entropy of the baseline head, and Nsubsets is the number of subsets. Data balancing is crucial for this step of the method, as both intra-subset and inter-subset imbalance are likely to be present during the training of the heads. Inter-subset imbalance refers to the difference in the number of samples and classes present in each subset, whereas intra-subset imbalance refers to the different number of samples per class within a subset. The inclusion of the ‘others’ class within the specialized heads implies that there will be a strong intra-subset imbalance that needs to be handled. To that end, FGFR tackles inter- and intra-subset imbalance individually. On the one hand, to fight inter-subset imbalance a method is proposed to determine the amount of samples per epoch Lthat are used to train each of the heads, which takes into account the number of classes nand the median number of samples per subset ms: Lsubset =n·ms k,(3.3) where kis a factor to avoid memory overload (the authors used k= 8). With this method, heads with a higher number of samples or classes will be trained with more samples, and vice versa. On the other hand, the problem of intra-subset imbalance is tackled by simply making a weighted random sampling of each image, based on the probability of occurrence of its class. 3.1.3 Step 3: Aggregation Step In the final step, the outputs of the classifiers of all heads (both the specialized ones and that of the original baseline) are combined to generate a final prediction. The authors [51] propose using a fully connected layer to join the predictions coming from different heads. That is, the class predictions of all heads will be concatenated and passed to the final FC layer to perform the final prediction. In order to retain the classification performance of the baseline, the weights of the final FC layer are initialized with the identity matrix. Assuming that weight wi,j connects the output i from the baseline classifier with neuron j,wi,j is initialized to 1 if i=j, and 0 otherwise. In this way, when given an image that does not belong to any subset, the final classification will likely be the same as that of the original baseline. Regarding the weights connected to the outputs of the specialized heads, these are initialized randomly. During the training of this last step, which 14 MASTER’S THESIS just involves training the final FC layer while keeping the rest of the model frozen, the model will learn how to leverage the information provided by the specialized heads to outperform the original baseline. Figure 3.1 shows the complete resulting model. FGFR managed to achieve validation results that outperformed the previous state-of-the-art on three public food recognition datasets containing fine-grained data: Food-101 [6], FoodX-251 [31] and Food1K (a sub-dataset built from Food2K [46]). 3.2 Baseline Model Architectures It must be noted that FGFR is designed so that it can be integrated with many different deep learning computer vision models, such as CNNs or Vision Transformers (ViTs). In our work, we experiment with two different model architectures of notably different nature and size, in order to assess the generalization capability of FGFR. The two architectures are EfficientNet-B0 [55] and CSWin Transformer-Large [13]. We selected these backbone architectures given the remarkable results they achieved in the bibliography [55, 13]. EfficientNet [55] is a family of CNNs that was developed to improve both the efficiency and accuracy of image classification tasks. One of its most remarkable features is its compound scaling method, which allows to adjust the network’s depth, width and resolution in a principled manner. Back when it was first published, the authors managed to achieve state-of-the-art results for a variety of datasets with an order of magnitude fewer parameters than the top-performing models. A diagram illustrating the architecture of EfficientNet models can be found in Figure 3.4. Figure 3.4: Diagram showing the structure of the generic EfficientNet [55] architecure. The EfficientNet family includes a range of eight different models that vary in their scale (depth, width and resolution), ranging from the smallest version, EfficientNet-B0 (with around 5.3M parameters), to the largest one, EfficientNet-B7 (66M parameters). For our work, we make use of EfficientNet-B0, as we wanted to evaluate the FGFR method on a performant CNN model of relatively small size. CSWin Transformer [13] is a recently introduced Transformer-based architecture designed for general-purpose vision tasks. The architecture addresses the challenge of balancing the trade-off between global self-attention, which is computationally expensive, and local self-attention, which limits the field of interactions of each token. To resolve this issue, the CSWin transformer employs a Cross-Shaped Window self-attention mechanism, which computes self-attention in parallel across horizontal and vertical stripes of equal width, forming a cross-shaped window. This approach leads to an efficient and effective design that can handle a wide range of vision tasks. The overall architecture of the CSWin transformer is shown in Figure 3.5. 15 3. METHODOLOGY Figure 3.5: Overview of the CSWin transformer[13] architecture. Figure borrowed from [13]. The authors introduced multiple variants of the CSWin Transformer [13], which vary in their number of parameters: CSWin-T (Tiny, 23M parameters), CSWin-S (Small, 35M parameters), CSWin-B (Base, 78M parameters) and CSWin-L (Large, 173M parameters). For our work, we experiment with CSWin-L, given that it was also used in the original work of FGFR [51], and because we can use it as a counterpart of the EfficientNet-B0: a transformer-based model of relatively big size. 3.3 Multi-Task Learning Loss Functions Given that the specialization step described in Section 3.1 is a crucial part of the method (as it is the part where the actual fine-grained learning takes place), we explore different ways of improving its training by leveraging existing MTL optimization methods. In particular, we focus on MTL optimization methods based on loss weighting, where the final loss value for a MTL problem is computed as a weighted sum of the losses of the individual tasks. For this work, we experimented with two popular approaches: weighting losses based on uncertainty [32], and the approach introduced in [36], which is presented as an improvement over the former. 3.3.1 Loss Weighting The key idea behind multi-task loss weighting is to balance the individual loss functions for different tasks. Each task will have its own corresponding loss, which must be combined with those from the other tasks in order to compute a single aggregated loss function which the model is trained to optimize. Loss weighting methods parameterize the final aggregated loss function as a weighted sum of the losses of the individual tasks. Different approaches have been proposed to find an optimal set of weights for any given MTL problem. One of the earliest and most well-known MTL loss weighting approaches was the one introduced in [32] (Uncertainty Weighted Loss, UWL, for brevity). Its authors argue that homoscedastic uncertainty can be used as a basis for weighting losses in a multi-task learning problem, treating the multi-task network as a probabilistic model, and deriving a weighted multi-task loss function by maximizing the likelihood of the ground truth output. The resulting loss function jointly maximizes the likelihood of each of the task output distributions, and is defined as follows in the case of having two single-task cross-entropy classification losses L1 and L2: 16 MASTER’S THESIS L(W, σ1, σ2) = 1 σ2 1L1(W) + 1 σ2 2L2(W) + log σ1+ log σ2(3.4) The model is trained to optimize both the parameters Wof the network, as well as the weights σiof each task i. The loss function is carefully designed so that it is smoothly differentiable while also preventing that the weights converge to zero. A similar loss weighing method is the one proposed by [36], which we refer to as AWL (Automatic Weighted Loss). The authors propose using a different regularization term for each task i,Ri= log(1 + c2 i) in order to enforce positive regularization values. This prevents one of the main issues with the method proposed in [32], which could lead to negative loss values. The complete formulation for their loss weighting method is the following for classification tasks: LT(x, yT, y′ T;wT) = X τ∈T 1 c2 τ·Lτ(x, yτ, y′ τ;wτ) + ln(1 + c2 τ).(3.5) As we demonstrate in Chapter 5, the use of AWL allowed the method to improve its results for both the specialization step as well as the aggregation step. Thus, we decided to include it in our final proposed method, FGFR+. 3.4 Self-Attention During the development of FGFR+ we also experimented with different ways of combining the outputs generated by the heads of the model. We hypothesized that self-attention could be an appropriate combination method that, ideally, would identify which heads are providing more relevant information for the image at hand (somehow acting as a ‘soft subset selector’ [17]). In this section, we briefly describe the popular attention methods introduced in [59], ranging from the scaled dot product attention mechanism to the transformer encoder architecture. We opted to use these methods given the recent success of attention-based methods in a wide variety of use cases. The authors in [59] introduce a generic definition for what an attention function is: a mechanism that maps a query and a set of key-value pairs to an output, where the queries, keys, values and output are all vectors. The output is simply computed as a weighted sum of the values. The weight of each value corresponds to the result of a compatibility function between the query and the corresponding key. In their work [59], they introduce a novel compatibility function, ‘scaled dot-product attention’. It first computes the dot product between the query and all the keys, then divides the resulting values by a constant √dkand applies a softmax function to obtain the weight values. The output is computed as the weighted sum of the values. Both the keys and queries are of dimension dk, whereas the values have a dimension of dv. To compute all the outputs simultaneously, all the queries, keys and values are packed together into matrices Q,Kand V. The following formula is used to compute the matrix of outputs: 17 3. METHODOLOGY Attention(Q, K, V ) = softmax(QKT √dk )V(3.6) This mechanism accepts an N-sized sequence of vectors, and generates another N-sized sequence of vectors, where there is a one-to-one correspondence between the vectors of the input and the output. An output vector can be understood as a modification of its corresponding input vector that incorporates relevant information extracted from other elements in the sequence. Building on top of the scaled dot-product attention, the authors in [59] introduce the multihead attention module, which performs hparallel scaled-dot product attention mechanisms for a single sequence. Assuming that the input sequence consists of vectors of dimension dmodel, each of the vectors will be projected into a dkdimensional space, where dk=dv=dmodel/h. This allows each parallel attention layer or head to attend to information from different representation subspaces. For each input vector, each of its corresponding houtput vectors of dimension dvwill be concatenated and projected using a feed-forward layer, retaining the initial dmodel dimensionality. This process is illustrated in Figure 3.6. Figure 3.6: Diagram showing the structure of the multi-head attention module [59]. Figure borrowed from [59]. Finally, in this work we also experimented with transformer encoders [59]. A transformer encoder layer is composed of two sub-layers: a multi-head attention module, and a simple, position-wise fully connected feed-forward layer. Each of the sub-layers is surrounded by a corresponding residual connection [23], followed by layer normalization [1]. This structure is shown in Figure 3.7. Even though the experimentation with self-attention constituted an important part of our work, we decided not to include it in our final method proposal, given that our empirical results clearly indicated that its inclusion would lead to worse performances compared to other methods we tested for the combination of head outputs, as we describe in more detail in Chapter 5. 3.5 Focal Loss We also explored modifying the single-task loss function used by FGFR. Cross-entropy is the single-task loss function used throughout the three steps of the method, including the training of the specialized heads (the cross-entropy loss of each head is computed and then aggregated 18 MASTER’S THESIS Figure 3.7: Overview of the architecture of the transformer encoder [59]. Figure borrowed and adapted from [59]. to obtain a single, aggregated loss value), as well as the training of the baseline model and the aggregation step. We argue that the method might benefit from using other kinds of loss functions, such as the popular focal loss. Focal loss [37] was introduced as a method to address class imbalance by modifying the standard cross-entropy so that the easily classified examples are assigned a smaller fraction of the loss. Its main difference with balanced cross-entropy is the fact that focal loss down-weights the loss assigned to easy examples, forcing the model to focus on hard negatives. Standard cross-entropy is defined as follows: CE(pt) = −log(pt),(3.7) where ptis the probability distribution for the current prediction. Focal loss includes a modulating factor (1 −pt)γto cross-entropy with a tunable focusing parameter γ≥0. Focal loss can then be defined as follows: FL(pt) = −(1 −pt)γlog(pt) (3.8) Note how, whenever an example is misclassified with a low confidence, the modulating factor will be near 1 (as ptwill be close to 0), which results in the loss being almost unaffected. Whenever pt is close to one, the modulating factor becomes closer to zero, weighting down the loss assigned to well-classified examples. The γparameter determines the rate at which easy examples are downweighted. Note that, whenever γ= 0, focal loss is equivalent to cross-entropy. Also note how the effect of the modulating factor grows as the value for γis increased. Focal loss is typically used in conjunction with αbalancing, so that each example is weighted according to the inverse frequency of its class. The complete formulation for α-balanced-focal loss would be the following: FL(pt) = −αt(1 −pt)γlog(pt).(3.9) 19 5. EVALUATION in Figure 5.1. The training set is virtually balanced, with all the classes containing 30 instances except for 6 which consist of 29 images. The test set is slightly more imbalanced, as seen in Figure 5.2, with five classes containing less than 20 images. Figure 5.1: Sample images from the CUB-200-2011 dataset. Figure 5.2: Class size count for the CUB-200-2011 test set. Stanford Cars is another popular fine-grained dataset consisting of images of a variety of real cars. The dataset contains 16,185 images in total, evenly split into train and test sets of around 8,000 images each. The dataset consists of 196 classes, each class typically being associated with a particular combination of car brand, model and year (e.g., 2012 BMW M3 coupe). Example images from this dataset are shown in Figure 5.3. Given that on this project we focus on multiclass classification, we use the cropped version of the dataset, cropping each image according to its associated bounding box information, so as to make the classification based solely on the main car shown in each image. Both the train and test sets present significant class imbalance, as shown in Figure 5.4. Figure 5.3: Sample images from the Stanford Cars dataset. 26 MASTER’S THESIS Figure 5.4: Class size counts for the Stanford Cars train and test sets. Food-101 is a popular dataset consisting of 101,000 images of food belonging to one of 101 food categories. The dataset is, in principle, perfectly balanced, with 750 and 250 images per class for the train and test sets, respectively. However, as the authors state [6], the dataset presents some annotation issues, namely the problem of labeling an image of multiple food items with a single class, resulting in some cross-category noise. Sample images from this dataset can be found in Figure 5.5. Figure 5.5: Sample images from the Food-101 dataset. 5.1.2 Framework and Tools We made use of the Python programming language for the development of the project, relying on the PyTorch framework [47]. We mostly used the model implementations provided by the torchvision [44] package, except for the CSWin model [13], for which we directly used the implementation provided by its authors1. We made extensive use of the timm library [63] to leverage the many utilities it implements. We used Weights & Biases [5] to track and visualize our experiments. The experimentation process was carried out using a NVIDIA GeForce RTX 3090 GPU. 5.1.3 Baseline Models Two different baseline architectures were used for the experimentation process: EfficientNet [55] and CSWin Transformer [13]. 1Implementation available in https://github.com/microsoft/CSWin-Transformer 27 5. EVALUATION EfficientNet is one of the most widely used CNN architectures. Thanks to its scaling method that uniformly scales all dimensions in model depth, width and resolution, there are multiple EfficientNets of varying sizes, ranging from the EfficientNet-B0 (5.3M parameters) to the EfficientNet- B7 (66M parameters). For this project, we opted to use the smallest variant, B0, for a number of reasons. First, to confirm that the original FGFR proposed in [51] is also applicable to relatively small models (given that they only reported results using large models, with ≈173M and ≈296M parameters). Second, a small model would allow us to significantly speed up the experimentation process, while also drastically reducing the amount of computational resources required. The choice for the EfficientNet architecture was taken carefully: we wanted to evaluate the performance of the method on convolutional models (the original work [51] only reported results for attentionbased models, CSWin-Transfomer [13] and VOLO [64]). Within the field of CNNs, we chose the EfficientNet family given not only its popularity, but also its strong performance over methods with a similar amount of parameters (e.g., ResNet [23] or DenseNet [27]). To integrate this model with the FGFR framework described in [51], a separation point within the model had to be determined, so that the model backbone and head can be separated in order to perform the specialization and aggregation steps of the method. Given that the main building blocks of the EfficientNet are seven mobile inverted bottleneck MBConv blocks [53, 56], we opted to make the separation after the sixth block, so that the head consists of the seventh block and the final layers after it (a 1x1 convolution, a pooling layer and a fully connected layer). Figure 5.6 shows a diagram visualizing this split. Figure 5.6: Diagram showing the selected split between backbone and head for the EfficientNet architecture. CSWin Transformer is a Transformer-based backbone that can be used for a variety of vision tasks. The authors published multiple variants, ranging from 23M parameters (CSWin-T) to 173M (CSWin-L). For this project, we opted to use the CSWin-L model, as it was also used to evaluate the original method in [51]. We use CSWin-L as the counterpart of EfficientNet-B0: a large, attention-based model. In this way, we can compare results obtained by two very different baseline models. Regarding the split between backbone and head, we followed the same approach as [51]: out of the four CSWin Transformer blocks, the first three are considered part of the backbone, and the last one is used as the head. 28 MASTER’S THESIS 5.1.4 Training Configuration All models were trained using 224x224 RGB input images, following [51]. Prior to the training of the baseline, both the EfficentNet and CSWin models were initialized using the pretrained weights for ImageNet [52]. The batch size varied depending on the model used, as the sizes of the two baseline models vary significantly. The batch size would also be affected by the FGFR step that was being trained, as different steps would require different amounts of memory. For instance, in the case in which the number of generated subsets is high, the training of the specialization step would require significantly more GPU memory than the initial step, as there would be many replicated heads to be trained. Thus, the batch size for the specialization step would need to be smaller. The batch size used for the first step (baseline training) was 256 for the EfficientNet-B0, and 32 for CSWin-Large. However, from this point on, the batch size used for each dataset was adapted (if needed) to maximize the amount of memory used without exceeding its limit, depending on the number of generated clusters. At some points in this document we report results obtained using gradient accumulation (GA) [26], to effectively increase the batch size without requiring additional memory. We only use GA in those cases where we explicitly state it. The optimizer used throughout the development of the project was AdamW [41] with betas of 0.9 and 0.999, and an epsilon value of 1e−8. A weight decay of 0.005 was used in all experiments. Regarding the learning rate (LR) scheduler, a cosine annealing scheduler with warm restarts [42] was used. The initial T0was set to 10, with a multiplier of 1.2 after each restart, and a total of 4 restarts. After each restart, the initial learning rate was multiplied by a factor of 0.75 unless otherwise stated. In total, this configuration led to 63 epochs of training. Regarding the learning rate, we found it to be sensitive to three factors: the baseline model (EfficientNet or CSWin), the dataset and the step within the method (the baseline training, the specialization step or the aggregation step). Consequently, for each of these scenarios, the learning rate was tuned using a grid search over different learning rates (typically ranging from 1e−6 to 1e−4). Whenever the multi-task loss weighting methods from [32] or [36] were used, a separate identical AdamW optimizer was used with a constant learning rate of 1e −3. The selected loss function for training was cross entropy, for each of the three steps of the pipeline. In the particular case of the specialization step, each of the heads is trained using its cross entropy loss, and then the final loss value of the whole model is computed by combining all the individual head losses using either their mean (original FGFR) or Automatic Weighted Loss [36] (FGFR+). The main evaluation metric was the top-1 validation accuracy across the three steps (following [51]). However, specially during the specialization and aggregation steps, a more detailed quantitative evaluation was performed by manually analyzing per-class metrics (e.g., precision, recall and F1) for each of the classes, in order to assess what the model was learning. During the training of the specialization step, given that each head would have its own top-1 accuracy, the overall evaluation metric was the average balanced top-1 accuracy across all heads. Additionally, for some of our experiments we report the overall top-1 validation accuracy together with two other accuracy metrics: the generic accuracy and the cluster accuracy. The former refers to the top-1 accuracy obtained for the subset of the validation set corresponding to images that do not belong to any cluster. The latter corresponds to the top-1 accuracy for the subset of the 29 5. EVALUATION validation set corresponding to images that belong to a cluster. 5.1.5 Data Augmentation As stated in Section 5.1.4, all models were fed with 224x224 RGB images. Even though we tried to keep the image preprocessing pipeline consistent across all datasets and models, we found that, for the particular case of the Stanford Cars dataset, better results were consistently obtained when using a simpler augmentation pipeline. The data augmentation operations applied when training for the CUB-200-2011 and Food-101 datasets are the following: •Random resized crop and interpolation (cropping a random size and aspect ratio with random interpolation) of size 224x224, random scale between 0.5 and 1.0, and random aspect ratio between 0.75 and 1.33. •Random horizontal flip with a probability of 0.5. •AugMix augmentations [25], with α= 1.0, width = 3 and a random depth value between 1 and 3. •Channel-wise normalization using ImageNet means and standard deviations. •Random Erasing [68] of a rectangular area of the image, with a probability of 0.25, a minimum erased area with respect to the image size of 0.02, and a maximum area fraction of 0.33. We found that omitting both the AugMix and Random Erasing augmentations consistently led to better results when training for the Stanford Cars dataset. Consequently, for this dataset, we replaced these strong augmentations with a simple random rotation within the range (−15◦,15◦). The preprocessing pipeline for validation images was the same for all datasets, and can be described as follows: •Image resizing to 248x248. •Center cropping of size 224x224. •Channel-wise normalization using ImageNet means and standard deviations. 5.2 Exploring the Original FGFR We performed an in-depth study of the behavior of the original FGFR as it was described in [51]. We focused on analyzing each of the most relevant aspects of the three main steps of the pipeline: the multi-subset extraction, the specialization step and the aggregation step. 5.2.1 Study of the Classes Subset Extraction In this section, we assess the generalization ability of the classes subset extraction method to different domains and baseline model architectures. We qualitatively confirm that the classes 30 MASTER’S THESIS within a cluster generally present small inter-class variance, making them ‘hard’ to distinguish. We also corroborate the findings reported in [51], showing that the obtained clusters tend to be also present in the embedding space of the model. We start by performing the initial step of the original FGFR, the training of baseline, for all six different combinations of datasets and models. Each dataset-model configuration is carefully trained by performing a grid search over the most relevant hyperparameters (namely the learning rate and the set of data augmentations used). Table 5.1 shows the top-1 validation accuracy of the best model obtained in each scenario. Top-1 validation acc. EfficientNet-B0 CSWin-Large CUB-200-2011 79.44 90.21 Stanford Cars 91.78 93.76 Food-101 87.56 94.10 Table 5.1: Best top-1 validation accuracy for each dataset-model pair, for the initial step of the method (baseline training). After applying the class subset extraction procedure introduced in [51] and explained in Section 3.1.1, we qualitatively evaluate the similarity of classes belonging to the same cluster. Figures 5.7, 5.8 and 5.9 show some examples of images of classes belonging to several clusters, for different datasets. (a) CUB-200-2011, CSWin-Large, cluster 1. (b) CUB-200-2011, CSWin-Large, cluster 2. Figure 5.7: Images sampled from two clusters generated for the CUB-200-2011 dataset using CSWin-Large as a baseline. Each row contains images belonging to the same class. (a) Stanford Cars, EfficientNet-B0, cluster 1. (b) Stanford Cars, EfficientNet-B0, cluster 2. Figure 5.8: Images sampled from two clusters generated for the Stanford Cars dataset using EfficientNet-B0 as a baseline. Each row contains images belonging to the same class. It can be seen how, regardless of the dataset, the subset extraction method is capable of finding 31 5. EVALUATION (a) Food-101, CSWin-Large, cluster 1. (b) Food-101, CSWin-Large, cluster 2. Figure 5.9: Images sampled from two clusters generated for the Food-101 dataset using CSWin- Large as a baseline. Each row contains images belonging to the same class. clusters of classes that are visually similar. Moreover, it is clear how the generated clusters tend to align with different real life object categories, such as sparrows or terns for the CUB dataset (Figure 5.7), 2012 Audi cars or 2009 Bugatti Veryons for Stanford Cars (Figure 5.8), or tartars or different kinds of cooked meat for Food-101 (Figure 5.9). We also evaluate the correlation between the obtained clusters and the embeddings learned by the model, to verify that classes within the same cluster are hard to distinguish not only for humans, but also for the models. To that end, we record the image embeddings or representations learned by each of the models (i.e., the N-dimensional vector that would be fed to the final classification layer) and visualize them in two dimensions using t-SNE [58]. Figure 5.10 shows the 2D embedding visualizations for three different dataset-model pairs, also including the location of the different clusters generated using the subset extraction procedure. We find that images within the same cluster tend to have similar embedding representations. The visual analysis also shows that there is certain overlap between some clusters in the embedding space, suggesting that, in some cases, distinguishing between two different clusters could also be difficult (for instance, when two clusters represent sub-categories of a larger category). 5.2.2 Study of the Specialization Step Following the generation of the clusters, the next step of the method involves the creation of the multi-subset classifier and the training of the specialized heads. This part of the document aims at providing an insight into what the specialized heads are capable of learning during this step. To that end, we build on top of the trained baselines mentioned in Section 5.2.1, with their corresponding clusters, and perform the specialization step for each of them. Again, we carefully train each of these models performing a grid search over the most relevant hyperparameters, namely 32 MASTER’S THESIS (a) CUB-200-2011, CSWin- Large. (b) Stanford Cars, EfficientNet- B0. (c) Food-101, CSWin-Large. Figure 5.10: t-SNE visualization of the embeddings generated by different baselines for all datasets. Each point represents an image. The color of a point represents the cluster it belongs to. For the sake of clarity, an ellipse has been placed around points belonging to the same cluster. the learning rate. Following the procedure described in [51], for each dataset-model pair we replicate the head of the baseline as many times as there are clusters, adapting the final classifier of each head to the number of classes belonging to the cluster plus one, to account for the ‘others’ class. To train the multi-task model, the cross-entropy loss of each head is calculated and averaged to obtain a final loss for the complete model. During this step, neither the shared backbone part of the model nor the baseline head are trained, as they were already trained in the previous step. We follow the data balancing method described in [51]. In order to analyze the learning of the specialized heads, we first inspect the evolution of the balanced top-1 validation accuracy of each of the heads. The use of the balanced accuracy is important, as each specialized head presents strong class imbalance between the class ‘others’ and the rest of the classes in the cluster. We include an example of the evolution of this metric for the case of Stanford Cars with the EfficientNet architecture in Figure 5.11. The balanced top-1 accuracy metric is computed individually for each head, measuring its classification accuracy for the classes within its cluster and for its corresponding ‘others’ class. We also report the average balanced top-1 validation accuracy across all heads, in order to be able to evaluate the learning of the model with a single metric. Figure 5.11 shows that, in general, all heads seem to be improving their performance throughout the training process. However, we notice a problem that is common within the field of multi-task learning: different tasks (heads) have different learning speeds. Consequently, some heads will achieve their peak performance early on during the training process, while others will peak during the last epochs. This introduces some problems, such as the difficulty of finding an appropriate LR schedule that suits all tasks. Once confirmed that the performance of the specialized heads is indeed improving during training, we compare, class by class, the performance of the specialized heads against the performance of the general baseline trained during the initial step of the method. We only consider those classes that are present in the clusters (i.e., the ‘hard’ classes). We measure the per-class precision and 33 5. EVALUATION Figure 5.11: Some example balanced top-1 validation metrics for the training of the specialization step (Stanford Cars + EfficientNet-B0). recall for both the initial baseline (with a single confusion matrix covering all classes) and for the specialized heads (where each head will have its own confusion matrix for its corresponding subset of classes, including the ‘others’ class). Table 5.2 shows the per-class precision and recall metrics for the model after the training of the baseline (step 1) and the specialization step (step 2), for the particular case of Stanford Cars with EfficientNet (validation set). An important observation to make from Table 5.2 is that, in general, the per-class recall for the cluster classes increases during the specialization step, hinting that the model is improving its ability to correctly identify instances of the ‘hard’ classes (visualized in Figure 5.12). However, the precision is typically lower in the specialization step. After a thorough analysis, we found that the precision metric for each of the heads is extremely sensitive to the classification performance of the ‘others’ class. When the recall for the ‘others’ class is low, there will be some ‘others’ images incorrectly classified as ‘subset’ classes. Considering the strong class imbalance between the class ‘others’ and the rest, even a seemingly high recall of 0.99 for ‘others’ can lead to a significant deterioration in the precision of the rest of the classes in the subset. Figure 5.13 illustrates this problem. We found a significant difference between EfficientNet and CSWin models in terms of the classification performance for the ‘others’ class, as CSWin would typically lead to superior results for this class. Consequently, the above mentioned issue is not as accentuated as it is for the EfficientNet models. However, we hypothesize that this problem, wrongly classifying ‘generic’ classes as ‘hard’ classes, is partially mitigated during the final step, the aggregation step, as the model will have at its disposal the information generated by the rest of the heads (including the original baseline head), and thus might be able to ignore the mistaken prediction made by this head by focusing more on other heads with more confident estimations. In any case, the improvement of the per-class recall is consistent across all dataset-model pairs (see Figure 5.12 for some examples), 34 MASTER’S THESIS Step 1 Step 2 Cluster ID Class Precision Recall Precision Recall 1 others - - 0.999 0.996 1 44 0.815 0.688 0.568 0.781 1 45 0.776 0.884 0.661 0.860 2 others - - 1.000 0.993 2 63 0.538 0.483 0.364 0.552 2 70 0.513 0.571 0.429 0.600 2 118 0.824 0.824 0.559 0.765 3 others - - 0.999 0.989 3 68 0.767 0.868 0.376 0.842 3 74 0.865 0.727 0.443 0.795 4 others - - 0.999 0.994 4 15 0.769 0.698 0.560 0.651 4 16 0.651 0.700 0.416 0.800 5 others - - 1.000 0.985 5 12 0.717 0.927 0.411 0.902 5 21 0.844 0.643 0.274 0.738 6 others - - 1.000 0.985 6 41 0.774 0.706 0.273 0.706 6 42 0.761 0.761 0.343 0.804 7 others - - 1.000 0.989 7 13 0.706 0.571 0.400 0.619 7 18 0.580 0.725 0.304 0.775 Table 5.2: Per-class precision and recall of cluster classes between the model after step 1 (baseline training) and step 2 (specialized heads training), for the Stanford Cars dataset and using an EfficientNet model. Only a subset of the clusters is shown for the sake of readability. (a) Stanford Cars, EfficientNet-B0. (b) CUB-200-2011, CSWin-Large. Figure 5.12: Diagrams showing the mean per-class improvement of the recall metric for each cluster, in two different scenarios. potentially leaving room for the aggregation step of the method to improve the final classification with respect to the baseline model. 5.2.3 Study of the Aggregation Step After training the specialized heads, the last part of the method consists in aggregating the outputs of each of the heads to make the final prediction. To train this final step, the procedure described in [51] is replicated: the output logits from the FC layers of each head (the specialized heads and 35 5. EVALUATION Method Top-1 PIM [9] 92.8 DCAL [69] 92.0 SR-GNN [4] 91.9 ViT-SAC [12] 91.8 SIM-Trans [54] 91.8 Ours (CSWin) 90.9* (a) CUB-200-2011. Method Top-1 CAP [3] 95.7 AttNet & AffNet [22] 95.6 CAL [50] 95.5 Inceptionv4 [49] 95.4 API-Net [70] 95.3 Ours (CSWin) 94.4* (b) Stanford Cars. Method Top-1 CAP [3] 98.6 Efficient Adaptive Ensembling [7] 96.9 Grafit [57] 93.7 GPipe [28] 93.0 EfficientNet-B7 [55] 93.0 Ours (CSWin) 94.2* (c) Food-101. Table 5.7: Accuracy comparison with the top five state-of-the-art approaches for each dataset, filtering out those that make use of extra training data. The results for our method are marked with an asterisk (*) as we report our results as validation results, so they are not directly comparable with those reported by other methods. method would rank third (to our best knowledge), although the difference with the first method (once again, CAP) is quite significant, of around 4%. It must also be taken into account that our method can theoretically be applied on top of any backbone architecture, so our results could potentially be improved if we used a more performant baseline model. 5.4 Analysis of FGFR+ In this section, we explore the effect of a variety of modifications we implemented on top of the original FGFR, as part of the development of FGFR+. Each of the following sections covers different ideas we experimented with: the effect of combining head embeddings for the aggregation step (Section 5.4.1), the use of self-attention as a head-output combination method (Section 5.4.2), using multi-task weighting losses for the specialization step (Section 5.4.3) and the effect using focal loss (Section 5.4.4). 5.4.1 Effect of Combining Head Embeddings for the Aggregation Step In this part of the analysis, we evaluate the effect of bypassing the classifier of each of the heads for the aggregation step, so that the final FC layer directly takes as inputs the embeddings of the heads. We explore multiple ways of combining the embeddings generated by the different heads. We also measure the impact of unfreezing different parts of the model during the training of the aggregation step. In order to be able to experiment in an agile way, we made use of the EfficientNet-B0 model as the baseline architecture (given that it is significantly smaller than CSWin-L), and we tested it on the smallest datasets, namely CUB-200-2011. 42 MASTER’S THESIS We compare all of our results against both the baseline model and those obtained using the original FGFR. Table 5.8 features the relevant metrics for each of these two models. Model Overall Top-1 Generic Top-1 Cluster Top-1 Baseline 79.44 83.63 65.59 Original FGFR 79.51 83.73 66.19 Table 5.8: Overall top-1 (for all classes in the dataset), generic top-1 (accuracy for classes that do not belong to any cluster) and cluster top-1 (accuracy for classes that do belong to a cluster) validation accuracy for the baseline and complete original FGFR, after the aggregation step. Scenario: CUB-200-2011 + EfficientNet-B0. We performed experiments to evaluate the effect of two different kinds of modifications: •The method used to combine the embeddings generated by each of the heads. We experimented with two methods: concatenating the embeddings, and calculating their mean. Assuming that there are Hheads and that each head generates an image embedding of length E, concatening all the embeddings would result in feeding the final FC connected layer with a vector of length H·Eper image. On the other hand, averaging the embeddings would result in a final vector of length Ethat would be passed to the final FC layer. •The fraction of the model that is trained during the aggregation step. During this step, the original FGFR only trained the final FC layer. We explore two additional approaches: unfreezing the whole model (so that the backbone and the heads are also trained during this step) and unfreezing only the heads, keeping the backbone frozen. We experimented with all different combinations of the aforementioned embedding combination and model unfreezing approaches, and we report the obtained results in Table 5.9. It must be noted that, for each combination-unfreezing approach pair, we performed a grid search over the learning rate to find the best model for each configuration. Overall Top-1 Generic Top-1 Cluster Top-1 Combination Unfreeze Backbone + heads 80.45 84.73 67.62 Concatenation Heads 79.70 83.96 68.02 Nothing 79.31 83.62 67.97 Backbone + heads 81.53 85.45 69.74 Mean Heads 80.43 84.59 68.89 Nothing 78.56 82.63 68.15 Table 5.9: Validation results obtained using different embedding combination methods and unfreezing different parts of the model (results for CUB-200-2011 + EfficientNet-B0). We can extract multiple conclusions from Table 5.9 if we compare its results to those reported in Table 5.8 (baseline and original FGFR). First, the embedding combination approach is not capable of improving with respect to the baseline if both the backbone and the heads remain frozen during this training step. In this sense, the original FGFR seems to be performing better, as it does not require any of these parts to be unfrozen in order to outperform the baseline results. However, by just unfreezing the heads, we already obtain results significantly higher than those 43 5. EVALUATION reported for the original FGFR, for both combination methods (79.70 and 80.43 against 79.51). If we let the whole model train during this step (jointly training the final FC layer and fine-tuning the backbone and the head), the results improve even more. We hypothesize that, in order for the combination of the embeddings to be effective, we need to give the network some margin to modify the way the embeddings are generated (by unfreezing it), so that they are optimized for the combination method used. We believe this is particularly important in the case of the mean combination method. A significant difference can be observed between the concatenation and mean combination methods, where the latter leads to substantially higher results whenever some parts of the model are unfrozen. By using the mean combination method and unfreezing the whole model during the aggregation step, we achieve a top-1 accuracy of 81.53%, an improvement of more than 2% with respect to the baseline (compared to the 0.07% of improvement by the original FGFR). By analyzing the performance for the generic and the cluster classes, it can be seen that this configuration improves both metrics significantly when compared to the baseline: an improvement of around 2% for the generic classes, and more than 4% for the fine-grained classes. This shows that this method is not only capable of improving for the fine-grained classes, but also for the generic ones. Moreover, the greatest relative improvement corresponds to the cluster classes, proving that this new approach is still suitable for fine-grained problems. By analyzing the evolution of the evaluation metrics, we observe a significant difference with respect to the original model (see Figure 5.16). Not only the use of embeddings facilitates the training of this step, but it also makes the learning more stable and it achieves a consistent performance that is superior to that of the baseline. In the original method, these plots were much more jagged, and the improvements over the baseline could typically be attributed to casual peaks, showing no consistent learning. With the new aggregation method, the upward trend is much more clear, showing that the model is indeed performing some meaningful learning. Figure 5.16: Top-1 validation accuracy evolution charts for two configurations, for the training of the aggregation step using head embeddings, combining them with the mean, and keeping the whole model unfrozen. To make the comparison as fair as possible, we also performed experiments with the original aggregation method, following the new model unfreezing policies, as one could think that the new approach only obtains better results because of the larger portion of the model that is being trained. Table 5.10 shows that, even if the results improve slightly by unfreezing the whole model, they are still very distant from those reported with the new aggregation method, showing the benefits of directly dealing with head embeddings rather than with the predictions made by them. Unlike 44 MASTER’S THESIS our new approach, the original one barely benefits from unfreezing previous parts of the model. Overall Top-1 Generic Top-1 Cluster Top-1 Unfreeze Backbone + heads 79.55 83.70 66.74 Nothing 79.51 83.73 66.19 Table 5.10: Results obtained after training the original aggregation step, unfreezing different parts of the model (CUB-200-2011 + EfficientNet-B0). Table 5.11 shows the results obtained using this new aggregation method (unfreezing the whole model and combining the head embeddings using the mean) for all dataset-model pairs. The better performance of this new approach is confirmed as it improves the overall top-1 validation accuracy in all cases. Baseline Original aggregation New aggregation Dataset Model CUB-200-2011 EfficientNet-B0 79.44 79.51 81.53 CSWin-Large 90.21 90.40 90.82 Stanford Cars EfficientNet-B0 91.78 91.89 92.85 CSWin-Large 93.76 93.84 94.28 Food-101 EfficientNet-B0 87.56 87.68 88.15 CSWin-Large 94.10 94.10 94.14 Table 5.11: Comparison of the top-1 validation accuracy obtained with new aggregation method (combine embeddings with mean, unfreeze everything) and the original one, for all dataset-model pairs. 5.4.1.1 Evaluating the Contribution from the Baseline Given that the new best aggregation method involves unfreezing the whole model, we would like to know how much of the improvement of this new approach can be attributed to the the mere improvement of the baseline. To that end, we take the new weights for the backbone and the baseline head resulting from the training of the new aggregation step, we freeze them, and train a linear classifier on top of them. With this, we evaluate how much the baseline has improved with respect to the initial step of the method. We report in Table 5.12 the results obtained with the original baseline, the new modified baseline, and the complete method after training the aggregation step. Overall Top-1 Generic Top-1 Cluster Top-1 Model Complete method 81.53 85.45 69.74 New baseline 80.26 84.42 67.18 Original baseline 79.44 83.63 65.59 Table 5.12: Validation metrics for the original baseline, the new modified baseline and the complete method using the new aggregation method (results for CUB-200-2011 + EfficientNet-B0). We observe that, after the aggregation step, the baseline has improved significantly, around 0.75% with respect to its initial version. The initial baseline was trained carefully and performing an 45 5. EVALUATION extensive grid search over hyperparameters, and we were not capable of achieving a top-1 accuracy higher than 79.44 using EfficientNet-B0 for CUB-200-2011. With this method, the baseline is improving significantly, suggesting that the new aggregation method is also facilitating the further improvement of the baseline. Nevertheless, the performance of the new baseline is still low compared to the results obtained with the complete model, which proves the importance of the specialized heads. Additionally, we perform an experiment regarding the dependency of the specialized heads on the baseline head. We train the new aggregation step, but we ignore the embeddings generated by the baseline head, only combining those from the specialized heads. With this, we aim to discover 1) how much generic information the specialized heads are capable of learning, and 2) how much the final performance depends on the information provided by the baseline. We find that the final performance of the model decreases significantly, falling around one percentage point below the top-1 accuracy of the baseline. This shows that, even though the specialized heads are obviously learning some information regarding the generic classes (otherwise the performance would be much lower), this generic information is still not as rich as the one provided by the baseline head, hence its importance for the good performance of the complete model. 5.4.2 Effect of Self-Attention in the Aggregation Step Building on top of the findings reported in Section 5.4.1, we wonder whether there could be a better method for combining the head embeddings. In particular, we hypothesize that, ideally, the final FC layer should only take into account the information provided by the baseline head and the head corresponding to the cluster the current image belongs to (in case it belongs to any subset). We argue that all other information could be misleading the final prediction, and that a head filtering method could help improve the final performance of the model. We hypothesized that the task of deciding which heads to focus on could be too complex for a simple FC layer. Based on the recent success of attention-based models, we evaluate the use of a Multi-Head Attention module [59] as a method to combine the embeddings generated by the heads. In the ideal case, we would like the attention module to learn which heads to pay attention to at each time, depending on the subset the image at hand belongs to. The resulting output embeddings from this module would then be enriched with information coming only from the relevant heads, simplifying the task of the final FC layer of distinguishing the class that the current embedding belongs to. Figure 5.17 illustrates the proposed architecture. For each image, all the embeddings generated by the heads (both the specialized and the baseline head) are passed to the multi-head attention module. This module takes as input a sequence of embeddings and outputs an embedding sequence of the same length. Each of the output embeddings can be understood as a weighted sum of the original input embeddings, depending on the attention scores that the module assigns to each of the input embeddings to generate the current one. In order to guarantee the proper training of the network, and also to ensure that no information is lost during the attention-based combination process, we add a residual connection around the attention module. In this way, each output embedding contains both information from its original, corresponding embedding, as well as enriched information from other heads as a result of the attention process. We use a multi-head attention module with eight internal parallel attention 46 MASTER’S THESIS Figure 5.17: Diagram illustrating the integration of multi-head attention into the aggregation step. In this case, after the attention we only take the embedding corresponding to the baseline head and pass it to the final FC layer. heads, following [59]. Our first approach simply takes the output embedding corresponding to the baseline head (as shown in Figure 5.17) and passes it to the final FC layer, ignoring the embeddings of all other heads. The rationale behind this process is that the baseline embedding already contains a decent generic representation for all classes, and that it is only missing some fine-grained details about the current cluster to be able to properly distinguish the current class. Consequently, we argue that we could use the attention module to ‘enrich’ the information of the baseline embedding with relevant information from the corresponding specialized head. Ideally, the resulting embedding would contain both generic information necessary to distinguish the current class from the generic ones (coming from the baseline head), and also fine-grained information essential to distinguish between the classes in the current cluster (coming from the corresponding specialized head). With this setting, we train the aggregation step of the method, while also evaluating the effect of unfreezing different parts of the model. The obtained results are shown in Table 5.13. Once again, we mainly report the results obtained for the dataset CUB-200-2011 using the EfficientNet-B0 model as the baseline, as it allowed us to experiment in a more agile way. Overall Top-1 Generic Top-1 Cluster Top-1 Unfreeze Backbone + heads 80.57 84.42 68.14 Heads 79.70 83.80 68.44 Nothing 79.36 83.39 67.69 Table 5.13: Validation results obtained using the multi-head attention module as the head embedding combination method, only keeping the output embedding corresponding to the baseline head. Results shown for the configuration CUB-200-2011 + EfficientNet-B0. We make multipe observations from the results shown in Table 5.13. On the one hand, we see that, without unfreezing any previous parts of the model, this approach for the aggregation step is not capable of matching the performance of the baseline (see Table 5.8 for the baseline results). However, when either the heads or the whole model are unfrozen, the model starts to outperform 47 5. EVALUATION both the baseline and the original aggregation method proposed in [51]. Nevertheless, this performance is still far from the one reported in Table 5.9, falling around one accuracy percentage point behind the best configuration we found for this dataset-model pair. We observe the same pattern we saw while evaluating the different embedding combination methods in Section 5.4.1: the accuracy for both the generic and the fine-grained classes is improving, but the improvement for the fine-grained classes is significantly larger. To better comprehend the learned behavior of the multi-head attention module, we visualize the attention scores that the module assigns to each of the heads. Given that the attention scores will be different depending on the image, we store the scores generated for all images in the validation set, and we group them by the subset they belong to (we also group together those images that do not belong to any cluster). We plot the average attention scores for each of the subsets in Figure 5.18. Figure 5.18: Attention scores generated by the best configuration (unfreezing the whole model), for CUB-200-2011 + EfficientNet-B0. Head 0 corresponds to the baseline head. The bar in red represents the head correponding to the cluster. Example: the plot on the top right corner shows the average attention scores for all images belonging to the second cluster. The average attention scores in the plot reflect that the model mainly focuses on the baseline head and the second head (the ‘correct’ one, in red) to generate the resulting embedding. The visualizations from Figure 5.18 suggest that the attention module is indeed learning the behavior we had originally thought of: in most of the cases, it is capable of identifying which is the head corresponding to the cluster of the current image, and consequently assigns a higher attention score to it. We also observe that the module tends to assign a high attention score to the baseline head, which we expected, as it can contain useful information for any class. However, we notice that, in some cases, the module is giving a very high attention score to a head 48 MASTER’S THESIS that is not the one corresponding to the current cluster (the most clear example is the plot for the subset 1 in Figure 5.18). By analyzing the images belonging to the two clusters involved (the actual one and the one that got the highest attention score, subset 8), we observe that they contain very similar objects (in this case, ‘black birds’), which could also be potentially indistinguishable by a non-expert human. Consequently, we believe that the attention module is either confusing these two clusters with one another, or it has learned that the embedding from the ‘wrong’ head is more useful to identify the current class than the one from the head it would correspond to. In any case, the quantitative results obtained using this method are considerably worse than those obtained using other combination methods, namely the mean. We argue that there might be two main reasons for this. On the one hand, with the current approach, it might be a complex task to compress all the relevant information from the different heads in to a single embedding (note that the input and output embeddings of the attention module have the same dimensionality). On the other hand, we also consider the possibility of the attention module giving importance to heads that are indeed irrelevant (as we previously commented with the example of the ‘black bird’ subsets), potentially adding some kind of noise to the final output embedding. 5.4.2.1 Combining Attention Embeddings In order to tackle the first of the problems mentioned, we experiment with an alternative method that does not discard the output embeddings corresponding to the specialized heads, but which takes all of them into account and combines them using the embedding combination approaches discussed in Section 5.4.1. Figure 5.19 describes the new approach. Using this method and thanks to the residual connection, the information from the original embeddings is guaranteed to make it past the attention module, plus the extra benefits of self-attention, which we already showed that is capable of identifying the most relevant heads for each image. Figure 5.19: Diagram illustrating the method combining the output embeddings from the attention module, using either the mean or the concatenation method. We experimented using both the element-wise mean and the concatenation as the embedding combination methods. This approach is exactly the same as the one described in Section 5.4.1, but modifying the embeddings using attention, prior to their combination. Again, we experiment with different ways of unfreezing the model too. The results obtained using this model are shown in Table 5.14. In this case, we see that the three methods (concatenation, mean, and just taking the embedding 49 5. EVALUATION Overall Top-1 Generic Top-1 Cluster Top-1 Combination method Unfreeze Backbone + heads 80.77 84.92 68.62 Concatenation Heads 80.00 83.95 67.27 Nothing 79.67 83.77 67.62 Backbone + heads 80.60 84.79 66.47 Mean Heads 79.74 83.90 67.21 Nothing 79.17 83.50 66.26 Backbone + heads 80.57 84.42 68.14 Baseline embedding Heads 79.70 83.80 68.44 Nothing 79.36 83.39 67.69 Table 5.14: Results obtained using self-attention followed by the combination of the embeddings using either the concatenation or the mean. We also include the results obtained using our initial approach with self-attention (‘Baseline embedding’, originally reported in Table 5.13). corresponding to the baseline head that the attention generates) achieve similar performances when trained while unfreezing the whole model. We also observe that, for the first time since we started experimenting with embedding combination methods for the aggregation step, we managed to outperform the baseline without unfreezing any previous parts of the model (with concatenation). Given the similar results obtained for the three methods unfreezing the complete model, we made use of statistical significance tests to determine whether there was any real difference between their performance. We relied on the Almost Stochastic Order (ASO) test [2]. Using ASO with a confidence level α= 0.05, we found the top-1 validation accuracy distribution of the mean method based on five random seeds to be stochastically dominant over both the concatenation and the original (baseline embedding) approach (ϵmin = 0.05 and 0.01, respectively). Nevertheless, these results are still far behind those obtained with the more simple approach of just computing the mean of the embeddings, without using any kind of attention mechanism. However, we believed that this line of research was promising, especially given the favorable findings from Figure 5.18. We experimented with different aspects of the approach, such as using positional encodings, or testing different values for the number of attention heads within the multi-head attention module. None of them led to an improvement of the results reported in Table 5.14. 5.4.2.2 Analyzing the Attention Scores of the New Combination Approaches To try to understand the behavior of the attention module when combining its outputs using either the mean or the concatenation operations, we opted to visualize the generated attention scores. Unlike the case of Figure 5.18, where there would only be one output embedding from the attention module, with the new approaches the attention generates as many embeddings as there are heads, and the attention scores distribution could potentially be different from one embedding to another. We start by visualizing the attention scores used to generate the output embedding corresponding to the baseline head, averaging the attention scores for images that belong to the same subset (as in Figure 5.18). The attention scores are shown in Figure 5.20, for the case of the concatenation 50 MASTER’S THESIS method, unfreezing the whole model. Figure 5.20: Visualization of the attention scores using the concatenation method and unfreezing the whole model during the aggregation step (CUB-200-2011 + EfficientNet-B0). The scores visualized are those used to generate the output embedding corresponding to the baseline head. It can be seen that the attention patterns in Figure 5.20 are very different from those shown in Figure 5.18. In this case, the attention module is failing to correctly highlight the corresponding head in each case. In most of the cases, the baseline is receiving most of the attention (which is expected), but all of the remaining attention is almost equally split among the specialized heads. This behavior remains consistent when evaluating the attention scores used to generate other output embeddings. By assigning all the specialized heads the same amount of attention, we believe that the contribution of the attention mechanism is essentially reduced to noise, as it is failing to correctly identify the most relevant aspects of each of the heads to determine whether they could be useful or not. Moreover, we believe that the relatively good performance of the model can be almost entirely attributed to the information coming from the residual connection, rather than the information generated by the attention module itself. This becomes even more plausible when considering that the attention patterns used to generate the different output embeddings are practically always the same. That is, we believe that the resulting embeddings are just the original embeddings (the input of the attention module) plus a constant vector that, as we mentioned, could potentially be considered noise. This idea is illustrated in Figure 5.21. This could explain the inferior performance of these approaches when compared to those described in Section 5.4.1. In order to test our hypothesis, we experiment with removing the residual connection, forcing the attention module to learn meaningful patterns to effectively combine the embeddings. We observe 51 6. CONCLUSIONS AND FUTURE WORK improving the performance for the rest of the classes, the generic ones. Using our method proposal, we achieved a validation performance comparable to some of the state- of-the-art approaches for at least the Food-101 dataset. By replacing the baseline architecture with a more performant one, our results could potentially be further improved. However, this could also imply significantly increasing the complexity of the model. In particular, we find that FGFR is considerably expensive to train, both for its inherent multi-step pipeline (which also introduces the additional cost of having to find suitable hyperparameters for not one but three different steps) and also the evident increase of the model size, typically more than doubling the size of the original baseline model, depending on the number of subsets identified. We consider it relevant to highlight our findings regarding the lack of performance resulting from using self-attention during the aggregation step. We spent a significant amount of time and effort experimenting with different approaches to make this integration work, as we believed it was a promising strategy, especially after having obtained results such as those shown in Figure 5.18. However, after an extensive experimentation process and comparisons using significance tests, we could do nothing but accept that a much simpler approach (simply taking the head embeddings and computing their mean, without any kind of attention) was undeniably superior in all aspects. Therefore, the idea of using self-attention in this part of the method was discarded. On the whole, we believe that this work successfully fulfilled its objectives. We managed to replicate and analyze the original FGFR, and we were capable of identifying some of its weak points and propose modifications that tackle them. Our final proposed method showed promising results for a variety of scenarios, and we believe that, with some additional improvements, these results could be further improved while also reducing the computational cost associated to its training process. We discuss some of these improvement ideas in the following section. 6.1 Future Work We consider multiple research lines that appear to be promising from our current perspective. On the one hand, we believe it could be interesting to verify whether state-of-the-art results could be obtained by applying FGFR+ on top of some other top-performing method for fine-grained classification, or at least other powerful backbone architectures. We propose continuing with the single-task loss experiments we eventually discarded given temporal and computational restrictions. We believe that the method, namely the specialization step, could highly benefit from using a different loss function, such as focal loss to better deal with its heavy data imabalance, or even some variations of the contrastive loss, so that the heads learn to generate more discriminative vector representations of the fine-grained images. We also suggest that, in order to fully embrace the potential of multi-task learning, the specialization step could be trained while unfreezing the complete model, rather than just the specialized heads. We hypothesize that, by doing this, the backbone could potentially benefit from the learning of the heads, enhancing the performance of the complete model. We also consider the possibility of jointly training the specialization and aggregation steps. The goal in this case would be two-fold. On the one hand, by jointly training the specialized heads and 58 MASTER’S THESIS the aggregation part of the network, the whole training of the heads would be oriented towards improving the final classification, rather than just focusing on the per-head performance. On the other hand, combining these two steps into one would significantly reduce the computational costs of training FGFR+, making it more appealing for future use in other applications. 59 6. CONCLUSIONS AND FUTURE WORK 60 MASTER’S THESIS Bibliography [1] Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. “Layer Normalization”. In: stat 1050 (2016), p. 21. [2] Eustasio del Barrio, Juan Cuesta-Albertos, and Carlos Matr´an. “An Optimal Transportation Approach for Assessing Almost Stochastic Order”. In: (May 2017). [3] Ardhendu Behera et al. “Context-Aware Attentional Pooling (CAP) for Fine-Grained Visual Classification”. In: Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 35. 2. 2021, pp. 929–937. [4] Asish Bera et al. “SR-GNN: Spatial Relation-aware Graph Neural Network for Fine-Grained Image Categorization”. In: IEEE Transactions on Image Processing 31 (2022), pp. 6017– 6031. [5] Lukas Biewald. Experiment Tracking with Weights and Biases. 2020. url:https://www. wandb.com/. [6] Lukas Bossard, Matthieu Guillaumin, and Luc Van Gool. “Food-101 – Mining Discriminative Components with Random Forests”. In: Computer Vision – ECCV 2014. Ed. by David Fleet et al. Cham: Springer International Publishing, 2014, pp. 446–461. isbn: 978-3-319-10599-4. [7] Antonio Bruno, Davide Moroni, and Massimo Martinelli. “Efficient Adaptive Ensembling for Image Classification”. In: ArXiv abs/2206.07394 (2022). [8] Zhao Chen et al. “GradNorm: Gradient Normalization for Adaptive Loss Balancing in Deep Multitask Networks”. In: International conference on machine learning. PMLR. 2018, pp. 794– 803. [9] Po-Yung Chou, Cheng-Hung Lin, and Wen-Chung Kao. “A Novel Plug-in Module for Fine- Grained Visual Classification”. In: arXiv preprint arXiv:2202.03822 (2022). [10] Michael Crawshaw. “Multi-Task Learning with Deep Neural Networks: A Survey”. In: arXiv preprint arXiv:2009.09796 (2020). [11] Jifeng Dai, Kaiming He, and Jian Sun. “Instance-Aware Semantic Segmentation via Multi- Task Network Cascades”. In: Proceedings of the IEEE conference on computer vision and pattern recognition. 2016, pp. 3150–3158. [12] Tuong Do et al. “Fine-Grained Visual Classification using Self Assessment Classifier”. In: arXiv preprint arXiv:2205.10529 (2022). [13] Xiaoyi Dong et al. “CSWin Transformer: a General Vision Transformer Backbone with Cross- Shaped Windows”. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2022, pp. 12124–12134. [14] Abhimanyu Dubey et al. “Maximum-Entropy Fine Grained Classification”. In: Advances in neural information processing systems 31 (2018). 61 6. CONCLUSIONS AND FUTURE WORK [15] Abhimanyu Dubey et al. “Pairwise Confusion for Fine-Grained Visual Classification”. In: Proceedings of the European conference on computer vision (ECCV). 2018, pp. 70–86. [16] Jianlong Fu, Heliang Zheng, and Tao Mei. “Look Closer to See Better: Recurrent Attention Convolutional Neural Network for Fine-Grained Image Recognition”. In: 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2017, pp. 4476–4484. doi: 10.1109/CVPR.2017.476. [17] ZongYuan Ge et al. “Fine-Grained Bird Species Recognition via Hierarchical Subset Learning”. In: 2015 IEEE International Conference on Image Processing (ICIP). 2015, pp. 561– 565. doi:10.1109/ICIP.2015.7350861. [18] ZongYuan Ge et al. “Subset Feature Learning for Fine-Grained Category Classification”. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition Workshops. 2015, pp. 46–52. [19] Ross Girshick et al. “Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation”. In: Proceedings of the IEEE conference on computer vision and pattern recognition. 2014, pp. 580–587. [20] Matthieu Guillaumin, Daniel K¨uttel, and Vittorio Ferrari. “ImageNet Auto-Annotation with Segmentation Propagation”. In: Int. J. Comput. Vision 110.3 (Dec. 2014), pp. 328–348. issn: 0920-5691. doi:10.1007/s11263-014-0713-9.url:https://doi.org/10.1007/s11263- 014-0713-9. [21] Michelle Guo et al. “Dynamic Task Prioritization for Multitask Learning”. In: Proceedings of the European conference on computer vision (ECCV). 2018, pp. 270–287. [22] Harald Hanselmann and Hermann Ney. “Fine-Grained Visual Classification with Efficient End-To-End Localization”. In: arXiv preprint arXiv:2005.05123 (2020). [23] Kaiming He et al. “Deep Residual Learning for Image Recognition”. In: Proceedings of the IEEE conference on computer vision and pattern recognition. 2016, pp. 770–778. [24] Xiangteng He and Yuxin Peng. “Weakly Supervised Learning of Part Selection Model with Spatial Constraints for Fine-Grained Image Classification”. In: Proceedings of the AAAI Conference on Artificial Intelligence 31.1 (Feb. 2017). doi:10.1609/aaai.v31i1.11223. url:https://ojs.aaai.org/index.php/AAAI/article/view/11223. [25] Dan Hendrycks et al. “AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty”. In: arXiv preprint arXiv:1912.02781 (2019). [26] Joeri R Hermans, Gerasimos Spanakis, and Rico M¨ockel. “Accumulated Gradient Normalization”. In: Asian Conference on Machine Learning. PMLR. 2017, pp. 439–454. [27] Gao Huang et al. “Densely Connected Convolutional Networks”. In: Proceedings of the IEEE conference on computer vision and pattern recognition. 2017, pp. 4700–4708. [28] Yanping Huang et al. “GPipe: Efficient Training of Giant Neural Networks Using Pipeline Parallelism”. In: Proceedings of the 33rd International Conference on Neural Information Processing Systems. Red Hook, NY, USA: Curran Associates Inc., 2019. [29] Zixuan Huang and Yin Li. “Interpretable and Accurate Fine-Grained Recognition via Region Grouping”. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2020, pp. 8662–8672. [30] S´ebastien Jean, Orhan Firat, and Melvin Johnson. “Adaptive Scheduling for Multi-Task Learning”. In: arXiv preprint arXiv:1909.06434 (2019). [31] Parneet Kaur et al. “FoodX-251: A Dataset for Fine-grained Food Classification”. In: arXiv preprint arXiv:1907.06167 (2019). 62 MASTER’S THESIS [32] Alex Kendall, Yarin Gal, and Roberto Cipolla. “Multi-Task Learning Using Uncertainty to Weigh Losses for Scene Geometry and Semantics”. In: Proceedings of the IEEE conference on computer vision and pattern recognition. 2018, pp. 7482–7491. [33] Masanari Kimura. “Understanding Test-Time Augmentation”. In: Neural Information Processing: 28th International Conference, ICONIP 2021, Sanur, Bali, Indonesia, December 8–12, 2021, Proceedings, Part I. Sanur, Bali, Indonesia: Springer-Verlag, 2021, pp. 558–569. isbn: 978-3-030-92184-2. doi:10.1007/978-3-030-92185-9_46.url:https://doi.org/ 10.1007/978-3-030-92185-9_46. [34] Jonathan Krause et al. “3D Object Representations for Fine-Grained Categorization”. In: 4th International IEEE Workshop on 3D Representation and Recognition (3dRR-13). Sydney, Australia, 2013. [35] Jonathan Krause et al. “Fine-Grained Recognition Without Part Annotations”. In: 2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2015, pp. 5546– 5555. doi:10.1109/CVPR.2015.7299194. [36] Lukas Liebel and Marco K¨orner. “Auxiliary Tasks in Multi-Task Learning”. In: arXiv preprint arXiv:1805.06334 (2018). [37] Tsung-Yi Lin et al. “Focal Loss for Dense Object Detection”. In: 2017 IEEE International Conference on Computer Vision (ICCV) (2017), pp. 2999–3007. [38] Tsung-Yu Lin, Aruni RoyChowdhury, and Subhransu Maji. “Bilinear CNN Models for Fine- Grained Visual Recognition”. In: Proceedings of the IEEE international conference on computer vision. 2015, pp. 1449–1457. [39] Lingqiao Liu, Chunhua Shen, and Anton Van den Hengel. “The Treasure Beneath Convolutional Layers: Cross-Convolutional-Layer Pooling for Image Classification”. In: Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2015, pp. 4749–4757. [40] Shikun Liu, Edward Johns, and Andrew J Davison. “End-to-End Multi-Task Learning with Attention”. In: Proceedings of the IEEE/CVF conference on computer vision and pattern recognition. 2019, pp. 1871–1880. [41] Ilya Loshchilov and Frank Hutter. “Decoupled Weight Decay Regularization”. In: arXiv preprint arXiv:1711.05101 (2017). [42] Ilya Loshchilov and Frank Hutter. “SGDR: Stochastic Gradient Descent with Warm Restarts”. In: arXiv preprint arXiv:1608.03983 (2016). [43] Jiaqi Ma et al. “Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture- of-Experts”. In: Proceedings of the 24th ACM SIGKDD international conference on knowledge discovery & data mining. 2018, pp. 1930–1939. [44] TorchVision maintainers and contributors. TorchVision: PyTorch’s Computer Vision library. https://github.com/pytorch/vision. 2016. [45] Shaobo Min et al. “Multi-Objective Matrix Normalization for Fine-Grained Visual Recognition”. In: IEEE Transactions on Image Processing 29 (2020), pp. 4996–5009. [46] Weiqing Min et al. “Large Scale Visual Food Recognition”. In: arXiv preprint arXiv:2103.16107 (2021). [47] Adam Paszke et al. “PyTorch: An Imperative Style, High-Performance Deep Learning Library”. In: Advances in Neural Information Processing Systems 32. Curran Associates, Inc., 2019, pp. 8024–8035. url:http : / / papers . neurips . cc / paper / 9015 - pytorch - an - imperative-style-high-performance-deep-learning-library.pdf. 63 6. CONCLUSIONS AND FUTURE WORK [48] Yuxin Peng, Xiangteng He, and Junjie Zhao. “Object-Part Attention Model for Fine-Grained Image Classification”. In: IEEE Transactions on Image Processing 27.3 (2017), pp. 1487– 1500. [49] Jo Plested, Xuyang Shen, and Tom Gedeon. “Non-Binary Deep Transfer Learning for Image Classification”. In: arXiv preprint arXiv:2107.08585 (2021). [50] Yongming Rao et al. “Counterfactual Attention Learning for Fine-Grained Visual Categorization and Re-identification”. In: Proceedings of the IEEE/CVF International Conference on Computer Vision. 2021, pp. 1025–1034. [51] Javier R´odenas et al. “Learning Multi-Subset of Classes for Fine-Grained Food Recognition”. In: Proceedings of the 7th International Workshop on Multimedia Assisted Dietary Management. MADiMa ’22. Lisboa, Portugal: Association for Computing Machinery, 2022, pp. 17– 26. isbn: 9781450395021. doi:10.1145/3552484.3555754.url:https://doi.org/10. 1145/3552484.3555754. [52] Olga Russakovsky et al. “ImageNet Large Scale Visual Recognition Challenge”. In: International journal of computer vision 115.3 (2015), pp. 211–252. [53] Mark Sandler et al. “MobileNetV2: Inverted Residuals and Linear Bottlenecks”. In: Proceedings of the IEEE conference on computer vision and pattern recognition. 2018, pp. 4510– 4520. [54] Hongbo Sun, Xiangteng He, and Yuxin Peng. “SIM-Trans: Structure Information Modeling Transformer for Fine-grained Visual Categorization”. In: Proceedings of the 30th ACM International Conference on Multimedia. 2022, pp. 5853–5861. [55] Mingxing Tan and Quoc Le. “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks”. In: International Conference on Machine Learning. PMLR. 2019, pp. 6105– 6114. [56] Mingxing Tan et al. “Mnasnet: Platform-Aware Neural Architecture Search for Mobile”. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2019, pp. 2820–2828. [57] H. Touvron et al. “Grafit: Learning Fine-Grained Image Representations with Coarse Labels”. In: 2021 IEEE/CVF International Conference on Computer Vision (ICCV). Los Alamitos, CA, USA: IEEE Computer Society, Oct. 2021, pp. 854–864. doi:10 . 1109 / ICCV48922 . 2021 . 00091.url:https : / / doi . ieeecomputersociety . org / 10 . 1109 / ICCV48922.2021.00091. [58] L.J.P. van der Maaten and G.E. Hinton. “Visualizing High-Dimensional Data Using t-SNE”. English. In: Journal of Machine Learning Research 9.nov (2008). Pagination: 27, pp. 2579– 2605. issn: 1532-4435. [59] Ashish Vaswani et al. “Attention Is All You Need”. In: Advances in neural information processing systems 30 (2017). [60] Catherine Wah et al. “The Caltech-UCSD Birds-200-2011 Dataset”. In: (2011). [61] Yaming Wang, Vlad I Morariu, and Larry S Davis. “Learning a Discriminative Filter Bank within a CNN for Fine-Grained Recognition”. In: Proceedings of the IEEE conference on computer vision and pattern recognition. 2018, pp. 4148–4157. [62] Xiu-Shen Wei et al. “Fine-Grained Image Analysis with Deep Learning: A Survey”. In: IEEE Transactions on Pattern Analysis and Machine Intelligence (2021). [63] Ross Wightman. PyTorch Image Models.https : / / github . com / rwightman / pytorch - image-models. 2019. doi:10.5281/zenodo.4414861. 64 MASTER’S THESIS [64] Li Yuan et al. “VOLO: Vision Outlooker for Visual Recognition”. In: IEEE Transactions on Pattern Analysis and Machine Intelligence (2022). [65] Matthew D Zeiler and Rob Fergus. “Visualizing and Understanding Convolutional Networks”. In: European conference on computer vision. Springer. 2014, pp. 818–833. [66] Zhanpeng Zhang et al. “Facial Landmark Detection by Deep Multi-task Learning”. In: Computer Vision – ECCV 2014. Ed. by David Fleet et al. Cham: Springer International Publishing, 2014, pp. 94–108. isbn: 978-3-319-10599-4. [67] Heliang Zheng et al. “Looking for the Devil in the Details: Learning Trilinear Attention Sampling Network for Fine-Grained Image Recognition”. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2019, pp. 5012–5021. [68] Zhun Zhong et al. “Random Erasing Data Augmentation”. In: Proceedings of the AAAI conference on artificial intelligence. Vol. 34. 07. 2020, pp. 13001–13008. [69] Haowei Zhu et al. “Dual Cross-Attention Learning for Fine-Grained Visual Categorization and Object Re-Identification”. In: 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). 2022, pp. 4682–4692. doi:10.1109/CVPR52688.2022.00465. [70] Peiqin Zhuang, Yali Wang, and Yu Qiao. “Learning Attentive Pairwise Interaction for Fine- Grained Classification”. In: Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 34. 07. 2020, pp. 13130–13137. 65