Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Feeding Future Generations With AI

DZone's Guide to

Feeding Future Generations With AI

Artificial Intelligence is being used to solve problems relating to breast cancer detection and speech recognition, so why can't it be used for agriculture?

· AI Zone ·
Free Resource

Insight for I&O leaders on deploying AIOps platforms to enhance performance monitoring today. Read the Guide.

As world population grows, crop production needs to keep up. Can we use Artificial Intelligence for Agriculture? Let's find out.

Right now, AI is being (and will be) used for so many things. If you follow journals, blogs, publications, and more, you can see people solving problems from speech recognition to breast cancer detection and much more. So, why not try to solve a problem for the agricultural space. I know you may be thinking, "What?", but actually, AI — and more specifically, Deep Learning — can be used for this purpose as well.

Agriculture is a big thing in the world, as it accounts for:

Early identification of grass and broad-leaved weeds saves time and money. Identifying crop seedlings from weed seedlings can help incite specific weed control. It can also help in the development of machines that can mechanically remove the weed seedlings. There are many projects that would benefit with such AI. As agriculture robotics are maturing, the need for such AI is ubiquitous. For example, this AI can be integrated with Farmbot (https://en.wikipedia.org/wiki/FarmBot), an open-source project to detect weeds.

How pictures of seedling are taken (courtesy of Signal processing group at Aarhus University) https://arxiv.org/abs/1711.05458

In this article, I will use Resnet50 with their weights initialized based on ImageNet training. We will use Deep Learning Studio (DLS) for building this deep learning model.

About the Dataset

The dataset for this problem has been collected by researchers at Aarhus University and the University of Southern Denmark. You can learn more about this dataset by checking out the original paper at https://arxiv.org/abs/1711.05458

The processed dataset has been compiled for use with Deep Learning Studio and has a total of 4750 images with a resolution of 256x256. The dataset consists of image and species labels. There is a total of 12 species.

Residual Neural Networks

ResNet architecture that uses residual connections has been very successful at image classification tasks. I discussed them briefly in my article about Detecting Breast Cancer with Deep Learning, but here I show a little more information. They tackle two common problems that plague any large-scale deep-learning model: vanishing gradients and representational bottlenecks. In general, adding residual connections to any model that has more than 10 layers is likely to be beneficial (according to Chollet in Deep Learning with Python).

The core idea of ResNet is introducing a so-called “identity shortcut connection” that skips one or more layers.

Residual Connection. From Deep Learning with Python, Chollet 2017.

The original authors of the paper hypothesized that letting the stacked layers fit a residual mapping is easier than letting them directly fit the desired underlying mapping. This indicates that the deeper model should not produce a training error higher than its shallower counterparts.

If you want to see how to implement a ResNet in Keras, checkout these repositories:

https://github.com/raghakot/keras-resnet

https://github.com/broadinstitute/keras-resnet

Classifying Seedling Images With Resnet50

ResNet architectures (https://arxiv.org/abs/1512.03385 ) that use residual connections have been very successful at image classification tasks. Here, I’m going to use a 50 layer Resnet for the task at hand. If you want to know more about ResNet50 and how to use it check the official Keras documentation, but I’ll be using the GUI from DLS to make the job easier.

Project Creation:

After you log in to Deep Learning Studio that is either running locally or in cloud, click on the + button to create a new project.

Dataset Intake:

We then setup dataset for this project in “Data” tab. Usually, 80% - 20% is a good split between training and validation but you can use another setting if you prefer. Also, don’t forget to set Load Dataset in Memory to “Full dataset” if your machine has enough RAM to load full dataset in RAM.

Create Neural Network:

You can create a neural network as shown below by dragging and dropping the layers.

ResNet Model

Make sure to set ResNet 100% trainable from the properties on the right side. Also, first Dense layer (Dense_5 in above image) should have 20 or so neurons with ReLU as the activation function. Final Dense layer (Dense_6) should have output dimension as 12 and activation as softmax as there are 12 categories that we should classify.

Hyperparameter and Training:

Hyperparameters that we used are shown below. Feel free to change and experiment with them.

Hyperparameters


Finally, you can start the training from Training Tab and monitor the progress with training dashboard. Once you complete your training, you can check the results in the results tab.

Training the nets

Deploying Your Model:

With Deep Learning Studio, deployment as a WebApp or REST API is child’s play and can be done using the deploy tab as shown below.

Single Click Deployment of the Model

The deployed model can be accessed as a WebApp or REST API as shown below:

Deployed Model as Auto-generated WebApp

So, you can see that with modern software like Deep Learning Studio, complex models can be built in minutes and deployed in seconds.

Thanks for reading this. I hope you found something interesting here.

If you have questions, just add me on twitter:

https://twitter.com/FavioVaz

And LinkedIn:

http://linkedin.com/in/faviovazquez/

See you there.

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

Topics:
deep learning ,agriculture ,artificial intelligence ,ai ,dataset ,neural networks

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}