Liwaiwai Liwaiwai
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • About
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • About
Liwaiwai Liwaiwai
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • About
  • Artificial Intelligence
  • Data
  • Data Science
  • Design

With AI, You Can Count 1000+ Sunflower Seeds In Seconds

  • June 2, 2021
  • admin

I’d like to explain briefly how we use artificial intelligence to count sunflower seeds in a photo taken with a mobile device.

Agenda:


Partner with liwaiwai.com
for your next big idea.
Let us know here.


cyberpogo

1. Business needs
2. Data preparation
3. Model structure
4. Used libs and tools
5. Results
6. Error analysis
7. Fails/Hypotheses
8. Conclusion
9. References

1. Business needs

Fortunately for me, I am working at Kernel. Where I am developing Computer Vision (CV) and other models to solve business problems and challenges. One of them is to count seeds on sunflower.

Kernel – the world’s leading and the largest in Ukraine producer and exporter of sunflower oil, and major supplier of agricultural products from the Black Sea region to world markets. Kernel exports its products into more than 80 countries of the world.

It is a common task for agronomist to count seeds on sunflower and corn, as these calculations will be used to predict “biologycal harvest”. Separately, agronomists calculate weight of 1000 kernels, which will further be used to estimate the overall yield per area of field.

Moreover, yield prediction is the primary function of agro analytics. The faster and more precise they make a forecast, the more money the company will earn.

These inspections should be carried out for every filed. And this is how it works now:

1. Agronomists go to the field
2. Take about 10 sunflowers from different parts of the field
3. Split every sunflower into 4 quarters
4. Count the seeds and multiply them by 4 to find the total number of seeds on every sunflower
5. Take random 1000 seeds and weight them
5. We get the density of plants on the field per hectare from other inspections (or use planned density), btw we also will use AI to solve this task, and this could be topic for next post
6. And calculate (density per ha * avg seed quantity on sunflower * weight of 1000) / 1000 = yield weight per ha

Here is an example of a common sunflower photo

 

Read More  AI Could Make More Work For Us, Instead Of Simplifying Our Lives

White (unformed) and black (formed) seeds can be seen, however only black seeds will be used to produce sunflower oil.

One disadvantage of this calculation is that agronomists must count black, formed seeds on sunflower, which is very inaccurate and inconvenient. Furthermore, each agronomist may count a different number of seeds on the same sunflower because some seeds may be unformed (white, non-pollinated by bees) and it is difficult to determine which kernel is formed and which is not.

2. Data preparation

To solve any Machine Learning problem, we need to get data and train the model. And for every specific task you cant find any free available labeled dataset. In our case, the dataset should contain hundreds of sunflower photos with label for every seed related to right class (black or white, for easy understanding), so we gathered our own dataset.

Our agronomists have made about 1000 photos of different sunflower hybrids from different regions of Ukraine. And subsequently, another team labeled photos in CVAT free tool for data labeling. There should be bounding_box (purple box) for each image, as well as black seeds (green points in the picture below), and white seeds (red points in the example below).

Following this, we can check distribution of kernels in sunflowers

looks normal with mean value – 1271. And correlation between number of black and white seeds.

Weak dependence exists, but it can not be used further.

3. Model structure

For business needs, all calculations should be done on a mobile device. That’s why I used U-net [1] with mobilenet_v2 [2] encoder pretrained on imagenet. What does this all means?

U-net is Neural Net structure where NN takes an input image and returns a segmentation map (in our case heatmap), with downsampling and upsampling data.
Our heatmap represents probability that pixel is related to some kernel.

Where up/down sampling blocks used weights from mobilenet_v2

Imagenet is a dataset with millions of images and tens thousands of classes.

 

Read More  PyCon 2019 | Beyond Two Groups: Generalized Bayesian A/B[/C/D/E...] Testing

Frankly speaking, for this task I trained 2 NN and 1 algorithm.
The first NN cut the sunflower from the image, like this:

 

The second NN build 2 heatmaps, one per class (black and white).

For training, input for this net is cropped image (from previous NN), and target is heatmap with builded gaussians on labeled points. For black kernels it looks like this:

 

According to this heatmap, the lighter the pixel, the more model is sure that pixel is related to kernel.

And the last algorithm (Laplacian of Gaussian approach) searches for centers of probability blobs (groups of bright pixels that are adjacent to each other), and on next image I used green points as the blob center above the cropped image.

With white kernels prediction looks like this:

 

4. Used libs and tools

For training, I used Python libs such as:

PyTorch and PyTorch Lightningfor training models
albumentations - for image augmentation
segmentation_models_pytorch - to use pretrained models
scikit_image - to work with blobs on heatmap
hyperopt - to tune hyperparams for blob detection
wandb - to track training experiments

5. Results

How do we validate the whole solution?

To calculate mean absolute percentage error (MAPE) I made prediction for every image and compared the number of found seeds by model and number of seeds found by assessors. As a result, we got normal distribution with mean 0, which is extremely good.

Blue bars – are for black kernels and MAPE is 3.6%,
Orange bars – are for white kernels and MAPE is 8.8%.

6. Error analysis

