This project implements a pest prediction model for agriculture using machine learning techniques.
- Python 3.12.1
- pip (Python package installer)
-
Clone the repository.
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
Note: The
requirements.txt
file includes the latest versions of all dependencies compatible with Python 3.12.1 and macOS ARM64 architecture.
-
Run data collection scripts:
python src/data_collection.py python src/weather_data_collection.py python src/soil_data_collection.py python src/crop_data_collection.py
-
Preprocess the data:
python src/data_preprocessing.py
-
Train the model:
python src/model_training.py
-
Start the Flask application:
FLASK_APP=src/app.py flask run
-
Open a web browser and navigate to
http://127.0.0.1:5000
to use the pest prediction interface.Note: The web interface features a centered design with a blurry greyish and blackish color scheme for improved user experience.
If you encounter any issues, please check the following:
- Ensure you're using Python 3.12.1
- Make sure all required packages are installed correctly
- Check if the data files are present in the
data
directory - Verify that the model files are present in the
model
directory
If you're using a Mac with Apple Silicon (ARM64 architecture), follow these additional steps:
-
Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Install OpenMP:
brew install libomp
-
Install XGBoost from source:
pip install --no-binary :all: xgboost
-
Verify OpenMP installation:
brew info libomp
This should display information about the installed OpenMP package.
-
Verify XGBoost installation:
python -c "import xgboost; print(xgboost.__version__)"
This should print the installed XGBoost version without any errors.
If you encounter issues with XGBoost, try the following:
-
Set the following environment variables before running the application:
export OPENBLAS_NUM_THREADS=1 export OMP_NUM_THREADS=1
-
If you still face issues, try using a CPU-only version of XGBoost:
pip uninstall xgboost pip install xgboost --install-option="--use-system-libxgboost" --no-binary :all:
For any other issues, please open an issue on the GitHub repository.
To ensure that the application is working correctly after making changes or setting up on a new system, follow these steps:
-
Run the data collection and preprocessing scripts:
python src/data_collection.py python src/weather_data_collection.py python src/soil_data_collection.py python src/crop_data_collection.py python src/data_preprocessing.py
-
Train the model:
python src/model_training.py
-
Start the Flask application in debug mode:
FLASK_DEBUG=1 FLASK_APP=src/app.py flask run
-
Open a web browser and navigate to
http://127.0.0.1:5000
-
Test the prediction functionality by entering sample data and verifying that you receive a prediction and management strategies.
-
Verify that the pest images (aphids, Japanese beetle, spider mite, grasshopper, corn rootworm, armyworms, and cutworm) are displayed correctly in the prediction results.
If you encounter any errors during this process, please check the console output for error messages and refer to the troubleshooting section above.