Preprint
Brief Report

This version is not peer-reviewed.

Using Deep Learning for Prediction of Edible and Poisonous Mushrooms

Submitted:

03 April 2025

Posted:

04 April 2025

You are already at the latest version

Abstract
This article presents an CNN based model to predict edible and poisonous mushrooms from image data. We have used dataset — Danish Fungi 2018 (DF18) with several unique characteristics: species-level labels, a small number of errors, and rich observation metadata. An advanced CNN model U2Net was implemented to build the model for prediction. While validating on a test data, the model could predict edible mushrooms with an accuracy of 62.5% and poisonous mushrooms with 85.45% respectively. The model has been finally deployed into a real-time mobile application front-end, to increase public interest in fungi in detecting edible and poisonous mushrooms.
Keywords: 
;  ;  ;  ;  

1. Introduction

Ingestion of poisonous mushroom species can cause severe life-threatening failure of organs in humans. Every year numerous food poisoning cases come up due to misidentification of mushrooms around the world. This issue is also prevalent to certain regions of India like Jammu & Kashmir, Himachal Pradesh, Uttarakhand, and Northeastern states. Also, wild mushrooms are part of diet of tribal and ethnic groups of India residing in hilly areas of India. 53 patients with mushroom poisoning were admitted to Meghalaya over the five-year study period (2014–2019) [1]. In recent years it is reported that in the tribal region of Central India, 209 cases of mushroom food poisoning were registered. Most cases (171 out of 81.81%) came from rural areas, while 86% of cases belonged to lower socioeconomic classes. The winter season accounted for 109 (52.15%) of these cases, with summer coming in second at 69 (33.11%) and rainy season at 31, 14.83 percent [2].
To mitigate the issue of misdetection of Mushrooms, many researchers have come up with Image Based CNN for predicting the edibility of Mushrooms [3,4]. However, no such smartphone applications are available In India till now. Therefore, an approach has been made to develop an application for the prediction of poisonous and edible mushroom from images. The current study uses CNN algorithm for building the predictive models and then deploy into a smartphone application to predict the edibility of Mushrooms from its image.

2. Methodology

Data Collection

The dataset used for training CNN model was downloaded from GitHub provided by the Danish Svampe Atlas for 2018 Fungi Classification [5,6] for research purposes. Dataset contains over 100,000 fungi images of nearly 1,500 wild mushrooms species.

Categorization of Mushrooms into Poisonous and Edible Mushrooms

The information of Poisonous and Edible Mushroom species was collected from mainly three web portals – First nature [7], Monaco nature encyclopedia [8] and MyKoweb [9]. These web portals contain extensive and detailed information regarding shape, color, size, smell, distinctive features and also its edibility. In these portals, edibility for only 122 mushrooms could be found. Out of 122 species, 57 species were found out to be edible and 65 species were poisonous.

Removal of Unwanted Background from Mushroom Images Using U2 Net Image Segmentation Model

The images present in the collected dataset often contains unwanted objects. Training a CNN model with such images or images having objects not related to output label might confuse the deep learning model. To remove such objects from the images, a python library named rembg was used. This library uses an image segmentation CNN model called U2Net [10] that recognizes the edge or boundary of an object and extracts it into a new image.

Manual Extraction of Region of Interest or Mushrooms Using OpenCV

After removal of unwanted objects or noise, OpenCV [11,12] was used to extract out multiple mushroom images in square shape. OpenCV operations like dilation, erosion, detecting contours were used to achieve or get the images in desired format. For every species, 32 images were obtained where half of these images were top view of the mushroom and other half was bottom view of the mushrooms.

Selection of Mushroom Species for Model Training While Maintaining Data Balance

A total of 14 mushroom species was selected for training where 7 species belonged to poisonous species and other 7 species belonged to edible mushroom species. These were selected such that equal number of both poisonous and edible species was taken having same genus.

Data Augmentation

To increase size or number of images, data augmentation was performed by rotating images, increasing and decreasing brightness and adding small amount of blurring.
For every mushroom image, a total of 5 augmented images were created.
No of image for each species = 32
No of images after augmentation = 32 x 5 + 32= 192
Therefore, total poisonous mushroom images = 192 x 7 = 1344
Total edible mushroom images = 192 x 7 =1344

3. Model Development on Top of InceptionV3 Pretrained on ImageNet Dataset

InceptionV3 pretrained on ImageNet dataset was used as the based model for the CNN model. InceptionV3 is a 48 layers CNN model consisting of 27 convolutional layers, 13 pooling layers, and 8 fully connected layers. The last layer is a Global average pooling layer followed by a Dense layer with 1000 neurons.
For training it on Mushroom images, the last layer of Inceptionv3 was removed and a layer of 128 neurons was attached followed by a single layer of 1 sigmoid neuron. And the model accepts an image with input shape of 299 x 299 x 3.

4. Model Evaluation

For training the CNN, SGD optimizer was used which resulted in lower training time and better prediction accuracy. To test or evaluate the trained model, a minimum of 16 mushroom images for each species was kept separated and not used in the training set. Below is the model’s performance on both edible and poisonous species in Table 1 and Table 2 respectively. From Table 1, it can be seen that considering all the species, the overall accuracy for predicting edible mushroom is ≈ 62.5 %. Similarly, from Table 2, the predictive accuracy of the model for poisonous mushroom is 85.45%.

