Code Monkey home page Code Monkey logo

justinamichael / cnn_sorghum_weed_classifier Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.97 MB

'CNN_Sorghum_Weed_Classifier' is an artificial intelligence (AI) based software that can differentiate a sorghum sampling image from its associated weeds images.

Home Page: https://data.mendeley.com/datasets/4gkcyxjyss/1

License: Apache License 2.0

Jupyter Notebook 100.00%
artificial-intelligence cnn-classification cnn-classifier cnn-model crop-weed-dataset crop-weed-detection deep-learning densenet201 image-classification mobilenetv2 multi-class-classification neural-networks pre-trained-model precision-agriculture resnet152v2 smart-farming sorghum-weed-dataset transfer-learning vgg19 weed-detection

cnn_sorghum_weed_classifier's Introduction

CNN_Sorghum_Weed_Classifier

'CNN_Sorghum_Weed_Classifier' is an artificial intelligence (AI) based software that can differentiate a sorghum sampling image from its associated weeds images. This repository releases the source code for pre-processing, augmenting, and normalizing the 'SorghumWeedDataset_Classification' dataset. It also contains the code for training, validating, and testing the AI model using transfer learning. The reproducible code of the CNN_SorghumWeed_Classifier is also available at https://codeocean.com/capsule/1446799/tree

Dataset utilized

CNN_Sorghum_Weed_Classifier is constructed using 'SorghumWeedDataset_Classification,' a crop-weed research dataset. The dataset is cloned in the source code for further processing and model building. The following references relate to the dataset:

Language and Dependencies

Language: Python 3.10.12
Dependencies:

  • Tensorflow: 2.14.0
  • Scikit-learn: 1.2.2
  • Seaborn: 0.12.2
  • Matplotlib: 3.7.1
  • Scipy: 1.11.3
  • Numpy: 1.23.5
  • Pandas: 1.5.3

CNN_Sorghum_Weed_Classifier.ipynb

The complete source code for pre-processing the dataset and creating the model is included in the interactive Python notebook "CNN_Sorghum_Weed_Classifier.ipynb."

Getting started

'CNN_Sorghum_Weed_Classifier.ipynb' can be opened in the 'Google colaboratory' (or any other Jupyter Notebook environment). The runtime of the source code is configured to 'T4 GPU' to expedite the model training process.

Dataset cloning

The dataset is cloned from the respective GitHub repository using the following command:

!git clone https://github.com/JustinaMichael/SorghumWeedDataset_Classification.git

Data pre-processing

The necessary libraries and packages are installed followed by initializing the tuned hyper-parameter values. The data is augmented and normalized before building the model. The following code snippet augments and normalizes the training data:

train_datagen = ImageDataGenerator(rescale = 1./255,
                                       rotation_range = 45,
                                       width_shift_range = 0.3,
                                       shear_range = 0.25,
                                       zoom_range = 0.25,
                                       height_shift_range = 0.3,
                                       horizontal_flip = True,
                                       brightness_range=(0.2, 0.9),
                                       vertical_flip = True,
                                       fill_mode = 'reflect')

Model building

Using transfer learning, the classifier is trained, validated, and tested on the following four pre-trained Convolutional Neural Network (CNN) models, whose codes are provided sequentially.

  • VGG19
  • MobileNetV2
  • DenseNet201
  • ResNet152V2
The model is trained using the SorghumWeedDataset_Classification dataset using the following code snippet:
history = model.fit(x = training_set,
                    batch_size = batch_size,
                    epochs = epochs,
                    callbacks = cd,
                    validation_data = valid_set,
                    steps_per_epoch = len(training_set),
                    validation_steps = len(valid_set),
                    validation_batch_size = batch_size,
                    validation_freq = 1)

'EarlyStopping' is triggered by the following code, which prevents overfitting even after the model has been initialized for 50 training epochs:

es = EarlyStopping(monitor = "val_accuracy", 
                   min_delta = 0.01,
                   patience = 5,
                   verbose = 1,
                   mode = 'auto')

Evaluating the best-performing model

The following code is used to evaluate each of the four models, and the results are compared. With the highest accuracy of 0.96 and a considerable loss of 0.4, DenseNet201 produced the best results out of the four models. The results are presented graphically for easy comprehension.

evaluate_test_data = model.evaluate(test_set)
Please Note: The model produces slightly different results each time it is trained, deviating from the specified values.

Licence

This project is licensed under the APACHE LICENSE, VERSION 2.0.

Citation

Please give credit to the "SorghumWeedDataset_Classification" dataset if you find it useful and utilize it in your work by citing

Justina, Michael J., and M. Thenmozhi. "SorghumWeedDataset_Classification And SorghumWeedDataset_Segmentation Datasets For Classification, Detection, and Segmentation In Deep Learning." Data in Brief (2023): 109935

Contributors profile

  1. Justina Michael. J
    Google Scholar: https://scholar.google.com/citations?user=pEEzO14AAAAJ&hl=en&oi=ao
    ORCID: https://orcid.org/0000-0001-8072-3230
  2. Dr. M. Thenmozhi
    Google Scholar: https://scholar.google.com/citations?user=Es49w08AAAAJ&hl=en&oi=ao
    ORCID: https://orcid.org/0000-0002-8064-5938

cnn_sorghum_weed_classifier's People

Contributors

justinamichael avatar

Stargazers

 avatar

Watchers

 avatar

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.