Deep Learning and Poisonous Mushrooms

Cyrill Glockner
Towards Data Science
5 min readApr 26, 2017

--

Using a Deep Learning Network to solve a common problem while knowing very little about mushrooms or machine learning.

INTRODUCTION

Machine Learning is such a fascinating topic, it allows machines to learn how to accomplish tasks that historically needed a human being. While machine learning used to require the most powerful supercomputers just a few years ago, the arrival of cloud computing, cheaper CPUs, and much better algorithms allowed Machine Learning to become accessible more broadly. Today, high-school students can use Machine Learning on a regular home computer with the power to deliver better image classification results than human beings. But first things first, here’s why I’m excited about Machine Learning, specifically Deep Learning.

Given the recent press coverage about the advancements in Artificial Intelligence especially on Deep Learning Networks, I decided to learn about some of the core concepts that allowed machines to beat humans in Jeopardy, Go, and poker or power self-driving cars and lots of other applications that typically require a human brain. I think of Deep Learning Networks as extremely large and sophisticated layered trial and error systems that can learn by themselves when given large data sets and a significant amount of computing resources.

RESEARCHING DEEP LEARNING NETWORKS

I turned to Google Search to identify the technology that powered AlphaGo, the Artificial Intelligence that beat the world’s best Go player. Google used a Deep Learning Network System called DeepMind. Shortly after winning against the best human player, DeepMind switched to an Open Source Deep Learning library called TensorFlow. Not having heard much about TensorFlow, I continued to look for a manageable entry point, that didn’t require a Ph.D., to understand the basics of TensorFlow and some examples that I could replicate on my laptop at home. And I found a large library of YouTube videos, GitHub projects, blog posts and similar.

I found these two resources most helpful for learning about TensorFlow:

1) Youtube videos by Siraj Raval, who wants to inspire and educate developers on Artifical Intelligence so they can build games, music, chatbots, create art and lots of other cool things using YouTube videos and Udacity. I watched his video on YouTube that supposedly teaches you to “Build a TensorFlow Image Classifier in 5 Min”. https://youtu.be/QfNvhPx5Px8.

The video is hands-on, fast paced and quite challenging to follow but after watching it several times, I was convinced that I could follow the example and was inspired to create my own image classifier that was not based on Darth Vader and Panda bears.

2) Google Developer Codelabs is providing an example for image classification called “TensorFlow for Poets” which allows you to identify the genus of a given flower. This example uses several, like daisies, sunflowers, dandelions, tulips, and roses. It provides a detailed step-by-step list that is fairly simple to follow as long as everything goes by plan. https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/#0

You can check out the links for complete instructions.

HOW THE MUSHROOMS CAME INTO PLAY

What’s a better use case for an image classifier than matching images against Darth Vader that can be implemented based on available image libraries? I turned to mushrooms. Whenever we’re seeing mushroom while on a hike somewhere in the woods, I usually do not know if the spotted mushroom is edible or not. A few years ago my partner and I thought it would be great to develop a mobile application that could tell if the subject is okay for consumption or not. Just point your camera at the mushroom and the app will tell you if it’s edible or not. To be clear, I have no plans to build out a web service that would is needed for such an application, but image classification based on TensorFlow is able to provide the most complicated part of the solution today and one could build the mushroom identifier app powered by a Deep Learning Network relatively easily.

THE PROJECT AND THE RESULTS

This is what I did:

I used Google image search to download 600 pictures of edible mushrooms and the same number of poisonous ones and fed them into my TensorFlow-based Deep Learning Network. After roughly 30 minutes of training, accuracy and loss function values pointed into the right direction so I knew the network would be able to deliver results.

Tensorboard graphs for accuracy and loss

This graph shows the accuracy level of the Deep Learning Network. The number of training steps on the x-axes and accuracy on the y-axes. Reaching ~97% is quite impressive.

Cross entropy on the y-axes is used as the loss function, in this case. It basically shows how efficient the network learns. Smaller numbers are better. The number of training steps on the x-axes.

Example: Fly agaric

Not edible! poison (score = 0.99746) edible (score = 0.00230)

Example: Chanterelles

I would eat these. edible (score = 0.96285) poison (score = 0.03706)

These are the two most impressive results. There were other less decisive results which I believe are based on the somewhat unscientific researched image library, as the accuracy of the network is pretty high. It would be an interesting project to clean up the image database and use a larger dataset of edible and poisonous mushrooms.

THE CONCLUSION

I’m amazed by the simplicity and low bar of technical knowledge that is required to get a functioning Deep Learning Network up and running. This groundbreaking technology is now accessible to developers and hobbyists worldwide, no Computer Science degree required for using it. We are witnessing an important shift, powerful Machine Learning technology is transitioning out of the labs of a few scientists into the hands of thousands of developers who will deliver hundreds of thousands AI applications with an unimaginable impact on our lives. Toolkits like TensorFlow and others will make this happen.

--

--