In this project, I classified 7 cattle breeds.
7 cattle breeds: Angus, Charolais, Hereford, Holstein, Jersey, Simmental, Montofon
Thus, it can be determined which breed a given cattle image belongs to.
Accurate cattle species detection is important for efficient farm management and breeding programs. This project leverages deep learning techniques to build a robust classifier for various cattle species.
The Cattle dataset used for this project consists of images of different cattle species. Each image is labeled with the corresponding species.
Clone the repository:
git clone https://github.com/KHRMNKY/Cattle_Species_Detection_with_Pytorch.git
cd Cattle_Species_Detection_with_Pytorch
pip install -r requirements.txtuvicorn api:app --reloadpython cli.py --modelPath <"path model"> --imagePath <"image path">The project is now deployed and available online:
- API URL: https://cow.kahramankaya.com
- API Documentation (Swagger UI): https://cow.kahramankaya.com/docs#/
- API Documentation (ReDoc): https://cow.kahramankaya.com/redoc
The API provides two endpoints for cattle breed classification:
/predict- Returns only the predicted breed with highest confidence/predicts- Returns all breed probabilities (detailed prediction)
The API also supports image storage and retrieval operations:
POST /images/- Upload and store an imageGET /images/{image_Id}- Retrieve image information by IDPUT /images/- Update image informationDELETE /images/- Delete an image from database
- Aberdeen Angus
- Charolais
- Hereford
- Holstein
- Jersey
- Montofon
- Simmental
{
"label": "Holstein",
"confidence": [0.1019, 0.1149, 0.0221, 0.0827, 0.1414, 0.3940, 0.1432]
}If you want, you can change the hyperparameters (epoch, lr) and train your own model by running the train_model.py file. This trained model will be saved in the models folder.
python train_model.pyThe ResNet50 architecture was used and fine-tuned on our dataset with PyTorch.
In this section, the dataset has been prepared using PCA method and kmeans2 clustering algorithm. These operations are located in the preprocessing.py file.