The biggest errors will have unusual sunflowers, that have with abnormally large number of kernels, or too many grey kernels, or with rounded edges, as it can be seen in the example below:

 

Read More  Hey Google ... What Movie Should I Watch Today? How AI Can Affect Our Decisions

Here, the model found 16% more than the assessor, and as we can see, the majority of extra seeds are on the edge of the sunflower.

Or biggest error -257% for white seeds in this case:

 

The total number of white seeds is 14, and the model found 50. As a percentage, it is a really big number, but in absolute terms, it is not critical.

 

7. Fails/Hypotheses

Once, I have found mathematically explained seeds positions in sunflowers and some other plants with fractal structure. Positions could be explained by Fermat’s spiral which has an equation in polar coordinates

wherenis index number of kernel andc – constant, I guess for every sunflower it is different. As result, we should get the following positions

But in practice it is doesn’t work. I have modified that equations and added new constants a, b

 

and the best result that I got was this:

 

where blue – dot is (0, 0)point. So it is close in some way but not applicable for to real case.

8. Conclusion

Currently, this task has been speeded up and standardized in our company in order to exclude human factor from counting. The MAPE is acceptable for business needs and this solution is working in mobile application now.

For me, it is still unbelievable that we can count more than 1000 kernels, separate points into 2 different classes and all of this can be done via mobile device.

Many thanks to Markiyan Kostiv for mentor ship in learning and support.

This article is republished from hackernoon.com


Our humans need coffee too! Your support is highly appreciated, thank you!

admin

Related Topics
  • AI
  • Artificial Intelligence
  • Python
  • PyTorch
  • Sunflower
You May Also Like
View Post
  • Artificial Intelligence

Introducing 100K Context Windows

  • May 30, 2023
View Post
  • Architecture
  • Artificial Intelligence
  • Design

Sandvik unveils the Impossible Statue – an AI-enabled collaboration between Michelangelo, Rodin, Kollwitz, Kotaro, Savage and Sandvik

  • May 30, 2023
View Post
  • Data
  • Machine Learning

Effective Management Of Data Sources In Machine Learning

  • May 29, 2023
View Post
  • Artificial Intelligence

How Auditoria.AI Is Building AI-Powered Smart Assistants For Finance Teams

  • May 29, 2023
View Post
  • Artificial Intelligence
  • Technology

AI Coming To The PC At Scale

  • May 27, 2023
View Post
  • Artificial Intelligence
  • Platforms

Build Next-Generation, AI-Powered Applications On Microsoft Azure

  • May 26, 2023
View Post
  • Artificial Intelligence
  • Data
  • Machine Learning

Faster Together: How Dun & Bradstreet Datasets Accelerate Your Real-Time Insights

  • May 24, 2023
View Post
  • Data
  • Engineering
  • Machine Learning

3 Essential Concepts Data Scientists Should Learn From MLOps Engineers

  • May 23, 2023

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay Connected!
LATEST
  • 1
    Introducing 100K Context Windows
    • May 30, 2023
  • 2
    Sandvik unveils the Impossible Statue – an AI-enabled collaboration between Michelangelo, Rodin, Kollwitz, Kotaro, Savage and Sandvik
    • May 30, 2023
  • 3
    Effective Management Of Data Sources In Machine Learning
    • May 29, 2023
  • 4
    How Auditoria.AI Is Building AI-Powered Smart Assistants For Finance Teams
    • May 29, 2023
  • 5
    G7 2023: The Real Threat To The World Order Is Hypocrisy.
    • May 28, 2023
  • 6
    AI Coming To The PC At Scale
    • May 27, 2023
  • 7
    Build Next-Generation, AI-Powered Applications On Microsoft Azure
    • May 26, 2023
  • 8
    Faster Together: How Dun & Bradstreet Datasets Accelerate Your Real-Time Insights
    • May 24, 2023
  • 9
    5 Skills Every Successful MLOps Engineer Should Have
    • May 24, 2023
  • 10
    London & UK Is The Best For International Students! You Have Been Warned.
    • May 23, 2023

about
About
Hello World!

We are liwaiwai.com. Created by programmers for programmers.

Our site aims to provide materials, guides, programming how-tos, and resources relating to artificial intelligence, machine learning and the likes.

We would like to hear from you.

If you have any questions, enquiries or would like to sponsor content, kindly reach out to us at:

[email protected]

Live long & prosper!
Most Popular
  • 1
    Wipro Expands Google Cloud Partnership To Advance Enterprise Adoption Of Generative AI
    • May 23, 2023
  • 2
    Google Cloud Launches AI-Powered Solutions To Safely Accelerate Drug Discovery And Precision Medicine
    • May 16, 2023
  • 3
    Huawei And Partners Announce Yucatan Wildlife Conservation Findings
    • May 18, 2023
  • 4
    Cloudflare’s R2 Is The Infrastructure Powering Leading AI Companies
    • May 16, 2023
  • 5
    TCS Announces Generative AI Partnership With Google Cloud And New Offering For Enterprise Customers
    • May 22, 2023
  • /
  • Artificial Intelligence
  • Explore
  • About
  • Contact Us

Input your search keywords and press Enter.