This project implements a deep learning model to recognize various actions in football matches from images. It uses a Convolutional Neural Network (CNN) based on the VGG16 architecture, trained using PyTorch Lightning.
The dataset used for this project was created by Muhammad and is freely available on Kaggle.
- Source: Kaggle - Football Match Actions Dataset
- Classes: The dataset currently supports the following action classes:
goals(Label: 0)red_card(Label: 1)tackles(Label: 2)
main.py: The entry point for training the model. Handles argument parsing, data loading, and initializing the PyTorch Lightning trainer.DataSet.py: Contains theFootBallDataSetclass, a custom PyTorch Dataset that handles image loading and preprocessing using Albumentations.Model.py: Defines the neural network architecture. It uses a pre-trained VGG16 backbone followed by custom MLP blocks for classification.PL_module.py: The PyTorch Lightning Module (PLModule) that defines the training, validation, and testing steps, as well as metric logging (Accuracy, F1 Score, Precision, Recall).
To run this project, you need the following Python libraries:
torchtorchvisionpytorch_lightningalbumentationsopencv-python(cv2)torchmetricstorchinfoargparse
You can install them using pip:
pip install torch torchvision pytorch-lightning albumentations opencv-python torchmetrics torchinfoYou can train the model using the main.py script. It accepts several command-line arguments to configure the training process.
python main.py --data_dir /path/to/your/dataset [OPTIONS]--data_dir(Required): Path to the root directory of the dataset containing the images.--lr: Learning rate (default:1e-4).--epochs: Number of training epochs (default:20).--bs: Batch size (default:32).--num_workers: Number of data loading workers (default:4).
python main.py --data_dir ./football_match_dataset --bs 16 --epochs 10 --lr 0.001The model (Model.py) consists of:
- Backbone: VGG16 with Batch Normalization (pretrained on ImageNet).
- Feature Extractor: The first few layers of VGG16 are used to extract features.
- Classifier Head:
- Adaptive Average Pooling.
- Two MLP blocks (Linear -> BatchNorm -> LeakyReLU -> Dropout).
- Final Linear layer mapping to the number of classes (3).
- Optimizer: Adam
- Scheduler: Cosine Annealing Warm Restarts
- Loss Function: Cross Entropy Loss
- Metrics: Accuracy, F1 Score, Precision, Recall are logged during training and validation.
- Callbacks:
ModelCheckpoint: Saves the top 3 models based on validation loss.EarlyStopping: Stops training if validation loss doesn't improve for 5 epochs.