06 - Food Calorie Estimation
06 - Food Calorie Estimation
Submitted by
Tanvi Gharte (12)
Kajal Hake (13)
Himani Patil (31)
i
CERTIFICATE
This is to certify that Miss. Tanvi Gharte, Himani Ravindra Patil and Kajal Hake
has successfully completed seminar work on the topic Food Calorie Estimation
satisfactorily in partial fulfillment for the Bachelor’s Degree in Computer Science and
Technology under the guidance of Prof. Sumedh Pundkar during the year 2020- 2021
as prescribed by the SNDT Women’s University.
Principal
Dr. Sanjay Pawar
Examiner 1 Examiner 2
ii
Abstract
An important attribute for a healthy body depends on the number of calories consumed,
hence monitoring calorie intake is necessary to maintain good health. As the like for trend
and variety of fast food items is increasing, people are also becoming more aware and con-
scious about calorie intake as the higher number of calorie intake creates a lot of problems
like obesity, hypertension, high cholesterol, diabetes, heart attack etc that invokes the need
of medical consultancy. People suffering from such problems require an easy way to control
their calorie content in their daily diet.
In order to keep track of the amount of calorie intake of a person, we made a food
recognition and calorie estimation system that identifies the food and estimates the calorie
of the food image which is given as input .We trained more than 1500 images in each category
for our model. We have used CNN (Convolutional Neural Network) as a classifier for food
recognition and obtained 97.11% accuracy. Based on the food weight in grams, volume is
estimated and the calorie of the food item is determined.
Acknowledgement
It gives us great pleasure in presenting the mini project report on ‘Food Calorie Estima-
tion’. We would like to take this opportunity to thank our internal guide Prof. Sumedh Pund-
kar sir for his continuous support, patience, motivation, enthusiasm and immense knowledge.
He helped us in doing the research work and implementation during which we got to learn
ample of new things. However, we would like to express our deep appreciation and indebt-
edness to our professors for their endless support, kindness and understanding during the
project duration.
Our thanks and appreciation goes to our team members in developing the project. All
in all, we would like to thank everyone involved in this project and helped us with their
suggestions to make the project better.
Date:
i
Contents
Abstract i
List of Figures iv
1 Introduction 1
1.1 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Literature Survey 3
3 Existing System
and Proposed System 7
3.1 Existing System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Proposed System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.1 Image Preprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.2 Image Classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.3 Image Segmentation and Feature Extraction . . . . . . . . . . . . . . 10
3.2.4 Volume Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2.5 Weight and Calorie Estimation . . . . . . . . . . . . . . . . . . . . . 12
4 Architectural Overview 13
5 Technology Used 15
5.1 Hardware and Software
Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
6 Implementation Details 19
7 Conclusion 30
7.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7.3 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
References 32
ii
List of Tables
iii
List of Figures
iv
Chapter 1
Introduction
1.2 Introduction
Obesity and overweight have traditionally been linked to intake of high calorie food and
lifestyle. Obesity is defined using Body Mass Index (BMI) of the individual. A person is
considered obese when the (BMI) is greater than or equal to 30 (kg/m2 ). Unfortunately, more
and more people will meet criteria for obesity. The main cause of obesity is the imbalance
between the amount of food intake and energy consumed by the individuals. It is noticed
that obesity or overweightness cause a number of chronic diseases such as breast and colon
1
1.2. INTRODUCTION CHAPTER 1. INTRODUCTION
cancer, blood pressure, heart diseases, type II diabetes. Food is the key of human’s body.
So, a diet plan always needs to take into consideration the total number of calories to be
consumed to maintain a fit and healthy life. But, in most of the cases, people face difficulties
in estimating the amount of food intake due to lack of nutritional information, which includes
the manual process of writing down this information, and other reasons. As such, it will be
useful if there is a system to keep track and maintain the calorie intake. Therefore correct
prediction of food calorie is equally important.
In recent years, many systems built for performing the same task require the manual
input of food items, their ingredients, amount and some other specific details which becomes
a tiresome process and the users of any system wants it to be user friendly and easy to access
and use. Using image as an input and providing to the system to give the result is supposed
to be a lot easier. Hence, in our proposed model we allow users to upload the picture of a
food item as input and the rest of work will be accomplished by the machine rather than
the user.
So, to reduce this difficulty of tracking the calories consumed by a person we came up with
an idea of building an automated system for prediction of calories.We are proposing an image-
based Food recognition and Calorie Estimation System which will only require the image of
the food item for the prediction of the calories present in the food item. This system will
allow users to upload food images in different views like top view, side view, etc. For image
classification we have used Convolutional Neural Network (CNN). Food(s) and calibration
objects are detected by an object detection method called CNN.We trained more than 1500
images in for our model. In this algorithm, we are providing an image to convolutional as an
input and we get a convolutional feature map as output. Using image segmentation we are
dividing an image into different regions based on contour, characteristics of pixels of food
image. We calculated calories with the help of segmented images using formulas and thumb
whose dimensions are already known to us. Using a segmented image, we first calculate the
volume of the food item and then mass of the item and finally the calorie of the item using
relation between the mass and calorie of a food item.
Experimental results of combination of different segmentation methods such as color,
texture, graph-cut segmentation and deep learning neural network showed an accuracy of
97.11%. An accurate estimation of daily nutritional intake provides a useful solution for
keeping healthy and to prevent diseases.
Literature Survey
The aim of this section is to provide the pros and cons of existing methods and the needs for
alternative approaches. This section will present a number of the most common food intake
measuring methods, plus their advantages and disadvantages. As a result, we will show the
importance of our calorie-intake measurement system which can be used for normal people
and clinical purposes in order to enhance the treatment methods for people who suffer from
obesity and overweightness. Different calorie measurement models have been developed for
research and patient health diagnosis and prescription. Most of the systems either developed
or proposed lack either in user friendliness and accessibility or performance and accuracy or
some other parameters. Several such models are enumerated below:
3
CHAPTER 2. LITERATURE SURVEY
Existing System
and Proposed System
7
CHAPTER 3. EXISTING SYSTEM
3.2. PROPOSED SYSTEM AND PROPOSED SYSTEM
Proposed food recognition and calorie measurement system aims to allow the user to
upload the picture of food items at any time and any place to measure calorie value
from the uploaded photo. This unique method will provide more accurate results than
other methods.
We are using a different variety of food dataset (e.g. fruits, fast food, vegetables ,
non-veg items) for training our model.
We are building our own food dataset with multiple brands of cameras to capture
the image of the same food item, providing an opportunity for the food recognition
system to become more robust with changes in camera brands. We provide multiple
shooting angles for the same food item, allowing the development of more accurate
food recognition methods.
We are using CNN algorithm to obtain more accuracy. Also we are using Python
language rather than Matlab for better performance.
Our aim is to obtain more accuracy (greater than 94 percent) than existing models.
CNN
1. Convolutional Layer: This layer is the first layer that is used to extract the various
features from the input images. In this layer, the mathematical operation of convolution is
performed between the input image and a filter of a particular size MxM. By sliding the
filter over the input image, the dot product is taken between the filter and the parts of the
input image with respect to the size of the filter (MxM). The output is termed as the Feature
map which gives us information about the image such as the corners and edges. Later, this
feature map is fed to other layers.
Average Pooling, calculates the average of the elements in a predefined size Image
section.
Sum Pooling, the total sum of the elements in the predefined section is computed in
this.
3. Full connection: After receiving inputs from the previous neurons, the final layer
is the fully connected one. It takes the output of the previous layers, “flattens” them and
turns them into a single vector that can be an input for the next stage.
The FC layer helps to map the representation between the input and the output.
5. Activation Functions: There are several commonly used activation functions such
as the ReLU, Softmax, tanH and the Sigmoid functions.Here we are using ReLU and softmax
functions.
ReLU: ReLu refers to the Rectifier Unit, the most commonly deployed activation
function for the outputs of the CNN neurons.The main advantage of using the ReLU
function over other activation functions is that it does not activate all the neurons at
the same time.The purpose of applying the rectifier function is to increase the non-
linearity in our images.
Softmax: Softmax is implemented through a neural network layer just before the
output layer. The Softmax layer must have the same number of nodes as the output
layer. The softmax function is a function that turns a vector of K real values into a
vector of K real values that sum to 1. The input values can be positive, negative, zero,
or greater than one, but the softmax transforms them into values between 0 and 1, so
that they can be interpreted as probabilities.
5.0
pix to cm multilpier = P ixelHeight
F oodpixelArea∗ActualSkinArea
EstimatedArea = SkinP ixelArea
4
EstimatedV olume = 3
∗ Π ∗ Radius
EstimatedF oodArea
EstimatedRadius = (2∗EstimatedHeight)
4
EstimatedV olume = 3
∗ Π ∗ Radius ∗ Height
Architectural Overview
13
CHAPTER 4. ARCHITECTURAL OVERVIEW
Step 1: User will upload the image of food item onto the webpage
Users can upload the image of the food product which is already clicked by them and
that image will act as input to the system. For all images we have considered a white plate
to ignore the background of the images.
Technology Used
Hard Drive: 64 GB
Software Requirements
1. Anaconda Navigator:
Navigator allows us to launch common Python programs and easily manage conda
packages, environments, and channels without using command-line commands.
We can use it to find the packages you want, install them in an environment, run the
packages, and update them – all inside Navigator.
15
5.1. HARDWARE AND SOFTWARE
REQUIREMENTS CHAPTER 5. TECHNOLOGY USED
2. Jupyter Notebook
Data visualizations:
Jupyter Notebook helps us for data visualizations, but also shares and allows us to do
interactive changes to the shared code and data set.
Code sharing:
With a Jupyter Notebook, we can view code, execute it, and display the results directly
in our web browser.
Jupyter Notebook code isn’t static; it can be edited and re-run incrementally in real
time, with feedback provided directly in the browser.
Notebooks can also embed user controls (e.g., sliders or text input fields) that can be
used as input sources for code.
If we have a piece of code and we want to explain line-by-line how it works, with live
feedback all along the way, we could embed it in a Jupyter Notebook.
The code will remain fully functional and we can add interactivity along with the
explanation, showing and telling at the same time.
3. Pycharm
PyCharm is the most popular IDE used for the Python scripting language. PyCharm
is a hybrid-platform developed by JetBrains as an IDE for Python. It is commonly used
for Python application development. Some of the unicorn organizations such as Twitter,
Facebook, Amazon, and Pinterest use PyCharm as their Python IDE!
Features of PyCharm:
It consists of color schemes for keywords, classes, and functions. This helps increase
the readability and understanding of the code.
It provides the autocomplete feature and instructions for the completion of the code.
Code Navigation:
It helps developers in editing and enhancing the code with less effort and time.
With code navigation, a developer can easily navigate to a function, class, or file.
A programmer can locate an element, a symbol, or a variable in the source code within
no time.
It supports popular web technologies such as HTML, CSS, and JavaScript. It also
supports AngularJS and NodeJS for developing web applications.
Developers have the choice of live editing with this IDE. At the same time, they can
preview the created/updated web page.
PyCharm supports web frameworks such as Django. It helps in debugging the codes
of Django.
It provides the autocomplete feature and suggestions for the parameters of Django.
It also assists web2py and Pyramid, the other popular web frameworks.
Assistance for Python Scientific Libraries:
PyCharm supports Python’s scientific libraries such as Matplotlib, NumPy, and Ana-
conda.
These scientific libraries help in building projects of Data Science and Machine Learn-
ing.
It consists of interactive graphs that help developers understand data.
It is capable of integrating with various tools such as IPython, Django, and Pytest.
This integration helps innovate unique solutions.
4. VS Code
Visual Studio Code is a powerful source code editor which is available for Windows, ma-
cOS and Linux. Instead of a project system, it allows users to open one or more directories,
which can then be saved in workspaces for future reuse.
Features of VS Code:
Language support:
Visual Studio Code includes basic built-in support for most common programming
languages such as C++, Java, Python, PHP, Go,etc.
It provides syntax highlighting, bracket matching, code folding, and configurable snip-
pets.
VS Code also ships with IntelliSense for JavaScript, TypeScript, JSON, CSS, and
HTML, as well as debugging support for Node.js.
Data collection:
Visual Studio Code collects usage data and sends it to Microsoft, although this can be
disabled.
It is in the open-source nature of the application, due to which the telemetry code is
accessible to the public.
Version control:
Source control is a built-in feature of Visual Studio Code.
It has a dedicated tab inside of the menu bar where you can access version control
settings and view changes made to the current project.
Implementation Details
Setting up of model
Image segmentation
Calorie estimation
The produced data set comprising 13 different categories of food and fruits. These food
and fruit images are divided into training and testing sets, where around 50 of the fruit
images from each group are used to train the system and the remaining images serve as the
testing set.
We took into consideration important factors that affect the accuracy of our results.
Specifically, we used a variety of the following components: Camera, Lighting, Shooting
Angle, White Plate, Thumb, Single and Mixed Food. Each component will be described in
details in the following subsections.
Camera
We used three different cameras for our experiments, consisting of Canon SD1400 (14.1-
megapixel resolution, 2.7-inch Pure Color System LCD, 28mm wide-angle lens; 4x optical
zoom and Optical Image Stabilizer) iPhone 4(5 megapixel resolution, LED flash, VGA-
quality photos and video at up to 30 frames per second with the front camera), and Samsung
S4 cameras (13 megapixel resolution, 41, autofocus, LED flash, Dual shot).
19
CHAPTER 6. IMPLEMENTATION DETAILS
Lighting
Lighting and illumination is one of the important parameters which affect the system
outcome because illumination directly affects the image segmentation algorithm, which in
turn affects the rest of the algorithms. To take this into account, we put the same plate in
three different locations with different illuminations (sunlight) and we took pictures.
Shooting Angle
Another effective parameter is the angle of photography; we have chosen three different
angles which are approximately 30, 90, and 150 degrees from the plate of food for all pictures.
This means that for each plate in 3 different lighting locations we have also taken 3 pictures
from different angles.
White Plate
For all images we have considered a white plate to ignore the background of the images.
By using white plate, food segmentation and food recognition will be easier to perform.
Thumb
The thumb of the user and its placement on the plate are also shown in Figure 2. There
is a one-time calibration process for the thumb, which is used as a size reference to measure
the real-life size of food portions in the picture. Compared to the calibration methods of
similar systems, using the thumb is more flexible, controllable, and reliable.
The dataset contains images taken with different cameras, illuminations, and angles.
Having a wide variety of food and fruits gives a better and more reliable dataset in order
to increase the accuracy of calorie food measurement systems. In the dataset, the images
are divided into 6 categories considering the capturing device, background, and lighting
condition. For example, images in category 1 are captured with a Samsung camera, within
a light environment with a white background, and from different shooting angles.
Setting up of model
Food Recognition deals with recognition of food items when given an image.For this
problem we used Convolutional Neural Network (CNN).
Firstly we imported all the libraries such as Tensorflow and tflearn which were needed
to implement CNN .
Then we have used 5 convolution layers such as convolutional layers, pooling layers
followed by fully-connected layers.Also used dropout layer and activation functions
such as ReLu and Softmax.
The CNN takes an input image and applies convolutional and then sub-sampling layers
. After two such computations, the data is fed into the fully connected neural network,
where it performs the classification task.
Also used Adam optimizer and categorical cross entropy loss function with learning
rate 0.0001 to calculate and minimize loss as well as optimize model accuracy.
Fine tuning the model on our dataset took about 1 hours on a single Windows 10 In-
tel(R) core(TM) i5-1035G1 CPU with 8GB of memory.For this training we used more than
100 images of each food with 400*400 image size. All this work done in Python 3.9.0 with
Anaconda Distribution 4.8.3. In this section we will be discussing the results about by using
CNN algorithm on our image dataset. For classification purposes we used 40 epochs. After
40 epochs we got an accuracy of about 97.11% in image classification and loss about 0.39% .
Till now we have only been able to find out the calories of spherical food items including
apple, onion, tomato and orange.
Image Segmentation
As we are using canny edge detection, watershed segmentation, morphological operators and
Otsu’s method to segment the food item, we are successfully able to recognize contour of
food and contour of thumb.
Calorie Estimation
After segmentation is done. We are able to find calorie correct calories of spherical food
items by volume and weight estimation.
To test the dataset we have run one demo to ensure the correct food is recognized.
Considered only spherical food items like apple, orange, onion, etc. and provided the
relevant formulas according to shape.
We know food density (g/cm3 ) and food calories (kcal/g), using this information we
have estimated weight and calories.
Conclusion
7.1 Conclusion
We have verified that our proposed measurement system is useful, convenient and very user-
friendly, which could encourage users to use the system at each and every meal time.We built
our own dataset comprising more than 1500 food images with careful attention of shooting
angle and illumination variations. In the above project, we have calculated the calories of
spherical shape food items using deep learning and image processing. For that we have
implemented three modules.First, we detect the object using CNN.Our results shown that
the accuracy of our model for food recognition is 97.11%. After that image segmentation is
performed and based on volume estimation, weight and calories are calculated successfully
for spherical food items.
In the next phase, we are going to work on volume and calorie estimation process for
all shapes of food.
We are planning to deploy our model into the web application for user convenience.
We plan to enhance our system by notifying the user about how much the user should
intake in calories.
7.3 Applications
Helps people to deal with problems like obesity, hypertension, high cholesterol, dia-
betes, heart attack,etc which may further lead to medical consultancy.
30
7.3. APPLICATIONS CHAPTER 7. CONCLUSION
[1] Jessie R Balbin, Leonardo D Valiente, Kim Martin P Monsale, Emmanuel D Olorvida,
Gerard Glenn V Salazar, and Lyzza Marie L Soto. Determination of calorie content
in different type of foods using image processing. In 2019 IEEE 11th International
Conference on Humanoid, Nanotechnology, Information Technology, Communication and
Control, Environment, and Management (HNICEM), pages 1–6. IEEE.
[2] Yuri Y Boykov and M-P Jolly. Interactive graph cuts for optimal boundary & region seg-
mentation of objects in nd images. In Proceedings eighth IEEE international conference
on computer vision. ICCV 2001, volume 1, pages 105–112. IEEE, 2001.
[3] Meng-Lin Chiang, Chia-An Wu, Jian-Kai Feng, Chiung-Yao Fang, and Sei-Wang Chen.
Food calorie and nutrition analysis system based on mask r-cnn. In 2019 IEEE 5th
International Conference on Computer and Communications (ICCC), pages 1721–1728.
IEEE, 2019.
[4] Manal Chokr and Shady Elbassuoni. Calories prediction from food images. In Twenty-
Ninth IAAI Conference, 2017.
[5] R Kohila and R Meenakumari. Predicting calorific value for mixed food using image
processing. In 2017 International Conference on Innovations in Information, Embedded
and Communication Systems (ICIIECS), pages 1–4. IEEE, 2017.
[6] Yanchao Liang and Jianhua Li. Deep learning-based food calorie estimation method in
dietary assessment. arXiv preprint arXiv:1706.04062, 2017.
[7] Parisa Pouladzadeh, Shervin Shirmohammadi, and Rana Al-Maghrabi. Measuring calorie
and nutrition from food image. IEEE Transactions on Instrumentation and Measurement,
63(8):1947–1956, 2014.
[8] Manpreetkour Basantsingh Sardar and Dr Sayyad D Ajij. Fruit recognition and its calorie
measurement: An image processing approach. Journal of Emerging Trends in Computing
and Information Sciences, 2016.
[9] Reza Dea Yogaswara, Eko Mulyanto Yuniarno, and Adhi Dharma Wibawa. Instance-
aware semantic segmentation for food calorie estimation using mask r-cnn. In 2019
International Seminar on Intelligent Technology and Its Applications (ISITIA), pages
416–421. IEEE, 2019.
32