5. Deployment of Model into Android App

After exporting the trained model to h5 file format, the file has been converted to tflite model to integrate it into an Android App. The development of the application was done on Android Studio using java programming language. The application has the functionality to either capture an image of a mushroom or pick from gallery of the device for prediction of the edibility of the mushroom. The detailed methodology followed in this study has been depicted in Figure 1.

Conclusion

It is evident that the accuracy of the Deep learning CNN model is not quite good due to low number of training images of Mushroom. Enhanced training dataset can significantly improve the accuracy of the Model. Alternative approaches like dual or multibranch CNN can be used to train on both top view and bottom view of mushroom images at once. This can significantly help the model to identify and distinguish between a poisonous and edible mushroom species.

References

  1. Pandita, K. K.; Topno, N.; Thappa, D. M. Mushroom poisoning and outcome of patients admitted in a tertiary care hospital in North East India. Journal of Medicine in the Tropics 2021, 23(1), 29–34. [Google Scholar] [CrossRef]
  2. Sharma, M. D.; Vaishnao, L. S.; Kewalramani, M. S.; Aggrawal, R. P.; Jawade, A. S.; Bathe, A. A. A Retrospective Observational Study of Poisoning Cases Admitted in a Tertiary Care Teaching Institute in a Tribal Area of Central India. Indian Journal of Forensic Medicine & Toxicology 2019, 13. [Google Scholar]
  3. Ketwongsa, W.; Boonlue, S.; Kokaew, U. (2022). A new deep learning model for the classification of poisonous and edible mushrooms based on improved alexnet convolutional neural network. Applied Sciences 2022, 12, 3409. [Google Scholar] [CrossRef]
  4. Wang, B. Automatic Mushroom Species Classification Model for Foodborne Disease Prevention Based on Vision Transformer. Journal of Food Quality 2022, 2022. [Google Scholar] [CrossRef]
  5. Fungi Classification 2018. https://sites.google.com/view/fgvc5/competitions/fgvcx/fungi. Last accessed December 2024.
  6. 2018 FGVCx Fungi Classification Challenge. https://github.com/visipedia/fgvcx_fungi_comp.
  7. First Nature. https://www.first-nature.com/. Last accessed December 2024.
  8. Monaco Nature Encyclopedia. https://www.monaconatureencyclopedia.com/ Last accessed December 2024.
  9. MykoWeb. https://www.mykoweb.com/ Last accessed December.
  10. Qin, X.; Zhang, Z.; Huang, C.; Dehghan, M.; Zaiane, O. R.; Jagersand, M. (2020). U2-Net: Going deeper with nested U-structure for salient object detection. Pattern recognition 2020, 106, 107404. [Google Scholar] [CrossRef]
  11. Culjak, Ivan, David Abram, Tomislav Pribanic, Hrvoje Dzapo, and Mario Cifrek. "A brief introduction to OpenCV." In 2012 proceedings of the 35th international convention MIPRO, pp. 1725-1730. IEEE, 2012.
  12. Bradski, Gary, and Adrian Kaehler. Learning OpenCV: Computer vision with the OpenCV library. O'Reilly Media, Inc., 2008.
Figure 1. Detailed methodology for development of CNN based model for predicting edible and poisonous mushrooms.
Figure 1. Detailed methodology for development of CNN based model for predicting edible and poisonous mushrooms.
Preprints 154695 g001
Table 1. Performance of CNN model in predicting edible mushroom species.
Table 1. Performance of CNN model in predicting edible mushroom species.
Species name Image Count Predictions Accuracy (%)
Agaricus augustus 16 Edible=11 Poisonous=5 68.75
Amanita fulva 16 Edible=14 Poisonous=2 87.5
Amanita rubescens 16 Edible=9 Poisonous=7 56.25
Lactarius deliciosus 16 Edible=12 Poisonous=4 75
Lactarius detterimus 16 Edible=7 Poisonous=9 43.75
Russula cyanoxantha 16 Edible=8 Poisonous=8 50
Russula vesca 16 Edible=9 Poisonous=7 56.25
Table 2. Performance of CNN model in predicting poisonous mushroom species.
Table 2. Performance of CNN model in predicting poisonous mushroom species.
Species name Image Count Predictions Accuracy (%)
Agaricus xanthodermus 16 Edible=3 Poisonous=13 81.25
Amanita muscaria 16 Edible=0 Poisonous=16 100
Amanita pantherina 16 Edible=2 Poisonous=14 87.5
Lactarius terminosus 16 Edible=6 Poisonous=10 62.5
Lactarius helvus 16 Edible=1 Poisonous=15 93.75
Russula emetica 14 Edible=0 Poisonous=14 100
Russula grata 16 Edible=4 Poisonous=12 75
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.
Prerpints.org logo

Preprints.org is a free preprint server supported by MDPI in Basel, Switzerland.

Subscribe

Disclaimer

Terms of Use

Privacy Policy

Privacy Settings

© 2026 MDPI (Basel, Switzerland) unless otherwise stated