scieee AI-readable full text Open interactive document viewer

Histopathology Image Analysis for Breast Cancer Diagnosis

Segon Mayans, Maria Elisabet

Abstract

Esta tesis investiga el uso de arquitecturas de aprendizaje profundo para el análisis automatizado de imágenes histopatológicas en el diagnóstico de cáncer de mama. Al comparar el rendimiento de HoVer-Net y U-Net en dos tipos de tinciones, HER2 y Ki67, utilizando métricas de F-score a nivel celular y centrándose en la tarea de clasificación, el estudio encontró que ambas arquitecturas logran resultados satisfactorios. Si bien HoVer-Net tuvo el rendimiento más alto en el conjunto de datos Ki67, con una F-score ponderada de 0,89, U-Net superó al método anterior en el conjunto de datos HER2, logrando una F-score ponderada de 0,84. El estudio también profundiza en las fortalezas y debilidades de ambas arquitecturas, revelando que HoVer-Net sobresale en la segmentación detallada, sin embargo, tiene dificultades al clasificar datos desbalanceados, mientras que U-Net tiene un rendimiento de clasificación sólido pero carece de segmentación detallada. El estudio también identifica áreas de mejora tanto en las arquitecturas como en los conjuntos de datos, como abordar la tendencia de HoVer-Net a la sobresegmentación, simplificar la implementación de U-Net y equilibrar las clases en los conjuntos de datos para mejorar el rendimiento general.

Full text

