Skip to content

Code for the paper: "Efficient Two-Stream Network for Violence Detection Using Separable Convolutional LSTM"

License

Notifications You must be signed in to change notification settings

zahid58/TwoStreamSepConvLSTM_ViolenceDetection

Repository files navigation

[Sorry, this codebase is no longer maintained! But the codes would still be useful for building video recognition deep learning pipelines. There might be some bugs and missing links to datasets (please collect data from the original source of these public datasets)!]

Zahidul Islam, Mohammad Rukonuzzaman, Raiyan Ahmed, Md. Hasanul Kabir, Moshiur Farazi

This repository contains the codes for our [PAPER] on violence detection titled Efficient Two-Stream Network for Violence Detection Using Separable Convolutional LSTM which is accepted to be presented at Int'l Joint Conference on Neural Networks (IJCNN) 2021.

Dataset preparation

To get RWF2000 dataset,

  1. go to github.com/mchengny/RWF2000-Video-Database-for-Violence-Detection
  2. sign their agreement sheet to get the download link from them.
  3. prepare the downloaded dataset like the following folder structure,
📦project_directory
  ┣ 📂RWF-2000
    ┣ 📂train
      ┣ 📂fight
      ┣ 📂nonFight
    ┣ 📂test
      ┣ 📂fight
      ┣ 📂nonFight
  1. When running train.py for the first time, pass the argument --preprocessData, this will uniformly sample 32 frames from each video, remove black borders and save them as .npy files. During the next times no need to pass the argument --preprocessData, as you already have converted the videos into .npy files during the first time.

Hockey and Movies dataset can be downloaded from these links -

Hockey_Dataset

Movies_Dataset

Then, preprocess the datasets in the same way as rwf2000 dataset.

How to run

train

To train models go to project directory and run train.py like below,

python train.py --dataset rwf2000 --vidLen 32 --batchSize 4 --numEpochs 150 --mode both --preprocessData --lstmType sepconv --savePath FOLDER_TO_SAVE_MODELS

The training curves and history will be saved in ./results and updated after every epoch.

evaluate

To evaluate an already trained model, use evaluate.py like below,

python evaluate.py --dataset rwf2000 --vidLen 32 --batchSize 4 --mode both --lstmType sepconv --fusionType M --weightsPath PATH_TO_SAVED_MODEL

this will save the results in test_results.csv.

run evaluate.py on trained_models

The trained models weigths are available in the drive folder trained_models. Copy the model you want to use into your project directory like shown below. Then you can evaluate the trained_model like below.

trained_model_evaluate

python evaluate.py --dataset rwf2000 --vidLen 32 --batchSize 4 --mode both --lstmType sepconv --fusionType M --weightsPath "/content/violenceDetection/model/rwf2000_model"

loading trained_models weights inside script

The trained models weigths are available in the drive folder trained_models. Copy the entire folder and its contents into the project directory. Then you can use the trained models like shown below.

path = "./trained_models/rwf2000_model/sepconvlstm-M/model/rwf2000_model"     
# path = "./trained_models/movies/sepconvlstm-A/model/movies_model"   
model =  models.getProposedModelM(...) # build the model
model.load_weights(path) # load the weights

The folder also contains training history, training curves and test results.

Required libraries

Python 3.7, Tensorflow 2.3.1, OpenCV 4.1.2, Numpy, Matplotlib, sci-kit learn

pip install -r requirements.txt

Bibtex

If you do use ideas from the paper in your work please cite as below:

@misc{islam2021efficient,
      title={Efficient Two-Stream Network for Violence Detection Using Separable Convolutional LSTM}, 
      author={Zahidul Islam and Mohammad Rukonuzzaman and Raiyan Ahmed and Md. Hasanul Kabir and Moshiur Farazi},
      year={2021},
      eprint={2102.10590},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

About

Code for the paper: "Efficient Two-Stream Network for Violence Detection Using Separable Convolutional LSTM"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published