Skip to content

A streamlined deep learning framework that fuses advanced image preprocessing, grid search-based hyperparameter tuning, CNN/Transformer fine-tuning, and ensemble strategies for high-precision soil classification along with adaptive fuzzy logic-based crop recommendations.

License

Notifications You must be signed in to change notification settings

Phantom-fs/Agro-Companion-Modules

Repository files navigation

Agro Companion: A Deep Learning Framework for Precise Agricultural Practices

Agro Companion is a comprehensive deep learning project focused on the classification of 7 types of soil using advanced computer vision techniques and adaptive crop recommendation using fuzzy logic. The project includes data preprocessing, augmentation, gan-based data augmentation, model training (with various state-of-the-art architectures), k-fold cross validation, hyperparameter optimization, ensemble learning, and a fuzzy logic-based decision system for crop recommendations. The goal is to provide a robust framework that can assist in agricultural practices by accurately classifying soil types and recommending suitable crops based on environmental conditions.

This code was curated as part of the research paper titled "An advanced artificial intelligence framework integrating ensembled convolutional neural networks and Vision Transformers for precise soil classification with adaptive fuzzy logic-based crop recommendations" by Farhan Sheth, Priya Mathur, Amit Kumar Gupta, and Sandeep Chaurasia, published in Engineering Applications of Artificial Intelligence.

Links

Application produced by this research is available at:

Note: If you are using any part of this project; dataset, code, application, then please cite the work as mentioned in the Citation section below.


Table of Contents


Directory Structure & Contents

1. Data-Generation-CycleGAN/

  • Generation/: Jupyter notebooks for generating augmented soil images using CycleGAN. Notebooks to train model to convert soil A to soil B and vice versa, enhancing the dataset diversity.

  • Data_Split.ipynb: Notebook for splitting the dataset for CycleGAN training and testing.

  • Dataset_Aug.ipynb: Notebook for generating augmented images using CycleGAN. It includes training the CycleGAN model and saving the generated images. Includes conversion from soil A to soil B and vice versa.

2. Preprocessing/

  • Augmentation/: Jupyter notebooks for image augmentation using Albumentations and OpenCV. Includes multiple strategies for increasing dataset diversity.

  • Data_Split/: Notebook for splitting the dataset into train, test, and validation sets (default: 70/15/15 split).

3. Optimal-Hyperparameters/

  • Optimal_Hyperparameters_Grid_Search.ipynb: Grid search for optimal batch size, learning rate, and weight decay. Includes training, validation, and test evaluation for each configuration.

4. Fine-Tuning/

Contains subfolders for each model family, each with a notebook for transfer learning and fine-tuning on the soil dataset:

  • EfficientNet/: EfficientNet_v2_Large.ipynb
  • MobileNet/: MobileNet_v3_Large.ipynb
  • ResNet/: ResNet101.ipynb, ResNet152.ipynb
  • ViT/: ViT_B_16_e2e.ipynb, ViT_B_16_v1.ipynb, ViT_L_16_e2e.ipynb, ViT_L_16_v1.ipynb

Each notebook covers:

  • Data loading and preprocessing
  • Model setup and architecture (along with parameter freezing, early stopping and other configurations)
  • Transfer learning (or Fine-tuning)
  • Training, validation, and evaluation (accuracy, F1, precision, recall, confusion matrix)

5. K-Fold-cross-validation/

Contains subfolders for each model family, each with a notebook for k-fold cross-validation:

  • EfficientNet/: k_EfficientNet_v2_large.ipynb
  • MobileNet/: k_MobileNet_v3_large.ipynb
  • ResNet/: k_ResNet101.ipynb, k_ResNet152.ipynb
  • ViT/: k_ViT_B_16_v1.ipynb, k_ViT_L_16_v1.ipynb

Each notebook includes:

  • K-fold cross-validation setup
  • Model training and evaluation across folds
  • Performance metrics (accuracy, F1, precision, recall, confusion matrix)

6. Ensemble/

Jupyter notebooks for combining predictions from multiple models to improve classification performance. Includes various ensemble strategies:

  • MobileNet v3 Large + ViT-B/16

  • ResNet101 + ViT-B/16

  • ResNet152 + ViT-L/16

  • EfficientNet v2 Large + ViT-L/16

  • MobileNet v3 Large + ResNet101 + ViT-B/16

  • ResNet152 + EfficientNet v2 Large + ViT-L/16

  • MobileNet v3 Large + ResNet101 + EfficientNet v2 Large + ViT-L/16

  • ResNet101 + ResNet152 + EfficientNet v2 Large + ViT-L/16

