Git Product home page Git Product logo

twostreamsepconvlstm_violencedetection's Introduction

[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}
}

twostreamsepconvlstm_violencedetection's People

Contributors

dependabot[bot] avatar zahid58 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

twostreamsepconvlstm_violencedetection's Issues

When I use tf2.0 training model, there is an error

AttributeError: 'AttenSepConvLSTM2D' object has no attribute '_maybe_reset_cell_dropout_mask'
AttributeError: 'SepConvLSTM2D' object has no attribute '_maybe_reset_cell_dropout_mask'
I can only use tf2.0 because of my GPU

A checkpoint was restored..

When i try to trained with pre-weights,it showed this ,I can't understand why...
My cudais 11.2,tf is 2.5...
image

File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/resource_variable_ops.py", line 308, in shape_safe_assign_variable_handle
shape.assert_is_compatible_with(value_tensor.shape)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/tensor_shape.py", line 1161, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (64,) and (16,) are incompatible
....
WARNING:tensorflow:A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details.

warning and wrong number of parameters in tensorflow2.6.0

when i use the code in tensorflow 2.6.0 there is a warning when i run the code.
WARNING:tensorflow: The following Variables were used a Lambda layer's call (tf.keras.backend.rnn), but are not present in its tracked objects: <tf.Variable 'SepConvLSTM2D_1/depth_kernel:0' shape=(3, 3, 56, 4) dtype=float32> <tf.Variable 'SepConvLSTM2D_1/point_kernel:0' shape=(1, 1, 56, 256) dtype=float32> <tf.Variable 'SepConvLSTM2D_1/recurrent_depth_kernel:0' shape=(3, 3, 64, 4) dtype=float32> <tf.Variable 'SepConvLSTM2D_1/recurrent_point_kernel:0' shape=(1, 1, 64, 256) dtype=float32> <tf.Variable 'SepConvLSTM2D_1/bias:0' shape=(256,) dtype=float32> It is possible that this is intended behavior, but it is more likely an omission. This is a strong indication that this layer should be formulated as a subclassed Layer rather than a Lambda layer. WARNING:tensorflow: The following Variables were used a Lambda layer's call (tf.keras.backend.rnn_1), but are not present in its tracked objects: <tf.Variable 'SepConvLSTM2D_2/depth_kernel:0' shape=(3, 3, 56, 4) dtype=float32> <tf.Variable 'SepConvLSTM2D_2/point_kernel:0' shape=(1, 1, 56, 256) dtype=float32> <tf.Variable 'SepConvLSTM2D_2/recurrent_depth_kernel:0' shape=(3, 3, 64, 4) dtype=float32> <tf.Variable 'SepConvLSTM2D_2/recurrent_point_kernel:0' shape=(1, 1, 64, 256) dtype=float32> <tf.Variable 'SepConvLSTM2D_2/bias:0' shape=(256,) dtype=float32> It is possible that this is intended behavior, but it is more likely an omission. This is a strong indication that this layer should be formulated as a subclassed Layer rather than a Lambda layer.
besides the model parameters number are wrong in 2.6.0 and in model summary, instead of SepConvLSTM2D_1 and SepConvLSTM2D_2 there is tf.compat.v1.zeros_like and some variables like that.
but everything is fine in tensorflow2.5.0 how should i solve it?

Getting the actual labels

Hi @zahid58 ! First of all, thank you for creating an easy to follow violence detection model. I would like to know how can I extract the actual labels when running the evaluate.py. I'm trying to create a classification report on my own dataset.

Here's what I made so far on the end part of evaluate.py :

     y_pred = (predictions > 0.5).astype("int32")
    # get the classification report
    print(classification_report(y_actual, y_pred))`

Just can't figure out how to get the y_actual . I have a guess that it's based on the directory structure of fight and non-fight but I don't know what I can call or which variable keeps the actual labels. Hoping to hearing from you soon!

Best regards.

The program uses GPU by default?

Hello, I am trying to train the model, but the time is too long, I have a NVIDIA RTX 3090 card, and it takes about 1 hour for each epoch.
Is it normal? Does the program use GPU?

Incompatible problem

I encountered an incompatibility issue while evaluating the trained model. Can anyone provide some suggestions
image

test on single video

I tried to convert the .mp4 video to .npy and send it to the trained model but it gives this error "tuple index out of range".
Will you please look into this issue.
Thank you in advance

Shapes (64,) and (1,) are incompatible

Dear author, the problem occurs when I run evaluate.py, the problem occurs in
model.load_weights(f'{weightsPath}')
throw exception display
Shapes (64,) and (1,) are incompatible
The weight information of the model has been obtained in the previous training, but the problem was found during the evaluation, so I would like to ask you for advice, thank you very much.

How to resume interrupted training?

I was training on RWF-2000 dataset and it stopped at 131 out of 150 due to CUDA error. The train.py contains --resumePath and --resume args for resuming the training. But, I don't know how to initializie them, because I was unable to find the weights (.h5) in the path provided by --savePath. It only contains a results folder along with some files (image below)
image

Isn't the training supposed to save the checkpoints in h5 format?
Could you provide an example command for resuming the training? Thank you!

Possible to use custom dataset

Hi! May I know if it's possible to utilize your repo code to test for other datasets except hockey, movies, surv, rwf2000? Big thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.