CropVision AI Crop Identification System using CNN and Flask | Final Year Project with Source Code

CropVision AI Crop Identification System using CNN and Flask | Final Year Project with Source Code

Upload one photo of a crop, get the name back in under a second β€” plus a heat map showing exactly which pixels the CNN looked at. Complete Python final year project with training notebook, Flask app and source code.

Technology Used

Python 3.10 | TensorFlow 2.16 | Keras | MobileNetV2 | Grad-CAM | Flask 3 | Jupyter Notebook | scikit-learn | Pillow | Gunicorn | Nginx

codeAj
βœ“
codeAjVerified
πŸ†5K+ Projects Sold
Google Review
β‚Ή499β‚Ή1999

Get complete project source code + Installation guide + chat support


Abstract

Identifying a crop from a photograph sounds trivial until you're the one staring at an unlabelled field image. Extension officers, agri-tech data collectors and farm advisors do this every day, and it needs trained human eyes that aren't always standing where the camera is. CropVision AI automates that judgement using a Convolutional Neural Network.

The model is trained on the Agricultural Crops Image Dataset β€” roughly 800 photographs across 30 classes covering almond, banana, cardamom, chilli, clove, coconut, coffee, cotton, cucumber, fox nut, gram, jowar, jute, lemon, maize, mustard, olive and more. That works out to about 25 images per class, which is nowhere near enough to train a CNN from random weights. We tried. It stalled under 45% accuracy and refused to move.

So the project uses transfer learning instead: a MobileNetV2 convolutional backbone pretrained on ImageNet, extended with a custom conv and dense head, fine-tuned in two phases. Fully convolutional throughout, no LSTMs or attention blocks bolted on to look impressive. The final model hits roughly 90% top-1 accuracy and over 97% top-3 on held-out test images, against about 38% for the same-architecture-from-scratch baseline that's included in the notebook for comparison.

Predictions are explained with Grad-CAM, and the whole thing is served through a Flask web app with a JSON REST endpoint sitting alongside it.

What This Project Actually Does

Two pieces, and they're separate on purpose.

The first is crop_classification_training.ipynb, a Jupyter notebook that takes the raw dataset folder, cleans it, trains the model, evaluates it, and writes everything into an artifacts/ directory β€” the .keras model file, a labels.json, a metrics.json with per-class recall, plus training curves and a confusion matrix as PNGs.

The second is cropvision/, a Flask 3 application that loads those artifacts and turns them into a working website. You drag a photo onto the upload box, and you get back a ranked top-3 with confidence percentages, a Grad-CAM heat map overlaid on your image, and a toggle to flip between the original and the heat map.

Here's the part examiners actually like: the confidence threshold. If the model isn't sure, it doesn't fake it. Below 0.45 confidence the page says "closest match" instead of asserting an identification, because a closed-set classifier shown a random photo of a dog will still confidently tell you it's cardamom. Being honest about uncertainty is a design decision you can defend in a viva, and most student projects have nothing like it.

The duplicate problem (this is the part nobody expects)

The source dataset stores the same photograph under multiple file extensions. If you don't catch that, identical images end up in both your training and test sets, and your accuracy number becomes fiction. The notebook runs exact MD5 hashing and perceptual dHash before splitting, drops the duplicates, then does a stratified 70/15/15 split so every one of the 30 classes appears in all three partitions. Class imbalance is handled with computed class weights and augmentation β€” flip, rotation, zoom, translation, contrast, brightness β€” applied on-GPU during training.

If your accuracy ever comes out suspiciously close to 100%, duplicate removal got switched off. That's the first thing to check.

