scieee AI-readable full text Open interactive document viewer

Convolutional neural networks for cell detection and counting : a case study of human cell quantification in zebrafish xenografts using deep learning object detection techniques

Albuquerque, Carina Isabel Andrade

Abstract

Deep learninghad,inrecentyears,becamethestateofthearttodealwithcomputer vision problems.Onthecomputervisionresearchfield,objectdetectionisatechnique thatallowstolocalizeandclassifyoneormoreobjectsinaninputimage.Thisapproach can beappliedtoseveraltasksandproblems,ascellcountinginmedicalimaging,as proposed inthisthesis. Cellcountingisafrequentlyneededtaskinseveralmedicaltypesofresearch,butof- ten stillmademanuallyduetoseveralconstraints.Theautomationofthisprocesscan be challengingtoachieve,especiallywhendealingwithcellclumpingandoverlapping, and cellsthatcanassumeseveralshapesandsizes.However,doingthisneededpro- cess manuallyturnsouttobeabottleneckconcerningspeedduringtheresearch.As so, anautomatictoolthatallowsresearcherstoquantifycellswithdifferentfeaturesin an accuratewayisalongdesiredapplicationinthemedicalcommunity.Inthisthesis, a fine-tunedarchitecturebasedonFasterR-CNNobjectdetectionalgorithmandIncep- tion ResnetV2featureextractorisproposedtodealwithcellquantificationinzebrafish xenografts,aninnovativeapproachforthestudyofcancer,metastasis,anddrugdiscov- ery,currentlybeingappliedatFundaçãoChampalimaud,worldwidereferenceinonco- logictreatmentinnovation. In thisway,itisshownthepracticalapplicationoftheproposedsolutiontoaddress a problemthatremainsinthecontextofmedicalresearchinFundaçãoChampalimaud, where ateamofresearchersexplorestheapproachofcellcountingandhistologicalanal- ysis inzebrafishlarvaexenotransplantstoevaluatetheresponseoftherapiesincancer. As so,thisthesisaimstobeacontributiontotheapplicationofobjectdetectiontech- niques tocellcountingtasks,andaddressseveralproblemsusuallyassociatedwiththis process, asthepresenceofoverlappedcells,thehighnumberofobjectstobedetected and theheterogeneityofcellsconcerningsizeandshape.

Full text

