# Smart Diet Diary: Real-Time Mobile Application for Food Recognition
## 3 Materials and Methods
### Object Detection and Classification  
Food identification is an image recognition challenge, and deep learning is a powerful instrument for solving such a problem [65], inspired by the animal visual cortex [66]. CNNs need less preprocessing compared to other image classification algorithms. However, this becomes computationally heavy if the ROI has diverse physical positions in the image. This problem is overcome using region-based convolutional neural networks, R-CNNs, which deploy selective search methods and extract fewer regions from the image, called region proposals. It still requires a substantial amount of time to train the network. An improved version of R-CNN is a single-stage fast R-CNN [67] object detection algorithm that eliminates the need for multiple SVMs using a softmax layer to predict object classes \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Sr. No.** & **Category** & **Training** & **Test** & **Total** \\ \hline
1 & Apple & 671 & 200 & 871 \\
2 & Bluebird sour cream & 805 & 200 & 1005 \\
3 & Chicken curry & 651 & 200 & 851 \\
4 & Coca-Cola can & 1035 & 200 & 1230 \\
5 & Coin & 1546 & 400 & 1946 \\
6 & ETA chicken & 817 & 200 & 1017 \\
7 & ETA sour cream & 809 & 200 & 1009 \\
8 & Fanta can & 1059 & 150 & 1209 \\
9 & McDonolds Big-Mac & 849 & 200 & 1049 \\
10 & McDonals Fillet-o-Fish & 872 & 200 & 1072 \\
11 & McDonals Fries & 849 & 200 & 1049 \\
12 & McDonals McChicken & 836 & 200 & 1036 \\
13 & Orange & 718 & 200 & 918 \\
14 & Pizza Hut & 846 & 200 & 1046 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Details of test and training dataset. and bounding box offsets directly. It is faster and more accurate than the original R-CNN but requires separate region proposal algorithms, thus limiting its performance. A recent incarnation, faster R-CNN, has only one network that predicts both object bounding box and class probability using an RPN and a fast R-CNN-like network, eliminating the need for external regional proposal algorithms. The network learns to generate proposals independently, making it faster, more efficient, and more accurate. Additionally, end-to-end training strategy, flexibility, scalability, and open-source implementation make it a popular choice for object-detection tasks. There are three neural networks that make up the faster R-CNN: a feature network that creates useful features from images; a region proposal network (RPN) that classifies and creates bounding boxes; and a detection network that produces the ultimate class and bounding boxes. The aim of neural network is to produce bounding boxes or ROI with a higher likelihood of an enclosing object. The final class and bounding box are generated by the detection network using data from the feature network and the RPN. It usually consists of four dense, completely interconnected layers. A classification layer and a bounding box regression layer are both part of these two layered common layers. The features were cut in accordance with the bounding frames to aid in classifying only the area inside of them. The process used to run the R-CNN algorithm on TensorFlow is shown in Figure 5. ConvNet yields a feature map founded by the input image, and RPN applies to these feature maps. ConvNet then returns the object proposals along with their object scores. These proposals are subjected to a ROI pooling layer to create a small, fixed-size feature image. The proposals are sent to a completely connected layer that consists of a linear regression layer and a soft-max layer. Bounding boxes for objects are categorized and produced using this method. We deployed a faster R-CNN for detecting foods and classifying them. We trained the model using around 800 images for each class, and 200 images from each class were reserved for testing. Our dataset had 14 distinct classes, roughly more than 16,000 pictures. After resizing the images into a 600 \(\times\) 600 resolution, the imageries were obtained via the OpenCV library that returns the image as a tensor.