Key Features

  • Identifies 30 agricultural crop classes from one photograph, with inference landing between 100 and 200 ms on a plain CPU β€” no GPU needed to serve it
  • Ranked top-3 output with per-class confidence percentages, adjustable via a top_k query parameter
  • Grad-CAM heat map generated per prediction and painted over the uploaded image, so you can see the network is reading the crop and not the background wall behind it
  • Confidence thresholding that flags uncertain predictions rather than bluffing
  • Two-phase training: frozen backbone first, then fine-tuning of the deeper conv blocks at a reduced learning rate
  • Optional from-scratch CNN baseline so your report has a real 38% vs 90% comparison instead of an unsupported claim
  • Model card page at /model built automatically from metrics.json β€” test accuracy, dataset composition, per-class recall, training charts
  • JSON REST API at /api/predict accepting either a multipart file upload or a base64 string
  • EXIF orientation correction, because phone photos arrive rotated and a sideways image tanks the prediction
  • Uploads processed entirely in memory. Nothing written to disk
  • Preprocessing baked into the saved model, which kills the classic train/serve mismatch bug before it happens
  • A /health endpoint that returns 503 if the model didn't load
  • Graceful failure β€” if the artifacts are missing, every page tells you what to copy instead of dumping a stack trace on your evaluator's screen
  • Works with JavaScript disabled; the drag-and-drop is progressive enhancement, not a dependency
  • Gunicorn, systemd and Nginx configs included in deploy/

Real-World Applications

Agricultural extension and advisory work. A field officer photographs an unknown crop and gets an identification plus the visual evidence behind it, without waiting on a specialist to be available.

Farmer-facing mobile apps. The JSON API can back an Android or Flutter client directly. Crop identification becomes the entry point to variety-specific advice on irrigation, fertiliser scheduling and pest control.

Agri-marketplace verification. Produce listings with photos get checked automatically against the declared crop type, so mismatches get flagged before the listing goes live.

Dataset labelling at scale. Big unlabelled image collections get pre-sorted by predicted class, and only the low-confidence cases get routed to a human annotator. Saves an enormous amount of manual work.

Agronomy teaching. Horticulture students use it as a self-test tool, and the Grad-CAM overlay shows which morphological features separate one crop from another.

Drone and ground survey pipelines. Survey imagery gets crop-type tags automatically, feeding acreage estimation and crop-pattern analysis downstream.

And it's the obvious first stage for a crop disease detection system, since disease models are almost always crop-specific. Same training pipeline, different dataset. If your guide asks "what's the extension of this work," that's your answer.

What's Honestly Hard, and What's Easier Than It Looks

The hard part is Grad-CAM. Not running it β€” the code works out of the box and locates the backbone and final conv layer by inspection, so it survives a backbone swap. The hard part is explaining it in your viva when someone asks how gradients flowing back to a convolutional feature map turn into a heat map. Read that section of the notebook properly. Don't skip it the night before.

The easy part surprises people. Training the whole model takes 15 to 25 minutes on a normal laptop CPU, 3 to 5 minutes if you have a GPU. There's also smoke_test.py, which renders every single template against a stubbed model β€” so you can confirm the entire web app works without installing TensorFlow at all. Handy when your laptop is already struggling.

Who Should Buy This

If you're a student who needs a working project for your college submission, final-year project, semester project, internship, or academic demonstration, this is for you. Whether you're studying BCA, B.Tech, MCA, M.Tech, Computer Science, IT, AI, Data Science, or another related field, you can choose a project that fits your requirements. If you need the source code, project report, documentation, or help setting up and running the project, CodeAj gives you the resources and support to get started faster.

Why CodeAj

You get the complete source code β€” the training notebook, every Flask route, the templates, the deploy configs, all of it β€” along with a project report you can actually submit and setup support if something breaks on your machine. TensorFlow installs are the usual culprit, especially on Python 3.12 where 2.16 doesn't play nice on every platform. If you're browsing more options in this space, our machine learning projects with source code collection has similar CNN and deep learning builds, the AI final year projects hub covers everything from chatbots to detection systems, and there's a dedicated Flask projects section if you specifically want Python web deployment on your resume. Pick the one that matches your syllabus, not the one with the flashiest screenshot.

Frequently Asked Questions