i Convolutional Neural Networks for Cell Detection and Counting Carina Isabel Andrade Albuquerque A Case Study of Human Cell Quantification in Zebrafish Xenografts using Deep Learning Object Detection Techniques Dissertation presented as partial requirement for obtaining the Master’s degree in Advanced Analytics NOVA Information Management School Instituto Superior de Estatística e Gestão de Informação Universidade Nova de Lisboa Convolutional Neural Networks for Cell Detection and Counting A Case Study of Human Cell Quantification in Zebrafish Xenografts using Deep Learning Object Detection Techniques by Carina Isabel Andrade Albuquerque Dissertation presented as partial requirement for obtaining the Master’s degree in Advanced Analytics Advisor: Leonardo Vanneschi Co Advisor: Roberto Henriques November 2018 ACKNOWLEDGEMENTS This thesis would have been impossible without the support and mentoring of my advisors, Leonardo Vanneschi and Roberto Henriques. More than words of wisdom, they also show me the importance of endurance and persistence, and more than mentors, they also have been friends with the right words at the right times. Thank you for your ongoing confidence. A special thank you to Professor Roberto Henriques for all the given opportunities during this academic path. I would also like to express my gratitude to Professor Vitor Santos and Professor Mauro Castelli for the altruist advice, words of enlightenment and support given, and to the many professors who have advised me along the way. I am grateful to Fundação Champalimaud for the chance of working with them and for giving me the needed "ingredients" to work on in this thesis. A special thank you to Nickolas Papanikolaou, Vanda Póvoa, Rita Fior and José-Maria Moreira for all the patience and transmitted knowledge. This research has been supported by Microsoft, who I would like to thank for giving me the needed tools to work in this thesis. Without this support, the present project would not be more than one idea. Thank you to Professor Henrique Carreiro for letting me know about this sponsorship. To my parents, my brother and my sister in law, because they were the ones who suffer most this path with me. A special thanks to my brother for reminding me that for every problem there is always a turn way around, and to make me see further. And to my parents, for years of patience and full support in my decisions, all the love, and guidance. To Vera Trindade and António Trindade, by all the extra night coffees, friendship, patience, company, support, words of wisdom, pressure, confidence, and so many other things. To Fábia Ribeiro and Maira Perdigão, for being my inspiration source for so many times, and to André Rodrigues for all the support. To Sofia Pinto, the most bright person that I have been proud to meet, and the one that crossed this path with me. Thank you for all the hugs! I would also like to thank for the precious advice from Renier Botha (last minute advice but of great value), Illya Bakurov, Paulo Lapa, Leonardo Custode, Ciro Tecce, Bruno Damásio and Jan Benedikt. I could not be more grateful to the people mentioned, and so many other friends who I am lucky to have and people that I know, who crossed my life and who walked with me I and lead me to the path where I am today. Thank you for all the support, for the belief in me, and all the words of enlightenment. This thesis is a product of several convolutions combining data and information obtained in 32 years of experiences, mistakes, inspiration, fortunate events and marvelous and bright people. It was an incredible, sometimes tough, but totally worthwhile, journey. Finally, I am grateful for life and all the opportunities I had. II "If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton ABSTRACT Deep learning had, in recent years, become the state of the art to deal with computer vision problems. On the computer vision research field, object detection is a technique that allows to localize and classify one or more objects in an input image. This approach can be applied to several tasks and problems, as cell counting in medical imaging, as proposed in this thesis. Cell counting is a frequently needed task in several medical types of research, but often still made manually due to several constraints. The automation of this process can be challenging to achieve, especially when dealing with cell clumping and overlapping, and cells that can assume several shapes and sizes. However, doing this needed process manually turns out to be a bottleneck concerning speed during the research. As so, an automatic tool that allows researchers to quantify cells with different features in an accurate way is a long desired application in the medical community. In this thesis, a fine-tuned architecture based on Faster R-CNN object detection algorithm and Inception Resnet V2 feature extractor is proposed to deal with cell quantification in zebrafish xenografts, an innovative approach for the study of cancer, metastasis, and drug discovery, currently being applied at Fundação Champalimaud, worldwide reference in oncologic treatment innovation. In this way, it is shown the practical application of the proposed solution to address a problem that remains in the context of medical research in Fundação Champalimaud, where a team of researchers explores the approach of cell counting and histological analysis in zebrafish larvae xenotransplants to evaluate the response of therapies in cancer. As so, this thesis aims to be a contribution to the application of object detection techniques to cell counting tasks, and address several problems usually associated with this process, as the presence of overlapped cells, the high number of objects to be detected and the heterogeneity of cells concerning size and shape. Keywords: Deep Learning, Faster R-CNN, Cell Counting, Machine Learning, Neural Networks, Computer Vision, Object Detection, Convolutional Neural Networks, Inception ResNet V2 III 6.12 Choosing the best model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 6.13 Use the final models in a new dataset partition . . . . . . . . . . . . . . . . 99 7 Final model 101 8 Test evaluation 107 9 Final application 112 10 Conclusions, limitations and future work 114 10.1Conclusions ....................................114 10.2Limitations.....................................116 10.3Futurework ....................................116 IX List of Figures 2.1 Schema of a hierarchical sequence of categorical representations processingafaceinputstimulus ............................. 14 2.2 The main components of a CNN . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3 Different 3x3 kernels applied to the raw image. . . . . . . . . . . . . . . . . 16 2.4 Illustration of how max pooling and average pooling significantly reduces parameters as we move up the network . . . . . . . . . . . . . . . . . . . . . 17 2.5 Activation functions widely used in ANN . . . . . . . . . . . . . . . . . . . 20 2.6 SSD architecture where we verify that this model adds several feature layers to the end of a base network, which predicts the offsets to default boxes of different scales and aspect ratios and their associated confidences [30]. . 22 2.7 Architecture of R-CNN [11] . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.8 Architecture of Fast R-CNN [10] . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.9 The region proposal network system [44] . . . . . . . . . . . . . . . . . . . . 24 2.10 Architecture of Faster R-CNN [44] . . . . . . . . . . . . . . . . . . . . . . . . 24 2.11 Architecture of LeNet-5 [28] . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.12 Architecture of AlexNet [27] . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.13 Architecture of ResNet 50 and the concept of residual block [17] . . . . . . 26 2.14 Architecture of GoogleNet/Inception [53] . . . . . . . . . . . . . . . . . . . 27 3.1 Overview of Faster R-CNN process . . . . . . . . . . . . . . . . . . . . . . . 30 3.2 Effect of image resolution in the overall mAP using different meta-architectures [20] ......................................... 31 X 3.3 Accuracy stratified by object size, meta-architecture and feature extractor, with an image resolution of 300 pixels [20] . . . . . . . . . . . . . . . . . . . 32 3.4 Illustration of the interpolation applied using different methods where the input is a 2x2 matrix and the output a 3x3 matrix . . . . . . . . . . . . . . . 33 3.5 TheIoUconcept.................................. 44 4.1 Arawimageexample............................... 50 4.2 The process of labeling images using labelImg . . . . . . . . . . . . . . . . . 51 4.3 Distribution of the quantity of cells per image . . . . . . . . . . . . . . . . . 54 4.4 Density of cells according to their width and height . . . . . . . . . . . . . . 56 4.5 Frequency of cells according to their ratio . . . . . . . . . . . . . . . . . . . 57 4.6 Possible aspect ratios taking into account the ratio distribution . . . . . . . 57 5.1 Basicflowdiagram ................................ 59 6.1 mAP using different meta-architectures . . . . . . . . . . . . . . . . . . . . 63 6.2 mAP using different feature extractors . . . . . . . . . . . . . . . . . . . . . 64 6.3 Architecture of the Inception Resnet v2 applied on the present project . . . 65 6.4 Freezing the layers in transfer learning . . . . . . . . . . . . . . . . . . . . . 67 6.5 mAP depending on the dimension of the input image . . . . . . . . . . . . 68 6.6 mAP using different resize methods . . . . . . . . . . . . . . . . . . . . . . . 70 6.7 mAP using differentoptimizers ......................... 73 6.8 mAP using different initial learning rates (100000 decay steps) . . . . . . . 74 6.9 mAP of the five final models . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 6.10 mAP of the model "Best MEDAE" using the two partitions . . . . . . . . . . 100 6.11 mAP of the model "Best RMSE & MAE" using the two partitions . . . . . . 100 7.1 Losses for the model "Best RMSE & MAE" with the original partition . . . . 101 7.2 Losses for the model "Best RMSE & MAE" with the final partition . . . . . . 102 7.3 Losses for the model "Best MEDAE" with the original partition . . . . . . . 103 7.4 Losses for the model "Best MEDAE" with the final partition . . . . . . . . . 103 8.1 Ground truth labeling and infered detections for images with Low, Medium andHighcomplexity ...............................110 XI 9.1 Initial screen of the application "CellCounter" . . . . . . . . . . . . . . . . . 112 9.2 Making inferences in the application "CellCounter" . . . . . . . . . . . . . . 113 XII List of Tables 3.1 Guidelines for transfer learning . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.1 Datapartition ................................... 52 4.2 Descriptive statistics related to the number of cells in input images . . . . . 54 4.3 Descriptive statistics related to the width and height of cells present on inputimages.................................... 55 6.1 mAP and speed using different meta architectures . . . . . . . . . . . . . . 63 6.2 mAP and speed using different feature extractors . . . . . . . . . . . . . . . 64 6.3 mAP and speed by using transfer learning . . . . . . . . . . . . . . . . . . . 66 6.4 Total losses, RPN losses in validation, mAP and speed of training for 3000 steps using different input images dimensions . . . . . . . . . . . . . . . . . 69 6.5 Training loss and speed using image normalization . . . . . . . . . . . . . . 70 6.6 Training loss and speed using grayscale images . . . . . . . . . . . . . . . . 71 6.7 mAP and speed using different batch sizes . . . . . . . . . . . . . . . . . . . 72 6.8 mAP and speed using different optimizers . . . . . . . . . . . . . . . . . . . 73 6.9 mAP according to the decay steps (initial LR of 0.0002) . . . . . . . . . . . 74 6.10 mAP using different data augmentation techniques . . . . . . . . . . . . . . 75 6.11 mAP according to the gradient clipping value . . . . . . . . . . . . . . . . . 76 6.12 mAP, speed and RPN losses depending on the stride of the feature extractor 78 6.13 mAP and speed depending on the use of the batch normalization . . . . . . 78 6.14 mAP and speed depending on the aspect ratio of the anchors . . . . . . . . 79 6.15 Width and height of the cells rescaled to the new image resolution . . . . . 80 XIII 6.16 mAP and speed according to different scales used in anchor generator . . . 80 6.17 mAP and speed according to different scales and aspect ratios used in anchorgenerator.................................. 81 6.18 mAP and speed according to the different strides applied on anchor generator........................................ 81 6.19 mAP and speed depending on the use of atrous rate . . . . . . . . . . . . . 82 6.20 mAP and speed using different regularizers during the first stage of the objectdetector................................... 82 6.21 mAP and speed according to the activation used in the first stage . . . . . . 83 6.22 mAP and speed depending on the use of batch normalization in the first stage......................................... 83 6.23 mAP and speed by using depthwise regularization on the first stage . . . . 83 6.24 mAP and speed according to the kernel size of box predictor . . . . . . . . 84 6.25 mAP and speed according to the depth of box predictor . . . . . . . . . . . 84 6.26 Total loss, RPN Validation Loss, mAP and speed depending on the size of theminibatch ................................... 85 6.27 Total loss, RPN Validation Loss, mAP and speed depending on the positive balancefraction .................................. 85 6.28 Total loss, Box Validation Loss, mAP and speed according to the IoU thresholdused....................................... 86 6.29 Total loss, Box Validation Loss, mAP and speed based on the number of proposals...................................... 86 6.30 mAP and speed changes using different combinations of localization and objectnesslossweights .............................. 87 6.31 mAP and speed according to the initial crop size . . . . . . . . . . . . . . . 88 6.32 mAP and speed according to the maxpool kernel size . . . . . . . . . . . . . 88 6.33 mAP and speed using different regularizers during the second stage of the objectdetector................................... 89 6.34 mAP and speed according to the activation used in the second stage . . . . 89 6.35 Total Loss, Box validation loss, mAP and speed depending on the use of batch normalization in the second stage . . . . . . . . . . . . . . . . . . . . 90 XIV 6.36 Total Loss, Box validation loss, mAP and speed by using depthwise regularization on the second stage . . . . . . . . . . . . . . . . . . . . . . . . . . 90 6.37 Total Loss, Box validation loss, mAP and speed by using dropout . . . . . . 91 6.38 Total Loss, Box validation loss, mAP and speed according to the IoU threshold.......................................... 92 6.39 Total Loss, Box validation loss, mAP and speed according to to maximum detections...................................... 92 6.40 Total Loss, Box validation loss, mAP and speed changes using different combinations of localization and classification loss weights . . . . . . . . . 93 6.41 Total Loss, Box validation loss and mAP using different classification losses 93 6.42 Regression metrics and mAP for different configurations in training and data augmentation parameters, where the symbol *represents the default modelforFasterR-CNN ............................. 94 6.43 Regression metrics and mAP for different configurations in some of the first stage parameters, where the symbol *represents the default model forFasterR-CNN ................................. 95 6.44 Regression metrics and mAP for different configurations for the remaining first stage parameters, where the symbol *represents the default model forFasterR-CNN ................................. 96 6.45 Regression metrics and mAP for different configurations for the second stage parameters, where the symbol *represents the default model for FasterR-CNN ................................... 97 6.46 Main results of five final models . . . . . . . . . . . . . . . . . . . . . . . . . 98 6.47Finaldatapartition ................................ 99 7.1 Inference and Regression metrics for model "Best RMSE & MAE" - Low complexity".....................................104 7.2 Inference and Regression metrics for model "MEDAE - Low complexity" . . 104 7.3 Inference and Regression metrics for model "Best RMSE & MAE" - Medium complexity.....................................105 7.4 Inference and Regression metrics for model "Best MEDAE" - Medium complexity .......................................105 XV 7.5 Inference and Regression metrics for model "Best RMSE & MAE" - High complexity.....................................106 7.6 Inference and Regression metrics for model "MEDAE" - High complexity . 106 8.1 Test Dataset for levels "Low", "Medium" and "High" . . . . . . . . . . . . . . 107 8.2 Results on test dataset - predicted vs. ground truth for low level using model "Best MEDAE" for a threshold of 0.9 . . . . . . . . . . . . . . . . . . 107 8.3 Results on test dataset - predicted vs. ground truth for medium level using model "Best RMSE & MAE for a threshold of 0.4 . . . . . . . . . . . . . . . 108 8.4 Results on test dataset - predicted vs. ground truth for high level using model "Best RMSE & MAE for a threshold of 0.2 . . . . . . . . . . . . . . . 108 8.5 Regression metrics results on test evaluation . . . . . . . . . . . . . . . . . . 109 8.6 Descriptive statistics associated to the error encontered on the different levelsofcomplexity................................109 XVI Nomenclature ACRONYMS / ABBREVIATIONS ANN Artificial Neural Network CNN Convolutional Neural Network DNN Deep Neural Network GA Genetic Algorithms GAN Generative adversarial network FC Fully convolutional IoU Intersection over Union mAP Mean average precision NN Neural network ReLU Rectified linear unit RGB Red-Green-Blue RFCN Region-based fully convolutional network MAE Mean absolute error MedAE Median absolute error XVII MSE Mean squared error R-CNN Region-based convolutional neural network RNN Recurrent neural network RPN Region proposal network ROIs Regions of interest SSD Single shot detector e.g. Exempli gratia ("for the sake of an example") i.e. Id est("it is") w.r.t. With respect to XVIII 2 Theoretical Background 2.1 Machine Learning and Neural Networks The field of machine learning is focused on developing computer programs that automatically improve with experience [32]. The concept was defined in 1959 by Arthur Samuel as "the field of study that gives computers the ability to learn without being explicitly programmed" [47]. In the last two decades, the machine learning activities evolved significantly due mainly to the increase of computational power and GPU acceleration, and the rise of large repositories of data, being almost ubiquitous nowadays. In the past decade, machine learning was responsible for the emergence of automatic cars, speech recognition tools, web optimization and other numerous applications across several fields of study. Regarding machine learning systems, we can classify them taking into account the amount and type of supervision they get during training into four different concepts: 1. Supervised learning - The training data includes the ground truth, i.e., the desired solutions, also called labels. Those labels were usually defined by humans, and the algorithm is able to predict the label for the unseen data. Common tasks in this field are classification and regression. In the case of object detection, training images that were previously annotated mark the locations and the classes of meaningful objects. 2. Unsupervised learning - In unsupervised learning, the training data is unlabeled, and the system tries to learn without guidance. The most relevant algorithms applied in this field are clustering, the visualization and dimensionality reduction, 7 and the association rule learning. The major goal of unsupervised learning is to discover patterns in unlabeled data. 3. Semi-supervised learning - In semi-supervised learning, the training data is composed partially (usually in small proportions) with labeled data. It is a combination of both labeled and unlabeled data to train the model. 4. Reinforcement learning - In reinforcement learning, the learning system, denominated as agent, select and perform actions in an environment, getting rewards in return, or penalties as negative rewards, which allows him to learn by itself, and able to identify the best strategy possible in order to get the most rewards. In this field, we can include genetic algorithms, swarm intelligence and many other disciplines. 2.1.1 Neural Networks and backpropagation The most basic structure of the artificial neural network (ANN) is the linear perceptron. Resembling the brain neurons, an ANN is composed of nodes linked to each other whose function is to receive, process and transmit information. A linear perceptron receives several inputs and performs a weighted summation to produce an output. The weights are determined during the training process and based on the training data. This training can be done through gradient-based methods, and the output of the perceptron can be passed through an activation function [49]. In order to deal with non-linear separable patterns, one of the limitations of the single perceptron, the multi-layer perceptron (MLP) was developed by adding more layers to the network. This class of ANN uses a supervised learning algorithm denominated as backpropagation to learn. The learning is achieved during the training, which is composed of two main phases: 1. The forward pass - The weight of each connection and the biases are already defined, and the input signal is propagated through the network until it ends. In the output, the error is calculated by comparing the output value of the network with the ground truth. 2. The backward pass - The error is propagated backward through each network layer, and adjustments are made to the weights and the biases in order to minimize 8 the error, by using gradient descent, an iterative optimization algorithm, which role is to minimize the cost function. 2.1.2 Generalization of a model, underfitting and overfitting problems The power of a learning algorithm is highly associated with its capability to generalize, i.e., to handle unseen data. There is no use of creating a model that is only able to deal with the instances that were used for its training. Together with the generalization concept, we can introduce two situations that are common while training a model: underfitting and overfitting. The underfitting can occur when the model trained is too simple to learn the underlying structure of the data, and fails to capture significant variables of the reality of the situation that we are trying to model. On the other hand, overfitting happens in the other way around, usually in the presence of complex models, giving more relevance to unimportant details and noise. Both situations lead to cases of lousy generalization, and they should always be avoided. In case of underfitting, several strategies can be applied in order to fix it, like selecting a more powerful model, with more parameters, feeding better features to the learning algorithms (a.k.a. feature engineering) [8], or reducing the constraints on the model, by reducing, as for example, the regularization hyperparameter. In the case of overfitting, some strategies can be applied, such as simplification of the model, reduction of the number of parameters (the use of more parameters tend to lead to a model prone to overfitting), gathering more training data (using, for example, data augmentation techniques), among others. The performance of an algorithm is measured by the quality and quantity of the errors. In order to measure this, one or more loss function are used, that could differ taking into account the type of the problem that we are dealing with. The primary goal during the training phase is to decrease as maximum as possible this loss. [8] 2.1.2.1 Avoiding overfitting When dealing with neural networks, we typically have thousands, if not millions, of parameters. The advantage of this is that the networks gain a huge amount of flexibility and can fit several problems and complex datasets. On the other way around, the great amount of freedom comes with the disadvantage of easily overfitting the training set. In order to prevent or to delay the overfitting when training, several approaches were 9 proposed: early stopping, l1and l2regularization, dropout, max-norm regularization, data augmentation, transfer-learning, reducing the number of parameters by reducing the complexity of networks and others. Usually, different methods are combined in order to prevent overfitting. Early stopping As the name suggests, the early stopping is the simple technique of stop training our model as soon as we achieve a status of overfitting, i.e., as soon as the performance on the validation set starts dropping. l1and l2regularization The l1and l2regularization will allow to constrain a neural networks’ connection weights. The L1 regularizer, as presented in equation (2.1), adds a penalty term to the cost function using the sum of absolute values. The L2 regularizer, shown in equation (2.2), adds a squared magnitude of coefficient as a penalty term to the loss function. Cost =Lossf unction +λ M X j=0 Wj(2.1) Cost =Lossf unction +λ M X j=0 W2 j(2.2) The main difference between L1 and L2 regularization is that the first one shrinks the less important feature’s coefficient to zero, allowing to remove those features, working as a feature selector. On the other hand, the L2 regularizer allows achieving a stable solution, even not so robust as the L1 regularizer [49]. Dropout The dropout technique was proposed by G.E. Hinton in 2012 [19] and detailed by Nitish Srivastava et al. [51]. In the dropout technique, at every training step, every neuron (including the input ones) have a probability associated of being "dropped out" in that step,i.e., to be ignored, but can be active on the next one. The dropout technique is defined by the hyperparameter p(the dropout rate). The dropout is only applied to the training phase. Max-Norm Regularization The max-norm regularization enforces an absolute threshold on the magnitude of the weight vector for each neuron, using projected gradient descent to enforce the constraint. In this way, if the weight exceeds a specific value, the 10 max-norm regularizer will scale the whole weight matrix by a factor in order to reduce the norm to the value of the threshold defined. Contrarily to L1 and L2 regularizers, in max-norm the regularization is made directly and not by penalization. [48]. Data augmentation The data augmentation is the process where new instances are created from the existing ones (usually on the fly in order to avoid waste of storage). Several techniques can be applied, like rotation, zoom, change in channel colors, change on the hue and saturation. Those approaches will introduce noise to the training process and force the model to be more tolerant to the possible changes in the images like position, orientation, and size of the picture, allowing the model to become more robust. On the other hand, this could be a useful process when dealing with smaller datasets, since it artificially boosts the size of the training set. 2.2 Deep learning Deep learning can be considered as a subset of machine learning algorithms that uses artificial neural networks. It has a diverse and wide range of applications, and seek to simulate human brain processing in tasks as visual recognition, natural language processing, and speech recognition. This concept emerges from the necessity of adding more layers to neural networks as a way to deal with more complex problems. However, adding more layers came with the problem of vanishing gradients, where the gradient tends to get smaller on the backward process, leading to poor solutions. The inclusion of innovative activation functions appears as a way to address this problem, allowing to add more layers to a network, and leading to the concept that nowadays is called Deep Learning. 2.2.1 Deep learning for computer vision and the object detection problem By applying deep learning to the field of computer vision, the aim is to simulate the properties of the human vision on a computer. Different problems arise from this field, that can be solved using different techniques of deep learning. Image classification Image classification takes as input an image and predicts the object of that image. The goal is to label the whole image with an object or concept. 11 Object detection Object detection goes further, and introduces the concept of location of that object in the image. In that way, object detection at a high level can be seen as a mix between two tasks: predict bounding boxes constituted by 4 variables (x and y coordinates, width and height) that will allow to uniquely identify a rectangle that circumscribes the object and the classification of the object inside the selected bounding boxes. The object detection approach is modeled as a classification problem where several windows of fixed sizes in the input image are defined at different locations, and those patches are fed into an image classifier. In order to create an object detection model, the first step is to have labeled data. In the present context, we refer to labeled data annotations of the coordinates of bounding boxes that correspond to a specific object we want to detect and the labels associated. Semantic segmentation The segmentation problem can be seen as an extension to the object detection problem since it is considered a pixel-wise classification task. The most known architectures to solve this problem at this moment are SegNet, DeepLab, RefiNet, PSPNet, UNET, among others [49]. Similarity learning When applying deep learning on the task of similarity, the aim is to learn how two images are similar. A few architectures have been proposed for this purpose, namely FaceNet, DeepNet, DeepRank, among others [49]. Image captioning In image captioning, the goal is to describe an image with text. In this case, techniques of natural language processing and computer vision are combined [49]. Generative models The purpose of generative models is to generate images as the name implies. Besides creating new images using style transfer, other purposes can exist when using this kind of technique: creating new images to serve as a sample for training, create super-resolution images and others [49]. Video analysis Video analysis can have several applications like sports tracking, intrusion detection, and surveillance cameras [49]. 12 2.3 CNNs Convolutional Neural Networks (CNNs), a subcategory of ANNs, have been proven highly effective in several areas such as image recognition and classification. On computer vision field, an image is taken as input, and that image will be passed through a series of convolution operations that ends up in a subsequent classification. These individual layers will learn particular structures to extract, and those features will become more complex as deeper as they go through the network, starting from simple edges to complex textures and arrangements. 2.3.1 The biological inspiration CNNs have as basis inspiration the visual cortex in animals, and its history begin with the neurophysiologists David Hubel and Torsten Wiesel that were able to determine the most basic facts about mammalian vision system works, and to identify the nucleus in the visual cortex whose job was to detect features like edges from the visual information, and denominated as primary visual cortex(V1) [14]. Higher level nucleus tends to detect more complex features, as seen in figure 2.1. The cells in the visual cortex are sensitive to small sub-regions of the input, and those smaller sub-regions are tiled together to cover the entire visual field. In convolutional networks, the idea is similar: an architecture is designed that resembles the organization of information in the human visual system simplistically. We try to extract features from an image and then classify those features. 13 Figure 2.1: Schematic of a hierarchical sequence of categorical representations processing a face input stimulus. In the first level, detection of elementary structures is made, like edges and lines. The higher the level, the more complex will be the visual features, which are arranged by combining processes, until the last level where "semantic" categories are associated with detections [36]. 2.3.2 The architecture of a CNN In a CNN we deal with an input and an output layer, as several hidden layers, as shown in figure 2.2. The input layer is going to be input images that we are going to analyze. The hidden layers are usually composed of convolutional layers, pool layers, and fully connected layers. Figure 2.2: The main components of a CNN In the following section, each type of layer is defined in further detail. 2.3.3 Main layers in a CNN Input layer The input layer is an image with the dimensions [width x height x depth]. The depth corresponds to the color channels of the images: in the presence of a color image, it is constituted by three channels (RGB), while on a grayscale image the depth 14 will be one. We can consider an image as an array of pixels where the elements are values that range between 0 and 255. During training, each input image will be passed several times through the network. Convolutional layer Convolutions are one of the essential operations in image processing. In an abstract level, convolution is a mathematical operation that allows merging two sets of information. We can apply convolutions in inputs of 1D (e.g., speech processing), 2D (e.g., image processing) and 3D (e.g., video processing). When applied to images, the primary purpose of convolution operations is to extract features, and in that way, we can consider the convolutional layer as the core buildings of CNNs. A convolutional layer is a layer that applies different convolutions in the data that receives. Each convolution operation is composed by a kernel/filter, a matrix smaller than the original input in height and width and extended over the entire depth of the input volume, that will slide through the input horizontally and vertically. The stride will define this movement behavior, and the matrix obtained after this process is denominated as a feature map. The more different filters used, the more features are extracted, which can have a high impact on the performance of the model but will also add constraints to the practicability of the training regarding speed and complexity. As so, the size of the feature map is defined by: 1. Depth / Channels(K) - The number of filters used. One convolutional layer can have multiple input channels and multiple output channels (a 2D matrix). 2. Stride (S) - The number of pixels that a kernel slides over the input matrix. The convolutional layer can have different values of stride for horizontal and vertical sliding, but commonly they assume the same value. 3. Zero padding (P) - The process of padding the input matrix with 0s around the border, a strategy often used to mantain the height and the width for the output matrix (and consequently build deeper networks), and that improves performance by keeping information of the image borders [14]. 4. Filter size (F) - The size of the filter refers to the dimensions of the filter/kernel in the convolutional network. 15 The dimension of the output convolution concerning the width (Wout), height (Hout) and depth (Dout) can then be calculated as [1]: Wout =Win −Fw+ 2P Sw + 1 Hout =Hin −Fh+ 2P Sh + 1 Dout =K where wand hstand for width and height, respectively. In figure 2.3 we can verify the different effects obtained by using a 3x3 kernel with different values to a input image. Figure 2.3: Different 3x3 kernels applied to the raw image. From left to right: Top - Raw Image, [[-0.0625, 0.125, 0.0625],[0.125, 0.25, 0.125],[0.0625, 0.125, 0.0625]],[[-1,2,1],[0,0,0],[1,2,1]]; Bottom:[[-2,-1,0],[-1,1,1],[0,1,2]],[[0,-1,0],[-1,5,- 1],[0,-1,0]],[[1,2,1],[0,0,0],[-1,-2-1]] Pooling layer The pooling layers are responsible for reducing the dimensionality of the convolutional layers output and try to make the representation robust to small input translations and variances. In convolutional neural networks, the pooling layers are usually inserted between successive convolutional layers in order to reduce the dimension of the feature maps and consequently reduce the number of parameters and computation in the network in a way that also allows controlling overfitting. [39] The most common approach used in pooling is max pooling, i.e., for each tile, it is computed the maxi- 16 In R-CNN, whose workflow is shown in figure 2.7, a selective search method was used to propose regions of potential interest by grouping the color and texture of windows, producing in the end around 2000 region proposals. The main drawbacks were related to the vast quantity of the region proposals which would imply several inferences, the fact that there was no training end-to-end and the requirement of three classifiers, which increases the number of parameters significantly [49]. Figure 2.7: Architecture of R-CNN [11] In Fast R-CNN, presented in figure 2.8, some of the drawbacks of the last model were surpassed. The CNN inference is applied only once, and its output is used to propose bounding boxes. In this way, a new concept was introduced, the Region of Interest Pooling, which takes features from the CNN and pools them in order to select regions of interest. This allows having an end-to-end training, avoiding the multiple classifiers needed in the previous version. The main drawback is the use of a selective search to find regions, which is time consuming [49]. Figure 2.8: Architecture of Fast R-CNN [10] The Faster R-CNN, presented in figure 2.10, will eliminate the need of using selective search by using CNN features of the architecture for proposals. Those features are passed through the region proposal network, shown in figure 2.9. A sliding window is passed 23 through different anchor boxes, using different aspect ratios, and outputs a score of the feature [49]. This approach will be detailed in section 3. Figure 2.9: The region proposal network system [44] Figure 2.10: Architecture of Faster R-CNN [44] 24 2.4.3 RFCN [3] RFCN was presented in 2016 as a new approach that claims to be faster than Faster R- CNN since the region-based detector is fully convolutional with almost all computation shared on the entire image, by proposing a position sensitive score maps to address the problem between translation-invariance in image classification and translation-variance in object detection [3]. 2.5 The feature extractor 2.5.1 Classical Networks LeNet-5 LeNet [28] was proposed in 1998 by Yann LeCun, the actual Director of AI research at Facebook, as a system to recognize handwritten digits. This network took as input images of 32 x 32 pixels, passing through a convolutional layer(C1), and then to a subsampling layer (S2), which nowadays is replaced by a pooling layer. Figure 2.11: Architecture of LeNet-5 [28] AlexNet AlexNet was proposed in 2012 [27], and introduced the usage of different techniques that proved as useful when dealing with computer vision problems, as the utilization of dropout to reduce overfitting and the implementation of data augmentation techniques. Now obsolete due to the emergence of new architectures more powerful and faster, the AlexNet was a pioneer in this field. With only eight layers, AlexNet has 60 million parameters in total. [49] 25 Figure 2.12: Architecture of AlexNet [27] 2.5.2 Resnet The Residual networks, also known as ResNets, were introduced by Microsoft in 2015, with the architecture ResNet50 [17]. This network introduced the subject of skipping connections in CNNs, a concept denominated as residual blocks, where some activations from one layer are fed into a deeper layer, which allows increasing the number of layers in the network efficiently. [48] Figure 2.13: Architecture of ResNet 50 and the concept of residual block [17] 2.5.3 Inception GoogleNet/ Inception [53] was presented in 2015 and introduced the concept of inception module, that reduced the number of parameters, even with 22 layers of depth. The network was constituted by nine inception modules, with a total of 100 layers on them. Inception modules create micro-architectures inside the macro-architecture of the net- 26 work, where operations happen in parallel, and filters are applied to the output to allow dimensionality reduction [49]. The number of parameters compared to AlexNet was reduced over than 12 times less, and this leads to a decrease in memory usage and an increase in the speed of the training. [48]. Figure 2.14: Architecture of GoogleNet/Inception [53] 2.5.4 Inception Resnet [52] The Inception Resnet takes as basis the Inception architecture and introduces a hybrid version with Resnet by applying residual blocks on the architecture. It was found by the authors that Inception-Resnet models were able to achieve higher accuracies at a lower epoch. 2.5.5 NASnet [58] Nasnet was proposed in 2017, and it was developed by making use of search methods to find good convolutional architectures on a dataset of interest. Inspired by the Neural Architecture Search (NAS) framework, the authors developed a architecture by "searching" a good system on a proxy smaller dataset (CIFAR-10), and then the learned architecture was transferred to a larger dataset (IMAGENET), making use of the concept of scalable architectures, and introducing the concept of flexibility of architectures that can be scaled in terms of computational cost and parameters to address a variety of problems easily. The authors claim that the accuracy of the resulting model exceeds all human-designed models until the article date. 27 3 The Faster R-CNN stages, parameters and hyperparameters: a theoretical introduction 3.1 Introduction to Faster R-CNN 3.1.1 Quick overview Like any other object detection algorithm, the purpose of faster R-CNN is to obtain, from an input image, three types of information: 1. A list of bounding boxes, that will correspond to the detected objects in an image; 2. A label, i.e., a classification of the content, assigned to each bounding box; 3. A probability for each label in a bounding box. The input images are converted to tensors whose shape will be [height x width x depth] and will be passed through a CNN until an intermediate layer composed by a convolutional feature map. Afterward, a Region proposal Network (RPN) is applied, where the features achieved on the previous step will be used in order to find up a pre-defined number of regions that could contain objects, which will be called Regions of Interest (ROIs). This is achieved by recurring to anchors, which are fixed size reference bounding boxes placed uniformly through the input image. For each anchor, two losses are calculated: 1. The RPN objectness loss, where it is measured if a box contains, or not, an object. 2. The RPN localization loss, where regression is used in order to evaluate the accuracy between the coordinates (x0, y0, width, height) of a bounding box and the ground truth. 28 After obtaining a list of possible objects and their locations from the original image, and by using the features extracted by the CNN and the final bounding boxes defined in the RPN phase, all accepted proposals get reshaped to a fixed size, in a process denominated as Region of interest Pooling, in order to extract those features which will correspond to the relevant objects into a new tensor. Finally, a R-CNN module is applied, where two new losses are computed for each bounding box: 1. The box classifier localization loss, where a new regression is calculated in order to improve the fit of the bounding box to the ground truth. 2. The box classifier classification loss, where classification of the content is made. In this way, we can say that the object detection algorithms, and more specifically, the faster R-CNN architecture, is composed of two main stages: 1. Region proposal – While processing an input image, it should identify all the possible locations where objects can be found. The output of this stage will be a list of bounding boxes of likely positions of objects, which we denominate as region proposals or regions of interest. 2. Final classification – For every region proposal defined on the previous step, we apply a deep convolutional network that will allow to classify it as a background or as a specific class of object. In the first phase, several region proposals should be generated, more than the number of the objects itself on the image. Otherwise, if an object is not detected during this step, it will not suffer the second phase process, and it will not be classified. The high recall needed in this step is achieved by generating a large number of proposals, and most of them will eventually be classified as background in the second phase of the algorithm. This demanding process can be computationally expensive, concerning processing and speed. The described workflow can be seen in figure 3.1. 29 Figure 3.1: Overview of Faster R-CNN process 30 3.2 Faster R-CNN step by step 3.2.1 The pre-processing 3.2.1.1 Image resizing When dealing with images of small resolution, the detection accuracy can be significantly reduced. In [20], the authors verify that decreasing resolution by a factor of two in both dimensions reduce accuracy by 15,88% on average, but also lowers inference time by a factor of 27.4% on average. One of the reasons pointed by the authors for this effect is that high-resolution images allow the detection of small objects, one of the main limitations of the existent object detection meta-architectures. The figure 3.2 compares the performance of detectors on large objects (input images of 600x600 pixels) against small objects (input images of 300x300 pixels), confirming that high-resolution images improve the mAP (mean Average Precision) results significantly. This difference is more notorious in meta-architectures like Faster R-CNN, while in SSD the difference is not significant. Figure 3.3 shows the performance for different models on different sizes of objects. It is possible to verify that all methods have a better performance on large objects, with SSD models recognized by their poor performance on smaller objects. Figure 3.2: Effect of image resolution in the overall mAP using different metaarchitectures [20] 31 Figure 3.3: Accuracy stratified by object size, meta-architecture and feature extractor, with an image resolution of 300 pixels [20] 3.2.1.2 Resize method According to [37] and [9], image interpolation is a technique used in order to resize images, where every pixel in the new image would be mapped back to a location in the old image in order to calculate the value of a new pixel. The nearest neighbor approach selects the value of the nearest pixel by rounding the coordinates of the desired interpolation point and can create pixelation or stepped edges. The bilinear interpolation takes a weighted average of the four neighborhood pixels to calculate the final value, producing smoother images than the original ones. The bicubic approach uses the 4x4 neighborhood of known pixels for a total of 16 pixels to calculate the interpolated value, giving more weight to closer pixels, producing sharper images. Finally, the area method is similar to the bilinear method, but the coefficient values can vary depending on if the division of the output scale versus the original scale is an integer or not. The different methods are exemplified on figure 3.4. 32 bounding boxes on the image. Those bounding boxes can have different sizes and aspect ratios, depending on the object shape. Each bounding box will be characterized by four values: ∆x_center,∆y_center,∆width and ∆height. The anchors are fixed bounding boxes placed through the original image with pre-defined aspect ratios and scales or sizes that will work as a reference for predict object locations. With that purpose in mind, in the first stage of the model, several parameters should be defined, not only regarding the convolutional network but also to the several specificities to find regions of interest in the image. 3.2.4.1 The anchors The anchors can be defined according to 8 different parameters: height and width of the anchor basis, defined as 256 pixels in the original implementation of faster R-CNN [44], height and width of the anchor stride, i.e., the space between each anchor, height and width offsets, list of scales and list of aspect ratios for the anchors. 3.2.4.2 Atrous rate The atrous rate has been cited as a mechanism that will allow increasing the performance of the models when detecting small objects [15]. This atrous rate is applied on the tensor associated to the features to crop in the first stage to obtain box predictions. 3.2.4.3 Network hyperparameters The network in the first stage should be adjusted in different parameters, namely those which specify the structure of the network itself and defines how the network will be trained. 1. The Regularizer - The regularizer will allow to prevent overfitting situations, as explained in section 2.1.2.1. By default, no regularizer is applied, but apply L1 (see equation 2.1) or L2(see equation 2.2) regularizers is possible. The regularizers will be defined by the weight, which determines how much we penalize higher parameter values. 2. Activation Function - As explained in section 2.3.4, the activation functions will define how the output of the convolutions are calculated. By default, Faster R- CNN applies RELU (see equation 2.3) activation functions, but it is also explored 39 the possibility of applying RELU_6 activation function (see equation 2.4). 3. The Initializer - The definition of an initializer in deep learning training algorithms can be an essential step to determine whether the algorithm converges at all [14]. Different approaches can be used, namely: (a) Random Normal initilizer - The random normal initializer is an initializer that generates a tensor with a normal distribution. It is possible to define the value of the mean and the standard deviation, which by default assume the values of 0 and 1, respectively. (b) Truncated Normal initializer - The truncated normal initializer is a initializer that generates a truncated normal distribution, i.e., the values generated are similar to the ones obtained from a random normal initializer, however the values with more than two standard deviations from the mean are excluded and re-drawn. It is the recommended approach for neural network weights and filters. (c) Variance Scaling Initializer - The variance scaling initializer has as advantage to keep the scale of the input variance constant, in order to not explode or vanish to zero by reaching the final layer. In this context, we can cite three different initializer proposed: 1 - MSRA Initialization [16] 2 - Convolutional Architecture for Fast Feature Embedding [22] 3 - Xavier [12] 4. The Batch Normalization - Perform a batch normalization using a standard set of parameters. This concept is explained in subsection 2.3.5. 5. Depthwise regularization This parameter defines whether or not apply L2regu- larization (see equation 2.2) on the depthwise convolution weights. 3.2.4.4 Minibatch size It corresponds to the batch size to use for computing the first stage objectness and location losses. 40 3.2.4.5 Positive Balance fraction Associated to cases of unbalanced data, this parameter will define the fraction of positive examples per image for the RPN. 3.2.4.6 NMS - IoU threshold After training, several box predictions are made to a unique object. In order to remove the unnecessary bounding boxes, a Non-Max supression (NMS) algorithm is applied which will filter out those overlapping boxes taking into account a specific threshold. Using the score_threshold parameter, the boxes where the score is lower than the threshold defined are removed immediately. The parameter iou_threshold will allow dealing with the situation where more than one bounding box is over only one object, i.e., the IoU threshold is a scalar threshold for IoU, where boxes that have high IOU overlap with previously selected boxes are removed. The algorithm applied in this case is: 1. Select the box with the highest score; 2. Compute its overlap with all other boxes and remove the boxes that overlap more than iou_threshold. 3. Iterate until there are no more boxes with a lower score than the currently selected box. 3.2.4.7 Maximum number of proposals This parameter corresponds to the maximum number of RPN proposals retained after first stage postprocessing. 3.2.4.8 Loss weights When dealing with multiloss functions, it can be advisable to adjust the magnitude of each loss and search for the best combinations which will lead to better results. 3.2.4.9 ROIs parameters After defining a good set of proposals, the filtered regions of interest will pass through the process of ROI pooling, a needed step to resize the feature maps that will allow the forward processing of those in the second stage of the algorithm. In this phase, we should define: 41 1. The crop size - The output size (width and height are set to be the same) of the initial bilinear interpolation based cropping during ROI pooling. 2. The kernel size - The kernel size of the max pooling operation on the cropped feature map during ROI pooling. 3. The stride - The stride of the max pooling operation on the cropped feature map during ROI pooling. 3.2.5 The second stage of Faster R-CNN In the second stage of Faster R-CNN, and after obtaining a set of proposals, the class of the detection will be defined and the bounding boxes are going to be refined. 3.2.5.1 Network hyperparameters Taking as input the proposals obtained during RPN, filtered in NMS and reconfigured in ROI Pooling, the network need to be adjusted for the new context. In this way, and similarly to what happened in the first stage of the algorithm, the hyperparameters of the network can be fine-tuned with the parameters exposed in 3.2.4.3. 3.2.5.2 Dropout Dropout cames as a regularization technique for neural networks that allows preventing overfitting by introducing noise to the training. At each training iteration, a fraction of the neurons is randomly set to zero, as explained in 2.1.2.1. By default, no dropout is applied in Faster R-CNN. 3.2.5.3 The IoU Threshold Likewise in the first stage, an IoU threshold should be defined on this phase in order to refine the bounding boxes. This process is better defined in 3.2.4.6. 3.2.5.4 The number of detections The parameters max_detection_per_class and max_total_detections define the maximum number of detections to maintain after the NMS is applied. Since we are dealing with a problem where we only have one class to predict, those parameters will have the same value. The default value in Faster R-CNN is 100. This value should be adjusted to 42 the problem in hand,i.e., to at least the maximum number of cells present in the image with the highest number of cells in the dataset. 3.2.5.5 The Loss Weights Similarly to the first stage, the loss weights of the multiloss function applied in this stage can be adjusted using different combinations of magnitude for each of them. 3.2.5.6 The Classification loss Related to the loss for the second stage box classifier, the different options analyzed, namely weighted sigmoid, focal sigmoid and bootstrapped sigmoid, are described in subsection 3.3.3.2. 3.2.5.7 The score converter The score converter will define how the classification is made and it can be of three types: 1. Identity – the input scores equals the output scores; 2. Sigmoid – Applies a sigmoid on input scores, as shown in equation 3.1. F(Xi)=1 1 + Exp(−Xj)(3.1) 3. Softmax – Applies a softmax on input scores, as shown in equation 3.2. F(Xi)=Exp(Xi) Pk j=0 Exp(Xi)(3.2) While the sigmoid function is used for binary classification, the softmax function calculate the probability distribution of the event over n different events, i.e., it will calculate the probabilities of each target class over all possible target classes. In this project, we are trying to classify an object as a human cell or not, and in this way, we apply the sigmoid function in order to calculate the probability of that object in being from human class. 43 3.3 Measuring the performance of a model 3.3.1 mAP The standard metric used to evaluate the performance and accuracy of an object detection algorithm is denominated as mean average precision (mAP). This metric is the product of precision and recall of the detected bounding boxes, and its values range from 0 to 1, where the higher the number, the better. The mAP is a good measure of the sensitivity of the network [49], being based on the Intersection over Union (IoU) concept. The IoU is the ratio of the overlapped area between the ground truth and predicted area to the total area, or area of union, as shown in figure 3.5, and is given by the following formula: IoU = Area of Overlap Area of Union (3.3) Figure 3.5: The IoU concept In this way, detections are assigned to ground truth objects and judged to be true or false positives by measuring bounding box overlap. To be considered a correct detection, the overlapping area between the predicted bounding box and ground truth bounding box must exceed 50% . Furthermore, we can define the following concepts [5]: True positive (TP) = number of detections with IoU > 0.5 False positive (FP) = number of detections with IoU <= 0.5 or detected more than once False negative (FN) = number of objects not detected, or detected with an IoU <= 0.5 Computing the mean average precision of a class afterward is a five-stage process where: 1. Calculate the precision (the proportion of true positives). The precision is defined by: Precision = True positive True Positive + False Positive (3.4) 44 2. Calculate the recall (the proportion of true positives out of all possible events): Recall = True positive True Positive + False Negative (3.5) 3. Compute the precision recall curve for the different thresholds 4. Average together the maximum precision value across all recall levels. By applying a 11 point interpolation, i.e., by averaging the precisions at a set of 11 recall levels, then the average precision score for each class is given by: AP = 1 11 X Recalli Precision(Recalli) (3.6) 5. Finally, the mAP is calculated by taking the mean AP over all classes and /or over all IoU Thresholds. In the present project, it is only considered one IoU threshold ([email protected]). 3.3.2 Regression performance measures On top of the mAP metric, the one used to fine tune the model, and taking into account the problem in hand, other metrics were considered in order to evaluate the performance of the model. While mAP is the standard metric used in object detections systems, it has limitations especially in cases where we are dealing with a large number of objects. This happens because if a specific object is not identified on a region proposal on the first stage of the algorithm, it will not be taken into account for the accuracy of the model. In this way, for each model, it was tested the performance of the model in the validation dataset and calculated several metrics that allow measuring regression performance between the predicted value, i.e., the number of objects predicted, versus the ground truth value. The following measures were taken into account [23]: Root mean squared error (RMSE) The root mean squared error, shown in equation 3.7, measures the average error performed by the model in predicting the outcome for an observation. Mathematically, the RMSE is the square root of the mean squared error (MSE), which is the average squared difference between the observed actual outcome values (y) and the values predicted ( ˆ y) by the model. RMSE(y, ˆ y) = rPn i=1(ˆ yi−yi)2 n(3.7) 45 Mean absolute error (MAE) The mean absolute error, presented in equation 3.8, is the sum of the absolute differences between the predictions and the real values, also denominated as l1 norm loss. This measure gives an idea of the magnitude of the errors, but not about the direction of those errors, i.e., if there is over or under prediction. A value of 0 indicates a perfect prediction with no errors, and as so, the lowest the value, the better. MAE(y, ˆ y) = 1 n n X i=1 yi−ˆ yi(3.8) Median absolute error The median absolute error, in equation 3.9, is the median of all of the absolute values between the predictions and the real values. This measure is more robust than the MAE in the presence of outliers. MEDAE(y, ˆ y) = median(|y1−ˆ y1|,...,|yn−ˆ yn|) (3.9) 3.3.3 The losses in Faster R-CNN The loss in Faster R-CNN is evaluated in the two stages of the algorithm, and each stage measures the error using a multi-loss function, which sums up to four losses in total. 3.3.3.1 First Stage Losses In the first stage of the algorithm, the RPN, it is measured the performance of the model taking into account the objectness loss and the localization loss, which lead to the multiloss function defined in equation 3.10. L({pi},{ti}) = 1 Ncls X i Lcls(pi,p∗ i) + λ1 Nreg X i p∗ iLreg(ti,t∗ i) (3.10) As so, the RPN takes an image (of any size) as input and outputs a set of rectangular object proposals, each with an objectness score [44]. In the equation exposed in 3.10, pstand for the predicted objectness class, p∗for the ground truth objectness class, tfor the ground truth bounding box and t∗for the predicted bounding box. The RPN objectness loss The objectness loss classifies a patch as having, or not, an object. In this phase the goal is not to find the class of the object identified, but if the 46 patch does have an object, and it is not background. This objectness score will be used to filter the bad predictions for the second stage. With this purpose in mind, Faster R-CNN uses a classifier with 2 possible classes: one for the presence of an object category and one for the background. The RPN localization loss For the bounding box regression, the authors of Faster R- CNN adopt the parameterizations of the 4 following coordinates, as shown in 3.11. tx=(x−xa) wa tw=w wa t∗ x=(x∗−xa) wa t∗ w=log w∗ wa ty=(y−ya) ha th=log h ha t∗ y=(y∗−ya) ha t∗ h=log h∗ ha (3.11) where x,y,wand hdenote the box’s center coordinates and its width and height. The variables x,xaand x∗are for the predicted box, anchor box and ground truth box respectively (likewise for y,w,h). 3.3.3.2 The second stage losses For the second stage of the algorithm, two new losses are computed, namely the box predictor localization loss and the box predictor classification loss. Each RoI is labeled with a ground truth class uand a ground truth bounding box regression target v. The multi-loss is defined as seen in equation 3.12: L(p,u,tu,v) = Lcls(p,u) + λ[u≥1]Lloc(tu,v) (3.12) where pstands for the discrete probability distribution over the categories, and tuthe bounding box regression achieved from the first stage using the RPN localization loss. The indicator function [u≥1] evaluates to 1 when u ≥1 and 0 otherwise (being the background labeled as 0). The hyperparameter λcontrols the balance between the two losses [10]. Box predictor localization loss The paper [44] applies a smooth-L1 loss on the position (x,y) of top-left of the bounding box, and the logarithm of the heights and widths , 47 similar to the one applied on the first stage, as shown in equation 3.13: LLoc(tu,v) = X ix,y,w,h smoothL1(tu i−vi) (3.13) where smoothL1(x) =          0.5x2if|x|<1 |x|−0.5 otherwise where xis the difference between predictions and target. Choosing a smooth L1 loss comes from the fact that this type of loss is less sensitive to outliers, and in that way, more robust, since when the regression targets are unbounded, training with L2 loss can demand careful tuning of learning rates in order to avoid exploding gradients [10]. This loss aims to refine the localization of the bounding boxes before classification. Box predictor classification loss Regarding classification loss, by default, it was used weighted sigmoid. However, focal sigmoid classification loss and bootstrapped sigmoid classification loss were also tested. As a binary classification, all of the former classifications losses are based on the crossentropy loss for binary classification [29], presented in equation 3.14: CE(p,y) =          −log(p) if y= 1 −log(1 −p) otherwise (3.14) In equation 3.14, y∈{±1}specifies the ground truth class and p∈[0,1]is the model’s estimated probability for the class with label y= 1. For notational convenience, ptis defined as: pt=         pif y= 1 1−potherwise (3.15) and CE(p,y) = CE(pt) = −log(pt) (3.16) The weighted sigmoid loss, presented in 3.17, addresses class imbalance by introducing a weighting factor α∈[0,1] for class 1 and 1 −αfor class -1. In this way, we can define the weighted sigmoid classification loss as: CE(pt) = −αtlog(pt) (3.17) 48 deal with a leptokurtic (kurtosis > 3) distribution, which can lead to situations where the predictive model will underestimate some of the predictions. With that in mind, the dataset was "partitioned" in three different (low, medium and high) levels in order to reduce the skewness and the kurtosis for each sample. Taking into account the small number of samples available, the fine-tuning of the model considered all the dataset, but the regression measures calculated take into account this partition. Besides the number of cells present in each image, it was important, due to the necessity of establishing aspect ratios and scales during anchor generation, to evaluate the distribution of width, height and aspect ratios of the 17128 cells present in the images. The following statistical measures in table 4.3 and presented in figure 4.4 refer to images with dimension 512x512 pixels. If resizing the image will be one of the steps during fine-tuning the model, the scaling of these values should be considered. Table 4.3: Descriptive statistics related to the width and height of cells present on input images Dimension Mean Std Min 25% 50% 75% max skew kurt Width 15.9 4.5 4 13 15 19 44 0.8 1.1 Height 15.2 4.3 3 12 15 18 45 0.9 2.8 Ratio 1 0.3 0.3 0.8 0.9 1.1 3.3 18.9 0.1 55 Figure 4.4: Density of cells according to their width and height We can verify in figure 4.5 that the aspect ratio of the cells range mainly between [0.5, 2.0]. One possible approach to select the aspect ratios in anchor generator will be to start with three different ratios (e.g. [0.5, 1.0, 2.0]) that will cover the majority of the distribution, as shown in figure 4.6. 56 Figure 4.5: Frequency of cells according to their ratio Figure 4.6: Possible aspect ratios taking into account the ratio distribution The magenta bounding box will be able to cover aspect ratios of 0.5, the cyan one ratios of 2 and finally the green one ratios of 1. 57 5 Prepare the data to work in TensorFlow In order to be able to train an object detection model in tensorflow, an open source machine learning library, the data to be considered as input should take the following considerations: 1. If images are not labeled, a graphical annotation tool, like labelImg 1should be used in order to create bounding boxes around every object of interest in the images we are going to use to train the model, evaluate and test. The labelImg will extract for each image a xml file with the coordinates of each bounding box and the corresponded label associated, in PASCAL VOC format. 2. TensorFlow works with TFRecord files, a binary file format, where all the information stored in all the xml files corresponding to each partition will be rearranged and stored in one single file in the appropriate format. All the individual xml files obtained using labelImg should be converted to this format. 3. Create a .pbtxt file that will contain the id and name for each of the possible labels in the dataset. The diagram presented in figure 5.1 presents a high overview of the workflow to train an object detection model in Tensorflow Object Detection API, a open source framework built on top of TensorFlow that makes it easy to construct, train and deploy object detection models. 1https://github.com/tzutalin/labelImg 58 Figure 5.1: Basic flow diagram 5.1 Default parameters The default parameters for the application of the object detector in the tensorflow Object Detection API has as object of study a multiclass problem where the number of objects in each image is relatively small. Taking into account the particularities of this project, the following parameters were updated: 1. Number of classes (num_classes) - Defined as 1, since the background should not be considered as a class while using tensorflow API. 2. Number of maximum proposals (first_stage_max_proposals) - By default, the value assumed is 300. Since the maximum number of cells in one single image was identified as more than 600, this parameter was changed to 2000 proposals. 3. Number of maximum detections per class (max_detections_per_class) - By default, this parameter is defined as 100. Concerning the maximum number possible of cells in one single image of the dataset, it was updated to 700. 4. Number of total detections (max_total_detections) - By default, this parameter is defined as 100. Since we are dealing with a one class problem, and for the reasons of the previous point, this parameter was updated to 700. 5. Score converter (score_converter) - By dealing with a uniclass problem, this parameter was changed from "SOFTMAX" to "SIGMOID". 59 6. Classification loss in the second stage (second_stage_classification_loss) - The classification loss was changed to a weighted sigmoid since we are dealing with a binary problem. Other options are explored further. 60 6 Experiments 6.1 Hardware used All considered tests in the following sections were carried out using Azure cloud computing resources, namely four Tesla K80 GPU (2 physical cards) with 32 GiB GPU memory, in a Virtual Machine with 24 vCPU, 224 GiB of memory and 1.44 TB SSD as temporary storage. 6.2 Dealing with a small dataset The main constraints faced in the current project were associated with two essential aspects: the need for massive computational resources and the small number of samples of the provided dataset. Taking into account those limitations, the experiments described in this section were restructured the following way: 1. The first set of experiments had as a primary goal to conceive the most accurate architecture and establish the more appropriate parameters for the problem in hand. In this way, nearly 80% of the input data was used for training and 13 images for validation. The tested models were evaluated initially by mAP, and the finetuning was guided by this metric, except on specific cases (as documented on the experiments), where there was an evident difference on the behavior of the model regarding losses or overfitting situations. 2. Hereafter, and since the majority of the models at a certain point started to achieve similar mAP values, each model was frozen, and the inference was applied on the validation images, as a way to compute regression metrics, namely RMSE, MAE 61 and MEDAE (see section 6.11). The purpose was to obtain a small set of models using the different insights to test in a smaller training dataset and to achieve more accurate statistic results. In this way, six finalist models were selected by taking into account different approaches of analyzing the results. 3. The finalist models were trained during more epochs (until achieving an overfitting situation) in a way to check if the performance would increase (see section 6.12). Again, those models were evaluated by mAP and the already mentioned regression metrics, and these last applied to two distinct validation datasets: the complete dataset and a dataset previously defined as medium complexity. The need of evaluation in a medium dataset comes from the fact that it was perceived on an early stage that models could achieve better results on images where the number of cells present was around the average of the population distribution. In this step, two models were chosen due to the particularity of achieving distinct results in the regression metrics for the "medium" level and to the whole dataset. 4. In the last step, a new stratified data partition was done, consisting on 53 images for training, 13 for validation and 30 for testing, and applied on both models selected on the previous step (see section 6.13). As expected, the mAP of those models had decreased significantly due to the reduction of the training dataset. The two models were frozen, and a new division of the level of image complexity was defined using the interquartile related to the number of cells. Furthermore, the inference was applied on the validation images to define the best threshold of probability to be applied on considering a detection as a human cell or not, i.e., defining the confidence level, and to choose which was the best model for the different pre-defined levels. 6.3 Choosing the object detection model With the aim of defining the most appropriate object detection architecture, the main pondering condition reflects on the preference of an algorithm that offers speed or primes per accuracy. Being accuracy the primary goal of this project, and as reported by [20], Faster R-CNN should be the one to go further, especially when dealing with objects of small size. Therefore, the performance of different meta-architectures went tested in 62 pre-trained models with COCO dataset 1. Figure 6.1: mAP using different meta-architectures As expected, and as can be seen in figure 6.1, Faster R-CNN was the meta-architecture associated with the best performance, followed by RFCN and finally SSD. Furthermore, training speed connects strongly with the meta-architecture used. Table 6.1: mAP and speed using different meta architectures mAP Meta-Architecture and Feature Extractor 4000 steps Maximum Speed/epoch (sec) Faster R-CNN Resnet101 0.53 0.53 47.08 RFCN Resnet101 0.31 0.31 13.19 Faster R-CNN Inception v2 0.34 0.39 6.17 SSD Inception v2 0.04 0.04 1.13 It is possible to verify in table 6.1 that SSD is the fastest approach, taking around one second to perform one epoch (with a batch size of 24), while Faster R-CNN is the slowest one, taking almost fifty seconds to finish an epoch. However, it should keep in mind that the speed of training is also highly related to the feature extractor chosen. In this way, one can conclude that Faster R-CNN is the meta-architecture to be chosen when accuracy 1https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md 63 is the primary goal of the problem, while SSD should be the one to use if speed is more important. RFCN gives a balanced option between speed and accuracy. 6.4 Choosing the feature extractor In this experiment, it was tested the performance of different feature extractors using a pre-trained model on COCO dataset. Figure 6.2: mAP using different feature extractors As seen in figure 6.2, the model with the best performance is the Inception Resnet v2, as defended on [20]. Concerning the speed of training, the more complex the network, the slowest the training is, as expected, and confirmed in table 6.2. Table 6.2: mAP and speed using different feature extractors mAP Feature Extractor 4000 steps Maximum Speed/epoch (sec) Resnet50 0.50 0.50 10.34 Resnet101 0.53 0.53 47.08 Inception v2 0.34 0.39 6.17 Nas 0.44 0.43 96.36 Inception Resnet v2 0.71 0.74 45.55 Taking into consideration the results of the previous experiments associated to the selec- 64 Considering the results exposed on table 6.5, it is possible to assume that, in this particular project, image normalization is not an approach to be used since training loss is higher when normalizing images. This can happen due to the fact of the use of a pretrained model where non-normalized images were used. Concerning speed, applying normalization leads to slightly slower training. Normalization will not be applied for the remaining tests. 6.6.4 Using grayscale Similarly to normalization, converting images to grayscale can influence the behavior of the model. Table 6.6: Training loss and speed using grayscale images Grayscale Train Total Loss Speed/epoch (sec) False 2.27 94.13 True 3.83 93.71 The results listed in table 6.6 lead to the conclusion that, alike normalization, converting images to a grayscale tone lead to worse results in the loss. Again, this could be associated to the fact of recurring to a pre-trained model where no grayscale conversion was applied. The speed decreases slightly since only one channel for each image is processed. Thus, image conversion to grayscale will not be used on the remaining experiments. 6.7 The training process 6.7.1 Batch size As mentioned previously, the batch size is highly associated with the memory available on the machine. By resizing the image to 1100x1100 pixels, the training was limited to a stochastic approach. For future works where the memory available could be higher and as a matter of reference, it was tested the influence of the batch size for an input image of 600x600 pixel, using a stochastic process versus using a batch size of two (per GPU). 71 Table 6.7: mAP and speed using different batch sizes Batch mAP by Epoch Speed Size 25 50 100 150 200 250 300 350 step (sec) epoch (sec) 1 0.07 0.17 0.60 0.70 0.70 - - - 2,25 45 2 0.05 0.06 0.44 0.62 0.65 0.67 0.68 0.70 3,71 37.1 According to table 6.7, the results show that by using a stochastic training, the model achieves 0.7 mAP during the 150th epoch / 3000 steps, which takes around 113 minutes to train. On the other hand, by training with a batch size of 2, the model achieves the same accuracy only in the 350th epoch / 3500 steps, after 216 minutes of training. Taking into account those values, we can assume that, and for this particular case, a smaller batch seems to speed up the converge of the model, even if the computational speed is higher by using a larger batch. 6.7.2 The optimizer Adam is the state of art of optimizers in object detection. The nature of the algorithm itself, joining characteristics of RMSProp and Momentum make it outperform the previous ones. While in the original Faster R-CNN the optimizer applied was momentum, three optimization algorithms were tested as a way to check the impact on them on the model itself. It was verified that Adam should be the one to be used on further experiments. 72 Figure 6.7: mAP using different optimizers In figure 6.7, we can verify that the optimizer Adam with exponential LR and Momentum are the ones that achieve better results, but Adam has the advantage of speeding up the convergence of the model. Table 6.8: mAP and speed using different optimizers Optimizer Best mAP step best mAP 0.8 mAP step Speed/epoch (sec) Momentum 0.843 2865 744 95.04 Adam 0.027 1402 - 91.59 RMSProp 0.795 1739 - 93.16 Adam w/ Exp_LR 0.835 1043 493 95.70 There is no significant evidence in this case that the speed of training is influenced by the optimizer used, as opposed to the models’ convergence. We can also verify based on the table 6.8 that all the optimizers can achieve reasonable rates of accuracy, but they should be fine-tuned regarding the learning rate and possibly other parameters in order to optimize their behavior. Clear evidence on this is that by using Adam optimizer with the default values, the model cannot increase their accuracy for more than 0.027, but when the initial learning rate and the type of decay were adjusted, this value increased to a mAP of 0.835. 73 6.7.3 The learning rate Assuming Adam as the best optimizer to proceed with the experiments, it was tested the impact that different initial learning rates and decay steps could have on the model performance. After some initial tests, not exposed here for the sake of brevity, it was verified that the best initial LR range was between 0.0001 and 0.0005. Figure 6.8: mAP using different initial learning rates (100000 decay steps) In the figure 6.8 we can verify that an initial rate of 0.0002 seems to be the one that give better accuracy and boost the performance of the model in earlier stages, compared to the other values. Table 6.9: mAP according to the decay steps (initial LR of 0.0002) mAP at step Decay steps 100 200 300 400 500 25000 0.06 0.39 0.74 0.81 - 50000 0.59 0.73 0.82 0.81 0.82 100000 0.26 0.75 0.80 0.82 0.84 By increasing the decay steps, the decrease of the learning rate will be slower, and a decay step of 100000 is proven as one good option regarding this parameter. 74 6.7.4 Data Augmentation Data augmentation is a set of techniques that can have positive effects on the overall accuracy in situations where those techniques enhance the current dataset. To test that effect, a set of experiments was carried out using different techniques individually by 400 steps (20 epochs). The results are shown in table 6.10. Table 6.10: mAP using different data augmentation techniques mAP at step Augmentation 100 200 300 400 (00) None 0.12 0.32 0.51 0.59 (01) Horizontal Flip 0.51 0.75 0.81 0.82 (02) Vertical Flip 0.12 0.57 0.78 0.81 (03) Pixel Value Scale 0.40 0.76 0.78 0.81 (04) Image Scale 0.72 0.79 0.80 0.80 (05) RGB to Gray 0.47 0.79 0.81 0.81 (06) Adjust brightness 0.68 0.82 0.82 0.80 (07) Adjust contrast 0.01 0.02 0.29 0.76 (08) Adjust hue 0.02 0.01 0.05 0.58 (09) Adjust saturation 0.02 0.11 0.66 0.78 (10) Distort color 0.25 0.75 0.80 0.81 (11) Jitter boxes 0.76 0.77 0.82 0.79 (12) Crop image 0.67 0.78 0.76 0.80 (13) Pad image 0.00 0.00 0.00 0.04 (14) Crop pad image 0.00 0.01 0.00 0.12 (15) Crop to aspect ratio 0.36 0.80 0.82 0.81 (16) Black patches 0.02 0.40 0.75 0.80 (17) Rotation 90 0.04 0.45 0.76 0.80 (18) Top4: (01)(06)(11)(15) 0.68 0.78 0.78 0.81 (19) All but (08)(13)(14) 0.51 0.74 0.81 0.82 (20) All 0.53 0.75 0.78 0.80 It is possible to verify that applying data augmentation can increase the performance of the model significantly, in most cases having a boost of over 30% of the accuracy comparing to not using any type augmentation. Still, augmentations using padding (13)(14) reduce the efficiency of the model to a state near zero accuracy. Adjusting the hue also seem to have a negative impact on the final mAP. The summary of the results shows that the augmentation techniques that seem to have more effect in a short term of the training are the image scale, the jitter boxes, the brightness adjustment and cropping the image. The saturation and the hue adjustment prove their efficiency only after more than 300 steps of training. After checking what were the techniques more worthwhile to the performance of the model individually, it was 75 tested three different situations: create a set of the techniques that gave the best result (0.82 mAP) individually, named as Top4 (18), test all augmentation techniques applied simultaneously(20), and finally test the set with all the techniques that gave good results, removing the variables that influence in a high level the performance of the model, including the adjust hue technique to the techniques to be excluded, since the results of that technique were not undoubtedly good(19). While the differences in the results are only slightly different, we can verify that using a set with techniques that have been proven individually as efficient can give better results than using a technique in an isolated way, using all the techniques possible (20) and improve significantly the model that do not use any type of data augmentation. The model that achieves better mAP during the first 400 steps was the model (19) with a mAP of 0.83 in step 342. 6.7.5 The gradient clipping By default, the gradient clipping parameter has a value of 10. By testing the values of 5 and 15, the results were the ones presented in the table 6.11. Table 6.11: mAP according to the gradient clipping value mAP at step Gradient clipping value 100 200 300 400 max(step) 10 (default) 0.51 0.74 0.81 0.82 0.83(342) 5 0.71 0.80 0.82 0.81 0.81(244) 15 0.64 0.80 0.82 0.81 0.83(348) Gradient clipping technique will allow preventing vanishing and exploding gradient problems and according to the results shown in table 6.11, the performance of the model does not seem to be affected significantly by changing this parameter. 6.7.6 The number of steps The number of steps is conditioned by several aspects, namely the convergence of the model, the need for applying early stopping due to overfitting, time limitations, among others. This parameter is going to suffer adjustments after the fine-tuning process. 76 6.7.7 The maximum number of boxes By default, it was defined the maximum number of boxes as 700, since the maximum value of cells in an image in our dataset had 661 cells. The minimum value for this parameter should be at least the maximum value of objects present in an image on the dataset used. 77 6.8 Configurations on feature extractor 6.8.1 The stride The output stride of the extracted RPN feature map was tested for 8 and 16 strides. Table 6.12: mAP, speed and RPN losses depending on the stride of the feature extractor mAP at step Speed/ RPN Loss Stride 100 200 300 400 max(step) epoch(sec) Objectness Localization 8 (default) 0.51 0.74 0.81 0.82 0.83(342) 94.99 0.06 0.87 16 0.20 0.24 0.33 0.27 0.33(306) 46.44 0.33 3.49 As presented in table 6.12, while increasing the stride will reduce by more than half the time of training, the accuracy of the model is profoundly affected with this parameter change, where the maximum mAP achieved for 400 steps was 0.33. It is also possible to verify that this difference concerning the accuracy of the model is mainly due to the loss increase in the RPN stage. 6.8.2 Batch norm trainable In this experiment, it was checked if updating the batch norm parameters during training would have an impact on the performance of the model. The updating is advisable especially in cases where we deal with large batch sizes. Table 6.13: mAP and speed depending on the use of the batch normalization Batch mAP at step Speed/ Norm 100 200 300 400 max(step) epoch (sec) FALSE (default) 0.51 0.74 0.81 0.82 0.83(342) 94.99 TRUE 0.0 0.0 0.0 0.0 0.11 (37) 92.05 By turning this parameter to True, we can verify in the table 6.13 that the model after the first steps stops learning, which could be related to a case of vanishing gradient. 78 6.9 First stage of Faster R-CNN 6.9.1 Anchor generator The grid anchor generator can be defined by the stride, the scales, and the aspect ratios. The following experiments show the behavior of the training according to some changes to those parameters. As a note, at any given location, i.e., in each anchor, the quantity of the scales times the number of the aspect_ratios anchors are generated with all possible combinations of scales and aspect ratios. Aspect ratio In chapter 4, during exploration of the dataset and the images features, it was possible to conclude in figure 4.5 that the cells ratio range between 0.5 and 2.0. Those values are not affected by the resizing of the image from 512x512 pixels to 1100x1100 pixels considering that the aspect ratio was kept. Table 6.14: mAP and speed depending on the aspect ratio of the anchors mAP at step Speed/ Aspect ratio 100 200 300 400 max(step) Epoch(sec) [0.5,1.0,2.0] (default) 0.51 0.74 0.81 0.82 0.83(342) 94.99 [0.5,1.0,1.5,2.0] 0.74 0.80 0.80 0.82 0.83(139) 96.00 The results in table 6.14 show that adding one more aspect ratio to the anchor generator do not improve the performance of the model in the long term. While the mAP rises faster using this additional value, we can verify that using only three aspect ratios are enough to detect the objects in our image, because eventually the bounding boxes are readjusted to the ground truth boxes using the losses regarding localization in the first and second stage of the object detector. Scales The image resizing to 1100x1100 pixels will affect the value of the scales to be used in the anchor generator. In this way, the values presented in chapter 3 regarding the values of width and height of the cells and their distribution should suffer adjustments to the new dimensions. The table 6.15 show those values already scaled for the new reality, and the descriptive statistics associated. 79 Table 6.15: Width and height of the cells rescaled to the new image resolution Dimension Mean Std Min 25% 50% 75% max Width 34.2 9.8 9 28 32 41 95 Height 32.6 9.4 6 26 32 39 97 To calculate the best scales to use for the anchors, and since the size basis for the anchor is 256 pixels, it was scaled the value of the pixels presented on table 6.15 to this size. In this way, we can say that the mean of the cells in width and height is around 0.13 of the basis anchor size, the minimum is around 0.03 and the maximum 0.38. Taking into account those values, with was experimented different scales to check the behavior of the mAP during 400 steps. Table 6.16: mAP and speed according to different scales used in anchor generator mAP at step Speed/ Scale 100 200 300 400 max(step) Epoch(sec) [0.25,0.5,1.0,2.0] (default) 0.74 0.80 0.80 0.82 0.83(139) 96.00 [0.05,0.15,0.3,0.5] 0.58 0.76 0.79 0.83 0.83(400) 97.11 [0.15,0.3,0.5] 0.76 0.82 0.81 0.82 0.83 (339) 95.74 [0.15,0.3,0.5,1.0] 0.67 0.82 0.82 0.85 0.85 (400) 96.77 [0.3] 0.01 0.02 0.01 0.01 0.02(194) 92.82 According to the results shown in table 6.16, we can verify that limit the scales to only approximate values similar to the cell size increases overfitting, leading to poorer performance. However, reducing the lowest value of the scale improves the model since it is more adjusted to the reality of the problem. Regarding speed, there is a slight difference in the training time, where we can verify that the less number of scales, the lower will be the step time. By testing a single scale (in this case it was tested the value 0.3), we can corroborate that the detection of the objects is profoundly affected. After concluding that the scales list [0.15,0.3,0.5,1.0] as the best achieved on the previous experiments, the mAP was re-evaluated, using the default list of aspect ratios in order to conclude what would be the best configuration to continue the experiments. 80 efficiently without any significant effects on the accuracy of the model. On the other hand, the losses associated with the second stage of the algorithm show a significant reduction by the increasing of proposals. Even though, that shrinkage is not visibly reflected on final mAP. For further experiments, the number of proposals is defined as 3000, since it shows the highest value regarding mAP. 6.9.8 Loss weights Localization and Objectness In this step of experiments, the goal was to evaluate how changes on the weights of the losses of the first stage would affect the final performance of the model. By default, the faster R-CNN system applies a double loss weight in the localization compared to objectness loss. The results are summarized in table 6.30. Table 6.30: mAP and speed changes using different combinations of localization and objectness loss weights mAP at step Speed/ Localization Objectness 100 200 300 400 max(step) Epoch(sec) 2.0 1.0 (default) 0.59 0.83 0.85 0.85 0.85(310) 104.34 1.0 1.0 0.75 0.80 0.84 0.82 0.84(314) 103.50 1.0 2.0 0.74 0.80 0.84 0.83 0.84(312) 103.78 According to the results in table 6.30, changing the weight of the losses of the first stage do not affect the performance of the model significantly, but slightly better results are achieved when the default configuration is used. 6.9.9 ROI pooling After the RPN phase, and having the final proposals selected and filtered during NMS technique, the Region of Interest pooling is performed. In this phase, the proposals should be redimensioned in order to proceed to the second phase. Initial crop size The crop size will define the size to crop the final region proposals. This parameter was changed to different values in order to perceive the effect of it in the model performance. 87 Table 6.31: mAP and speed according to the initial crop size mAP at step Speed/ Crop size 100 200 300 400 max(step) Epoch(sec) 14 0.73 0.83 0.84 0.79 0.84(376) 98.90 17 (default) 0.59 0.83 0.85 0.85 0.85(310) 104.34 20 0.74 0.82 0.83 0.82 0.83(299) 107.97 According to the results shown in table 6.31, the default configuration is the one to choose between the options tested. There is no evident difference between the several validation losses of the algorithm. Concerning speed, the lower the crop size, the faster will be the training process. The higher mAP using the default configuration defined the value of this parameter to further tests. Maxpool Kernel size and stride In ROI pooling phase, the values corresponding to kernel size and the stride should be defined. By default, it is applied a 1x1 pooling. Other combinations were tested, and the results are exhibited in table 6.32. Table 6.32: mAP and speed according to the maxpool kernel size Maxpool kernel mAP at step Speed size stride 100 200 300 400 max(step) Epoch(sec) 1 1 (default) 0.59 0.83 0.85 0.85 0.85(310) 104.34 3 3 0.72 0.83 0.83 0.85 0.85(400) 104.76 3 1 0.66 0.80 0.82 0.81 0.84(339) 92.04 With no evident differences in losses, the different configurations result in similar performances of the model, with a significant difference regarding speed when applying a kernel 3x3 with a stride of 1. 88 6.10 Second stage of Faster R-CNN The second stage in Faster R-CNN will allow to refine the location of the bounding boxes and ultimately, classify the objects identified. The remaining layers of the CNN should be tuned to complete the training. 6.10.1 Box predictor network hyperparameters Regularizer The second stage demands the hyperparameters evaluation of the remaining network. As so, it was tested the impact of adjusting the regularizer for this phase, as can be seen in table 6.33. Table 6.33: mAP and speed using different regularizers during the second stage of the object detector mAP at step Speed/ Regularizer Weight 100 200 300 400 max(step) Epoch(sec) l2 0.0 (default) 0.59 0.83 0.85 0.85 0.85(310) 104.34 l2 0.5 0.52 0.78 0.82 0.82 0.83(310) 104.92 l2 1.0 0.74 0.82 0.82 0.84 0.84(400) 103.79 l1 0.5 0.71 0.82 0.85 0.84 0.85(311) 104.35 l1 1.0 0.60 0.81 0.83 0.81 0.83(357) 104.07 As table 6.33 indicates, the speed of training is not affected by the application of regularizers. Further, the mAP does not seem to improve by the use of regularizers, and there are no notable differences between the several losses evaluated along the process. Thus, the remaining tests for parameter tuning were made with no resource to any regularizer. Initializer Due to the decision of using the weights from a pre-trained model, the effect of the initializer was not tested. Activation The activation function used was examined for the second stage of the algorithm. Results are presented in table 6.34. Table 6.34: mAP and speed according to the activation used in the second stage mAP at step Speed/ Activation 100 200 300 400 max(step) Epoch(sec) NONE 0.77 0.83 0.83 0.82 0.84(221) 106.16 RELU (default) 0.59 0.83 0.85 0.85 0.85(310) 104.34 RELU6 0.41 0.78 0.82 0.85 0.85(400) 103.78 89 Again, results show that changing the activation function do not affect in a significant way the performance of the model. Maintaining the RELU as the option to the next experiments, it will be tested in the final finetuning of the model the use of RELU_6, since this activation gives better results when applying the regression metrics. Batch normalization The influence of batch normalization was analyzed, and results can be observed in table 6.35. Table 6.35: Total Loss, Box validation loss, mAP and speed depending on the use of batch normalization in the second stage Maximum Total Loss Box Validation Loss Best Speed/ Proposals Validation Training Localization Classification mAP(step) Epoch(sec) False (default) 1.15 1.73 0.11 0.25 0.85(310) 104.34 True 1.87 2.15 0.20 0.89 0.81(400) 104.35 The results defend that batch normalization should not be applied again on this stage since it will decrease the mAP value for more than 0.04. Furthermore, batch normalization has a significant negative impact on the classification loss, increasing this value from 0.25 to 0.89. Regularize depthwise Regularization was applied at a depth level at the layers of the CNN in the second stage of Faster R-CNN. Table 6.36: Total Loss, Box validation loss, mAP and speed by using depthwise regularization on the second stage Maximum Total Loss Box Validation Loss Best Speed/ Proposals Validation Training Localization Classification mAP(step) Epoch(sec) False (default) 1.15 1.73 0.11 0.25 0.85(310) 104.34 True 1.28 2.11 0.14 0.22 0.84(263) 105.21 While no meaningful differences can be found comparing both approaches, as can be seen in 6.36, differently from the first stage, applying this type of regularization at this step seem to improve the accuracy evaluated by the regression metrics, as exposed on 6.45. 90 6.10.2 Dropout The use of dropout can be a handful technique when dealing with overfitting situations. While there was no evidence of an overfitting situation on the model fine-tuned until this moment, the dropout technique was applied in order to assess the effect of it on the network evaluation. Table 6.37: Total Loss, Box validation loss, mAP and speed by using dropout Maximum Total Loss Box Validation Loss Best Speed/ Proposals Validation Training Localization Classification mAP(step) Epoch(sec) True (0.5) 0.80 1.94 0.14 0.28 0.84(355) 104.35 True (0.6) 0.80 1.70 0.13 0.29 0.84(353) 105.20 True (0.7) 0.84 2.08 0.15 0.26 0.83(307) 105.49 True (0.8) 0.80 1.71 0.13 0.33 0.83(349) 104.00 True (0.9) 0.81 2.33 0.14 0.22 0.83(400) 105.88 False (default) 1.15 1.73 0.11 0.25 0.85(310) 104.34 Comparing the results exposed in table 6.37, there is no clear indication of the benefit of using dropout during training in this case. Furthermore, the speed of training does not seem to suffer significant modifications, as defended in the bibliography. However, we can verify that applying dropout will drive to more significant differences between validation and training loss since dropout is activated only when training, and not applied during validation. 6.10.3 Post processing - Batch Non-Max supression Similarly to the first stage of Faster R-CNN, a Non-Max suppression is implemented again in the second stage in the detections as a way to avoid having more than one bounding box for each object. Thus, the IoU threshold should be adjusted, and the number of maximum detections should be defined. IoU threshold To test the repercussion of adjusting the IoU threshold, different values for this parameter were tested in a range between 0.4 and 0.8. 91 Table 6.38: Total Loss, Box validation loss, mAP and speed according to the IoU threshold IoU Total Loss Box Validation Loss Best Speed/ Threshold Validation Training Localization Classification mAP(step) Epoch(sec) 0.4 1.16 1.82 0.13 0.24 0.83(351) 105.43 0.5 1.20 1.49 0.13 0.25 0.83(400) 105.79 0.6 (default) 1.15 1.73 0.11 0.25 0.85(310) 104.34 0.7 1.24 2.00 0.14 0.31 0.84(307) 105.97 0.8 1.27 1.98 0.14 0.32 0.83(307) 105.78 In table 6.38, the default value for the IoU threshold is the one that gives better results involving mAP. The speed of training does not seem to suffer depending on the change of this parameter. Values higher than the default one seem to converge to worse results regarding total loss for validation and training, but not significant ones. Maximum detections per class and total detections The maximum detections per class and total detections parameter are always limited by the highest value of objects in the input images. Table 6.39: Total Loss, Box validation loss, mAP and speed according to to maximum detections Maximum Total Loss Box Validation Loss Best Speed/ Detections Validation Training Localization Classification mAP(step) Epoch(sec) 700 (default) 1.15 1.73 0.11 0.25 0.85(310) 104.34 1000 1.24 2.12 0.14 0.25 0.83(400) 106.25 1500 1.40 1.74 0.12 0.44 0.86(303) 111.84 In order to understand if a higher number of detections would influence the final mAP, the model was tested using the value of 700, 1000 and 1500, as shown in table 6.39. The results defend that increasing the number of maximum detections imply a higher classification loss. However, using 1500 detections increases the mAP for the value of 0.86. Due to the loss increase mentioned previously, it was selected the default value of 700 to continue the tests. However, the version of 1500 detections is tested afterward as the magenta model in section 6.12. The speed in training is also affected by the number of detections applied: the higher the number of detections, the slower will be the process. 92 6.10.4 Loss weights Localization and Objectness Having two different losses in this stage, the impact of changing the loss weights during the process was assessed. Table 6.40: Total Loss, Box validation loss, mAP and speed changes using different combinations of localization and classification loss weights Localization & Total Loss Box Validation Loss Best Speed Classification Validation Training Localization Classification mAP(step) Epoch(sec) loss weights 2.0 & 1.0 (default) 1.15 1.73 0.11 0.25 0.85(310) 104.34 1.0 & 1.0 1.16 1.39 0.07 0.23 0.83(315) 106.25 1.0 & 2.0 1.37 1.77 0.07 0.50 0.83(310) 106.53 Giving a double weight to localization loss lead to the best model in terms of mAP, as can be seen in table 6.40. 6.10.5 Classification loss The classification loss can be changed to different options in order to adapt better the results for our problem. In this way, besides the weighted sigmoid, the bootstrapped and focal sigmoid were tested as options to the classification loss. Table 6.41: Total Loss, Box validation loss and mAP using different classification losses Classification Total Loss Box Validation Loss Best Loss Validation Training Localization Classification mAP(step) Weighted sigmoid (default) 1.15 1.73 0.11 0.25 0.85(310) Bootstrapped sigmoid 1.03 1.36 0.13 0.12 0.84(400) Sigmoid Focal 1.07 1.84 0.13 0.13 0.83(400) Comparing the results in table 6.41, the best mAP is still achieved using weighted sigmoid. Nonetheless, using Bootstrapped classification grant lower total losses. 6.11 Evaluating the regression metrics of the models Choosing the model in the previous steps was made taking into account mostly the mAP obtained after training. In a way to try to improve the model the best way possible, the different models were evaluated using the regression metrics RMSE, MAE, and MEDAE on the dataset with medium complexity. The results are shown in table 6.42, for the 93 use of different parameterizations to a faster R-CNN model with a feature extractor Inception Resnet v2, where the transfer learning applied is "only weights", and without normalization or the use of grayscale images. Table 6.42: Regression metrics and mAP for different configurations in training and data augmentation parameters, where the symbol *represents the default model for Faster R-CNN Parameter Configuration RMSE MAE MEDAE mAP Dimension 256x256 117.2 94.7 83.5 0.07 512x512 52.9 33.4 17.5 0.60 600x600*21.1 15.5 11.5 0.74 1024x1024 29.5 20.3 13.5 0.81 1100x1100 nnnnnn13.5 11.4 9.5 0.82 Bilinear*nnnnn13.5 11.4 9.5 0.82 Resize Nearest Neighbor 15.6 11.5 8.5 0.77 Method Bicubic n14.0 10.6 7.0 0.78 Area 17.8 15.9 13.5 0.75 Optimizer Momentum *n7.0 5.8 4.5 0.84 Adam 139.2 129.8 122.0 0.03 RMSProp 15.0 12.2 13.5 0.79 Adam with exp. LR nnnnn9.6 8.5 9.0 0.83 0.0005 11.1 8.9 9.5 0.80 Initial 0.0004 9.6 8.5 9.0 0.83 Learning 0.0003*nnn6.1 5.4 5.0 0.83 Rate 0.0002 nnn11.5 9.9 10.0 0.84 0.0001 7.1 6.2 7.0 0.83 25000 17.0 13.0 7.5 0.33 Decay 50000 13.9 11.1 10.0 0.83 steps 100000 nnnnnn11.5 9.9 10.0 0.84 None 35.1 27.9 23.5 0.59 Horizontal Flip *12.0 9.1 7.5 0.82 Vertical Flip 16.6 13.6 13.5 0.82 Pixel Value Scale 12.3 9.9 9.5 0.81 Image Scale 15.1 12.1 13.5 0.80 RGB to GraY 8.5 7.8 9.0 0.81 Adjust brightness 12.7 12.0 13.5 0.82 Adjust Contrast 37.2 27.2 20.5 0.58 Adjust Hue 15.5 12.6 9.0 0.78 Data Adjust Saturation 12.5 8.4 5.0 0.81 Augmentation Distort color 16.6 13.6 12.5 0.83 Jitter Boxes 13.0 9.9 6.0 0.76 Crop Image 21.4 16.1 15.0 0.80 Pad Image 135.3 122.9 116.5 0.04 Crop pad Image 70.6 52.6 36.0 0.12 Crop to aspect ratio 11.8 10.7 10.0 0.82 Black Patches 17.9 14.0 13.0 0.80 Rotation 90 15.1 11.9 9.0 0.80 Top4 n7.2 5.9 6.5 0.81 All but (08)(13)(14) nnnnn15.5 11.9 11.5 0.83 All 16.1 13.1 12.0 0.80 94 Table 6.43: Regression metrics and mAP for different configurations in some of the first stage parameters, where the symbol *represents the default model for Faster R-CNN Parameter Configuration RMSE MAE MEDAE mAP 5n12.0 9.5 8.5 0.81 Gradient 10 *nnnnn15.5 11.9 11.5 0.83 Clipping 15 21.3 17.2 16.5 0.83 Feature Extractor 8 *nnnnnn15.5 11.9 11.5 0.83 Stride 16 30.7 24.6 18.0 0.33 Feature Extractor TRUE 139.2 129.8 122 0.11 Batch Norm FALSE *nnnnnn15.5 11.9 11.5 0.83 Aspect Ratios [0.5,1.0,1.5,2.0]&[0.15,0.3,0.5,1.0] nnnnn11.2 8.7 6.0 0.85 and Scales [0.5,1.0,2.0]&[0.15,0.3,0.5,1.0] 11.3 9.0 6.5 0.82 Atrous rate 1 (FALSE) 11.3 9.0 6.5 0.84 2 (TRUE)*nnnnnn11.2 8.7 6.0 0.85 No regularizer*nnnnnn11.2 8.7 6.0 0.85 1st Stage l2 0.5 12.7 9.6 9.0 0.82 Regularizer l2 1.0 17.3 14.2 9.0 0.80 l1 0.5 33.4 28.4 30.5 0.61 l1 1.0 41.0 34.2 29.5 0.63 Activation NONE 14.9 11.7 8.5 0.82 RELU*nnnnnn11.2 8.7 6.0 0.85 RELU_6 14.7 11.4 11.0 0.84 Batch TRUE 25.2 17.4 11.0 0.79 Normalization FALSE*nnnnnn11.2 8.7 6.0 0.85 Regularize TRUE 73.1 38.9 20.0 0.80 Depthwise FALSE*nnnnnn11.2 8.7 6.0 0.85 95 Table 6.44: Regression metrics and mAP for different configurations for the remaining first stage parameters, where the symbol *represents the default model for Faster R-CNN Parameter Configuration RMSE MAE MEDAE mAP Kernel Size 3*nnnnnn11.2 8.7 6.0 0.85 2 11.7 8.5 6.5 0.82 4 18.3 13.8 9.0 0.84 Depth 256 13.2 11.6 10.0 0.84 512*nnnnnn11.2 8.7 6.0 0.85 1024 17.5 14.8 13.0 0.83 Minibatch 128 13.7 11.5 11.0 0.83 Size 256*nnnnnn11.2 8.7 6.0 0.85 512 13.1 9.0 5.0 0.83 Positive 0.25 n9.9 7.8 6.5 0.83 Balance 0.5*nnnnn11.2 8.7 6.0 0.85 Fraction 0.75 18.5 15.0 11.5 0.82 0.3 14.2 11.4 8.0 0.84 0.4 nnn15.0 12.1 10.0 0.84 NMS IoU 0.5 11.5 10.1 10.0 0.84 threshold 0.6 14.5 11.5 7.5 0.83 0.7*nnn11.2 8.7 6.0 0.85 0.8 13.7 10.9 9.5 0.83 1000 11.9 8.9 6.5 0.83 Maximum 1500 15.3 11.2 8.5 0.83 Proposals 2000*n15.0 12.1 10.0 0.84 2500 n11.1 8.6 6.0 0.83 3000 nnnn21.1 15.5 11.5 0.85 Loss weights Localization 1.0 & Objectness 1.0 17.5 15.7 13.0 0.84 Localization 2.0 & Objectness 1.0*nnnn21.1 15.5 11.5 0.85 Localization 1.0 & Objectness 2.0 nn11.0 9.7 8.5 0.84 Initial 14 nn11.3 8.7 7.0 0.84 crop size 17 *nnnn¸21.1 15.5 11.5 0.85 Maxpool Kernel 1 and Stride 1 *nnnn21.1 15.5 11.5 0.85 kernel & Kernel 3 and Stride 3 10.4 8.9 10.5 0.85 stride Kernel 3 and Stride 1 nn11.3 8.8 8.5 0.84 96 Figure 7.3: Losses for the model "Best MEDAE" with the original partition Figure 7.4: Losses for the model "Best MEDAE" with the final partition 103 In order to identify the best model with the new data partition for each complexity level, each model was frozen at the step where overfitting starts to be evident, and regression metrics were evaluated using validation dataset. Results are summarized in tables 7.1 to 7.6. An early stopping criterion to avoid overfitting was selected in this phase to freeze the models with the new partition, with the purpose to maintain the characteristics of the original model. However, better results could be achieved if techniques like dropout and regularization were used in this step. Table 7.1: Inference and Regression metrics for model "Best RMSE & MAE" - Low complexity" Value predicted per Score threshold Image 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 GT Image4 65 48 42 36 36 35 31 30 28 39 Image2 119 81 66 57 49 44 40 31 24 59 Image5 175 129 110 96 81 75 65 56 32 83 RMSE 65 30 16 8 6 10 16 23 36 - MAE 59 26 12 6 5 9 15 21 32 - medae 60 22 7 3 3 8 18 27 35 - Table 7.2: Inference and Regression metrics for model "MEDAE - Low complexity" Value predicted per Score threshold Image 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 GT Image4 174 114 92 72 66 56 48 42 37 39 Image2 329 221 167 136 114 98 81 60 44 59 Image5 432 307 246 205 172 156 139 109 77 83 RMSE 266 165 117 85 62 49 35 15 9 - MAE 251 154 108 77 57 43 29 10 8 - medae 270 162 108 77 55 39 22 3 6 - Comparing the results obtained for the Low complexity dataset, in tables 7.1 and 7.2, we can verify that the best results according to validation were achieved by using the model "Best MEDAE", using a score threshold of 0.9. 104 Table 7.3: Inference and Regression metrics for model "Best RMSE & MAE" - Medium complexity Value predicted per Score threshold Image 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 GT Image10 230 174 140 124 105 93 74 62 39 105 Image7 193 149 137 125 111 99 84 72 42 121 Image11 271 181 143 118 102 86 69 58 28 124 Image3 252 192 160 134 109 94 80 64 33 155 Image12 313 228 185 167 146 128 116 85 49 168 Image6 281 198 168 152 136 120 101 81 28 201 RMSE 115 48 23 23 35 48 63 80 115 - MAE 111 42 21 17 28 42 58 75 109 - MEDAE 111 47 18 13 22 39 54 75 108 - Table 7.4: Inference and Regression metrics for model "Best MEDAE" - Medium complexity Value predicted per Score threshold Image 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 GT Image10 674 466 358 307 261 226 190 160 126 105 Image7 480 333 263 212 175 158 139 123 97 121 Image11 700 581 427 324 256 212 180 149 100 124 Image3 700 534 393 295 245 208 164 128 74 155 Image12 700 605 466 375 308 254 218 180 130 168 Image6 585 406 330 283 247 215 189 168 135 201 RMSE 502 356 237 162 111 75 47 31 48 - MAE 494 342 227 154 103 67 38 26 42 - MEDAE 539 370 246 170 111 70 34 26 31 - As presented in tables 7.3 and 7.4, the results obtained for the medium complexity dataset show that, according to the validation dataset, it should be chosen the model "Best RMSE & MAE", using a score threshold of 0.4. 105 Table 7.5: Inference and Regression metrics for model "Best RMSE & MAE" - High complexity Value predicted per Score threshold Image 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 GT Image1 372 297 271 253 232 207 178 142 87 278 Image8 366 296 272 250 214 194 169 118 68 349 Image9 539 454 416 379 330 291 244 190 95 506 RMSE 58 44 69 94 131 158 192 239 308 - MAE 48 41 58 84 119 147 181 228 294 - MEDAE 33 52 77 99 135 155 180 231 281 - Table 7.6: Inference and Regression metrics for model "MEDAE" - High complexity Value predicted per Score threshold Image 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 GT Image1 700 700 573 486 426 379 339 304 237 278 Image8 700 587 484 421 378 350 314 279 223 349 Image9 700 700 700 627 565 520 475 417 330 506 RMSE 336 301 218 145 93 59 44 67 127 - MAE 322 285 208 134 79 39 42 62 114 - MEDAE 351 238 194 121 59 14 35 70 126 - Comparing the results obtained and presented in 7.5 and 7.6 for the high complexity dataset, we can verify that the best results according to the validation dataset were obtained by using the model "Best RMSE & MAE", with a score threshold of 0.2. 106 8 Test evaluation In order to evaluate the performance of the final model, a set of 30 images were defined as test during the dataset partition, as defined in table 8.1. Table 8.1: Test Dataset for levels "Low", "Medium" and "High" Dataset #cells %cells #images %images Avg. #cells per image Low 399 7.83 7 23.33 57.00 Medium 2315 45.41 16 53.33 144.69 High 2384 46.76 7 23.33 340.57 Total 5098 100 30 100 169.93 From those 30 images, and after freezing the model, we can infer the number of cells present in each image. The results for each level are presented on tables 8.2, 8.3 and 8.4, where ystands for the ground truth value and ˆ yfor the predicted value: Table 8.2: Results on test dataset - predicted vs. ground truth for low level using model "Best MEDAE" for a threshold of 0.9 Level Image yˆ y|ˆ y−y| Low Image_037 30 24 6 Image_169 35 45 10 Image_091 44 44 0 Image_085 57 51 6 Image_151 65 55 10 Image_193 77 80 3 Image_094 91 97 6 107 Table 8.3: Results on test dataset - predicted vs. ground truth for medium level using model "Best RMSE & MAE for a threshold of 0.4 Level Image yˆ y|ˆ y−y| Medium Image_289 95 101 6 Image_097 103 109 6 Image_124 110 89 21 Image_019 115 111 4 Image_196 119 111 8 Image_010 124 127 3 Image_181 129 118 11 Image_286 134 138 4 Image_154 137 114 23 Image_076 154 155 1 Image_205 157 133 24 Image_100 159 153 6 Image_103 177 174 3 Image_064 185 186 1 Image_007 198 153 45 Image_241 219 175 44 Table 8.4: Results on test dataset - predicted vs. ground truth for high level using model "Best RMSE & MAE for a threshold of 0.2 Level Image yˆ y|ˆ y−y| High Image_004 236 235 1 Image_238 245 256 11 Image_250 284 227 57 Image_226 298 320 22 Image_268 343 350 7 Image_223 407 328 79 Image_115 571 503 68 Table 8.5 presents the results regarding regression metrics for the test evaluation. As can be seen, and comparing as an example the results obtained for the medium level and presented on 6.46, the new data partition had led the performance of the model to significantly worse behavior, where the error measured by the RMSE, MAE and MEDAE went from 8.8, 6.4 and 3.5 to 22.04, 18.06 and 16.50, respectively. 108 Table 8.5: Regression metrics results on test evaluation Level RMSE MAE MedAE Low 9.25 7.71 6.00 Medium 22.04 18.06 16.50 High 53.29 43.71 37 Finally, descriptive statistics were inferred from the final results, as shown in table 8.6, and conclusions can be made. Table 8.6: Descriptive statistics associated to the error encontered on the different levels of complexity Level Min Max Mean STD 1st Qrt 2nd Qrt 3rd Qrt Low 0 10 5.86 3.58 3 6 10 Medium 1 45 14.37 13.12 3.25 6 22.5 High 1 79 35 32.13 7 22 68 All 0 79 16.53 20.96 3.75 6.5 22.25 According to the results exposed in table 8.6: 1. For the level low, the error found in samples was in the range of [0,10] units, with a standard deviation of 3.58. Half of the samples had less than 6 units or error. 2. For the medium level, the error range was between [0,45], with a standard deviation of 13.12. Half of the samples had less than 6 units of error and 75% less than 22.5 units of error. 3. For the high level, the error ranged between [1,79], with a standard deviation of 32.13 and half of the samples had less than 22 units of error. 4. Overall, the samples error range was between [0,79], with a standard deviation of 20.96, and half of the predicted values had an absolute difference to the real values lower than 6.5 units. In figure 8.1 is presented the inference to images of the three levels as an example, side by side to the original labeled ones. 109 Figure 8.1: Ground truth labeling and infered detections for images with Low, Medium and High complexity 110 In the first row, we have a test example with 44 cells. The model proposed predicts 44 cells in the image. In the second row, a test example is presented with 159 cells. The model predicts that 153 cells are present in the image. In the lower row, a test sample with 236 cells is shown. The model infers the cell counting as 235 cells. 111 9 Final application The final application aims to deliver an executable easy-friendly to work on in order to make inferences on images similar to the ones used to build the final model. Figure 9.1: Initial screen of the application "CellCounter" As a simple and concise tool, users can select two main options: 1. Browse Image - The user can infer the detection in an isolated image, and compare both raw and image with detections side by side, as also the number of detections predicted. 2. Browse directory - The user can select a directory and make the inference to all the 112 [8] Aurélien Géron. Hands-on machine learning with Scikit-Learn and TensorFlow: concepts, tools, and techniques to build intelligent systems. " O’Reilly Media, Inc.", 2017. [9] Pascal Getreuer. Linear methods for image interpolation. Image Processing On Line, 1:238–259, 2011. [10] Ross Girshick. Fast r-cnn. In Proceedings of the IEEE international conference on computer vision, pages 1440–1448, 2015. [11] Ross Girshick, JeffDonahue, Trevor Darrell, and Jitendra Malik. Rich feature hierarchies for accurate object detection and semantic segmentation. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 580–587, 2014. [12] Xavier Glorot and Yoshua Bengio. Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the thirteenth international conference on artificial intelligence and statistics, pages 249–256, 2010. [13] Rafael C. Gonzales and Paul Wintz. Digital Image Processing (2Nd Ed.). Addison- Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1987. [14] Ian Goodfellow, Yoshua Bengio, Aaron Courville, and Yoshua Bengio. Deep learning, volume 1. MIT press Cambridge, 2016. [15] Tongfan Guan and Hao Zhu. Atrous faster r-cnn for small scale object detection. In 2017 2nd International Conference on Multimedia and Image Processing (ICMIP), pages 16–21. IEEE, 2017. [16] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Delving deep into rectifiers: Surpassing human-level performance on imagenet classification. In Proceedings of the IEEE international conference on computer vision, pages 1026–1034, 2015. [17] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 770–778, 2016. [18] Carlos X Hernández, Mohammad M Sultan, and Vijay S Pande. Using deep learning for segmentation and counting within microscopy data. arXiv preprint arXiv:1802.10548, 2018. 119 [19] Geoffrey E Hinton, Nitish Srivastava, Alex Krizhevsky, Ilya Sutskever, and Ruslan R Salakhutdinov. Improving neural networks by preventing co-adaptation of feature detectors. arXiv preprint arXiv:1207.0580, 2012. [20] Jonathan Huang, Vivek Rathod, Chen Sun, Menglong Zhu, Anoop Korattikara, Alireza Fathi, Ian Fischer, Zbigniew Wojna, Yang Song, Sergio Guadarrama, et al. Speed/accuracy trade-offs for modern convolutional object detectors. In IEEE CVPR, volume 4, 2017. [21] Sergey Ioffe and Christian Szegedy. Batch normalization: Accelerating deep network training by reducing internal covariate shift. arXiv preprint arXiv:1502.03167, 2015. [22] Yangqing Jia, Evan Shelhamer, JeffDonahue, Sergey Karayev, Jonathan Long, Ross Girshick, Sergio Guadarrama, and Trevor Darrell. Caffe: Convolutional architecture for fast feature embedding. In Proceedings of the 22nd ACM international conference on Multimedia, pages 675–678. ACM, 2014. [23] Alboukadel Kassambara. Machine Learning Essentials: Practical Guide in R. STHDA, 2018. [24] Nitish Shirish Keskar, Dheevatsa Mudigere, Jorge Nocedal, Mikhail Smelyanskiy, and Ping Tak Peter Tang. On large-batch training for deep learning: Generalization gap and sharp minima. arXiv preprint arXiv:1609.04836, 2016. [25] Diederik P Kingma and Jimmy Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014. [26] Alex Krizhevsky and GeoffHinton. Convolutional deep belief networks on cifar-10. Unpublished manuscript, 40(7), 2010. [27] Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton. Imagenet classification with deep convolutional neural networks. In Advances in neural information processing systems, pages 1097–1105, 2012. [28] Yann LeCun, Léon Bottou, Yoshua Bengio, and Patrick Haffner. Gradient-based learning applied to document recognition. Proceedings of the IEEE, 86(11):2278– 2324, 1998. 120 [29] Tsung-Yi Lin, Priyal Goyal, Ross Girshick, Kaiming He, and Piotr Dollár. Focal loss for dense object detection. IEEE transactions on pattern analysis and machine intelligence, 2018. [30] Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, and Alexander C Berg. Ssd: Single shot multibox detector. In European conference on computer vision, pages 21–37. Springer, 2016. [31] Erik Meijering. Cell segmentation: 50 years down the road [life sciences]. IEEE Signal Processing Magazine, 29(5):140–145, 2012. [32] T.M. Mitchell. Machine Learning. McGraw-Hill International Editions. McGraw- Hill, 1997. [33] João C Neves, Helena Castro, Ana Tomás, Miguel Coimbra, and Hugo Proença. Detection and separation of overlapping cells based on contour concavity for leishmania images. Cytometry Part A, 85(6):491–500, 2014. [34] Andrew Ng. Why does batch norm work? https://pt.coursera.org/lecture/ deep-neural-network/why-does-batch-norm-work-81oTm. Online; accessed 11- October-2018. [35] Daniel Onoro-Rubio and Roberto J López-Sastre. Towards perspective-free object counting with deep learning. In European Conference on Computer Vision, pages 615–629. Springer, 2016. [36] Randall C O’Reilly, Y Munakata, MJ Frank, TE Hazy, et al. Computational cognitive neuroscience. PediaPress, 2012. [37] DPVV Pankaj S Parsania and PV Virparia. A comparative analysis of image interpolation algorithms. Advanced Research in Computer and Communication Engineering, 5, 2016. [38] Razvan Pascanu, Tomas Mikolov, and Yoshua Bengio. On the difficulty of training recurrent neural networks. In International Conference on Machine Learning, pages 1310–1318, 2013. [39] Josh Patterson and Adam Gibson. Deep Learning: A Practitioner’s Approach. " O’Reilly Media, Inc.", 2017. 121 [40] Boris T Polyak. Some methods of speeding up the convergence of iteration methods. USSR Computational Mathematics and Mathematical Physics, 4(5):1–17, 1964. [41] Maryam Rahnemoonfar and Clay Sheppard. Deep count: fruit counting based on deep simulated learning. Sensors, 17(4):905, 2017. [42] Joseph Redmon, Santosh Divvala, Ross Girshick, and Ali Farhadi. You only look once: Unified, real-time object detection. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 779–788, 2016. [43] Scott Reed, Honglak Lee, Dragomir Anguelov, Christian Szegedy, Dumitru Erhan, and Andrew Rabinovich. Training deep neural networks on noisy labels with bootstrapping. arXiv preprint arXiv:1412.6596, 2014. [44] Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster r-cnn: Towards real-time object detection with region proposal networks. In Advances in neural information processing systems, pages 91–99, 2015. [45] Mikel Rodriguez, Ivan Laptev, Josef Sivic, and Jean-Yves Audibert. Density-aware person detection and tracking in crowds. In Computer Vision (ICCV), 2011 IEEE International Conference on, pages 2423–2430. IEEE, 2011. [46] Sebastian Ruder. An overview of gradient descent optimization algorithms. arXiv preprint arXiv:1609.04747, 2016. [47] Arthur L Samuel. Some studies in machine learning using the game of checkers. IBM Journal of research and development, 3(3):210–229, 1959. [48] Mohit Sewak, Md Rezaul Karim, and Pradeep Pujari. Practical Convolutional Neural Networks: Implement advanced deep learning models using Python. Packt Publishing Ltd, 2018. [49] Rajalingappaa Shanmugamani. Deep Learning for Computer Vision: Expert techniques to train advanced neural networks using Tensorflow and Keras. Packt Publishing Ltd, 2018. [50] Samuel L Smith, Pieter-Jan Kindermans, and Quoc V Le. Don’t decay the learning rate, increase the batch size. arXiv preprint arXiv:1711.00489, 2017. 122 [51] Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov. Dropout: a simple way to prevent neural networks from overfitting. The Journal of Machine Learning Research, 15(1):1929–1958, 2014. [52] Christian Szegedy, Sergey Ioffe, Vincent Vanhoucke, and Alexander A Alemi. Inception-v4, inception-resnet and the impact of residual connections on learning. In AAAI, volume 4, page 12, 2017. [53] Christian Szegedy, Wei Liu, Yangqing Jia, Pierre Sermanet, Scott Reed, Dragomir Anguelov, Dumitru Erhan, Vincent Vanhoucke, and Andrew Rabinovich. Going deeper with convolutions. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 1–9, 2015. [54] Weidi Xie, J Alison Noble, and Andrew Zisserman. Microscopy cell counting and detection with fully convolutional regression networks. Computer methods in biomechanics and biomedical engineering: Imaging & Visualization, 6(3):283–292, 2018. [55] Mingliang Xu, Zhaoyang Ge, Xiaoheng Jiang, Gaoge Cui, Pei Lv, and Bing Zhou. Depth information guided crowd counting for complex crowd scenes. arXiv preprint arXiv:1803.02256, 2018. [56] Yao Xue and Nilanjan Ray. Cell detection in microscopy images with deep convolutional neural network and compressed sensing. 2018. [57] Cong Zhang, Hongsheng Li, Xiaogang Wang, and Xiaokang Yang. Cross-scene crowd counting via deep convolutional neural networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 833–841, 2015. [58] Barret Zoph, Vijay Vasudevan, Jonathon Shlens, and Quoc V Le. Learning transferable architectures for scalable image recognition. arXiv preprint arXiv:1707.07012, 2(6), 2017. 123 i Title: Convolutional Neural Networks for Cell Detection and Counting Subtitle: A case study of Human cell Quantification in Zebrafish Xenografts using DL Object Detection Techniques Student full name: Carina Isabel Andrade Albuquerque MAA 2018 i