Multi-model ensembles (e.g., ResNet, EfficientNet, ResNet101, ViT)

7. Fuzzy-Logic/

Contains Jupyter notebooks for implementing a fuzzy logic system to recommend crops based on soil type, nutrients, pH, and climatic conditions. The system uses fuzzy rules to infer the best crop for given soil conditions.


Getting Started

  1. Requirements: Python 3.8+, PyTorch, torchvision, tensorflow, keras, scikit-learn, albumentations, OpenCV, matplotlib, tqdm, colorama, PIL, numpy, pandas, scikit-image.

  2. Data: Place your soil image dataset in the appropriate directory as referenced in the notebooks.

  3. CycleGAN: For data augmentation, run the CycleGAN notebooks to generate augmented images before proceeding with model training.

  4. Run Notebooks: Follow the order: Preprocessing → Hyperparameter Search (for best hyperparameters) → Fine-Tuning → K-Fold Cross Validation → Ensemble Learning → Fuzzy Logic Crop Recommendation.

To use the code, clone the repository and run the Jupyter notebooks in the respective directories. Ensure you have all dependencies installed and the dataset is correctly placed.

git clone https://github.com/Phantom-fs/Agro-Companion-Modules.git
cd Agro-Companion-Modules

Project Highlights

  • CycleGAN Augmentation: Utilizes CycleGAN for generating augmented soil images, expanding the dataset from 1189 to 8413 images.
  • Flexible Preprocessing: Advanced image preprocessing and augmentation techniques using Albumentations and OpenCV.
  • Multiple Architectures: Fine-tuning of CNNs (ResNet, EfficientNet, MobileNet) and Transformers (ViT).
  • Transfer Learning: Efficient transfer learning strategies for leveraging pre-trained models on the soil classification task.
  • K-Fold Cross Validation: Robust evaluation using k-fold cross-validation for reliable performance metrics.
  • Hyperparameter Optimization: Grid search for optimal hyperparameters to enhance model performance.
  • Ensemble Learning: Combine strengths of different models.
  • Fuzzy Logic Crop Recommendation: Adaptive fuzzy logic system for recommending crops based on soil conditions, nutrients, pH, and climate.
  • Agro Companion Application: A user-friendly application for farmers to identify soil types and get crop recommendations based on environmental data.
  • Reproducibility: Fixed random seeds and clear data splits.

Soil Dataset

Dataset used in this project is a comprehensive soil classification dataset that includes images of various soil types. The dataset has been augmented using CycleGAN to enhance the diversity and size of the dataset, making it suitable for training deep learning models.

Dataset Details

  • Total Images: The original dataset contains 1189 images, which have been augmented to 8,413 images using CycleGAN.
  • Soil Types: The dataset includes images of 7 different soil types: Alluvial, Black, Laterite, Red, Yellow, Arid, and Mountain soil.
  • Image Format: The images are in JPG/JPEG format, with varying resolutions and qualities to provide a diverse set for training and testing.

Dataset Links


Citation

If you are using this dataset or the code in your research, please cite the following paper:

@article{SHETH2025111425,
    title = {An advanced artificial intelligence framework integrating ensembled convolutional neural networks and Vision Transformers for precise soil classification with adaptive fuzzy logic-based crop recommendations},
    journal = {Engineering Applications of Artificial Intelligence},
    volume = {158},
    pages = {111425},
    year = {2025},
    issn = {0952-1976},
    doi = {https://doi.org/10.1016/j.engappai.2025.111425},
    url = {https://www.sciencedirect.com/science/article/pii/S0952197625014277},
    author = {Farhan Sheth and Priya Mathur and Amit Kumar Gupta and Sandeep Chaurasia},
    keywords = {Soil classification, Crop recommendation, Vision transformers, Convolutional neural network, Transfer learning, Fuzzy logic}
}

License

This project is for academic and research purposes licensed under the MIT License. Project code and datasets are intended for educational use only. No commercial use is allowed without prior permission from the authors.

Acknowledgments

This study is not to be used for commercial purposes. The code is intended for research and educational purposes only. If you have any concerns or requests regarding the code, please contact the repository owner.

About

A streamlined deep learning framework that fuses advanced image preprocessing, grid search-based hyperparameter tuning, CNN/Transformer fine-tuning, and ensemble strategies for high-precision soil classification along with adaptive fuzzy logic-based crop recommendations.

Topics

Resources

License

Stars

Watchers

Forks