Code Monkey home page Code Monkey logo

global-wheat-head-detection's Introduction

AI Wheat🌾 Harvesting System

wheat

Model OUTPUT glimpse ♾️:

wheat

Reach out here for more videos!

Abstract :

Wheat is a staple across the globe, which makes this project more accountable.

Detection of wheat heads is an important task allowing to estimate pertinent traits including head population density and head characteristics such as sanitary state, size, maturity stage and the presence of awns. Project aims to analyze and detect wheat heads from outdoor images of wheat plants around the globe🌐 by leveraging the power of Computer Vision on pretty large image(with its annotation) dataset.

This project is a part of Global Wheat Detection challenge hosted on Kaggle.

Dataset 🗃️:

The Global Wheat Head Dataset is led by nine research institutes from seven countries: University of Tokyo, Institut national de recherche pour l’agriculture, l’alimentation et l’environnement, Arvalis, ETHZ, University of Saskatchewan, University of Queensland, Nanjing Agricultural University, and Rothamsted Research. These institutions are joined by many in their pursuit of accurate wheat head detection, including the Global Institute for Food Security, DigitAg, Kubota, and Hiphen.

Using worldwide data, the DL model will focus on a generalized solution of detecting the wheat heads. To better gauge the performance for unseen genotypes, environments, and observational conditions, the training dataset covers multiple regions. 3,000 images from Europe (France, UK, Switzerland) and North America (Canada). The test data includes about 1,000 images from Australia, Japan, and China. Data can be accessible from below links:

Pre-Processed Images with Bounding Boxes

It encapsulate:

  • Train.csv of shape (147793, 5) with following columns:

    1. image_id - the unique image ID(3,373)
    2. width, height - the width and height of the images
    3. bbox - a bounding box, formatted as a Python-style list of [xmin, ymin, width, height]
    4. source
    
  • 3,422 training images with given 10 test images.

  • Rest test images are hidden.

Exploratory Data Analysis 📊:

Notebook link:

In order to avoid unnecessary computation during the Exploratory Data Analysis(EDA) that follows, here we will prepare custom dataframe encapsulating necessary image oriented features such as :

  • image_id - The unique image ID(3,373).
  • width, height - The width and height of the images.
  • source - Image belonging source tags.
  • boxes - All bounding box per unique image, formatted as a Python-style list of [xmin, ymin, width, height].
  • box_count - Totall Bounding box count per unique image.
  • per_area- Totall percent area of B.boxes covered per unique image.
  • max_area - Largest B.box area covered per unique image.
  • brightness- Brightness Percentage.

SOURCE INFO.:

  • ARVALIS - Plant Institute. Institut du Végétal: ARVALIS - Institut du vegetal is an applied agricultural research organization dedicated to arable crops : cereals, maize, sorghum, potatoes, fodder crops, flax and tobacco. … It considers technological innovation as a major tool to enable producers and agri-companies to respond to societal challenges.

  • ETHZ- ETH Zurich trains true experts and prepares its students to carry out their tasks as critical members of their communities, making an important contribution to the sustainable development of science, the economy and society.

  • INRAE is France's new National Research Institute for Agriculture, Food and Environment, created on January 1, 2020, It was formed by the merger of INRA, the National Institute for Agricultural Research, and IRSTEA, the National Research Institute of Science and Technology for the Environment and Agriculture.

  • RRES 90003. Rothamsted Research is the longest-running agricultural research institution in the world. Its foundation dates from 1843 when John Bennet Lawes, the owner of the Rothamsted Estate, appointed Joseph Henry Gilbert, a chemist, as his scientific collaborator and planted the first of what were to become the classical Rothamsted long term experiments, on Broadbalk field. The scientific partnership between Lawes and Gilbert lasted 57 years, and together they laid the foundations of modern scientific agriculture and established the principles of crop nutrition. https://www.rothamsted.ac.uk/history-and-heritage

  • University of Saskatchewan (USask) researchers played a key role in an international consortium that has sequenced the entire genome of durum wheat—the source of semolina for pasta, a food staple for the world's population, according to an article published today in Nature Genetics.

TOP data Contributers (Sources)

  • arvalis_1
  • ethz_1
  • arvalis
  • rres_1

Bright image contributers

  • arvalis_1
  • arvalis_2
  • i.e They have collected image in Day-Light condition.

Dark(dim) image contributers

  • rres_1
  • inrae_1
  • i.e They have collected image in Low-Light condition. Also may the area is very Dense or Deep.

