Mitti Mentor
Tags: rebase01, gdsciiitkalyani
Published: 2024-04-20 18:09:05

## **Mitti Mentor**
A technological solution to detect which crop is suitable and most fruitful for your soil type

## Team Code Voyagers :

- Anipriyo Mandal - @melodious_one
- Arup Matabber - @arup_matabber
- Ronita Patra - @ronita_2003
- Arpan Mandal -@enthusiasticodr

## Project Description:
A soil analysis and crop recommendation system, aims to improve agricultural practices for farmers. It's built on Flask backend framework incorporating advanced technologies for seamless user experience and robust functionality. HTML, JS & CSS power the frontend, ensuring flawless performance and responsiveness across devices. Based on its component-based architecture, we will craft a modular UI facilitating easy navigation, interaction & implementation. On the backend, Flask provides a reliable framework that acts as a strong backbone of our project working along API communication. The key to our website is the integration of Machine Learning algorithms for Soil analysis and Crop suggestion judging parameters mainly based on 4 major soil types i.e. alluvial, black, red, clayey. This functionality is developed using TensorFlow and Keras CNN, enabling speedy and responsive diagnosis directly on the client-side. The soil analysis feature provided by our ML algorithm allows farmers to photograph and upload the picture of soil on their fields and get accurate insight with real-time analysis, minimizing latency. This will enable us to meet our Sustainability Goals and also facilitate the Increase in Agricultural Yield and make the most efficient use of Available & Cultivable lands. The analysis results in personalized crop suggestions, planting techniques and guidelines tailored to the most suitable crops, empowering farmers with the knowledge required to succeed. Our model would be efficient enough to provide the farmers the necessary suggestions thereby eliminating the need to hire a separate consultant, thus mitigating their biased opinions generally in favor of the company paying them commissions, rendering farmers independent.

**Current Features:**
1. - Soil Prediction and analysis from a jpg picture.
2. - Crop Suggestion based on the Soil Prediction.

**Planned Updates for future:**
1. Geolocation feature for a better Soil Prediction and analysis.
2. A weather update feature for better crop suggestions based on the soil type.
3. Adding a translation feature that’ll translate the text to regional languages for the convenience of the farmer.
4. Adding hardwares like soil moisture sensor to get accurate data for prediction.

## Submission Track:

- Sustainability 
- Replit Track
- Open Innovation

## Overview of My Submission
Our application, Mitti Mentor is a sophisticated soil analysis and crop recommendation system, aims to improve agricultural practices for farmers which would be efficient enough to provide the farmers the necessary suggestions thereby eliminating the need to hire a separate consultant, thus mitigating their biased opinions generally in favor of the company paying them commissions, rendering farmers independent. Also it would lead to efficient use of Cultivable land and increase Agricultural Yield.

This project is a collective effort of our members following the tech stack as provided in the proposal also following the deadline. Since the beginning we aimed for a clean and user-friendly UI and with the collective effort of all the team members, we achieved the desired result in a few days. The next challenge was to build a robust ML model which actually burdened us a lot due to our insufficient experience in the domain. But with the help from our seniors, Youtube, AI and some other open source resources of keras libraries, we successfully implemented it with 98.5% accuracy in the best version . Finally it was the backend which actually we had no prior experience of implementation but finally after a couple of sleepless nights, even the backend fell in line with a Flask framework implementation and finally we’re in possession of a sophisticated system built to serve the needy.

## Tech Stack :

- **Frontend:** HTML, CSS and JavaScript.
- **Backend:** Flask framework.
- **UI/UX:** Figma, Canva, Adobe Photoshop and Adobe Illustrator.
- **Machine Learning:** Tensorflow and Keras CNN.

**Services:** 

- **Replit & Github** for Version control and deployment.
- 	**Figma** for UI/UX and prototyping.
- 	**Adobe Illustrator** for rendering vector images.

## Challenges We Faced :

- **Implementation of ML & Backend:** Significant challenges were faced during the deployment of the model as the allocated RAM in the free version of Replit overflowed due to the tensorflow and Python packages.
- **Deployment of the Model :** Lack of free Space in Repelit due to the lack of funding and free subscription forced us to prototype the project in a free server which curtailed our capabilities a bit
- **Scalability and competition from existing products in the market :** During our surveys, we came across an already established startup ‘fasal’ which worked on similar lines which made us realize that we might lack a bit in R&D and Deployment. However, our future plans include more extensive market & field surveys to enhance the accuracy of our model and provide a better user experience by the use of location, weather and other such effective parameters.

## Public Code Repo:
**Github :** https://github.com/anipriyo/Mitti-Mentor
**Replit :** https://replit.com/@anipriyo2004/Mitti-Mentor?v=1

We’re running in for the replit track as well alongside others provided above in the order of our choice.

**NOTE :**
The web-app is dynamic so the deployable link changes each time & since our replit plan is free so we can't keep the project up & running. Therefore no deployment link could be provided.
While you fork & run add ':3000/home' to the webview link for viewing the homepage from the routed port. 

**Current link -** "https://08694472-0cd5-4d46-93fb-cf0e6bd5cc04-00-26443w7h5cbi7.pike.replit.dev:3000/home"

## Demo Link :
https://youtu.be/NjzjYnoxMos

## Additional Resources / Info :

**1. Backend :**

- Import & Initialization

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6w430f7k0hqlzdqzu22b.PNG)

- Model Prediction:
This function accepts the image path and the model as parameters and returns the predicted soil type in the image.We pre-process the image by loading and resizing the image as required, then colour normalizing and expanding dimensions such that it can be fed into the model for prediction.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgi2q46p0by7v089bqsq.PNG)

- End-Points:
Defining the paths and functionalities individually thereby creating a dynamic nature of our outputs. The routed function corresponds to different sections of our webpage to the different files that are responsible to render that section.
For example, here the function home is routed to endpoint home and renders the homepage of our website index.html

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ssz51eyjgpda6pw0608.PNG)

- Soil Prediction:
The POSTed image is downloaded and fed into the loaded model for prediction. The user is then redirected to the predictSoil endpoint with appropriate massage for the predicted soil type

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/205vydty3xrbamxeesbn.PNG)

- Crop Prediction:
The POSTed image is downloaded and fed into the loaded model for prediction. The user is then redirected to the predictCrop endpoint with appropriate Crop Suggestion for the predicted soil type.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezln7xouxuagogx2ea12.PNG)

Now,  finally we’re in possession of a sophisticated Backend for our webpage.

**2. ML Model :**

- Importing Libraries :

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nxuuelds05vlacv1i5gy.PNG)

- Data Labeling :

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/efuvhpahwl4g1qz8i9rr.PNG)

- Model Architecture : 
Sequential Model having 5 Layers. Optimized using Adam, loss handled using Categorical CrossEntropy, on the metric of accuracy.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gf3hqo8ode0yjf0sbgqt.PNG)

- Model Training :
50 epochs for better accuracy

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evr402j3jh5gjsfi9wt9.PNG)

- Model Evaluation :
Accuracy 98.5% and Loss 34.2%

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rr9et7rgim3yx8wq7s5x.PNG)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mp85eyrjzqwv68u3u1my.PNG)

- Model Save :

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kcx2iq8kqzsv1otpb0xb.PNG)

- Prediction using Model :
Function of similar structure implemented in backend after loading the model from storage.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r4c32d5ocdz3vxnsluen.PNG)