Degree in Data Science and Engineering Title: Histopathology Image Analysis for Breast Cancer Diagnosis Author: Maria Elisabet Segon Mayans Advisor: Philippe Salembier Clairon and Ferran Marqués Acosta Department: Image Processing Group Month and year: January 2023 Facultat d’Informàtica de Barcelona Facultat de Matemàtiques i Estadística Escola Tècnica Superior d'Enginyeria de Telecomunicació de Barcelona 2 Acknowledgements I would like to express my gratitude to my thesis tutors, Philippe Salembier and Ferran Marqués, and to Montse Pardas for their guidance throughout the duration of this project. I would also like to extend my appreciation to the members of the DigiPatICS project for providing me with the opportunity to work with their datasets and for their help. I additionally want to thank my friends at UPC and the University of Edinburgh for their support and feedback throughout this journey. The knowledge shared, and the discussions we had, have been instrumental in the development of my understanding of the topic. Lastly, I would like to extend my gratitude to my family and friends outside of university for their support and encouragement throughout this journey. Their love and constant believe in me have been an invaluable source of motivation and inspiration. 3 Abstract This thesis investigates the use of deep learning architectures for the automated analysis of histopathological images in breast cancer diagnosis. By comparing the performance of HoVer- Net and U-Net on two types of stainings, HER2 and Ki67, using F-score metrics at a cell level and focusing on the classification task, the study found that both architectures achieve satisfactory results. While HoVer-Net had the highest performance on the Ki67 dataset, with a weighted F-score of 0.89, U-Net outperformed the former method on the HER2 dataset, achieving a weighted F-score of 0.84. The study also delves into the strengths and weaknesses of both architectures, revealing that HoVer-Net excels in detailed segmentation, nevertheless struggles with unbalanced classification tasks, meanwhile U-Net has a robust classification performance but lacks in detailed segmentation. The study also identifies areas for improvement in both architectures and the datasets, such as addressing HoVer-Net's tendency for oversegmentation, simplifying the implementation of U-Net, and balancing the classes in the datasets to enhance overall performance. Keywords: Breast cancer, histopathology image, immunohistochemistry test, HER2, Ki67, panoptic segmentation, HoVer-Net, U-Net. 4 Resumen Esta tesis investiga el uso de arquitecturas de aprendizaje profundo para el análisis automatizado de imágenes histopatológicas en el diagnóstico de cáncer de mama. Al comparar el rendimiento de HoVer-Net y U-Net en dos tipos de tinciones, HER2 y Ki67, utilizando métricas de F-score a nivel celular y centrándose en la tarea de clasificación, el estudio encontró que ambas arquitecturas logran resultados satisfactorios. Si bien HoVer-Net tuvo el rendimiento más alto en el conjunto de datos Ki67, con una F-score ponderada de 0,89, U-Net superó al método anterior en el conjunto de datos HER2, logrando una F-score ponderada de 0,84. El estudio también profundiza en las fortalezas y debilidades de ambas arquitecturas, revelando que HoVer-Net sobresale en la segmentación detallada, sin embargo, tiene dificultades al clasificar datos desbalanceados, mientras que U-Net tiene un rendimiento de clasificación sólido pero carece de segmentación detallada. El estudio también identifica áreas de mejora tanto en las arquitecturas como en los conjuntos de datos, como abordar la tendencia de HoVer-Net a la sobresegmentación, simplificar la implementación de U-Net y equilibrar las clases en los conjuntos de datos para mejorar el rendimiento general. 5 Resum Aquesta tesi investiga l’ús d’arquitectures d’aprenentatge profund per a l’anàlisi automatitzada d’imatges histopatològiques en el diagnòstic de càncer de mama. En comparar el rendiment de HoVer-Net i U-Net en dos tipus de tincions, HER2 i Ki67, utilitzant mètriques de F-score a nivell cel·lular i centrant-se en la tasca de classificació, l'estudi va trobar que les dues arquitectures aconsegueixen resultats satisfactoris. Si bé HoVer-Net va tenir el rendiment més alt en el conjunt de dades Ki67, amb una F-score ponderada de 0,89, U-Net va superar el mètode anterior en el conjunt de dades HER2, aconseguint una F-score ponderada de 0 ,84. L'estudi també aprofundeix en les fortaleses i debilitats de les dues arquitectures, revelant que HoVer-Net sobresurt en la segmentació detallada, però té dificultats en classificar dades desbalancejades, mentre que U-Net té un rendiment de classificació sòlid però no ofereix una segmentació detallada. L'estudi també identifica àrees de millora tant a les arquitectures com als conjunts de dades, com abordar la tendència de HoVer-Net a la sobresegmentació, simplificar la implementació d'U-Net i equilibrar les classes als conjunts de dades per millorar el rendiment general. 6 Index 1. INTRODUCTION .......................................................................................................................... 8 1.1. MOTIVATION ................................................................................................................... 8 1.2. MEDICAL BACKGROUND .............................................................................................. 8 1.2.1. CANCER ........................................................................................................................ 8 1.2.1.1. BREAST CANCER ......................................................................................................... 8 1.2.1.1.1. BREAST CANCER DETECTION .............................................................................. 9 1.2.2. IHC AND HISTOPATHOLOGY IMAGES .................................................................... 9 1.2.2.1. HER2 STAINING ......................................................................................................... 10 1.2.2.2. KI67 STAINING ........................................................................................................... 10 1.3. OBJECTIVES ................................................................................................................... 11 1.4. DIGIPATICS .................................................................................................................... 11 2. LITERATURE REVIEW.............................................................................................................. 13 2.1. IMAGE SEGMENTATION .............................................................................................. 13 2.1.1. U-NET .......................................................................................................................... 14 2.1.2. HOVER-NET ................................................................................................................ 14 2.2. PREVIOUS WORK ON THE ANALYSIS OF HISTOPATHOLOGY IMAGES IN DIGIPATICS ................................................................................................................................ 16 2.2.1. PREVIOUS WORK ON THE ANALYSIS OF HER2 STAINING ................................ 16 2.2.2. PREVIOUS WORK ON THE ANALYSIS OF KI67 STAINING .................................. 17 3. METHODOLOGY ...................................................................................................................... 19 3.1. DATASETS ...................................................................................................................... 19 3.1.1. HER2 ............................................................................................................................ 19 3.1.2. KI67 .............................................................................................................................. 20 3.2. HOVER-NET .................................................................................................................... 20 3.3. EVALUATION TECHNIQUES FOR CELL CLASSIFICATION .................................... 21 CONFUSION MATRIX ................................................................................................................................ 21 PRECISION AND RECALL .......................................................................................................................... 21 F-SCORE .................................................................................................................................................. 22 3.3.1. IMPROVEMENT OF THE EVALUATION METRICS ............................................... 22 3.4. CALCULA ........................................................................................................................ 23 4. RESULTS ................................................................................................................................... 24 4.1. HER2 ................................................................................................................................ 24 4.1.1. U-NET .......................................................................................................................... 24 4.1.2. HOVER-NET ................................................................................................................ 25 4.1.2.1. DATA CROPS .......................................................................................................................... 25 4.1.2.2. THE TWO HOVER-NET TRAINING PHASES .............................................................................. 25 4.1.2.3. ANALYSIS OF THE DISTRIBUTION OF CLASSES IN THE DATASET ............................................. 26 4.1.2.4. BATCH SIZE ............................................................................................................................ 27 4.1.2.5. TRAINING DATASET EXTENSION WITH VH HER2 STAININGS ................................................ 27 7 4.1.2.5.1. ANALYSIS OF THE NEW TRAINING DATASET ...................................................................... 28 4.1.2.5.2. IMPACT OF THE TRAINING DATASET EXTENSION ON THE MINORITY CLASSES .................... 29 4.1.2.5.3. CONCLUSIONS ON THE TRAINING DATASET EXTENSION .................................................... 30 4.1.2.6. HYPERPARAMETER TUNNING ................................................................................................. 31 4.1.2.7. OVERFITTING ANALYSIS ........................................................................................................ 31 4.1.3. COMPARISON OF HOVER-NET AND U-NET FOR HER2 ....................................... 31 4.1.3.1. INFERENCE EXAMPLES ........................................................................................... 33 4.1.3.2. CONCLUSIONS ON THE HER2 DATASET ............................................................... 36 4.2. KI67 .................................................................................................................................. 37 4.2.1. U-NET .......................................................................................................................... 37 4.2.2. HOVER-NET ................................................................................................................ 37 4.2.2.1. FAST MODE: PANNUKE PRETRAINED MODEL ......................................................................... 38 4.2.2.2. ORIGINAL MODE: CONSEP PRETRAINED MODEL ................................................................... 38 4.2.2.3. OVERFITTING ANALYSIS ........................................................................................................ 39 4.2.3. ANALYSIS OF THE KI67 DATASET .......................................................................... 40 4.2.4. COMPARISON OF HOVER-NET AND U-NET FOR KI67 ......................................... 40 4.2.4.1. INFERENCE EXAMPLE ............................................................................................. 41 4.2.5. CONCLUSIONS ON THE KI67 DATASET ................................................................. 42 5. DISCUSSION .............................................................................................................................. 44 6. CONCLUSIONS .......................................................................................................................... 45 7. REFERENCES ............................................................................................................................ 46 8 1. Introduction 1.1. Motivation Breast cancer is one of the leading causes of cancer-related deaths among women worldwide. Early diagnosis and treatment of breast cancer are critical for improving patient outcomes and reducing mortality rates [1]. One important aspect of breast cancer diagnosis is the examination of tissue samples taken from biopsies or surgical specimens. These tissue samples are typically examined by a pathologist, who looks for signs of cancer in the tissue under a microscope. Computer vision has the potential to improve the accuracy and efficiency of breast cancer diagnosis by automating the analysis of these samples. In particular, automatic segmentation and classification of histopathology images (images of tissue samples taken from biopsies or surgical specimens) can help identify cancerous cells in the tissue. However, there are several challenges that need to be addressed in order to develop effective computer vision algorithms for breast cancer diagnosis. One major challenge is the large intraclass variability in the data, as histopathology images can vary significantly in terms of cell appearance. Another challenge is the fact that the ground truth of the cells’ classification can differ between different pathologists, as there is often subjectivity in the interpretation of tissue samples. Despite these challenges, the potential impact of computer vision on breast cancer diagnosis is significant. Automated analysis of histopathology images could improve the accuracy and efficiency of breast cancer diagnosis, leading to better patient outcomes and potentially saving lives. This bachelor’s thesis, as a continuation of previous theses in the Image Processing group at UPC, proposes a computer vision approach for the segmentation and classification of cells in histopathology images. It aims to demonstrate the potential impact of this approach on breast cancer diagnosis. 1.2. Medical background 1.2.1.Cancer Cancer is a disease in which abnormal cells multiply and spread in the body, often forming tumors. These tumours can be cancerous (malignant) or non-cancerous (benign). Cancerous tumours can spread to other parts of the body and form new tumors, while benign tumours do not spread but can still cause symptoms [2]. Cancer is a major public health challenge, and research into prevention, detection, and treatment is ongoing. This thesis focuses specifically on breast cancer detection. 1.2.1.1. Breast cancer Breast cancer is a type of cancer that affects the cells of the breast. It mostly affects women, although it can also occur in men. 9 According to the World Cancer Research fund, it was the most common type of cancer globally in 2020. It represented 12.5% of all cancer cases, which is equivalent to 2.26 million cases. It is estimated that about 627,000 women died from breast cancer in 2018, making up around 15% of all female cancer deaths [3]. In addition, the American Cancer Society warns of an increasing incidence of breast cancer, growing annually by 0.5% in recent years. In the United States, the likelihood of a woman developing breast cancer at some point in her life is about 13%, or a 1 in 8 chance [4]. Fortunately, mortality rates from this disease have declined considerably over time. From 1989 to 2020, there has been a 43% decline in the death rate of breast cancer in the US. This decrease is attributed to earlier breast cancer detection, in addition to the development of better treatments [4]. “Early detection of breast cancer is important because it often means the person is more likely to have treatment options that are much less aggressive, while still maintaining incredibly positive treatment outcomes," says Dr. Ana Benveniste, breast radiologist at Houston Methodist [5]. 1.2.1.1.1. Breast cancer detection As mentioned in the previous section, early detection of breast cancer is critical because it can significantly improve the chances of successful treatment. Breast cancer can be diagnosed using breast ultrasounds, diagnostic mammograms, breast magnetic resonance imaging, and biopsies[6]. The scope of this thesis focuses on the latest diagnostic method. A biopsy is a procedure in which a sample of breast tissue or fluid is extracted from a patient and examined for further testing. To make specific structures of the tissue visible under the microscope, the tissue is stained with dyes (staining). After that, pathologists examine slides of the stained tissue to determine if it is benign or malignant. This diagnosis process is called histopathology [7]. In recent years, there has been growing interest in using computer vision techniques to analyze stained biopsy images in order to improve the accuracy and efficiency of breast cancer diagnosis, particularly when dealing with large datasets. Following this interest, this thesis will experiment with new computer vision models on real staining images provided by the ICS. 1.2.2.IHC and histopathology images Immunohistochemistry (IHC) is a laboratory technique used to identify specific proteins within cells and tissue samples. It involves the use of antibodies that bind to specific proteins, which are then detected and visualised using a microscope. IHC is frequently used in cancer diagnosis because certain proteins may be expressed at higher levels or only found in cancerous tissue. Histopathology images are pictures of stained tissue, obtained as part of the IHC process. These are used in the context of breast cancer diagnosis to identify the presence of cancerous cells. There are different types of breast cancer histopathology images. Each type is characterised by the type of staining used to obtain it. In the DigiPatICS project, the following stainings are being used: 1. Antigen KI67 (Ki67) 2. Estrogenreceptor (ER) 3. Progesteronereceptor (PR) 16 classifying minority classes, as its performance is significantly lower for these. The authors recommend expanding the dataset for these classes [13]. 2.2. Previous work on the analysis of histopathology images in DigiPatICS As part of the DigiPatICS project, students have previously developed their theses on histopathological image analysis. As this thesis is defined as the continuation of other projects, a summary of the relevant ones is given below. 2.2.1.Previous work on the analysis of HER2 staining On the analysis of HER2 staining, two theses were previously developed in DigiPatICS: Boneta (2021) and Rosell in (2022), as a continuation of the previous. In the first project, Boneta presented a computer vision approach to automatically detect and classify cells in HER2 staining from Vall d’Hebron hospital (VH). She trained a basic U-Net architecture, with a ResNeXt network pre-trained on the ImageNet dataset as the encoder [14]. The U-Net was used to generate a semantic segmentation of the image, but the desired output was a panoptic segmentation that classified cells instead of individual pixels. To achieve this, the output of the U-Net was post-processed in two steps: Before post-processing, a U-Net generates semantic segmentation, classifying each pixel in the image. In the first post-processing step, a binary mask is retrieved from the U-Net output and used as input to a watershed algorithm, which splits the binary mask into various connected components representing individual cells. This step produces an instance segmentation of the image. In the final step, a majority vote of the pixel classification performed by the U-Net is used to determine the class of each cell, resulting in the panoptic segmentation of the image. The best model’s F1-score for cell classification on the VH dataset was 0.744. Moreover, Boneta conducted a study on how to best handle stroma cells in HER2. Three strategies were tested: labelling the stroma as a separate class, labelling the stroma as background, and training a U-Net to detect and remove the stroma from the ground truth image. The best performing strategy was to label the stroma as background, but the other strategies performed similarly. After the development of Boneta's project on the Vall d’Hebron HER2 dataset, the DigiPatICS group obtained a new dataset of HER2 stains from the Bellvitge hospital (BE). The Vall d’Hebron dataset was created in 2019 and the Bellvitge dataset in 2021. Consequently, the staining images in the new dataset are more modern and, therefore, more relevant to train models that can generalise well to HER2 stainings currently used in hospitals. The two HER2 datasets have significant differences in the colour of the images. The Vall d’Hebron stainings have a dark reddish tone, while the Bellvitge stainings have a lighter, orange color. This difference can be seen in Figure 8. 17 Figure 8: Comparison of Vall d’Hebron and Bellvitge HER2 stainings based on various scores. (Rosell, 2022) The new dataset obtained by the DigiPatICS group had a limited number of ground truth annotations. This limited the ability to use the dataset to train a new model. As a result, Rosell continued Boneta's work by studying different strategies for adapting the previously developed semantic segmentation model for the Vall d’Hebron dataset to the new Bellvitge dataset. The strategies included training the model from scratch using BE data only, and VH and BE combined, and adapting the pre-trained model to the BE data using transfer learning techniques. Moreover, when training exclusively on the BE dataset, Rosell detected that the lack of balance in the data was preventing the model from learning to classify the minoritarian classes. Additional strategies were tested to address this issue, including replicating images of a specific class, increasing the batch size, and using a new loss function. The last two strategies were successful. However, training with a combination of BE and VH data resulted in a significant improvement in performance, from an averaged F1-score of 0.65 to 0.74. The latter value represents the best model, which transferred learning from Boneta's model [15]. 2.2.2.Previous work on the analysis of Ki67 staining On the analysis of Ki67 staining, one thesis was previously developed in DigiPatICS: Sala (2021). The algorithm proposed in this project for the analysis of the KI67 dataset is very similar to the one proposed for the HER2 dataset. As shown in Figure 9, it involves three steps: semantic segmentation, cell count, and merging the results. In the first step, a U-Net network is used to obtain a semantic segmentation of the image. It classifies each pixel in the image into one of the four possible classes: positive cell, negative cell, stroma cell, or background. In the second step, the objective is to find the centre of each individual cell to be able to separate connected components. A U-Net model is trained again, with the difference that the ground truth contains dot annotations representing the centre of each cell. In the final step, a watershed algorithm is used to divide each predicted connected component from block A into individual cells based on the number of predicted centres from block B. The class of each cell is determined through majority voting of the pixel class. The final result is the panoptic segmentation of the image. 18 Figure 9: Structure of the final algorithm and example of the input and output of each block (Sala, 2021). The performance of the algorithm reported in Sala’s thesis has a weighted F-score of 0.727. More specifically, 0.79 for the negative class, 0.82 for the positive class, and 0.57 for the stroma [16]. Moreover, during the development of this thesis, errors were discovered in the ground truth of the staining images. This finding highlights the fact that the ground truth is not always accurate and reliable, and may introduce bias into the models, leading to forecast errors. 3. 19 3. Methodology This section outlines the methods and experimental setup used in the study. The research includes two datasets: the primary focus is on HER2, while Ki67 is included as a complementary dataset. The main objective of the study is to experiment with HoVer-Net and compare its performance to that of U-Net on the datasets in scope. Therefore, the section also explains why HoVer-Net was chosen for comparison with U-Net and introduces its relevant technical details. In addition, the section describes the evaluation metrics that are used to compare the performance of the two approaches on the datasets in scope. Finally, the experiments are conducted using a specific computational setup, which is also outlined in this section. 3.1. Datasets 3.1.1.HER2 The most recent HER2 dataset, introduced in previous sections, was provided by Bellvitge hospital (BE). In this, there are 141 labelled tiles coming from 4 patients. More specifically, the distribution of the 141 images available is as follows: a. 9 from patient 29914 b. 9 from patient 29884 c. 35 from patient 4730 d. 88 from patient 6173 This shows that most of the labelled dataset belongs to a single patient. On the other hand, the Vall d’Hebron (VH) HER2 dataset has 105 labelled tiles from 12 patients. The ground truth of the HER2 database has six classes of pixels with the meaning and codification shown in Figure 10. Class Class number Colour code Background 0 Black Cell of class 0 1 Cyan Cell of class 1 2 Blue Cell of class 2 3 Red Cell of class 3 4 Green Stroma 5 Yellow Figure 10: Table displaying the numeric and colour codes for the different classes in HER2. Moreover, the dimensions of the tiles are 1024x1024, and they have been partitioned into training and test sets according to the split defined in Rosell (2022), where there was the intention to fairly represent all the classes in the test set. The training set contains 97 tiles, and the test set contains 46 tiles. 20 In an ideal scenario, the test and training datasets would include images from different patients to simulate the process of testing new patients in real life, as proposed in Bonet (2021) for the VH dataset. However, due to the limited number of patients labelled in the BE dataset, the partition proposed by Rosell is used, which favours the balance between classes. 3.1.2.Ki67 For Ki67 staining, a new dataset is also available. This was created at the end of December 2022. It contains 48 tiles in the train set and 4 in the test set. In the new Ki67 dataset, the ground truth only includes two classes: negative cells and positive cells. The stroma class is not included because the strategy is to have the model only predict these classes, to later apply a stroma mask generated by another model to mark the stroma cells. Stroma must be removed because it is often mistaken for the negative class. Therefore, the ground truth of the Ki67 database has the following codification: Class Class number Colour code Background 0 Black Negative 1 Green Positive 2 Red Figure 11: Table displaying the numeric and colour codes for the different classes in Ki67. 3.2. HoVer-Net HoVer-Net gained recognition after winning the CoNiC challenge, a Kaggle competition for colon cancer detection. As a result, it is considered a state-of-the-art model in colon cancer detection. Based on this result, we considered it relevant to investigate whether HoVer-Net can also be applied to breast tissue stainings and evaluate its performance on DigiPatICS’ data compared to U-Net’s. To evaluate the compatibility of HoVer-Net with the DigiPatICS datasets, it has been taken into account that HoVer-Net is available in two modes: original and fast. Different pre-trained versions for the tasks of instance segmentation and classification are available within each mode: • Original o CoNSeP dataset (5 classes) • Fast (reduced version) o MoNuSAC dataset (5 classes) o PanNuke dataset (6 classes) These pretrained models were trained by the authors of the paper on stainings from a wide variety of organs, and are documented in their GitHub repository [17]. To train HoVer-Net with the DigiPatICS data using a pretrained version of the model, we must choose the appropriate mode based on the number of classes in the dataset. For HER2 stainings, we must use the fast mode pretrained on PanNuke, as it is the only one available for 6 classes. 21 In contrast, for fine-tuning the model for the Ki67 database, any of the three pretrained versions can be used, as the KI67 dataset only has three classes. Regarding the difference between the original and fast modes, it is found in the output size of the model, where the fast mode outputs a bigger image size of 164x164, compared to 80x80 in the original model. The output of the original HoVer-Net mode is smaller than its input size of 270x27, because the three decoders use valid convolution, i.e., convolution with no padding, in the up-sampling branches to prevent poor predictions at the boundary of the image. In contrast, the fast mode, includes padding to increase the output size. 3.3. Evaluation techniques for cell classification To compare the performance of HoVer-Net and U-Net in cell classification for breast cancer diagnosis, specific metrics that evaluate based on cells rather than pixels are used. These metrics are important in the medical context of the project because the diagnosis is obtained by counting the number of cells in each class rather than the pixels themselves. Moreover, the shape of the cells is not as relevant as the number and classification of cells detected. Consequently, the evaluation metrics used in the project prioritise the performance of this task over detailed segmentation. The evaluation metrics were developed by Adria Marcos and Jose Perez for a binary classification problem and were adapted to multi-class within this project. These metrics assess the similarity in class between pairs of cells in the ground truth and prediction, which are matched based on proximity. The following multi-class evaluation methods at a cell level are included: confusion matrix, precision, recall, and f-score. Confusion matrix A confusion matrix is a table used to evaluate the performance of a classifier. It displays the number of correct and incorrect predictions made by the classifier for each class. The rows of the matrix represent the actual classes of the samples, and the columns represent the predicted classes. Each cell in the matrix represents the number of samples that belong to a given actual class and were predicted to belong to a given predicted class [18]. Confusion matrices can be used for both binary and multi-class classification problems. In a binary confusion matrix, there are four cells: true positive (TP), false negative (FN), false positive (FP), and true negative (TN). In a multi-class confusion matrix, there is one row and one column for each class, and the values for TP, TN, FP, and FN can be calculated by looking at the entries in the matrix for a particular class. Precision and recall Precision is a measure of the accuracy of a classifier, specifically the proportion of true positive results among all positive results. It is calculated as the number of true positives divided by the total number of predicted positives, using the following formula: 𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 = 𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 / (𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 + 𝐹𝑎𝑙𝑠𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠) 22 Recall, on the other hand, is a measure of the completeness of a classifier, specifically the proportion of true positive results among all relevant samples. It is calculated as the number of true positives divided by the total number of actual positive samples, using the following formula: 𝑅𝑒𝑐𝑎𝑙𝑙 = 𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 / (𝑇𝑟𝑢𝑒 𝑃𝑜𝑠𝑖𝑡𝑖𝑣𝑒𝑠 + 𝐹𝑎𝑙𝑠𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑣𝑒𝑠) Both precision and recall are important for evaluating the performance of a classifier, as they provide complementary information about the quality of the classifier's predictions. A classifier with high precision is one that is able to make accurate predictions, while a classifier with high recall is one that is able to identify a large proportion of relevant samples [19]. F-score The F1 score is a metric that considers both precision and recall and provides a single composite score that reflects the model's performance. It is calculated as the harmonic mean of precision and recall, using the following formula: 𝐹1 𝑆𝑐𝑜𝑟𝑒 = 2 ∗ (𝑝𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 ∗ 𝑟𝑒𝑐𝑎𝑙𝑙)/(𝑝𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 + 𝑟𝑒𝑐𝑎𝑙𝑙) In a multi-class classification problem, the F-score can be calculated in four different ways: macro averaging, weighted averaging, micro averaging and separately for each class. Macro averaging calculates the F1 score by taking the unweighted mean of all per-class F1 scores, treating all classes equally regardless of their support values. This can be useful when the classes are balanced, and all classes are equally important [20]. Weighted averaging calculates the F1 score by taking the mean of all per-class F1 scores, but taking into account the relative support. It weights the contribution of each class by the number of examples in that class. Therefore, it is useful when the classes are imbalanced, as it considers the fact that some classes may have more samples than others [20]. Micro averaging calculates the overall F1 score by summing the True Positives, False Negatives, and False Positives across all classes and plugging them into the F1 equation. Micro averaging calculates the proportion of correctly classified observations out of all observations, so it is equivalent to the calculation of overall accuracy [20]. In addition, the F1 score can be calculated for individual classes, allowing for identification of classes where the model performs poorly and for comparison of the model's performance across different classes. In conclusion, the four variations of the F1 score are used to evaluate the model, with a particular emphasis on the weighted F1 score and the per-class version, given that they are particularly well-suited to the problem at hand and will be discussed in more detail in the results section. 3.3.1. Improvement of the evaluation metrics During this project, the evaluation metrics of cell detection and classification were improved by extending them to the multiclass case and resolving inconsistencies in the confusion matrices. This was achieved through collaboration with Jose Pérez and David Anglada, student researchers in the DigiPatICS project. 23 One of the main challenges encountered was that the metrics initially only evaluated matched cells in the GT and prediction, neglecting cells that were not segmented by the model or cells that were generated by the prediction but didn’t match the GT. To address this issue, the confusion matrix was analysed and corrected to ensure that the sum of each row matched the total number of predicted cells of each class found in the cell classification output of the model, and the sum of each column matched the number of cells in each class in the GT. It is crucial that these conditions are met, as it provides a reliable foundation for the evaluation metrics to start from, capturing all the details of matched cells in prediction and GT, as well as unmatched cells. Failure to do so results in an incorrect and significant decrease in the number of false positives and false negatives, leading to invalid F-score values. 3.4. Calcula Calcula is a computing service of the UPC. It has been used to carry out this project, allowing the execution of processing-intensive experiments, using 1 GPU. 4. 24 4. Results 4.1. HER2 This study aims to analyse the performance of HoVer-Net on the HER2 dataset from Bellvitge. Different parameters of HoVer-Net and variations in the input data are tested to identify the optimal version of the model for this dataset. The results are then compared to those obtained with U-Net, which is considered to be the state-of-the-art for this problem, using both the evaluation metrics defined in the methods section, and visual inference examples. Last, the strengths and weaknesses of both architectures in relation to the HER2 dataset are discussed. 4.1.1.U-Net The model currently used by DigiPatICS for cell segmentation and classification is a U-Net with post-processing that utilises watershed algorithms. This model was trained using both the Vall d’Hebron (VH) and Bellvitge (BE) datasets, but it is tested on the BE test dataset. To later compare the performance of HoVer-Net, Figures 12 and 13 present the evaluation of U- Net's inference on the HER2 dataset. The U-Net is evaluated using the evaluation metrics proposed in the methodology section, which allows for a fair comparison between the two architectures. Weighted F1-score Micro F1-score (acc) Macro F1-score U-Net 0.8458 0.7840 0.7863 Figure 12: Table of the evaluation of U-Net’s inference on the BE HER2 test set. F1-score per class Class 0 Class 1 Class 2 Class 3 Stroma U-Net 0.602 0.865 0.723 0.857 0.885 Figure 13: Table of the per-class evaluation of U-Net’s inference on the BE HER2 test set. Figure 14: Confusion matrix of the U-Net’s inference at a cell level on the BE HER2 test set. The confusion matrix, shown in Figure 14, shows that a large portion of the misclassified class 0 cells are mainly confused with class 1 and class stroma in second place. Class 2 also stands out as it is frequently confused with class 3. 25 4.1.2.HoVer-Net To determine how well HoVer-Net performs in identifying and classifying cells that have been stained with HER2, several experiments were conducted, with the objective of maximising its performance. The most relevant of these experiments and their results are described above: 1. Data crops 2. The two HoVer-Net training phases 3. Analysis of the distribution of classes in the dataset 4. Batch size 5. Extension of the training dataset with VH data 6. Hyperparameter tunning 7. Overfitting analysis 4.1.2.1. Data crops As previously mentioned, the HER2 staining dataset consists of images that are 1024x1024 in size. However, HoVer-Net has a fixed input size of 270x270 at most. Therefore, when the whole image is used as input, HoVer-Net only processes a cropped piece of the centre with those dimensions, discarding the rest of the image during training. Consequently, the first experiment was designed to evaluate the model's ability to generalise on the test set when trained on all the information in the training set instead of only cropped centres. To do so, each image in the train set was split into 16 chunks of size 270x270. The same hyperparameters were used in both executions. The evaluation of the inference in the test set is as displayed in Figure 15. Weighted F1-score Micro F1-score (acc) Macro F1-score Inputting the whole image 0.7572 0.6873 0.6615 Inputting 16 270x270 crops per image 0.8124 0.7448 0.7327 Figure 15: Table of the evaluation of the inference results on the BE HER2 test set, comparing HoVer-Net trained with two different variations of the dataset. In summary, using all the information in the image for training significantly improves the model's performance on the test set, from a weighted F1-score of 0.76 to 0.81. Therefore, this approach will be used in all subsequent experiments. It should be noted that this increase in performance comes at the cost of longer training time. 4.1.2.2. The two HoVer-Net training phases HoVer-Net is trained in two phases. In the first phase, the encoder is frozen and only the decoders are trained, while in the second phase both the encoder and the decoders are trained. To determine whether it might be better to end training after the first phase, the model's performance on the test set was evaluated at the end of both phases. The results, shown in Figure 16, showed that the second phase is important and helps the model generalise better when applied to new images. By unfreezing the encoder, the model can modify 32 Weighted F1- score Micro F1-score (acc) Macro F1-score # Correctly segmented cells U-Net 0.8458 0.7840 0.7863 10,606 HoVer-Net 0.8124 0.7448 0.7327 9452 Figure 26: Table of the evaluation of U-Net’s and HoVer-Net’s inference on the BE HER2 test set. F1-score per class Class 0 Class 1 Class 2 Class 3 Stroma U-Net 0.602 0.865 0.723 0.857 0.885 HoVer-Net 0.470 0.825 0.678 0.827 0.864 Figure 27: Table of the per-class evaluation of U-Net’s and HoVer-Net’s inference on the BE HER2 test set. Taking a deeper look into the confusion matrices, it can be inferred that HoVer-Net tends to predict with higher frequency minority classes, achieving a higher true positive rate (TP) for class 0 and class 2. However, this comes at the expense of significantly increased false positives (FP) when compared to U-Net. This has a negative impact on the F1-score, making it lower than U-Net's even for the minority classes. Furthermore, from the confusion matrices in Figure 28, it can be inferred that both U-Net and HoVer-Net have comparable numbers of segmented cells that have no correspondence in the ground truth. These are represented in the first row of the confusion matrix. U-Net detects 1,051 non-existent cells, while HoVer-Net detects 976 cells. In terms of cells that are missed by the model, i.e., not segmented cells that exist in the GT, HoVer-Net suffers more from this issue, missing 1,016 cells, which represents 8.9% of the total number of cells in the GT. Most of these belong to the stroma class, which is not a significant error, since stroma cells are discarded from the computation of the HER2-score. On the other hand, U-Net, missed 838 cells, representing 7.3% of the total number of cells in the GT. When stroma is excluded from the comparison, U-Net misses more cells in segmentation than HoVer- Net. U-Net confusion matrix HoVer-Net confusion matrix Figure 28: U-Net’s and HoVer-Net’s confusion matrices on the BE HER2 test set. Furthermore, regarding the classification of the models, both U-Net and HoVer-Net tend to confuse cells from contiguous classes, except for the stroma class, which is expected due to the similarity in appearance and shape of these classes. 33 4.1.3.1. Inference examples In this section, the inferences of HoVer-Net and U-Net are visually compared on the HER2 test dataset. In the first example, which corresponds to the highest performing staining in the test set for both models, shown in Figure 29, it can be observed that both U-Net and HoVer-Net are very good at classifying cells from majority classes, such as stroma and class 3. HoVer-Net seems to segment in a more detailed way the cells, while U-Net seems to classify more accurately, as shown in Figure 30. Comparing the confusion matrices in Figure 29, we can see that HoVer-Net fails to segment more frequently. However, while the FN in the background are mostly related to cells wrongly segmented in areas with no GT cells in U-Net, HoVer-Net tends to split big existing cells into two or more cells, instead of inventing inexistent ones in other parts of the image. As we can see in the fragment of Figure 29 shown in Figure 31, HoVer-Net sometimes wrongly divides stroma cells into two cells. Moreover, both HoVer-Net and U-Net are unable to detect the smallest stroma cell in the inferior left corner. Original Ground truth U-Net inference HoVer-Net inference 34 U-Net confusion matrix HoVer-Net confusion matrix Figure 29: “Example 1, best performing staining sample in U-Net”. GT and inference of a tile in the HER2 BE test set, and confusion matrices of the inference. Example 1 Weighted F1-score Micro F1-score (acc) Macro F1-score U-Net 0.950 0.905 0.853 HoVer-Net 0.931 0.882 0.811 Figure 30: Table of the evaluation of U-Net’s and HoVer-Net’s inference on the example 1 tile. GT U-Net HoVer-Net Figure 31: Fragment of Figure 29. Looking at examples from different tiles, such as Figure 32 and Figure 33, the same behaviour can be observed: HoVer-Net often divides big cells into two or more predicted cells, regardless of the cell class. GT U-Net HoVer-Net Figure 32: Fragment of the GT and inference of a tile in the HER2 BE test set. 35 On the other hand, in Figure 33 some cells that are not part of the ground truth are predicted both by U-Net and HoVer-Net. In this example, it can also be observed that U-Net tends to predict classes with a higher presence in the train set, such as class 3, even if the GT is class 2. HoVer-Net suffers from the same issue, especially with the stroma class, the majority class. GT U-Net HoVer-Net Figure 33: Fragment of the GT and inference of a tile in the HER2 BE test set. Furthermore, the following example in Figure 34 is the worst-performing tile for both U-Net and HoVer-Net, which have the highest presence of class 0 cells, the minority class. U-Net is accurate in the most present classes, while HoVer-Net is able to better capture classes with little presence in the image, such as class 2 cells in this example. Original Ground truth U-Net HoVer-Net 36 U-Net confusion matrix HoVer-Net confusion matrix Figure 34: “Example 2, tile with an abundance of class 0 cells, the worst performing”. GT and inference of a tile in the HER2 BE test set and confusion matrices of the inference Example 2 Weighted F1-score Micro F1-score (acc) Macro F1-score U-Net 0.774 0.727 0.663 HoVer-Net 0.707 0.659 0.666 Figure 35: Table of the evaluation of U-Net’s and HoVer-Net’s inference on the example 2 tile. In conclusion, both U-Net and HoVer-Net exhibit clear superior performance in stainings with a high presence of majority classes, but struggle to correctly classify in stainings with a high presence of minority classes. However, it is important to note that in both cases, the models are still able to segment and classify with good quality, even in the worst examples, reaching a minimum weighted F1-score of 0.77 for U-Net and 0.7 for HoVer-Net in the HER2 test set. One notable difference between the two architectures is that HoVer-Net tends to oversegment by splitting large cells into multiple pieces, while U-Net tends to segment non-existent cells. This is considered an advantage of HoVer-Net as it is generally considered an easier issue to fix. Additionally, HoVer-Net provides a more detailed segmentation of the shape of cells, even when the ground truth is represented by ellipses, which suggests it is successful in transferring learning from its pretraining. 4.1.3.2. Conclusions on the HER2 dataset During this analysis, various variations within the HoVer-Net architecture were explored to gain insight into its advantages and disadvantages. Advantages of HoVer-Net include high quality segmentation even when the GT is inaccurate, a good balance of simplicity in implementation and performance, a highly capable encoder that can generalise to new datasets, and resistance to overfitting. Disadvantages include the assumption of balanced classes, which leads to minority classes being predicted more frequently than they should in unbalanced datasets, and a lack of ability to leverage the performance of the model when extending the training dataset with data from different sources. 37 When comparing HoVer-Net with U-Net in the HER2 context, it was found that U-Net exhibits superior classification, with a difference of 0.03 in weighted score compared to HoVer-Net. Additionally, U-Net copes better with unbalanced classes and can use VH data to boost its performance, while HoVer-Net was unable to do so. In terms of segmentation, U-Net is better at cell counting, while HoVer-Net captures the shape of cells in more detail. However, HoVer-Net's cell counting errors are primarily the result of over-partitioning of large cells rather than the detection of non-existent cells, which is more common in U-Net. In conclusion, U-Net's advantages are more suitable for the priorities of the project and the characteristics of the current HER2 dataset. Nevertheless, HoVer-Net has significant advantages that could potentially outperform U-Net if the class imbalance problem was fixed and HoVer- Net was adjusted to avoid over-segmentation of large cells. 4.2. Ki67 This study aims to analyse the performance of HoVer-Net on the Ki67 dataset. The results are then compared to those obtained with U-Net, which is considered to be the state-of-the-art for this problem, using both the evaluation metrics defined in the methods section, and visual inference examples. 4.2.1.U-Net At the conclusion of December 2022, a new dataset of KI67 stainings was generated. To compare the two architectures under consideration, the best-performing model previously developed for the old KI67 data, as identified in Julia Sala's research [16], was evaluated on the new Ki67 dataset. The evaluation results are shown in Figure 36. Weighted F1- score Micro F1- score (acc) Macro F1- score F1-score per class Negative Positive U-Net 0.879 0.801 0.896 0.874 0.918 Figure 36: Table of the evaluation of U-Net’s inference on the Ki67 test dataset. 4.2.2.HoVer-Net This section presents the results of several experiments that were conducted using the HoVer- Net architecture on the newly generated KI67 staining database. The aim of these experiments was to optimise the performance of this model. The following main experiments were carried out: 1) Fast mode 2) Original mode 3) Overfitting analysis To perform these experiments, the previous research findings on the behaviour of HoVer-Net on the HER2 dataset were considered. Specifically, 16 sections of 270x270 of each image were utilised to train the model. The same parameters and configuration were kept throughout the experiment, including the learning rate and decay that were found to be beneficial for the 38 convergence of the model in earlier experiments on the HER2 stainings. These have also proved to work effectively to train the model on KI67 staining data. 4.2.2.1. Fast mode: PanNuke pretrained model The initial experiment was carried out using the same variation of HoVer-Net that was previously used in the HER2 dataset, specifically the fast version of HoVer-Net pretrained on the PanNuke dataset. The evaluation of the inferences on the test set is shown in Figure 37. Weighted F1-score Micro F1- score (acc) Macro F1- score F1-score per class Negative Positive HoVer-Net fast 0.890 0.805 0.885 0.891 0.879 Figure 37: Table of the evaluation of fast HoVer-Net’s inference on the Ki67 test dataset. 4.2.2.2. Original mode: CoNSeP pretrained model As previously described in the methodology section, both the original and fast pre-trained versions of HoVer-Net can be fine-tuned with the Ki67 dataset. The original version has a smaller output size in comparison to the fast version, but the receptive field remains approximately the same. Consequently, it is hypothesised that the original version has the potential to perform better. Thus, in this section, the original version of HoVer-Net is tested and compared with the fast version. Furthermore, an evaluation of the impact of the second training phase in the original mode is also included, and its results are compared with those obtained during the first training phase, where the encoder is frozen. As displayed in Figure 38, the fast version of HoVer-Net pretrained with the PanNuke dataset outperforms the original version in all metrics. However, it is worth noting that the performance of the original version after 29 epochs in the first training phase is very good and is not far from the better-performing result obtained after the second phase. This suggests that the pretrained encoder has the ability to generalise to new datasets, leading to high-quality results within a relatively small number of fine-tuning epochs. Weighted F1-score Micro F1- score (acc) Macro F1- score F1-score per class Negative Positive HoVer-Net fast 0.890 0.805 0.885 0.891 0.879 Hover- Net original 1st phase, epoch 29 0.868 0.771 0.848 0.873 0.823 2nd phase, epoch 44 0.879 0.789 0.862 0.884 0.841 Figure 38: Table of the evaluation of the inference on the Ki67 test dataset, comparing different modes and training phases of HoVer-Net. 39 Fast mode confusion matrix Original mode, first training phase confusion matrix Original mode, second training phase confusion matrix Figure 39: Confusion matrices comparing different modes and training phases of HoVer-Net. 4.2.2.3. Overfitting analysis The presence of overfitting can be detected by comparing the evaluation of the model in the test and training partitions. As illustrated in Figure 40, it is observed that the performance of HoVer- Net in both the Ki67 train and test datasets is comparable. Based on this observation, it can be concluded that there is no evidence of overfitting in this model. Weighted F1-score Micro F1- score (acc) Macro F1- score F1-score per class Negative Positive Fast HoVer- Net Train set 0.896 0.814 0.899 0.894 0.903 Test set 0.890 0.805 0.885 0.891 0.879 Figure 40: Table of the evaluation of fast HoVer-Net’s inference on the Ki67 training and test datasets. 40 Train dataset confusion matrix Test dataset confusion matrix Figure 41: Confusion matrices of fast HoVer-Net’s inference on the Ki67 training and test datasets. 4.2.3.Analysis of the Ki67 dataset The analysis of the Ki67 dataset reveals that it contains almost 20,000 cells, 10% of which belong to the test dataset. Within the test set, as depicted in Figure 42, 11% of the cells are Ki67-positive, and 89% are negative. On the other hand, the training dataset exhibits a distribution of 14% positive cells. Figure 42: Bar plot of the distribution of classes in the KI67 training and test datasets 4.2.4.Comparison of HoVer-Net and U-Net for Ki67 Based on the experiments conducted, it appears that the fast version of HoVer-Net is best suited for the Ki67 dataset. The results from the test set show that HoVer-Net achieved comparable performance with U-Net, even surpassing U-Net based on the weighted F-score metric. However, U-Net is superior in the macro F1-score, which suggests that HoVer-Net is more accurate in the negative class, while U-Net is better in the positive class. 15035 1825 2625 236 0 5000 10000 15000 20000 Train set Test set Number of cells per class Negative Positive 41 Weighted F1- score Micro F1- score (acc) Macro F1- score F1-score per class Negative Positive U-Net 0.879 0.801 0.896 0.874 0.918 HoVer-Net 0.890 0.805 0.885 0.891 0.879 Figure 43: Table of the evaluation of U-Net’s and HoVer-Net’s inference on the Ki67 test dataset. 4.2.4.1. Inference example In this section, a visual comparison of inference for HoVer-Net and U-Net is performed to derive conclusions about the strengths and limitations that cannot be captured by the evaluation metrics alone. Figure 45 illustrates the worst-performing scenario for HoVer-Net in the Ki67 test set, where a high presence of positive cells, the minority class, can be observed. Furthermore, the visual analysis allows us to infer a conclusion previously found in the analysis of the HER2 dataset: HoVer-Net tends to over-partition large cells, resulting in an increase in false positives in the segmentation. However, as shown in Figure 44, HoVer-Net outperforms U-Net in this example by a small difference, providing a slightly more accurate cell classification. Moreover, when comparing both inferences visually, Hover-Net provides a much more detailed and accurate cell segmentation, countering better the cells in the original image. Example 3 Weighted F1-score Micro F1-score (acc) Macro F1-score U-Net 0.833 0.724 0.840 HoVer-Net 0.837 0.727 0.843 Figure 44: Table of the evaluation of U-Net’s and HoVer-Net’s inference on the example 3 Ki67 tile.