Skip to content
Background subtraction using deep learning method.
Python
Branch: master
Clone or download
Latest commit 6a3d29c Aug 31, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Create LICENSE Mar 29, 2018
README.md Update README.md Jul 1, 2018
bgsCNN_v1.py update Sep 14, 2017
bgsCNN_v2.py update Sep 14, 2017
bgsCNN_v3.py update Sep 14, 2017
bgsCNN_v4.py update Nov 18, 2017
bgsCNN_v5.py update Nov 18, 2017
generate_bg.py update Aug 29, 2017
prepare_data.py update Sep 1, 2017
result.py update Sep 14, 2017
test.py update Sep 14, 2017
test_on_video.py update Sep 15, 2017
train.py Update train.py Aug 31, 2018
utilities.py update Sep 24, 2017

README.md

Background Subtraction Using Deep Learning Method

DOI AUR


Most Recent Updates
May 23, 2018: Some pre-trained models are released.


You can find the details about my model in the following reports:

  1. Background Subtraction Using Deep Learning--Part I
  2. Background Subtraction Using Deep Learning--Part II
  3. Background Subtraction Using Deep Learning--Part III

A poster is also available. (The poster is only based on experiment results of v1~v3)
JPG version
PDF version

Pre-trained models

Unfortunately, pre-trained models of v1 and v4 are missing :(
Version 2
Version 3
Version 5

Contents of this repository

  • generate_bg.py
    generating background images; very time consuming to run
    You can get the preprocessed dataset from here.(If you have problem accessing Google Drive, please use this alternative link) Extract this and you will get a directory containing the original dataset with the generated background images. You can directly use it and run prepare_data.py.

  • prepare_data.py
    constructing TFrecords files for preparation of training the model

  • bgsCNN_v*.py
    training the model
    v1 ~ v3 respectively correspond to Model I ~ III mentioned in the second report; v4, v5 haven't been included in reports yet

How to run

1. Dependences

  • Tensorflow
  • OpenCV compiled with Python support (you can refer to this repository for compiling OpenCV)
  • bgslibrary (needed only if you want to run generate_bg.py yourself)
  • Downloaded Checkpoint file of ResNet_V2_50 from Tensorflow Model Zoo, and put resnet_v2_50.ckpt at the same directory as Python script files.
  • Downloaded Checkpoint file of vgg_16 from Tensorflow Model Zoo, and put vgg_16.ckpt at the same directory as Python script files.

2. Training


NOTE
If you use bgsCNN_v1, v2 or v3, set the image_height & image_width as multiples of 32 plus 1, e.g. 321.
If you use bgsCNN_v4 or v5, set the image_height & image_width as multiples of 32, e.g. 320.


In the following demos, suppose we use bgsCNN_v2.

  • If you want to run both generate_bg.py and prepare_data.py (trust me, you don't want to run generate_bg.py yourself!):
python train.py \
  --generate_bg True \
  --prepare_data True  \
  --dataset_dir dataset \
  --log_dir logs \
  --model_version 2 \
  --image_height 321 \
  --image_width 321 \
  --train_batch_size 40 \
  --test_batch_size 200 \
  --max_iteration 10000
  • If you've downloaded the dataset I provided and don't need to run generate_bg.py (suppose the downloaded data is stored in directory "dataset"):
python train.py \
  --prepare_data True  \
  --dataset_dir dataset \
  --log_dir logs \
  --model_version 2 \
  --image_height 321 \
  --image_width 321 \
  --train_batch_size 40 \
  --test_batch_size 200 \
  --max_iteration 10000
  • If you've already had the TFrecords files and don't want to tun prepare_data.py (suppose the two TFrecords files are train.tfrecords & test.tfrecords):
python train.py \
  --prepare_data False  \
  --train_file train.tfrecords \
  --test_file test.tfrecords \
  --log_dir logs \
  --model_version 2 \
  --image_height 321 \
  --image_width 321 \
  --train_batch_size 40 \
  --test_batch_size 200 \
  --max_iteration 10000

3. Test on the test set

When you've finished the training, you can evaluate the model on test to see average test loss. The logs of this test procedure will be in sub-directory "model_test" under your identified logs directory.

python test.py \
  --test_file test.tfrecords \
  --log_dir logs \
  --model_version 2 \
  --image_height 321 \
  --image_width 321 \
  --optimal_step 9600

4. Test on video

You can also run the model on your own video.

python test_on_video.py \
  --log_dir logs \
  --model_version 2 \
  --image_height 321 \
  --image_width 321 \
  --video_file test.mp4
  --optimal_step 9600
You can’t perform that action at this time.