This repo contains training and evaluation code of CCTV-GUN model. It uses mmdetection to train object detection models.
We follow the installation instructions in the mmdetection documentation here. Specifically, our code requires mmcls=0.25.0,
mmcv-full=1.7.0
and torch=1.13.0
.
The output of conda env export > env.yml
can be found in env.yml. It can be used to create a conda virtual environment with
conda env create -f env.yml
conda activate env_cc
pip install openmim
mim install mmcv-full==1.7.0
pip install -e .
We use images from three datasets :
- Youtube Images
- US Real-time Gun detection dataset (USRT)
Instructions on how to download these datasets can be found in dataset_instructions.md .
All of the above datasets consists of two classes : Person (class 0) and Handgun (class 1). To train a detection model on this dataset, run
python tools/train.py --config <path/to/model/config.py> --dataset-config <path/to/dataset/config.py> <extra_args>
To adjust the training batch size
<base_command> --cfg-options data.samples_per_gpu=<batch-size>
Using weights and biases to log metrics:
After you create an account in wandb, change entity
and project
in train.py to your wandb username and project name. Then
<base_command> --use-wandb --wandb-name <name-of-the-experiment>
Train a Swin-T on Ytimgs (Intra-dataset)
python tools/train.py --config configs/gun_detection/swin_transformer.py --dataset-config configs/_base_/datasets/gun_detection/ytimgs.py --cfg-options data.samples_per_gpu=6
To evaluate a trained model, run
python tools/test.py --config <path/to/model/config.py> --dataset-config <path/to/dataset/config.py> --checkpoint <path/to/trained/model> --work-dir <path/to/save/test/scores> --eval bbox
Evaluate a ConvNeXt trained on USRT
python tools/test.py --config configs/gun_detection/convnext.py --dataset-config configs/_base/datasets/gun_detection/usrt.py --checkpoint <path/to/mgd+usrt/trained/model.pth> --work-dir <path/to/save/test/scores> --eval bbox
To save the bounding box predictions on test set , add --save-path <path/to/output/folder>
to the above command.