This project implements a deep learning approach to classify crops using image datasets. We provide two parallel implementations — TensorFlow and PyTorch — for performance comparison and reproducibility. In addition, a Streamlit-based GUI is developed to make predictions interactive and fetch additional information about the crop.
The goal of this project is to build and evaluate deep learning models for crop classification using image data. Both TensorFlow and PyTorch implementations are provided to compare training pipelines, performance metrics, and overall usability. The GUI allows users to upload images and view predictions along with nutritional information, crop benefits, and market price.
- Languages: Python
- Frameworks: TensorFlow, PyTorch, Streamlit
- Model: CNN (Convolutional Neural Network)
- Tools: NumPy, Pandas, Matplotlib, Scikit-learn, Pillow, Requests, BeautifulSoup
- Collected and preprocessed crop images.
- Performed train-test split.
- Applied normalization and resizing for compatibility with CNN models.
- Used data augmentation (rotation, flipping, zoom) to reduce overfitting.
- TensorFlow: Implemented a CNN using
tf.keras.Sequential. - PyTorch: Implemented a CNN using
torch.nn.Module. - Layers included convolutional, pooling, dropout, and dense layers.
- Defined loss functions: Cross-Entropy Loss.
- Optimizers: Adam / SGD.
- Used early stopping and checkpoints (TensorFlow).
- Trained on GPU (if available).
- Calculated accuracy, precision, recall, and F1-score.
- Compared macro and weighted averages for imbalanced classes.
- Generated confusion matrices and classification reports.
| Framework | Accuracy |
|---|---|
| TensorFlow | ~0.95 |
| PyTorch | ~0.76 |
📊 Conclusion: TensorFlow outperformed PyTorch in this classification task, maintaining higher accuracy and balanced metrics.
To make the model user-friendly, we created a Streamlit web application.
-
Upload an image (fruit or vegetable).
-
Classify into Fruit or Vegetable.
-
Detect whether it is a Rabi crop (winter) or Kharif crop (monsoon).
-
Fetch details dynamically from Google:
- Calories (per 100 grams)
- Description
- Health Benefits
- Average Price (in Pakistan)
-
Ensure the trained model
FV.h5is available in the project root. -
Start the app:
streamlit run Utilizing TensorFlow Model Using Streamlit GUI.py
-
Upload an image and view predictions along with crop insights.
- Streamlit GUI showing:
-
Clone this repository:
git clone https://github.com/ummeabiha/CropClassification.git cd CropClassification -
Install dependencies:
pip install -r requirements.txt
-
Run either training notebooks or the GUI:
Training Tensor Flow Model.ipynbTraining PyTorch Model.ipynbUtilizing TensorFlow Model Using Streamlit GUI.py(for GUI)
