## 3 Materials and Methods
### Method
#### 3.1.2 Stage 2 Training  
For the second stage, we hypothesized that the ONH and its parts (OD/OC) are usually visually similar across datasets, so emphasizing the mask loss during the training will help in boosting the performance, even if a dataset that is originally from a different distribution is used for testing. To test this hypothesis, we performed two experiments in the second stage. In one experiment, the weights associated with each loss in Equation (1) are set to 1, and in the second experiment, the weights of the bounding box and mask (w4, w5 in the equation) were increased to 1.5 and 2.0, respectively. The bounding box weight is increased because the masking process depends on finding a proper bounding box around an object, hence it is increased slightly to make sure a bounding box is found first before attempting to do the segmentation. The Mask R-CNN in stage 2 also used COCO pre-trained weights as starting point, and all layers before C3 are frozen during the training. After localizing the optic nerve head in stage 1, its bounding box is used to crop the image to be used for the analysis in the second stage. The bounding box is padded with extra pixels from each side before using it for cropping the image to get more context for the ONH for better analyses. To assess the performance of the proposed method, we use different parameters; the first stage is judged with one more parameter compared to the second stage. In the first stage, we are concerned with two outcomes of the network: the localization of the optic nerve head (which includes the optic disc and optic cup) and the segmentation of the optic disc and the optic cup. Assessing the segmentation in the first stage will help us to determine if the extra steps of cropping the images and training another model are worth the effort. In the second stage, we are not concerned much about the localization; we care more about the segmentation. The bounding box of the optic disc or the optic cup will be used to assess the accuracy of the localization in the first stage. From the experiments (especially when using a dataset with distribution outside the training dataset), we saw that sometimes the optic disc is not detected by the network. However, the optic cup is detected. Figure 2: Overall segmentation process. In stage 1 (top box) the network produces classification, masks and bounding boxes. We only use the bounding box information to crop the input images (during the training the ground truth bounding box is also cropped). In the second stage (bottom box) the cropped image (based on bounding box from stage 1) is put through the second stage network producing classification, masks, and bounding boxes. The masks output is used for vertical cup-to-disc ratio (vCDR) calculation and segmentation evaluation. Hence the optic cup detection will also be used to determine the success of localization if the optic disc is not detected correctly. The strict definition of the localization used in the literature is the intersection over union (IoU), also known as the Jaccard index or Jaccard score, which is defined in Equation (2). \[IoU=\frac{|A|\cap|B|}{|A|\cup|B|} \tag{2}\]  
where \(IoU\) is the Jaccard score (intersection over union), \(A\) is the ground truth bounding box (or segmentation mask), \(B\) is the predicted bounding box (or segmentation mask). The bounding box is used to assess localization accuracy while the segmentation mask is used to assess the segmentation accuracy. Another standard measurement for medical image segmentation is the Dice score which is related to the Jaccard score by Equation (3). \[D=\frac{2J}{1+J} \tag{3}\]  
where \(D\) is the dice score, and \(J\) is the Jaccard score (\(IoU\)). We will report the results using the Dice score to have comparable results with the literature. Since we are padding the bounding box, we can use a loose definition for successful localization, still based on \(IoU\). We need to find the minimum \(IoU\) needed to contain the entire ONH for a given padding size.