International Journal of Academic Information Systems Research (IJAISR) ISSN: 2643-9026 Vol. 3 Issue 12, December – 2019, Pages: 12-18 www.ijeais.org/ijaisr 12 Classifying Nuts Types Using Convolutional Neural Network Ibtesam M. Dheir, Alaa Soliman Abu Mettleq, Abeer A. Elsharif, Samy S. Abu-Naser Department of Information Technology, Faculty of Engineering and Information Technology, Al-Azhar University Gaza, Palestine Abstract: Nuts are nutrient-dense foods with complex matrices rich in unsaturated fatty and other bioactive compounds. By virtue of their unique composition, all types of nuts are likely to beneficially impact health outcomes. In this paper, we classified five types of Nuts with a dataset that contains 2868 images. Convolutional Neural Network (CNN) algorithms, a deep learning technique extensively applied to image recognition was used for this task. The trained model achieved an accuracy of 98% on a held-out test set, demonstrating the feasibility of this approach. Keywords: Deep learning, CNN , Nuts , Classifying 1. INTRODUCTION 1.1 Nuts and its health benefits In botanical terms, the word 'nut' is used to describe a wide range of seeds, it is a fruit composed of an inedible hard shell and a tough, often lignified, seed coat and generally edible. True nuts include the brazil nut, chestnut, and hazelnut. Nuts are nutrient dense foods with complex matrices rich in unsaturated fatty and other bioactive compounds. By virtue of their unique composition, nuts are likely to beneficially impact health outcomes [1]. There is increasing interest in nut consumption and human health outcomes [2]. The use of nuts and seeds to improve Human nutritional status has proven successful for a variety of conditions including in the treatment of high cholesterol, reduced risk of Type-2 Diabetes, and weight control.[3]. In general, nuts are good sources of fat, fiber and protein. Tree nuts, such as almonds, hazelnuts, cashew nuts, Brazil nuts, macadamias, walnuts, and pistachios, as well as legume seeds, such peanuts, are nutrient-dense foods each with a unique composition.[4] In general, these foods contain healthy monounsaturated (MUFA) and polyunsaturated (PUFA) fatty acid profiles; protein; soluble and insoluble fibers; vitamins E and K; folate; thiamine; minerals such as magnesium, copper, potassium, and selenium; and substances such as zanthophyll carotenoids, antioxidants, and phytosterols compounds, with recognized benefits to human health [5-7]. Many studies have investigated the health benefits of increased nut intake. One meta-analysis of 33 studies found that diets high in nuts do not significantly affect weight gain or weight loss.[8] Yet, despite having little effect on weight, many studies have shown that people who eat nuts live longer than those who don't. This may be due to their ability to help prevent a number of chronic diseases [9]. For example, nuts may reduce risk factors for metabolic syndrome, such as high blood pressure and cholesterol levels [10]. Furthermore, nuts may reduce your risk of other chronic diseases. For example, eating nuts may improve blood sugar levels and lower your risk of certain cancers [11] 1.2 Nuts Types Nuts are a good source of healthful fats, fiber, and other beneficial nutrients. Each type of nut offers different nutritional benefits [21]. 1.2.1 Peanuts : International Journal of Academic Information Systems Research (IJAISR) ISSN: 2643-9026 Vol. 3 Issue 12, December – 2019, Pages: 12-18 www.ijeais.org/ijaisr 13 Peanuts are the most popular nuts in the United States. Most peanuts are made into oil or ground into butter, but they are delicious eaten out of hand. They are also used in baked goods or chopped to top Asian noodle dishes [12] Peanuts are grown in warm climates below ground, contrary to popular belief. The plant flowers above ground, and the peanuts grow under the soil. To prepare peanuts for consumption, they should be harvested and washed, and left to dry in the sun. They can be shelled at the time of harvesting, or the shell left on to be shelled later. Once they are shelled, they are ready to eat!. The peanut is a staple in the diets of many people and has many uses. One of the most well-known uses of peanuts is peanut butter [13] 1.2.2 Almonds: The majority of the world's almonds are grown in California, United States. They can also be found in Spain and Italy. Almonds are grown on trees similarly to pecans. While you can eat an almond fresh from the tree, its best to let them dry out for at least two weeks first to maximize flavor and minimize mold on the almond. After this they can be shelled and eaten. Almonds have more fiber, protein, and other nutrients than any other nuts; They are also high in monounsaturated fats, and vitamins. they may even be good for heart. Toasting improves their rather chewy texture and mild flavor. Sliced or slivered almonds add an elegant touch to everyday green beans, and ground almonds make a delicious nut butter. (They're also the basis of marzipan.) Bigger, flatter, and higher in fat, Spanish Marcona almonds are prized for their sweet, delicate taste. They are useful in dishes such as: almond-crusted chicken, in salads, and in cereals.they're also sold as flour to be baked in tortes and flourless cakes. Almonds have a mildly sweet flavor that is magnified in products such as almond extract, almond paste, and marzipan [12],[13]. 1.2.3 Pecan: Pecans grow in south-central North America in Florida, Alabama, Arkansas, Arizona, California, Louisiana, Texas, and New Mexico, as well as in Mexico. They grow on trees, frequently in orchards or groves. The plants can take 7 to 10 years to begin producing an abundance of pecans. Pecans are frequently harvested by shaking the trees or gathering the nuts from the ground. The pecans will need to be dried for at least two weeks in their shells. Many people prefer to shell them and roast them as well. Pecans contain monounsaturated fats and are antioxidants [12]. One of the most famous dishes using pecans is pecan pie. Pecans are also an essential ingredient in chocolate turtle candies, candied pecans, chicken salad, and as an accent to a chicken or beef dish. An especially high fat content helps give pecans their rich, creamy, buttery taste. This native American nut is often used in pies and candies; it also combines well with cayenne and other spices in savory dishes. The thin shells break easily, which speeds decay, so if buying unshelled specimens, avoid any with cracked shells [13]. 1.2.4 Hazelnut : Hazelnuts are commonly grown in North America, Europe, and Asia. They are a very hardy plant, and typically grow in medium-sized bushy trees. Once the nuts are picked, they need to begin drying out within 24 hours of harvest. They can be kept for months with the shells left on, but if shelled for human consumption should be used within a few weeks. Regarding uses of hazelnuts, they are rich in monounsaturated oil as well as vitamins and minerals. Hazelnuts are commonly used in conjunction with chocolate to make desserts, such as chocolate truffles and Nutella. They are also commonly used in coffee flavoring, and can be used in savory dishes to accompany meat, such as sausage [12]. 1.2.5 Chestnuts Chestnuts are found primarily in China, the United States, South Korea, Italy, Greece, and South America. These types of nuts are grown on trees or shrubs. While the nuts can be eaten at harvest, they are somewhat bland. They are best if stored in the refrigerator for a few days to change the starches to sugars. Chestnuts can be eaten raw if peeled, or can be roasted to prepare for consumption. They can also be candied, boiled, steamed, deep-fried, or grilled. Chestnuts are high in carbohydrates, as opposed to oils as is found with most nuts. They are used in desserts such as cakes and pies, but can also be used as a thickener for soups and sauces.[13] International Journal of Academic Information Systems Research (IJAISR) ISSN: 2643-9026 Vol. 3 Issue 12, December – 2019, Pages: 12-18 www.ijeais.org/ijaisr 14 1.2.6 Walnuts Walnuts are grown mainly in China, the United States, Iran, Turkey, Mexico, and the Ukraine. They are a stone fruit that grows on large trees. Walnuts can be eaten raw after they are thoroughly sprayed down with a pressure washer and dried. At this point the walnuts can be shelled and eaten raw, or roasted and seasoned. Walnuts are rich in antioxidants and Omega-3s. They can be found in walnut butter, khoresh, brownies, dessert mix-ins, and as a garnish for both sweet and savory dishes[13]. 1.2.7 Pistachios: Pistachios are grown in the West in the United States in the states of California, Arizona, and New Mexico. They can also be found in Turkey, Iran, Afghanistan, Italy, and Syria. Pistachios grow on small trees in desert-like sand. pistachios have a naturally tan shell (those with red shells have been dyed) and a pale green nut that's high in calcium. The green color is the result of chlorophyll that develops as the seeds grow. While pistachios can be eaten raw and washed, many people prefer to roast them and salt them for consumption. Pistachios are used in famous dishes such as spumoni, baklava, kulfi, pistachio ice cream, and pistachio salad. They are also high in protein, fiber, and vitamins [12],[13]. 1.2 Deep learning Deep learning (also known as deep structured learning or hierarchical learning) is an artificial intelligence function that imitates the workings of the human brain in processing data and creating patterns for use in decision making. Deep learning is a subset of machine learning in artificial intelligence (AI) that has networks capable of learning unsupervised from data that is unstructured or unlabeled. Also known as deep neural learning or deep neural network [15]. Deep learning, a division of machine learning, uses a hierarchical level of artificial neural networks to perform the process of machine learning. The artificial neural networks are constructed like the human brain, with neuron nodes linked together like a web [16]. In deep learning, each level learns to transform its input data into a slightly more abstract and composite representation. In an image recognition application, the raw input may be a matrix of pixels; the first representational layer may abstract the pixels and encode edges; the second layer may compose and encode arrangements of edges; the third layer may encode a nose and eyes; and the fourth layer may recognize that the image contains a face. Importantly, a deep learning process can learn which features to optimally place in which level on its own. (Of course, this does not completely obviate the need for hand-tuning; for example, varying numbers of layers and layer sizes can provide different degrees of abstraction)[17],[18]. 1.3 CNN Convolutional Neural Networks or CNNs are really the superstars of neural networks in Deep Learning. These networks are able to perform relatively complex tasks with images, sounds, texts, videos, etc, and most commonly applied to analyzing visual imagery. The first successful convolution networks were developed in the late 1990s by Professor Yann LeCunn for Bell Labs [14]. CNN uses a variation of multilayer perceptrons designed to require minimal preprocessing [18]. They are also known as shift invariant or space invariant artificial neural networks (SIANN), based on their shared-weights architecture and translation invariance characteristics [19],[20]. In computer vision, CNNs have been known to be powerful visual models that yield hierarchies of features enabling accurate segmentation. They are also known to perform predictions relatively faster than other algorithms while maintaining competitive performance at the same time [14]. 1.3.1 Design A convolutional neural network consists of an input and an output layer, as well as multiple hidden layers. The hidden layers of a CNN typically consist of a series of convolutional layers that convolve with a multiplication or other dot product. The activation function is commonly a RELU layer, and is subsequently followed by additional convolutions such as pooling layers, fully connected layers and normalization layers, referred to as hidden layers because their inputs and outputs are masked by the activation function and final convolution. The final convolution, in turn, often involves backpropagation in order to more accurately weight the end product.[21] Though the layers are colloquially International Journal of Academic Information Systems Research (IJAISR) ISSN: 2643-9026 Vol. 3 Issue 12, December – 2019, Pages: 12-18 www.ijeais.org/ijaisr 15 referred to as convolutions, this is only by convention. Mathematically, it is technically a sliding dot product or crosscorrelation. This has significance for the indices in the matrix, in that it affects how weight is determined at a specific index point.[23] 1.3.2 Convolutional When programming a CNN, the input is a tensor with shape (number of images) x (image width) x (image height) x (image depth). Then after passing through a convolutional layer, the image becomes abstracted to a feature map, with shape (number of images) x (feature map width) x (feature map height) x (feature map channels). A convolutional layer within a neural network should have the following attributes:  Convolutional kernels defined by a width and height (hyper-parameters).  The number of input channels and output channels (hyper-parameter).  The depth of the Convolution filter (the input channels) must be equal to the number channels (depth) of the input feature map. Convolutional layers convolve the input and pass its result to the next layer. This is similar to the response of a neuron in the visual cortex to a specific stimulus.[22]. Each convolutional neuron processes data only for its receptive field. Although fully connected feedforward neural networks can be used to learn features as well as classify data, it is not practical to apply this architecture to images. A very high number of neurons would be necessary, even in a shallow (opposite of deep) architecture, due to the very large input sizes associated with images, where each pixel is a relevant variable. For instance, a fully connected layer for a (small) image of size 100 x 100 has 10,000 weights for each neuron in the second layer. The convolution operation brings a solution to this problem as it reduces the number of free parameters, allowing the network to be deeper with fewer parameters.[32] For instance, regardless of image size, tiling regions of size 5 x 5, each with the same shared weights, requires only 25 learnable parameters. In this way, it resolves the vanishing or exploding gradients problem in training traditional multi-layer neural networks with many layers by using backpropagation[23]. 1.3.3 Pooling Convolutional networks may include local or global pooling layers to streamline the underlying computation. Pooling layers reduce the dimensions of the data by combining the outputs of neuron clusters at one layer into a single neuron in the next layer. Local pooling combines small clusters, typically 2 x 2. Global pooling acts on all the neurons of the convolutional layer.[24][25] In addition, pooling may compute a max or an average. Max pooling uses the maximum value from each of a cluster of neurons at the prior layer.[26][27] Average pooling uses the average value from each of a cluster of neurons at the prior layer.[28] 1.3.4 Fully connected Fully connected layers connect every neuron in one layer to every neuron in another layer. It is in principle the same as the traditional multi-layer perceptron neural network (MLP). The flattened matrix goes through a fully connected layer to classify the images[23]. 1.3.5 Receptive field In neural networks, each neuron receives input from some number of locations in the previous layer. In a fully connected layer, each neuron receives input from every element of the previous layer. In a convolutional layer, neurons receive input from only a restricted subarea of the previous layer. Typically the subarea is of a square shape (e.g., size 5 by 5). The input area of a neuron is called its receptive field. So, in a fully connected layer, the receptive field is the entire previous layer. In a convolutional layer, the receptive area is smaller than the entire previous layer [23]. 1.3.6 Weights Each neuron in a neural network computes an output value by applying a specific function to the input values coming from the receptive field in the previous layer. The function that is applied to the input values is determined by a vector of weights and a bias (typically real numbers). Learning, in a neural network, progresses by making iterative adjustments to these biases and weights. The vector of weights and the bias are called filters and represent particular features of the input (e.g., a particular shape). A distinguishing feature of CNNs is that many neurons can share the same filter. This reduces memory International Journal of Academic Information Systems Research (IJAISR) ISSN: 2643-9026 Vol. 3 Issue 12, December – 2019, Pages: 12-18 www.ijeais.org/ijaisr 16 footprint because a single bias and a single vector of weights are used across all receptive fields sharing that filter, as opposed to each receptive field having its own bias and vector weighting.[29] 2. RELATED WORK The Authors in [30] used deep learning to detect five tomato leaves diseases. They achieved a high accuracy in detecting the tomato disease. The authors in [31] demonstrated the effectiveness of a convolutional neural network to learn unsupervised feature representations for 44 different plant species with high accuracy. The authors in [32] addressed the problem of CNN-based semantic segmentation of crop fields separating sugar beet plants, weeds, and background solely based on RGB data by proposing a deep encoder-decoder CNN for semantic segmentation that is fed with a 14-channel image storing vegetation indexes and other information that in the past has been used to solve crop-weed classification. The authors in [32] used transfer learning for Image Classification. 3. METHODOLOGY In this section, we describe the proposed solution as selected convolutional network (ConvNet) architecture and discuss associated design choices and implementation aspects. 2.1 Dataset The dataset contains a set of 2868 images, 1390 images as a training set, 550 images as a validation set, and 910 images as a test set. Each set is classified into 5 categories based on types of Nuts. 2.2 Model Architecture The first part of the model (features extraction) , it consist of 4 Convolutional layers with Relu activation function, each followed by Max Pooling layer. The second part after the flatten layer contains two dense layers, the first has 512 hidden units which makes the total number of network trainable parameters 2,603,205, and the last layer has Softmax as activation and 5 outputs representing the 5 classes. The model summery is shown in the figure below: After training, we reach a validation accuracy of about 81.28% as shown in figure2, However, our plots indicate that we are overfitting almost from the start. This is because this technique does not leverage data augmentation, which is essential to preventing overfitting with small image datasets. After using the following augmentation: International Journal of Academic Information Systems Research (IJAISR) ISSN: 2643-9026 Vol. 3 Issue 12, December – 2019, Pages: 12-18 www.ijeais.org/ijaisr 17 train_datagen = ImageDataGenerator( rescale=1./255, rotation_range=40, width_shift_range=0.25, height_shift_range=0.25, shear_range=0.25, zoom_range=0.25, horizontal_flip=True, fill_mode='nearest') The validation accuracy was about 94% as shown in figure 3. This is much better ! 3 LIMITATION The current proposed CNN focus on learning five types of Nuts, which are Chestnut, Hazelnut, Nut Forest, Nut Pecan, and Walnut. 4 CONCLUSION We proposed a classifying model of nuts types using a convolutional neural network, and our approach proudly achieves excellent results with accuracy of 98%. REFERENCES 1. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3257681/, access-date: 15-12-2019 2. https://www.researchgate.net/publication/289036515_Nuts_and_seeds, access-date: 15-12-2019 3. https://www.researchgate.net/publication/298028116_Nuts_and_Seeds_in_Health_and_Disease_Prevention, access-date:15-12-2019 4. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5748761/, access-date: 15-12-2019 5. Souza R.G.M., Gomes A.C., Naves M.M.V., Mota J.F. Nuts and Legume Seeds for Cardiovascular Risk Reduction: Scientific Evidence and Mechanisms of Action. Nutr. Rev. 2015;73:335–347. doi: 10.1093/nutrit/nuu008. 6. Cardoso B.R., Silva Duarte G.B., Reis B.Z., Cozzolino S.M.F. Brazil Nuts: Nutritional Composition, Health Benefits and Safety Aspects. Food Res. Int. 2017;100:9–18. doi: 10.1016/j.foodres.2017.08.036. 7. Taş N., Gökmen V. Phenolic Compounds in Natural and Roasted Nuts and Their Skins: A Brief Review. Curr. Opin. Food Sci. 2017;14:103–109. doi: 10.1016/j.cofs.2017.03.001 8. https://www.ncbi.nlm.nih.gov/pubmed/23595878, access-date: 16-12-2019 9. https://www.ncbi.nlm.nih.gov/pubmed/26066329, access-date: 16-12-2019 10. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2640451/, access-date: 16-12-2019 11. https://www.ncbi.nlm.nih.gov/pubmed/20458092, access-date: 16-12-2019 12. https://www.realsimple.com/food-recipes/shopping-storing/food/common-types-nuts, access-date: 17-12-2019 13. https://www.popoptiq.com/types-of-nuts/, access-date: 17-12-2019 14. Werbos, P.J. (1975). Beyond Regression: New Tools for Prediction and Analysis in the Behavioral Sciences. 15. Bengio, Y.; Courville, A.; Vincent, P. (2013). "Representation Learning: A Review and New Perspectives". IEEE Transactions on Pattern Analysis and Machine Intelligence. 35 (8): 1798–1828. arXiv:1206.5538. 16. LeCun, Yann. "LeNet-5, convolutional neural networks".. 17. Zhang, Wei (1988). "Shift-invariant pattern recognition neural network and its optical architecture". Proceedings of Annual Conference of the Japan Society of Applied Physics. 18. Zhang, Wei (1990). "Parallel distributed processing model with local space-invariant interconnections and its optical architecture". Applied Optics. 29 (32): 4790 19. "CS231n Convolutional Neural Networks for Visual Recognition". cs231n.github.io. Retrieved 2018-12-13. International Journal of Academic Information Systems Research (IJAISR) ISSN: 2643-9026 Vol. 3 Issue 12, December – 2019, Pages: 12-18 www.ijeais.org/ijaisr 18 20. "Convolutional Neural Networks (LeNet) – DeepLearning 0.1 documentation". DeepLearning 0.1. LISA Lab. Retrieved 31 August 2013. 21. Habibi, Aghdam, Hamed (2017-05-30). Guide to convolutional neural networks : a practical application to trafficsign detection and classification. Heravi, Elnaz Jahani. Cham, Switzerland. ISBN 9783319575490. OCLC 987790957. 22. Ciresan, Dan; Ueli Meier; Jonathan Masci; Luca M. Gambardella; Jurgen Schmidhuber (2011). "Flexible, High Performance Convolutional Neural Networks for Image Classification" (PDF). Proceedings of the Twenty-Second International Joint Conference on Artificial Intelligence-Volume Volume Two. 2: 1237–1242. Retrieved 17 November 2013. 23. Krizhevsky, Alex. "ImageNet Classification with Deep Convolutional Neural Networks" (PDF). Retrieved 17 November 2013. 24. Yamaguchi, Kouichi; Sakamoto, Kenji; Akabane, Toshio; Fujimoto, Yoshiji (November 1990). A Neural Network for Speaker-Independent Isolated Word Recognition. First International Conference on Spoken Language Processing (ICSLP 90). Kobe, Japan. 25. Ciresan, Dan; Meier, Ueli; Schmidhuber, Jürgen (June 2012). Multi-column deep neural networks for image classification. 2012 IEEE Conference on Computer Vision and Pattern Recognition. New York, NY: Institute of Electrical and Electronics Engineers (IEEE). pp. 3642– 3649. arXiv:1202.2745. CiteSeerX 10.1.1.300.3283. doi:10.1109/CVPR.2012.6248110. ISBN 978-1-4673-12264. OCLC 812295155. 26. "A Survey of FPGA-based Accelerators for Convolutional Neural Networks", NCAA, 2018 27. LeCun, Yann. "LeNet-5, convolutional neural networks". Retrieved 16 November 2013. 28. Jeon, Wang-Su, and Sang-Yong Rhee, Plant leaf recognition using a convolution neural network, International Journal of Fuzzy Logic and Intelligent Systems 17, no. 1, pp 26-34. 2017. 29. A. Milioto, P. Lottes, and C. Stachniss, Real-time semantic segmentation of crop and weed for precision agriculture robots leveraging background knowledge in CNNs, cs.CV, 2018. URL