# Utilizing Mask R-CNN for Solid-Volume Food Instance Segmentation and Calorie Estimation
## 5 Experimental Results  
### Gimbap Instance Segmentation Using Mask R-CNN  
The training uses the Windows10 operating system. The server uses the NVIDIA GeForce GTX1650 graphics card, and the memory is 6 GB. Mask-RCNN-inception_v2 is used as a pre-trained model. Two sets of training parameters are used for experimental comparison: (1) max training steps are 200,000, the initial learning rate is set as 0.0002, momentum optimizer value is 0.9; (2) max training steps are 300,000, the initial learning rate is 0.0001, momentum optimizer value is 0.9. Using the first training parameters, the network will recognize the object, which is not Gimbap. In addition, the network will repeatedly identify the same object as different classes. Therefore, this article will choose the second set of parameters. Training takes about 27.7 h to run. On the training set, the total loss, classification loss, localization loss, and mask loss of the network are changed along with increasing training steps, as shown in Figure 8. After 300,000 steps, the total loss curve value of the training set is close to and falls below 0.2, oscillating in a small range. The network produces the correct result output for most image samples. Figure 9 shows Gimbap's sample original images and instance segmentation images. The column (a) images are original images, which include Gimbap1 class and Gimbap2 class, as discussed in Section 3.1. Input the original image into the trained Mask R-CNN model, and the results are as column (b) images. Target Gimbaps are covered by different colors of masks, in the pictures. Each Gimbap is in a separated bounding box. The content in the upper left corner of the bounding box is the predicted label and score of the target Gimbap in the bounding box. Target Gimbap classification in the bounding box is Gimbap1 and Gimbap2. The probability that the target Gimbap belongs to this class is 100%. Figure 7: The pseudo-code to estimate Gimbap calorie, where \(s_{ap1}\), \(s_{ap1}\) and \(s_{ap2}\) are the surface area of the labeled Gimbap. \(L_{pyx}\) and \(L_{pyy}\) are the physical sizes corresponding to each pixel on the \(x\) and \(y\) axes, based on calibration process. \(s_{g}\) is a constant scale gain. The Gimbap is detected by the Mask R-CNN model. The effect of the Mask R-CNN Gimbap detection model is evaluated by the Intersection over Union (IoU) between the predicted Gimbap bounding box and ground truth bounding box. The IoU is calculated as:  
\[\text{IoU}=\frac{\text{Area of Intersection}}{\text{Area of Union}}=\frac{\text{ area}(B_{p}\cap B_{gt})}{\text{area}(B_{p}\cup B_{gt})} \tag{12}\]  
where \(B_{p}\) is the predicted bounding box and \(B_{gt}\) is the ground truth bounding box. If IoU \(\geq\) 0.5, the detection result is considered a True Positive (TP); otherwise, if 0 \(<\) IoU \(<\) 0.5, the result is considered a False Positive (FP). If a mask is generated without Gimbap in the image, the result is also considered a False Positive. If the image contains Gimbap, but it is not detected, the result is considered a False Negative (FN). If the image does not contain Gimbap and no mask was generated, the result is considered a True Negative (TN). As in (13), the precision indicates the ratio of the correct number of Gimbap identified by the model to the total number. In (14), Recall is the ratio of the number of Gimbaps correctly identified by the model to the number of Gimbaps that actually exist. \[\text{Precision}=\frac{\text{TP}}{\text{TP}+\text{FP}} \tag{13}\]  
\[\text{Recall}=\frac{\text{TP}}{\text{TP}+\text{FN}} \tag{14}\]  
The Average Precision (AP) is the area under the precision-recall curve for detection. Based on [31], AP is calculated from the mean precision at a set of eleven equally spaced recall levels [0, 0.1,..., 1]:  
\[\text{AP}=\frac{1}{11}\sum_{r\in\{0,0.1,...,1\}}P_{interp}(r) \tag{15}\]  
The precision for each recall level \(r\) is interpolated by taking the maximum precision value for any recall value greater than \(r\).