{"id":164549,"date":"2022-06-01T09:54:00","date_gmt":"2022-06-01T08:54:00","guid":{"rendered":"https:\/\/multi.liora.io\/?p=164549"},"modified":"2026-02-06T09:08:34","modified_gmt":"2026-02-06T08:08:34","slug":"mushroom-recognition","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/mushroom-recognition","title":{"rendered":"Mushroom recognition : Using Computer Vision in Machine Learning"},"content":{"rendered":"<h3>Context<\/h3>\n<p id=\"4998\" data-selectable-paragraph=\"\">One of the most widely used and oldest species identification techniques is <strong>\u201cmorphological identification\u201d<\/strong>, which identifies individuals by their anatomical characteristics. However, this technique has the disadvantage of not being always accurate since it depends on the observation and the identification protocol of the person who performs it.<\/p>\n<p id=\"8588\" data-selectable-paragraph=\"\">An alternative to this identification technique could be computer vision algorithms. These algorithms allow us to identify <strong>the characteristics of an image in a fast and accurate way<\/strong>, so the identification of a species can be made only through a photo, making it more portable.<\/p>\n<p id=\"58ed\" data-selectable-paragraph=\"\">In the following, we try to identify different mushroom images with the help of computer vision. This work was realized together with my promotion colleague Cyril Vandenberghe and supervised by Adrien Ruimy. It corresponds to the <a href=\"\/en\/courses\/data-ai\/data-scientist\" target=\"_blank\" rel=\"noopener ugc nofollow noreferrer\"><strong>Liora data scientist course<\/strong><\/a> final project. The development took a hundred hours and allowed us to utilize our newly acquired knowledge in a practical application.<\/p>\n<p id=\"6e6d\" data-selectable-paragraph=\"\">Project Authors : <a href=\"https:\/\/www.linkedin.com\/in\/karina-castillo-perez\/\" target=\"_blank\" rel=\"noopener ugc nofollow noreferrer\"><strong>Karina Castillo<\/strong><\/a> &amp; <a href=\"https:\/\/www.linkedin.com\/in\/vdbcyril\/\" target=\"_blank\" rel=\"noopener ugc nofollow noreferrer\"><strong>Cyril Vandenberghe<\/strong><\/a>.<\/p>\n<h3>The project<\/h3>\n<h4>Data source<\/h4>\n<p id=\"78b9\" data-selectable-paragraph=\"\">For this project, we used data from <strong><a style=\"color: #5e36f3\" href=\"\/\" target=\"_blank\" rel=\"noopener ugc nofollow noreferrer\">http:\/\/mushroomobserver.org<\/a><\/strong>, a website dedicated to collect and identify mushroom images: Users upload images, and the community identifies them. Currently, it counts over 10,000 registered users.<\/p>\n<p id=\"de0d\" data-selectable-paragraph=\"\">During our initial bibliographical research, we found that a previous project hosted on Github, <strong>\u00ab<\/strong> <a style=\"color: #5e36f3\" href=\"https:\/\/github.com\/bechtle\/mushroomobser-dataset\" target=\"_blank\" rel=\"noopener ugc nofollow noreferrer\"><strong>mushroomobser-dataset<\/strong><\/a> \u00bb had already explored this site to create a dataset of images dating from 2006 to 2016. Additionally, 12 JSON files contain additional information about each image.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-v2pJ4VymwVI-F55xa1b2rA-1024x778.png\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"778\"><figcaption>Fig. 1. Example of a JSON entry for one image. (image by Github: bechtle).<\/figcaption><\/figure>\n<h4>Data exploration<\/h4>\n<p>The first step in processing our data was to create a data frame with information about the images and <strong>taxonomy<\/strong> of the mushrooms. In biology, a taxonomy is a way of defining hierarchical groups based on common characteristics, as shown in the figure below :<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-QAW4Cc-KLRAr6rIb0Yix7w-1024x511.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"511\"><figcaption>Fig. 2. Taxonomy organization (Image by author).<\/figcaption><\/figure>\n<p>In the table 1, the `<em>rank<\/em>` column indicates the last taxonomic level reached in the mushroom identification in our data frame. Thus, if an entry has the value `<strong><em>KINGDOM<\/em><\/strong>` in the `<em>rank<\/em>` column, the `<em>label<\/em>` column value will be the most general identification, e.g., `<em>Fungi<\/em>.` The identified images can therefore belong to any mushroom.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-gy4Ol0Ho6HvQ6A4j0zYYNA-1024x297.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"297\"><figcaption>Table 1. Example of values in the data frame when &#8220;rank&#8221; = &#8220;KINGDOM&#8221;.<\/figcaption><\/figure>\n<p>In contrast, if the `<em>rank<\/em>` column is `<strong><em>SPECIES<\/em><\/strong>` (a more specific taxon), we have a more detailed description of the images (table 2).<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-1c5S6Y_YwSZhVHCBHUhR4g-1024x204.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"204\"><figcaption>Table 2. Example of values in the data frame when &#8220;rank&#8221; = &#8220;SPECIES&#8221;.<\/figcaption><\/figure>\n<p>Therefore, images with `<em><strong>KINGDOM<\/strong>`<\/em>, `<strong><em>PHYLUM<\/em><\/strong>`, `<strong><em>CLASS<\/em><\/strong>` and `<strong><em>ORDER<\/em><\/strong>` values in the `<em>rank<\/em>` column were discarded, as they are too general and non-informative. For the rest of the project, we will only work with data belonging to the taxa <em>SPECIES<\/em>, <em>GENUS<\/em>, and <em>FAMILY<\/em> as shown in the figure below :<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-ifuPCIhGO7v68XxXopolUA-1024x511.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"511\"><figcaption>Fig. 3. Selected taxa (Image by author).<\/figcaption><\/figure>\n<h4>Data Visualisation<\/h4>\n<p id=\"f6e7\" data-selectable-paragraph=\"\">Having a large number of images is essential for successfully developing a <strong>computer vision<\/strong> project. In this project, we need labels (i.e., values in the `<em>label<\/em>` column) to have a large number of images to represent it for each taxon.<\/p>\n<p id=\"04e9\" data-selectable-paragraph=\"\">The image below (fig. 4) is a visualization of the distribution of the number of images in the taxa. Each of the four panels shows the number of labels <strong>(y-axis)<\/strong> for a given taxon <strong>(x-axis)<\/strong> represented by 1 to 10 images, 11 to 100 images, 101 to 1000 images, and over 1000 images.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-i8SP6yWXRGAW2J1kivj_mg-1024x320.png\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"320\"><figcaption>FIg. 4. Number of labels per taxon by range. (image by author).<\/figcaption><\/figure>\n<p id=\"dbe0\" data-selectable-paragraph=\"\">The species taxon is the ideal one because it is the most specific one. However, the number of labels represented by only <strong>1 to 10 images corresponds to 75% of the total number of species<\/strong>. In the interval [101\u20131000], only seven species have more than 500 images, and only one species has more than 1000 images.<\/p>\n<p id=\"3a67\" data-selectable-paragraph=\"\">In contrast, in the panel for categories with more than 1000 images, we observe the genus and family taxa with about 40 labels each, making them good targets. Taxonomically, family is the least specific level, so we would expect more heterogeneity in images if we pick this level. Using genus seems then a good compromise between the taxonomic level and the number of images available.<\/p>\n<h4>Final Dataset : Genus Taxa<\/h4>\n<p>The bar chart below shows the number of images for 41 selected genus (Fig. 5). We decided to limit ourselves to the 15 highlighted genera containing ~1,000 images to reduce computation time and avoid a biased representation. With this, we have a total of 18,412 images available for the classification\/modeling part of our project.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-uv8wrQ30Blxf8D1YdRJPwA-1024x574.png\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"574\"><figcaption>Fig. 5. Histogram showing the distribution of images in the 41 genus containing more than 1000 images and the 15 genus selected for the project analyses (in the red square). (Image by author)<\/figcaption><\/figure>\n<h3>Classification using Neural Networks<\/h3>\n<h4>Architectures<\/h4>\n<p>As mentioned before, this project aims to identify mushroom images, which is a typical image classification problem that is usually addressed by <strong>deep learning methods<\/strong>. To achieve our goal, we tested three models, detailed below.<\/p>\n<h5>&#8211; LeNet<\/h5>\n<p id=\"54ff\" data-selectable-paragraph=\"\">First, we tested our data on a <strong>CNN model<\/strong> with a LeNet architecture (Y. LeCun <em>et a<\/em>l., 1998) that contains layers adapted for image processing. We tested this model with two convolutional layers.<\/p>\n<p id=\"b803\" data-selectable-paragraph=\"\">With a value of 0.98% accuracy, the basic model does not seem suitable for our goal, so we did not pursue this model further.<\/p>\n<h5>&#8211; VGG16<\/h5>\n<p id=\"c6b0\" data-selectable-paragraph=\"\">Next, we used the <strong>VGG16<\/strong> model (Simonyan and Zisserman, 2015), an image classification model with a Transfer Learning approach.<\/p>\n<p id=\"3eea\" data-selectable-paragraph=\"\">In the first step, our model had one classification layer with a Sequential model, two neural layers <strong>(Dense)<\/strong>, and two regularization layers <strong>(Dropout)<\/strong>.<\/p>\n<p id=\"0242\" data-selectable-paragraph=\"\">The results obtained were encouraging, with an accuracy of about 70%, but the model suffered from overfitting. To counter this, we added a Dense layer and increased the Dropout value. The figure 6 shows the final architecture of the model.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-ccuLJoXZLE7ySYxfB4hGjQ-1024x364.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"364\"><figcaption>Fig. 6. Final VGG16 Architecture (image by author).<\/figcaption><\/figure>\n<p>Additionally, we used the <strong>EarlyStopping<\/strong> and <strong>ReduceLROnPlateau<\/strong> callbacks from the Keras package with patience values of 5 and 3 respectively. With this, we achieved an accuracy value of 75.5% without overfitting.<\/p>\n<h5>&#8211; EfficientNetB1<\/h5>\n<p>The third image classification method we used in this project was also a <strong>Transfer Learning<\/strong> approach with the <strong>Tensorflow EfficientNet model <\/strong>(Tan and Le, 2019). We took inspiration from our previous model (VGG16) for the classification architecture we implemented, as we had positive results (fig. 7). We also used the callbacks <strong>EarlyStopping <\/strong>and <strong>ReduceLROnPlateau <\/strong>with the same values.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-WR5X52mYnAYWvy5vS1Odag-1024x365.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"365\"><figcaption>Fig. 7. Fnal EfficientNetB1 architecture (image by author).<\/figcaption><\/figure>\n<p id=\"056e\" data-selectable-paragraph=\"\">The first results show an accuracy value of about 80%, better than with VGG16, but still showing overfitting, so we increased the value of the Dropout layers and finally got a score of 79% without overfitting.<\/p>\n<p id=\"671d\" data-selectable-paragraph=\"\">Here is a display of the <strong>model\u2019s predictions<\/strong> on six images :<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-3_BydMeljxkUSkFguGyCEQ.png\" alt=\"\" loading=\"lazy\" width=\"796\" height=\"449\"><figcaption>Fig. 8. Example of prediction result, showing the predicted genus vs true genus. (image by author).<\/figcaption><\/figure>\n<h4>Error Analysis<\/h4>\n<h5>&#8211; Confusion matrix<\/h5>\n<p>The confusion matrix (fig. 9) shows that classes 0, 3, and 8 tend to be classified as classes 7, 4, and 13, respectively :<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-dyRBEhcoZ9ST5Po4rYDOOQ.png\" alt=\"\" loading=\"lazy\" width=\"616\" height=\"533\"><figcaption>Fig. 9. Confusion matrix from EfficientNet prediction (image by author).<\/figcaption><\/figure>\n<p>Literature shows that these confused classes are very similar morphologically and belong to the same taxonomic family (table 3).<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-JAkeplTY0KtrSQ3NTeepZQ-1024x394.png\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"394\"><figcaption>Table 3. Confused classes.<\/figcaption><\/figure>\n<p>The figure 10 show these morphological similarities between confused classes :<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-_v0_lXNVE-Ol8302C8mUxQ-1024x313.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"313\"><figcaption>Fig. 10. Morphological similarities between confused classes (source: Wikipwdia).<\/figcaption><\/figure>\n<p id=\"f41e\" data-selectable-paragraph=\"\">One reason for the confusion of classes may be that the taxonomic identification of mushrooms is wrong. The images we use come from a web page where users classify images of mushrooms only by looking at the images and according to their experience and not according to<strong> an objective taxonomic identification protocol<\/strong>.<\/p>\n<p id=\"4374\" data-selectable-paragraph=\"\">Considering the <strong>confusion matrix<\/strong> results, we wanted to evaluate our model without one of the confounded genera to see the influence of the data in our model, as show in the table 4.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-OvM7bHWEPLUQuMtokEszsg-1024x405.png\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"405\"><figcaption>Table 4. In red the suppresed genus.<\/figcaption><\/figure>\n<p>The accuracy values for the 12 genera (without the three eliminated) is 85%, 6% higher than the previous result (79%). This result suggests that we would probably increase our accuracy if we had had a more accurate data set of classifications to train the model.<\/p>\n<h5>&#8211; Quality of the images<\/h5>\n<p>We have also noticed that the quality of the images is very diverse (Fig. 11). Indeed, some images contain elements that can prevent the model from identifying the mushroom correctly, such as images with a lot of noise around the mushroom to be classified (images 1 and 2). Images with no mushroom to classify (image 3). Images with more than one mushroom (image 4).<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-afiVjhVh7UNOs1ZPyF8qYQ-1024x847.png\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"847\"><figcaption>Fig. 11. Exemple of image quality (image by author).<\/figcaption><\/figure>\n<h4>Wrapping Up<\/h4>\n<p>The summary table below (table 5) shows the accuracy values for the three methods used. We also calculated the <strong>\u201c<a style=\"color: #5e36f3\" href=\"https:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.metrics.top_k_accuracy_score.html#sklearn.metrics.top_k_accuracy_score\" target=\"_blank\" rel=\"noopener ugc nofollow noreferrer\">top-k accuracy classification score<\/a>\u201d<\/strong> of the package sklearn.metrics (Pedregosa <em>et al.<\/em>, 2011.) with k = 2 and 3 to assess how often the actual category falls between the two or three most likely categories. According to the results, EfficientNet would be the most suitable approach for our mushroom image classification problem with 80% and 86% accuracy.<\/p>\n<figure>\n\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" src=\"https:\/\/multi.liora.io\/app\/uploads\/2022\/06\/1-mpzE_M7_TTJPg79biOvTlg-1024x393.jpeg\" alt=\"\" loading=\"lazy\" width=\"1024\" height=\"393\"><figcaption>Table 5. Summary of results.<\/figcaption><\/figure>\n<p id=\"61f6\" data-selectable-paragraph=\"\"><em>Given the results, computer vision appears as an excellent alternative to the morphological classification of species, if the model could be trained using <\/em><strong><em>a large number of good quality images <\/em><\/strong><em>and that the species appearing in the image have a <\/em><strong><em>taxonomic classification made by a specialist<\/em><\/strong><em>.<\/em><\/p>\n<h4>Areas of improvement<\/h4>\n<p id=\"fbf4\" data-selectable-paragraph=\"\">These results can be improved in several ways. The first thing should be to train the model with an adequate <strong>dataset<\/strong>, i.e., better quality images and a more detailed taxonomic classification. Also, increasing the number of images in each label (e.g., from 1000 to 2000) could help to reduce morphological classification errors due to subjective human evaluation.<\/p>\n<p id=\"5508\" data-selectable-paragraph=\"\">Another improvement will be increasing the number of genus. Currently, we trained the model using 15 of the 41 genus that had ~1000 images per label. Furthermore, training the same model to further identify images of mushrooms at the species level can also increase the accuracy.<\/p>\n<p id=\"c6a6\" data-selectable-paragraph=\"\">Finally, combining the feature extraction part of our model with a classical classification model, such as <strong>Random Forest<\/strong> or <strong>SVM<\/strong>, could improve the classification.<\/p>\n<h3>References<\/h3>\n<ol>\n<li id=\"a5dd\" data-selectable-paragraph=\"\">Y. LeCun, L. Bottou, Y. Bengio, and P. Haffner. 1998. \u201cGradient-based learning applied to document recognition \u201d.Proceedings of the IEEE.<\/li>\n<li id=\"7d7d\" data-selectable-paragraph=\"\">K. Simonyan, A. Zisserman. 2015. \u201cVery Deep Convolutional Networks for Large-Scale Image Recognition\u201d. Proceedings of the ICLR.<\/li>\n<li id=\"6e70\" data-selectable-paragraph=\"\">Tan, Mingxing, and Quoc Le. 2019. \u201cEfficientNet: Rethinking Model Scaling for Convolutional Neural Networks\u201d. Proceedings of Machine Learning Research 97.<\/li>\n<li id=\"6d87\" data-selectable-paragraph=\"\">F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot and E. Duchesnay. 2011. \u201cScikit-learn: Machine Learning in Python\u201d. Journal of Machine Learning Research.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Context One of the most widely used and oldest species identification techniques is \u201cmorphological identification\u201d, which identifies individuals by their anatomical characteristics. However, this technique has the disadvantage of not being always accurate since it depends on the observation and the identification protocol of the person who performs it. An alternative to this identification technique [&hellip;]<\/p>\n","protected":false},"author":74,"featured_media":165680,"comment_status":"open","ping_status":"open","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2433],"class_list":["post-164549","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/164549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/74"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=164549"}],"version-history":[{"count":1,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/164549\/revisions"}],"predecessor-version":[{"id":206471,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/164549\/revisions\/206471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/165680"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=164549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=164549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}