Image Data Analysis 🎞️:





Outlier fixation 🛠️:

We have encountered with Mis-matched Large Bounding Boxes in certain images in EDA

Bounding Boxes Area Distribution( With Outliers)

out

Bounding Box Area outliers:

  • We can see majority of the Bounding Boxes coverd less than 4% of totall area on Actuall Image.
  • Outliers are those BBoxes which have coverd more than 4% of tatall area of Image, as WHEAT HEAD covers less space in an image.
  • Also we will discard those Boxes with area less than 0.3%

Bounding Boxes Area Distribution( Without Outliers)

out1

Data Per-Processing for Keras RetinaNet 👨‍💻:

Annotations format:

The CSV file with annotations should contain one annotation per line. Images with multiple bounding boxes should use one row per bounding box. Note that indexing for pixel values starts at 0. The expected format of each line is:

'path/to/image.jpg', x_min, y_min, x_max, y_max, class_name

whqd

Also we have to specify the label mapping classes.csv as follows:

with open("classes.csv","w") as file: file.write("wheat_head,0")

Keras RetinaNet Installation🧰:

  • Clone this⏫ repository.
  • Ensure numpy is installed using pip install numpy --user
  • In the repository, execute pip install . --user. Note that due to inconsistencies with how tensorflow should be installed, this package does not define a dependency on tensorflow as it will try to install that (which at least on Arch Linux results in an incorrect installation). Please make sure tensorflow is installed as per your systems requirements.
  • Alternatively, you can run the code directly from the cloned repository, however you need to run python setup.py build_ext --inplace to compile Cython code first.

You can Use Pre-trained models using this SCRIPT.

Traning RetinaNet Model ⚙️:

Notebook link:

  1. Download Pre-trained Base models [resnet101, resnet50, resnet152]

  2. Save it in snapshots/pretrained_model.h5.

  3. Get ready with annotations.csv and classes.csv files in same running directory.

  4. Then Run the following command:

    !keras_retinanet/bin/train.py --freeze-backbone \
     --random-transform \
     --weights {snapshots/pretrained_model.h5} \
     --batch-size 8 \
     --steps 200 \
     --epochs 10 \
     csv annotations.csv classes.csv
    
  5. While traning, model will get saved in each epoch at snapshots/ folder. With More compu

  6. For Loading the Traned model, we can follow this:

         model_path = os.path.join('snapshots', sorted(os.listdir('snapshots'), reverse=True)[0])
         model = models.load_model(model_path, backbone_name='resnet50')
         model = models.convert_model(model)
    
  7. You can use perd_from_model(model, image, th=0.5, box_only=False) from this SCRIPT to draw bounding boxes on an Image.

  8. Download Trained(8 epochs) Wheat head Detection Model from here. You can go ahead for more epoch with more computational💻 power.

Visualizing model performance 🔖:

📸

pred2


pred3


🎦

wheat

Python Packages📦 used:

  • Numpy: NumPy stands for Numerical Python. It support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.
  • Pandas: pandas is a Python package that provides fast, flexible, and expressive data structures designed to make working with structured (tabular, multidimensional, potentially heterogeneous) and time series data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python.
  • Matplotlib: Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. It can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits.
  • Plotly: It is an interactive, open-source, and browser-based graphing library for Python.
  • Seaborn: Seaborn is a library for making statistical graphics in Python. It is built on top of matplotlib and closely integrated with pandas data structures.


  • Tqdm: Instantly make your loops show a smart progress meter - just wrap any iterable with tqdm(iterable), and you’re done! tqdm works on any platform (Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS), in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
  • OpenCv: OpenCV is a cross-platform library using which we can develop real-time computer vision applications. It mainly focuses on image processing, video capture and related features analysis. OpenCV runs on the following desktop operating systems: Windows, Linux, macOS, FreeBSD, NetBSD, OpenBSD.
  • Tensorflow: TensorFlow is a free and open-source software library for dataflow and differentiable programming across a range of tasks. It is a symbolic math library, and is also used for machine learning applications such as neural networks. It is used for both research and production at Google.
  • Keras: Keras is an API designed for human beings, not machines. Keras follows best practices for reducing cognitive load: it offers consistent & simple APIs, it minimizes the number of user actions required for common use cases, and it provides clear & actionable error messages. It also has extensive documentation and developer guides.

Thank you for reading :-)

global-wheat-head-detection's People

Contributors

adk2001tech avatar

Stargazers

 avatar

Watchers

paper2code - bot avatar

Forkers

vanshksharma

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.