Skip to content

KHRMNKY/Cattle_Classification_with_Pytorch

Repository files navigation

Cattle Species Detection with PyTorch

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.

Table of Contents

Introduction

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.

Dataset

The Cattle dataset used for this project consists of images of different cattle species. Each image is labeled with the corresponding species.

Installation

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.txt

Using API

uvicorn api:app --reload

image

Using CLI

python cli.py --modelPath <"path model"> --imagePath <"image path">

image

Deployment

Live API

The project is now deployed and available online:

Usage Examples

Cattle Classification

The API provides two endpoints for cattle breed classification:

  1. /predict - Returns only the predicted breed with highest confidence
  2. /predicts - Returns all breed probabilities (detailed prediction)

Image Database Operations

The API also supports image storage and retrieval operations:

  • POST /images/ - Upload and store an image
  • GET /images/{image_Id} - Retrieve image information by ID
  • PUT /images/ - Update image information
  • DELETE /images/ - Delete an image from database

Supported Cattle Breeds

  • Aberdeen Angus
  • Charolais
  • Hereford
  • Holstein
  • Jersey
  • Montofon
  • Simmental

API Response Example

{
  "label": "Holstein",
  "confidence": [0.1019, 0.1149, 0.0221, 0.0827, 0.1414, 0.3940, 0.1432]
}

Training

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.py

Model Architecture

The ResNet50 architecture was used and fine-tuned on our dataset with PyTorch.

Data Preprocessing

In this section, the dataset has been prepared using PCA method and kmeans2 clustering algorithm. These operations are located in the preprocessing.py file.

About

This project implements a deep learning-based cattle breed classification system using PyTorch and ResNet50 architecture. The model can identify 7 different cattle breeds (Angus, Charolais, Hereford, Holstein, Jersey, Simmental, Montofon) with high accuracy, providing a valuable tool for livestock management and agricultural application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors