We aim to address the challenge of accurate and efficient sport image classification within our service. The goal is to enhance the precision of categorizing sports based on user-provided images by leveraging a Convolutional Neural Network (CNN) model trained on a diverse sport-specific dataset.
Kaggle data set used - https://www.kaggle.com/datasets/sidharkal/sports-image-classification
As a part of this application, a pre-trained model - Inceptionv3 was further trained with a dataset containing images of different sports classes- cricket, wrestling, tennis, badminton, soccer, swimming, and karate and wrapped as tf-serving(based on the above kaggle dataset). The trained model has an accuracy of 94% in classifying the sport. Please note the training dataset contained only 7 sport classes [cricket, wrestling, tennis, badminton, soccer, swimming, and karate]
Images, model are checked into the repo making it a large repo interms of size. Hence git-lfs was used to store file greater than 100MB. Follow the installation instructions for git-lfs here.
Folder | Description |
---|---|
dataset | Directory containing training and test data - image files. |
gateway | Directory containing flask application which acts as a gateway for tf-serving |
model | Directory containing '.h5' model which was trianed and tensorflow generated model which can be used in tf-serving. |
trainer | Directory containing notebooks and script which were used for training the model. |
kube-config | Configuration related to kubernetes deployments. |
- python 3.10 or above.
- docker, docker-compose, Kind, kubectl
- pip3, pipenv
- git-lfs
Use pipenv install
to install dependencies from respective directories, Only if you want to train model and build images yourself.
- Folder
gateway
- contains dependencies related to flask and tf-serving. - Folder
trainer
- contains dependencies related to tensorflow and other libraries required for training the model.
- Clone this repo
- Install git-lfs.
git lfs pull
.(The trained model is saved in themodel
directory already)docker-compose up
- check if the containers is up
docker ps
- Ensure
kind
kubernetes in installed - run
./deploy-local-kube.sh <cluster-name>
kubectl port-forward services/sports-gateway-service 9696:9696
cd
into./gateway
directorypipenv install
pipenv shell
python3 predict_test.py
run ./predict_test.sh
or
curl --request POST \
--url http://localhost:9696/predict \
--header 'Content-Type: application/json' \
--data '{"url": <<image url>>}'
<<image url>>
- any image url from internet
http://bit.ly/3RtIOTq
https://bit.ly/3GMDW6T
https://bit.ly/48nRO3l
Both the Gateway and the Model is deployed on AWS EKS cluster.
The gateway is available for testing
hostname:a1192352e2f8a43ca8923f350baf8983-1337907194.us-east-2.elb.amazonaws.com
you can test the application deployed on AWS Cluster running
./predict_test.sh a1192352e2f8a43ca8923f350baf8983-1337907194.us-east-2.elb.amazonaws.com <<image_url>>
API | Description | Response | Response-type |
---|---|---|---|
/ping |
ping api to check the status | pong | String |
/predict |
Return the prediction of the classification | check below sample | Json |
Sample Response for '/predict'
{
"prediction": "Karate",
"probability_percentage": {
"Badminton": 1.887187517368716e-09,
"Cricket": 8.943498869484756e-06,
"Karate": 0.9999909400939941,
"Soccer": 1.0174683495733916e-07,
"Swimming": 3.659216159246359e-12,
"Tennis": 2.4010535781826547e-09,
"Wrestling": 1.1995511250972868e-09
}
}
The trained model is already checked into the repos under model
directory along with the notebooks used for training and testing. Incase you want to do from scratch follow below steps
cd into trainer
directorypipenv install
pipenv shell
python3 ./train_model.py
- Running this code saves the .h5 model with highest accuracy.python3 ./convert_model.py
- converts to tensor saved model format.- Note: verify
h5_model_name
&tensor_model_name
inconvert_model.py
before running.