This project is a part of the course "Information Technology Project" at the University of New England, Armidale Australia. The goal of this project is to detect the crop and its state. The state of the crop can be 'healthy' or one of the various diseases or pest infestations associated with that crop. The dataset used for this project is the "Dataset for Crop Pest and Disease Detection" dataset which contains images of crops in different states. The dataset can be downloaded from here.
Before you begin, ensure you have the following installed:
or
If you do not have them installed you can find instructions to install them here.
The project is structured in to de-coupled frontend and backend components. The frontend is built using Next.js with Tailwind CSS and NextUI. The backend is built using Python Flask. The project is containerized using Docker and Docker Compose.
COSC320-GROUPD/
├── CropDoc/ # Backend (Python Flask)
├── frontend/ # Frontend (Next.js with Tailwind & NextUI)
├── Dockerfile.prod.backend
├── Dockerfile.prod.frontend
├── Dockerfile.dev.backend
├── Dockerfile.dev.frontend
├── docker-compose.prod.yml
└── docker-compose.dev.yml
Start containers (first time or after Dockerfile/dependency changes):
docker-compose -f docker-compose.dev.yml up --build
For subsequent development sessions:
docker-compose -f docker-compose.dev.yml up
Make changes to the code. These changes should be reflected immediately due to volume mounting and hot reloading.
If you make changes that require a rebuild (like changing dependencies), stop the containers and use --build
again.
To start the application in production mode:
```docker-compose -f docker-compose.prod.yml up --build```
To stop the running containers:
docker-compose -f docker-compose.dev.yml down # For development mode
docker-compose -f docker-compose.prod.yml down # For production mode
There are two methods to use the application, the most useful method is using the command line interface (CLI), the second method which is less useful but more user-friendly is using the frontend.
To use the frontend, you can access it by navigating to the following URL in your browser for a locally hosted application
To use the CLI, you need to make sure you have start the application in development mode, or production mode. Then you can open a new terminal, further instructions are below.
The backend application includes several custom commands that can be run using the 'manage.py' script. To execute these commands, you need to start the application (instructions above), open a new terminal and access the backend container first.
Access the backend container:
docker-compose -f docker-compose.dev.yml exec backend bash
Note, change 'dev' to 'prod' if you are using the production mode.
Once inside the container, you can run the following commands:
Hello World test:
python manage.py hello
Run formatters over the code:
python manage.py format
Train the model:
python manage.py train -c <config_file>
Make a prediction using the model:
python manage.py predict -c <config_file> -i <image_path>
Test the model using dataset in the config file:
python manage.py test -c <config_file_name>
Predict many images using dataset in the config file:
python manage.py predict_many -c <config_file>
Produce evaluation metrics, plots and details:
python manage.py evaluate -c <config_file>
For developers, unit tests can be run using the following command:
python manage.py unittest
python manage.py unittest --coverage
Add coverage flag to get coverage report.
python manage.py unittest --filename <filename>
Add filename flag to run a specific test file.
For developers, to run the formatter over the code:
python manage.py format
Config file is a yml file that contains the configuration for the training process, located in CropDoc/app/config/ directory, just use the name of the file, not the full path.
Optionally, you can add in additional key word (kwargs) arguments to the train command by adding the flag -k
or --kwargs
.
If you don't have access to Docker (e.g., on a university server), you can use Apptainer as an alternative. Here are the steps to install Apptainer:
sudo apt-get update
sudo apt-get install rpm2cpio
curl -s https://raw.githubusercontent.com/apptainer/apptainer/main/tools/install-unprivileged.sh | \
bash -s - ~/apptainer
Add Appttainer to your PATH:
echo 'export PATH=$PATH:~/apptainer/bin' >> ~/.zshrc
source ~/.zshrc
Note: If you're using bash instead of zsh, replace .zshrc with .bashrc in the above commands.
Verify Installation:
apptainer --version
If you're using Apptainer instead of Docker, follow these steps:
Ensure Apptainer is installed
Ensure build script and run script are executable:
chmod +x build_apptainer.sh
chmod +x run_apptainer.sh
chmod +x run_cropdoc.sh
Build the containers if they are not built or if you have made changes to dependencies, packages or docker files:
./build_apptainer.sh
Note: You can add --backend or --frontend flags to build only the backend or frontend containers respectively. Note: if prompted to overwrite the existing image, type 'y' and press Enter.
./run_apptainer.sh
run_apptainer.sh
script.To run customer backend commands:
Open a new terminal window after using the run_apptainer.sh
script.
Run the backend container interactively:
./run_cropdoc.sh
Once inside the container, you can run the same commands as listed in the Docker section
Exit the container when done:
exit
CropDoc now includes automatically generated API documentation using Swagger UI. This provides an interactive interface to explore and test the API endpoints.
Ensure the CropDoc server is running (follow the "Running the server" instructions above).
Open a web browser and navigate to:
http://localhost:5000/doc/
Note: If you've configured a different host or port, adjust the URL accordingly.
This documentation is automatically updated when changes are made to the API, ensuring it always reflects the current state of the application.
For developers: When adding new endpoints or modifying existing ones, make sure to use appropriate Flask-RESTX decorators and models to ensure they are correctly reflected in the Swagger UI.