This tutorial assumes you're running Python version 3.9.
Before we get started, we need to download two pretrained model files.
In BiRSwinT.py, there are two checkpoints where we need to use these files.
-
config.DATA.SWIN_TRANSFORMER_CHECKPOINT_PATH - the default value of this config is
ckpt_epoch_44.pth -
swin_small_patch4_window7_224.pthYou can download these two files from here: https://huggingface.co/Pluto2469/BiRSwinT/tree/main, and put these file in the root directory of this project.
The paper indicates that the dataset used for training and validation is the State Farm Distracted Driver Detection and AUC Distracted Driver V1 and V2.
You can download the State Farm Distracted Driver Detection dataset from Kaggle: https://www.kaggle.com/c/state-farm-distracted-driver-detection/data.
For AUC Distracted Driver V1 and V2, you need to sign a License Agreement and email the author to request the dataset. The two license agreement and instructions can be found in the https://abouelnaga.io/distracted-driver/.
After we obtained the dataset, we need to prepare the training and validation dataset. Take State Farm Distracted Driver Detection dataset as an example.
-
Create a directory named
AUCCamerain the root directory. -
Download the dataset from Kaggle: https://www.kaggle.com/competitions/state-farm-distracted-driver-detection/data
-
Extract the data into the
AUCCameradirectory. The two CSV files are not needed and can be safely deleted. -
Move the 'train' and 'test' folders out of the 'imgs' folder. Remove the 'imgs' folder if you like.
Your
AUCCameradirectory should now look like this: -
Since we don't have category labels for the test images, we can partition our training images into a training and a validation set. We have written a Jupyter notebook (split_train_val.ipynb) for this purpose, which you can find in the root directory.
-
After completing the steps above, your project folder should look like this:
Verify the total number of images in the training and validation sets to ensure that you've partitioned the data correctly.
If you prefer to run the code in your conda or virtual environment, rather than a Docker container or a virtual machine, you can simply install the requirements using pip and then execute run.sh.
pip install -r requirements.txtIf you don't have PyTorch, CUDA, or other dependencies, or if you'd like to simplify the process, it's recommended to run the code in Docker.
-
Run docker.build.sh.
-
Edit docker.run.sh to mount your project folder. In our case, we've stored the project in my E drive, and we run scripts in Windows WSL2 Ubuntu, so we've mounted the project folder in the E drive(
/mnt/e/BirSwinT) to the Docker container.docker run -it --gpus=all -v /mnt/e/BirSwinT:/BirSwinT birswint:base /bin/bash
Replace
/mnt/e/BirSwinTwith the path of your own project folder. -
Run docker.run.sh.
docker.run.shwill navigate you to the Docker container, where you can execute run.sh or the following script (which is the same asrun.sh) to train and validate the framework:python train_valid.py --cfg=configs/BiRSwinT/BiRSwinT.yaml
If you've started run.sh correctly, you should see a prompt like this:



