CNN-based classifier to detect Coccidiosis vs Healthy from chicken fecal images. The project is production-lean with modular pipelines, configuration-driven training, DVC for reproducibility, and a minimal Flask app for serving predictions.
- VGG16 backbone with configurable head (see
params.yaml) - Reproducible training using DVC stages (
dvc.yaml) - Clean component/pipeline layout under
src/cnnClassifier - Flask UI and JSON API (
app.py,templates/,static/) - Metrics tracked in
scores.json
Prerequisites
- Python 3.8 or higher
- Git
- DVC (pip install dvc)
On Windows PowerShell:
# 1) Create and activate a virtual environment
python -m venv .venv
./.venv/Scripts/Activate.ps1
# 2) Install dependencies
python -m pip install --upgrade pip
pip install -r requirements.txt
# 3) Reproduce the full pipeline (data -> model)
dvc repro
# 4) Optional: visualize pipeline graph
dvc dagAlternatively, you can run the full training pipeline directly:
python main.pyArtifacts (datasets, models, logs) are produced under the artifacts/ directory as configured in config/config.yaml.
Run the web app with UI and JSON endpoint:
python app.py- UI: open http://127.0.0.1:8080/ and upload an image.
- API:
POST /predictwith JSON body{ "image": "<base64>" }.
Minimal request example:
{
"image": "<base64-encoded-image>"
}Response shape:
[
{
"prediction": "Healthy | Coccidiosis",
"status": "success",
"message": "Prediction completed successfully"
},
{ "image": "<echoed-input-as-base64>" }
]- Pipeline and I/O paths:
config/config.yaml - Hyperparameters:
params.yaml - DVC stages:
dvc.yaml - Logs:
logs/running_logs.log
Model details (default):
- Base: VGG16 (Keras Applications)
- Input size:
IMAGE_SIZEfromparams.yaml(default: 224x224x3) - Top: Flatten + Dense(softmax,
CLASSES) - Optimizer: SGD(learning_rate =
LEARNING_RATE) - Training config:
BATCH_SIZE,EPOCHS,AUGMENTATION
.
├── app.py # Flask app (UI + API)
├── main.py # Run full training pipeline sequentially
├── dvc.yaml # DVC stages (ingestion, base, train, eval)
├── params.yaml # Hyperparameters
├── config/config.yaml # Paths and stage configs
├── src/cnnClassifier/ # Components, pipelines, utils
│ ├── components/ # data_ingestion, prepare_base_model, training, evaluation, callbacks
│ ├── config/ # Configuration management
│ ├── constants/ # Constant values (e.g., config and params file path)
│ ├── entity/ # Data classes for configs
│ ├── pipeline/ # stage_01..04 + predict.py
│ ├── utils/ # common helpers (e.g., base64 decode)
│ └── ...
├── artifacts/ # Data + models produced by stages
│ ├── data_ingestion/Chicken-fecal-images/{Coccidiosis,Healthy}/
│ ├── prepare_base_model/
│ └── training/model.h5
├── templates/index.html # Frontend
├── static/style.css # Styles
├── scores.json # Evaluation metrics (DVC-tracked)
├── requirements.txt
├── Dockerfile
└── README.md
Common commands:
# Run all stages
dvc repro
# Show pipeline graph
dvc dag
# Inspect metrics
dvc metrics showStages defined in dvc.yaml:
- data_ingestion → 2) prepare_base_model → 3) training → 4) evaluation
You can also run the same stages via python main.py.
Build and run locally:
# Build image
docker build -t chicken-disease-classifier-cnn .
# Run container (expose Flask on 8080)
docker run -p 8080:8080 chicken-disease-classifier-cnnThen open http://127.0.0.1:8080/.
Examples from the ingested dataset (for illustration):
- Coccidiosis:
artifacts/data_ingestion/Chicken-fecal-images/Coccidiosis/cocci.0.jpg - Healthy:
artifacts/data_ingestion/Chicken-fecal-images/Healthy/healthy.0.jpg
- Package install is editable via
-e .inrequirements.txt(seesetup.py). - The Flask
/trainroute runsdvc reproserver-side to retrain using your current configs. - Prediction pipeline loads the model from
artifacts/training/model.h5and expects 224×224 RGB.
Issues and PRs are welcome. Please open an issue first for significant changes.
This project is licensed under MIT License - see the LICENSE file for details.

