Is this honey bee carrying pollen?

Use deep learning to differentiate between honey bees that are and aren’t carrying pollen.

Photo by Thinkmojo on Dribbble

Bee pollen is a ball or pellet of field-gathered flower pollen packed by worker honeybees, consisting of simple sugars, protein, minerals and vitamins, fatty acids, and other components in small quantities. This is the primary food source for the hive.

This article aims to use deep learning to differentiate between images of honey bees carrying pollen and those that aren’t.

These deep learning models can prove useful in bee farming for analysis/inference generation.

The implementation of the idea on cAInvas — here.

The dataset

Citation:

Ivan Rodriguez, Rémi Mégret, Edgar Acuña, José Agosto, Tugrul Giray. Recognition of pollen-bearing bees from Video using Convolutional Neural Network, IEEE Winter Conf. on Applications of Computer Vision, 2018, Lake Tahoe, NV. https://doi.org/10.1109/WACV.2018.00041

This image dataset has been created from videos captured at the entrance of a bee colony in June 2017 at the Bee facility of the Gurabo Agricultural Experimental Station of the University of Puerto Rico.

The dataset consists of high-resolution images of individual bees on the ramp. The dataset folder in the notebook has the following content —

  • images folder — Contains 300×180 resolution images of bees of both categories. The image file names contain the categories — P (for pollen) or NP (for non-pollen).
  • pollen_data.csv — A .csv file containing the image names and corresponding labels.

A peek into the pollen_data.csv file —

The dataset has 714 images divided into 2 categories.

The ‘Unnamed: 0’ column is unnecessary and can be removed.

https://gist.github.com/Gunjan933/c8db4c3827116a81c88c3dcffc3339a6

Looking into the spread of category values in the dataset —

https://gist.github.com/Gunjan933/d778bb331b2e193cacd5c906e30f0b13

This seems to be a fairly balanced dataset.

Here are a few images of both categories from the images folder.

There are no visually separable features to help us differentiate between the honey bees.

The X and y arrays that correspond to the input and output of the model are built from the images folder with the help of the CSV file.

https://gist.github.com/Gunjan933/640f64bf8d347413a5174b6cdf375af3

The above function returns the X array with 714 elements, where each element is the normalized pixel values of each image.

The images in the dataset are of size 300×180 with 3 channels. Thus the shape of X will be (714, 300, 180, 3).

Similarly, the y array can be built directly using the ‘pollen_carrying’ attribute of the CSV file. The shape of the y array will be (714,).

https://gist.github.com/Gunjan933/02f8111ca7db84a98995aa46fffd1a07

The train and test sets are created using an 80–20 split on the original dataset.

https://gist.github.com/Gunjan933/23278746f9bf4ce09b3ddb28bb78a81e

The model

The model has four pairs of Conv2D-MaxPooling2D layers followed by a Flatten layer that reduces the values to a 1D array. A Dropout layer is used followed by two Dense layers, one with ReLU and the other with sigmoid activation.

https://gist.github.com/Gunjan933/a636a3a455a91ebe4edb5a654c87c1a7

The model is compiled with Adam optimizer with a learning rate of 0.001.

The binary cross-entropy loss is used as the last layer has sigmoid activation.

The accuracy of the model on the data is tracked.

The model achieves 94.4% accuracy on the test set after training for 16 epochs.

The metrics

Plot of accuracies
Plot of losses

Prediction

VIsualizing the predictions of random values in the test set.

https://gist.github.com/Gunjan933/fa88de06d5206fc2c9a0f2ee50273937

deepC

deepC library, compiler, and inference framework are designed to enable and perform deep learning neural networks by focussing on features of small form-factor devices like micro-controllers, eFPGAs, CPUs, and other embedded devices like raspberry-pi, odroid, Arduino, SparkFun Edge, RISC-V, mobile phones, x86 and arm laptops among others.

Compiling the model with deepC to get .exe file —

Head over to the cAInvas platform (link to notebook given earlier) and check out the predictions by the .exe file!

Credit: Ayisha D