People’s awareness about their nutrition habits is increasing either because they suffer from some kind of food intolerance; they have mild or severe weight problems; or they are simply interested in keeping a healthy diet. This increasing awareness is also being reflected in the technological world. Several applications exist for manually keeping track of what we eat, but they rarely offer any automatic mechanism for easing the tracking of the nutrition habits . Tools for automatic food and ingredient recognition could heavily alleviate the problem.
Since the reborn of Convolutional Neural Networks (CNNs), several works have been proposed to ease the creation of nutrition diaries. The most widely spread approach is food recognition. These proposals allow to recognize the type of food present in an image and, consequently, could allow to approximately guess the ingredients contained and the overall nutritional composition. The main problem of these approaches is that no dataset covers the high amount of existent types of dishes worldwide (more than 8,000 according to Wikipedia).
On the other hand, a clear solution for this problem can be achieved if we formulate the task as an ingredients recognition problem instead . Although tens of thousands of types of dishes exist, in fact they are composed of a much smaller number of ingredients, which at the same time define the nutritional composition of the food. If we formulate the problem from the ingredients recognition perspective, we must consider the difficulty of distinguishing the presence of certain ingredients in cooked dishes.Their visual appearance can greatly vary from one dish to another (e.g. the appearance of the ingredient ’apple’ in an ’apple pie’, an ’apple juice’ or a ’fresh apple’), and in some cases they can even be invisible at sight without the proper knowledge of the true composition of the dish. An additional benefit of approaching the problem from the ingredients recognition perspective is that, unlike in food recognition, it has the potential to predict valid outputs on data that has never been seen by the system.
In this paper, we explore the problem of food ingredients recognition from a multi-label perspective by proposing a model based on CNNs that allows to discover the ingredients present in an image even if they are not visible to the naked eye. We present two new datasets for tackling the problem and prove that our method is capable of generalizing to new data that has never been seen by the system. Our contributions are four-fold. 1) Propose a model for food ingredients recognition; 2) Prove that by using a varied dataset of images and their associated ingredients, the generalization capabilities of the model on never seen data can be greatly boosted; 3) Delve into the inner layers of the model for analysing the ingredients specialization of the neurons; and 4) Release two datasets for ingredients recognition.
This paper is organized as follows: in Section 2, we review the state of the art; in Section 3, explain our methodology; in Section 4, we present our proposed datasets, show and analyse the results of the experiments performed, as well as interpret the predictions; and in Section 5, we draw some conclusions.
2 Related work
Food analysis. Several works have been published on applications related to automatic food analysis. Some of them proposed food detection models 
in order to distinguish when there is food present in a given image. Others focused on developing food recognition algorithms, either using conventional hand-crafted features, or powerful deep learning models. Others have applied food segmentation ; use multi-modal data (i.e. images and recipe texts) for recipe recognition ; tags from social networks for food characteristics perception ; food localization and recognition in the wild for egocentric vision analysis , etc.
Multi-Label learning. Multi-label learning  consists in predicting more than one output category for each input sample. Thus, the problem of food ingredients recognition can be treated as a multi-label learning problem. Several works  argued that, when working with CNNs, they have to be reformulated for dealing with multi-label learning problems. Some multi-label learning works have already been proposed for restaurant classification. So far, only one paper  has been proposed related to ingredients recognition. Their dataset, composed of 172 food types, was manually labelled considering visible ingredients only, which limits it to find 3 ingredients on average. Furthermore, they propose a double-output model for simultaneous food type recognition and multi-label ingredients recognition. Although, the use of the food type for optimizing the model limits its capability of generalization only to seen recipes and food types. This fact becomes an important handicap in a real-world scenario when dealing with new recipes. As we demonstrate in Sections 4.3 and 4.4, unlike , our model is able to: 1) recognize the ingredients appearing in unseen recipes (see Fig.0(b)); 2) learn abstract representations of the ingredients directly from food appearance (see Fig.2); and 3) infer invisible ingredients.
Interpreting learning through visualization. Applying visualization techniques is an important aspect in order to interpret what has been learned by our model. The authors in have focused on proposing new ways of performing this visualization. At the same time, they have proven that CNNs have the ability to learn high level representations of the data and even hidden interrelated information, which can help us when dealing with ingredients that are apparently invisible in the image.
Deep multi-ingredients recognition. Most of the top performing CNN architectures have been originally proposed and intended for the problem of object recognition. At the same time, they have been proven to be directly applicable to other related classification tasks and have served as powerful pre-trained models for achieving state of the art results. In our case, we compared either using the InceptionV3  or the ResNet50  as the basic architectures for our model. We pre-trained it on the data from the ILSVRC challenge  and modified the last layer for applying a multi-label classification over the
possible output ingredients. When dealing with classification problems, CNNs typically use the softmax activation in the last layer. The softmax function allows to obtain a probability distribution for the input sampleover all possible outputs and thus, predicts the most probable outcome, .
The softmax activation is usually combined with the categorical cross-entropy loss functionduring model optimization, which penalizes the model when the optimal output value is far away from 1:
In our model, we are dealing with ingredients recognition in a multi-label framework. Therefore, the model must predict for each sample
a set of outputs represented as a binary vector, where is the number of output labels and each is either 1 or 0 depending if it is present or not in sample
. For this reason, instead of softmax, we use a sigmoid activation function:
which allows to have multiple highly activated outputs. For considering the binary representation of , we chose the binary cross-entropy function :
which during backpropagation rewards the model when the output values are close to the target vector(i.e. either close to 1 for positive labels or close to 0 for negative labels).
In this section, we describe the two datasets proposed for the problem of food ingredients recognition. Later we describe our experimental setup and at the end, we present the final results obtained both for ingredients recognition on known classes as well as recognition results for generalization on samples never seen by the model.
In this section we describe the datasets proposed for food ingredients recognition and the already public datasets used.
Food101  is one of the most widely extended datasets for food recognition. It consists of 101,000 images equally divided in 101 food types.
Ingredients101111http://www.ub.edu/cvub/ingredients101/ is a dataset for ingredients recognition that we constructed and make public in this article. It consists of the list of most common ingredients for each of the 101 types of food contained in the Food101 dataset, making a total of 446 unique ingredients (9 per recipe on average). The dataset was divided in training, validation and test splits making sure that the 101 food types were balanced. We make public the lists of ingredients together with the train/val/test split applied to the images from the Food101 dataset.
Recipes5k222http://www.ub.edu/cvub/recipes5k/ is a dataset for ingredients recognition with 4,826 unique recipes composed of an image and the corresponding list of ingredients. It contains a total of 3,213 unique ingredients (10 per recipe on average). Each recipe is an alternative way to prepare one of the 101 food types in Food101. Hence, it captures at the same time the intra-class variability and inter-class similarity of cooking recipes. The nearly 50 alternative recipes belonging to each of the 101 classes were divided in train, val and test splits in a balanced way. We make also public this dataset together with the splits division. A problem when dealing with the 3,213 raw ingredients is that many of them are sub-classes (e.g. ’sliced tomato’ or ’tomato sauce’) of more general versions of themselves (e.g. ’tomato’). Thus, we propose a simplified version by applying a simple removal of overly-descriptive particles333https://github.com/altosaar/food2vec (e.g. ’sliced’ or ’sauce’), resulting in 1,013 ingredients used for additional evaluation (see Section 4.3).
We must note the difference between our proposed datasets and the one from . While we consider any present ingredient in a recipe either visible or not, the work in  only labelled manually the visible ingredients in certain foods. Hence, a comparison between both works is infeasible.
|InceptionV3 + Ingredients101||80.86||72.12||76.24||83.51||76.87||80.06|
|ResNet50 + Ingredients101||84.80||67.62||75.24||88.11||73.45||80.11|
|InceptionV3 + Ingredients101||23.80||18.24||20.66|
|ResNet50 + Ingredients101||26.28||16.85||20.54|
|InceptionV3 + Recipes5k||36.18||20.69||26.32||35.47||21.00||26.38|
|ResNet50 + Recipes5k||38.41||19.67||26.02||38.93||19.57||26.05|
|InceptionV3 + Ingredients101||44.01||34.04||38.39|
|ResNet50 + Ingredients101||47.53||30.91||37.46|
|InceptionV3 + Recipes5k||56.77||31.40||40.44||55.37||31.52||40.18|
|ResNet50 + Recipes5k||56.73||28.07||37.56||58.55||28.49||38.33|
|InceptionV3 + Recipes5k simplified||53.91||42.13||47.30||53.43||42.77||47.51|
4.2 Experimental setup
Our model was implemented in Keras444www.keras.io
, using Theano as backend. Next, we detail the different configurations and tests performed.Random prediction: (baseline) a set of
labels are generated uniformly distributed among all possible outputs.depends on the average number of labels per recipe in the corresponding dataset. InceptionV3 + Ingredients101
: InceptionV3 model pre-trained on ImageNet and adapted for multi-label learning.ResNet50 + Ingredients101: ResNet50 model pre-trained on ImageNet and adapted for multi-label learning. InceptionV3 + Recipes5k: InceptionV3 model pre-trained on InceptionV3 + Ingredients101. ResNet50 + Recipes5k: ResNet50 model pre-trained on ResNet50 + Ingredients101.
4.3 Experimental results
In Table 1, we show the ingredient recognition results on the Ingredients101 dataset. In Fig.0(a) some qualitative results are shown. Both the numerical results and the qualitative examples prove the high performance of the models in most of the cases. Note that although a multi-label classification is being applied, considering that all the samples from a food class share the same set of ingredients, the model is indirectly learning the inherent food classes. Furthermore, looking at the results on the Recipes5k dataset in Table 2 (top), we can see that the very same model obtains reasonable results even considering that it was not specifically trained on that dataset. Note that only test results are reported for the models trained on Ingredients101 because we only intend to show its generalization capabilities on new data.
Comparing the results with the models specifically trained on Recipes5k, it appears that, as expected, a model trained on a set of samples with high variability of output labels is more capable of obtaining high results on never seen recipes. Thus, it is more capable of generalizing on unseen data.
Table 2 (bottom) shows the results on the Recipes5k dataset with a simplified list of ingredients. Note that for all tests, the list was simplified only during the evaluation procedure for maintaining the fine-grained recognition capabilities of the model, with the exception of Inception V3 + Recipes5k simplified, where the simplified set was also used for training. The simplification of the ingredients list enhances the capabilities of the model when comparing the results, reaching more than 40% in the metric and 47.5% also training with them.
Fig.0(b) shows a comparison of the output of the model either using the fine-grained or the simplified list of ingredients. Overall, although usually only a single type of semantically related fine-grained ingredients (e.g. ’large eggs’, ’beaten eggs’ or ’eggs’) appears at the same time in the ground truth, it seems that the model is inherently learning an embedding of the ingredients. Therefore, it is able to understand that some fine-grained ingredients are related and predicts them at once in the fine-grained version (see waffles example).
4.4 Neuron representation of ingredients
When training a CNN model, it is important to understand what it is able to learn and interpret from the data. To this purpose, we visualized the activations of certain neurons of the network in order to interpret what is it able to learn.
Fig.2 shows the results of this visualization. As we can see, it appears that certain neurons of the network are specialized to distinguish specific ingredients. For example, most images of the 1st and 2nd rows illustrate that the characteristic shape of a hamburger implies that it will probably contain the ingredients ’lettuce’ and ’ketchup’. Also, looking at the ’granulated sugar’ row, we can see that the model learns to interpret the characteristic shape of creme brulee and macarons as containing sugar, although it is not specifically seen in the image.
5 Conclusions and future work
Analysing both the quantitative and qualitative results, we can conclude that the proposed model and the two datasets published offer very promising results for the multi-label problem of food ingredients recognition. Our proposal allows to obtain great generalization results on unseen recipes and sets the basis for applying further, more detailed food analysis methods. As future work, we will create a hierarchical structure  relationship of the existent ingredients and extend the model to utilize this information.
-  Eduardo Aguilar, Marc Bolaños, and Petia Radeva. Exploring food detection using cnns. In Proceedings of the 16th International Conference on Computer Aided Systems Theory, pages 242–243. Springer, 2017.
-  Kiyoharu Aizawa and Makoto Ogawa. Foodlog: Multimedia tool for healthcare applications. IEEE MultiMedia, 22(2):4–8, 2015.
Marc Bolaños and Petia Radeva.
Simultaneous food localization and recognition.
Proceedings of the 23rd International Conference on Pattern Recognition (ICPR), 2016.
Lukas Bossard, Matthieu Guillaumin, and Luc Van Gool.
Food-101–mining discriminative components with random forests.In
European Conference on Computer Vision, pages 446–461. Springer, 2014.
Andreas Buja, Werner Stuetzle, and Yi Shen.
Loss functions for binary class probability estimation and classification: Structure and applications.Working draft, November, 2005.
-  Jingjing Chen and Chong-Wah Ngo. Deep-based ingredient recognition for cooking recipe retrieval. In Proceedings of the 2016 ACM on Multimedia Conference, pages 32–41. ACM, 2016.
-  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.
-  Niki Martinel, Gian Luca Foresti, and Christian Micheloni. Wide-slice residual networks for food recognition. arXiv preprint arXiv:1612.06543, 2016.
-  Ferda Ofli, Yusuf Aytar, Ingmar Weber, Raggi al Hammouri, and Antonio Torralba. Is saki# delicious? the food perception gap on instagram and its relation to health. arXiv preprint arXiv:1702.06318, 2017.
-  Olga Russakovsky, Jia Deng, Hao Su, Jonathan Krause, Sanjeev Satheesh, Sean Ma, Zhiheng Huang, Andrej Karpathy, Aditya Khosla, Michael Bernstein, et al. Imagenet large scale visual recognition challenge. International Journal of Computer Vision, 115(3):211–252, 2015.
-  Wataru Shimoda and Keiji Yanai. Cnn-based food image segmentation without pixel-wise annotation. In International Conference on Image Analysis and Processing, pages 449–457. Springer, 2015.
-  Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, Jon Shlens, and Zbigniew Wojna. Rethinking the inception architecture for computer vision. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 2818–2826, 2016.
-  Grigorios Tsoumakas and Ioannis Katakis. Multi-label classification: An overview. International Journal of Data Warehousing and Mining, 3(3), 2006.
-  Jiang Wang, Yi Yang, Junhua Mao, Zhiheng Huang, Chang Huang, and Wei Xu. Cnn-rnn: A unified framework for multi-label image classification. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 2285–2294, 2016.
-  Xin Wang, Devinder Kumar, Nicolas Thome, Matthieu Cord, and Frederic Precioso. Recipe recognition with large multimodal food dataset. In Multimedia & Expo Workshops (ICMEW), 2015 IEEE International Conference on, pages 1–6. IEEE, 2015.
-  Hui Wu, Michele Merler, Rosario Uceda-Sosa, and John R Smith. Learning to make better mistakes: Semantics-aware visual food recognition. In Proceedings of the 2016 ACM on Multimedia Conference, pages 172–176. ACM, 2016.
-  Jason Yosinski, Jeff Clune, Anh Nguyen, Thomas Fuchs, and Hod Lipson. Understanding neural networks through deep visualization. arXiv preprint arXiv:1506.06579, 2015.