You will get the complete source code along with an installation guide and chat support to help you set up and understand the project.
All our projects are thoroughly tested multiple times, so the code is completely error-free. But in case you still face any issue, you can reach out to us on WhatsApp (+91 8603862290) and we will fix it and provide you the updated code.
You can book a 1-on-1 Setup & Explanation Session where we connect via AnyDesk and Google Meet, set up the project on your laptop, and explain the complete code working and flow.
No, you cannot re-sell the project. This is completely illegal and a violation of our terms. If we find any such activity, we will take legal action.
It'll train fine. Budget 15 to 25 minutes on CPU, and around 3 to 5 minutes if you do have a GPU. You need roughly 4 GB free while it trains and 2 GB to run the Flask app afterwards. If you want it to finish sooner, set CFG['TRAIN_SCRATCH_BASELINE'] = False in the config cell, which skips the from-scratch comparison model. Just remember you'll lose the 38% vs 90% number for your report.
Say the dataset made that choice for you. There are only about 25 images per class, and a network trained from random weights overfits and stalls under 45% accuracy. The notebook actually trains that scratch baseline so you can show the number: roughly 38%. Transfer learning with a MobileNetV2 ImageNet backbone takes the same data to about 90%. That's not a shortcut, it's the correct method for a small dataset, and having the failed baseline in your report makes the argument for you.
That's Grad-CAM, and yes, understand it. It computes gradients of the predicted class flowing back into the last convolutional layer and turns them into a heat map over your photo, showing which regions pushed the model toward its answer. It's the difference between saying 'the model predicted maize' and proving the model looked at the maize instead of the wall behind it. Read that notebook section properly before your presentation.
Nope, that's a closed-set classifier working exactly as designed. It only knows 30 classes, so anything outside them gets mapped to the nearest one. That's precisely why the confidence threshold exists at 0.45 β€” a genuine out-of-class image usually falls below it and gets shown as an uncertain closest match. If you want to go further, adding an out-of-distribution check is a solid 'future scope' point for your report.
Check your Python version first. TensorFlow 2.16 doesn't support 3.12 on every platform, so drop to 3.10 or 3.11. On Apple Silicon skip the normal package entirely and install tensorflow-macos plus tensorflow-metal instead. And if you just want to confirm the web pages work while you sort this out, install flask, pillow and numpy and run smoke_test.py. It renders every template against a stubbed model with no TensorFlow anywhere.
Yes, and you don't need to retrain anything. The Flask app already exposes /api/predict which takes either a multipart file or a base64 image and returns JSON with the ranked predictions and confidence scores. Point a Flutter or Android client at it and you're done. There's also a TFLite export at around 7 MB in the artifacts folder if you'd rather run it fully on-device with no server.
No, don't trust it. That almost always means duplicate removal got switched off, which lets the same photo sit in both your training and test sets. The source dataset genuinely stores identical images under different file extensions. Set CFG['DROP_DUPLICATES'] = True, retrain, and you'll get an honest number in the 90% region. An examiner who spots an inflated figure will tear the whole report apart, so fix this before submission.
You get everything. The training notebook, app.py, config.py, model_service.py, all five Jinja templates, the CSS and JS, the deploy folder with the Gunicorn, systemd and Nginx configs, the requirements file, the .env example. Nothing is held back and nothing is obfuscated. The project report and documentation come along with it, plus setup help if something breaks on your machine.
Installation Guide

Extra Add-Ons Available – Elevate Your Project

Add any of these professional upgrades to save time and impress your evaluators.

Live 1-on-1 Mentorship

Personal session with an expert developer

Project Setup

We'll install and configure the project on your PC via remote session (Google Meet, Zoom, or AnyDesk).

Source Code Explanation

1-hour live session to explain logic, flow, database design, and key features.

Want to know exactly how the setup works? Review our detailed step-by-step process before scheduling your session.

β‚Ή999

Custom Documents (College-Tailored)

  • Custom Project Report: β‚Ή1,500
  • Custom Research Paper: β‚Ή1,000
  • Custom PPT: β‚Ή800

Fully customized to match your college format, guidelines, and submission standards.

Project Modification

Need feature changes, UI updates, or new features added?

Charges vary based on complexity.

We'll review your request and provide a clear quote before starting work.

Project Files

GoogleReviews

What Our Students Say

4.9(38+ reviews)
Google review 1
Google review 2
Google review 3
Google review 4
Google review 5
Google review 6
Google review 7
Google review 8
Google review 9
Google review 10
Google review 11
Google review 12
Google review 13
Google review 14
Google review 15
Google review 16
Google review 17
Google review 18
Google review 19
Google review 20
Google review 21
Google review 22
Google review 23
Google review 24
Google review 25
Google review 26
Google review 27
Google review 28
Google review 29
Google review 30
Google review 31
Google review 32
Google review 33
Google review 34
Google review 35
Google review 36
Google review 37
Google review 38
⭐ 98% SUCCESS RATE
  • βœ“ Full Development
  • βœ“ Documentation
  • βœ“ Presentation Prep
  • βœ“ 24/7 Support