Home

Awesome

A Faster Pytorch Implementation of R-C3D

News:

We reorganized the code and make it faster and more convenient. The old branch is with tag: 201810

Introduction

This project is a faster pytorch implementation of R-C3D, aimed to accelerating the training of R-C3D temporal action detection models. During our implementing, we referred the below implementations:

Our implementation has several unique and new features compared with the above implementations:

Benchmarking

We benchmark our code thoroughly on two action detection datasets: Activitynet-v1.3 val subset, THUMOS14, using two different network architecture: C3D and 3d-resnet. Below are the results:

Note!!!

The prev URLs of benchmark are not working anymore, we provide they here: the benckmark models: trained models

1). THUMOS14 (buffer length=768; pooled_lhw=4,2,2; anchor scales=2,4,5,6,8,9,10,12,14,16; fixed the 2 bottom layers)

model  #GPUsbatch sizelr      lr_decaymax_epoch    time/epochmem/GPUmAP(IoU thresh=0.5)
R-C3D published paper111e-44.95 hr~700MB28.9
C3D    221e-43  5  2.97 hr600MB  38.5

2). Activitynet-v1.3 (buffer length=768; pooled_lhw=4,2,2 for c3d, pooled_lhw=16,4,4 for 3d-resnet; anchor scales=1,1.25, 1.5,1.75, 2,2.5, 3,3.5, 4,4.5, 5,5.5, 6,7, 8,9,10,11,12,14,16,18,20,22,24,28,32,36,40,44,52,60,68,76,84,92,100;)

model  #GPUsbatch sizelr      lr_decaymax_epoch    time/epochmem/GPUmAP(IoU thresh=0.5)Average mAP(IoU thresh=0.5:0.05:0.95)
R-C3D published paper111e-44.95 hr~700MB26.4513.33
C3D    441e-46  8  2.97 hr600MB  28.815.1
3d-resnet18    441e-46  8  1.29 hr255MB  26.214.2
3d-resnet34    441e-48  10  1.75 hr285MB  28.815.5
3d-resnet50    441e-48  10  2.06 hr~800MB  30.416.6

What we are going to do

Preparation

First of all, clone the code

git clone https://github.com/sunnyxiaohu/R-C3D.pytorch.git

Then, create a folder:

cd R-C3D.pytorch && mkdir data

prerequisites

Data Preparation

  1. Download the data.
  2. Extract the video frames.
cd ./preprocess/thumos14
python generate_frames.py
  1. Generate training and validation roidb
python generate_roidb_training.py
python generate_roidb_validation.py
  1. Download the data. Please follow the instructions in
  2. Extract the video frames.
cd ./preprocess/activitynet
python generate_frames.py
  1. Generate training and validation roidb
python generate_roidb_training.py
python generate_roidb_validation.py

Pretrained Model

####Note!!! The prev URLs of pretrained models are not working anymore, we provide they here: the pretrained models: pretrained models

We used two pretrained models in our experiments, VGG and ResNet101. You can download these two models from:

NOTE. We would suggest to use Caffe pretrained models from the above link to reproduce our results.

If you want to use pytorch pre-trained models, please remember to transpose images from BGR to RGB, and also use the same data transformer (minus mean and normalize) as used in pretrained model.

Compilation

As pointed out by ruotianluo/pytorch-faster-rcnn, choose the right -arch in make.sh file, to compile the cuda code:

GPU modelArchitecture
TitanX (Maxwell/Pascal)sm_52
GTX 960Msm_50
GTX 1080 (Ti)sm_61
Grid K520 (AWS g2.2xlarge)sm_30
Tesla K80 (AWS p2.xlarge)sm_37

More details about setting the architecture can be found here or here

Install all the python dependencies using pip:

pip install -r requirements.txt

Compile the cuda dependencies using following simple commands:

cd lib
sh make.sh

It will compile all the modules you need, including NMS, ROI_Temporal_Pooing. The default version is compiled with Python 3.6, please compile by yourself if you are using a different python version.

As pointed out in this issue, if you encounter some error during the compilation, you might miss to export the CUDA paths to your environment.

Train

Before training, set the right directory to save and load the trained models. Change the arguments "save_dir" and "load_dir" in trainval_net.py and test_net.py to adapt to your environment.

To train a R-C3D model with C3D on THUMOS14, simply run:

CUDA_VISIBLE_DEVICES=$GPU_ID ./script_train c3d thumos14 
                   --gpus 0 1 2 3 --bs 4 \
                   --nw $WORKER_NUMBER \
                   --lr $LEARNING_RATE --lr_decay_step $DECAY_STEP

where 'bs' is the batch size with default 1. Above, BATCH_SIZE and WORKER_NUMBER can be set adaptively according to your GPU memory size.

Change dataset to "activivity" or 'charades' if you want to train on ActivityNet or Charades. Change network to "res34" or "res18" if you want to use 3d-resnet34 network or 3d-resnet18 network

Test

If you want to evaluate the detection performance of a c3d model on thumos14 test set, simply run

CUDA_VISIBLE_DEVICES=$GPU_ID ./script_test c3d thumos14 
                   --gpus 0 1 2 3 --bs 4 \
                   --nw $WORKER_NUMBER \
                   --checksession $SESSION1 --checkepoch $EPOCH --checkpoint $CHECKPOINT

Specify the specific model session, chechepoch and checkpoint, e.g., SESSION=1, EPOCH=3, CHECKPOINT=13711.

Authorship

This project is contributed by Shiguang Wang, and many others (thanks to them!).

Citation

@article{swfaster2rc3d,
    Author = {Shiguang Wang and Jian Cheng},
    Title = {A Faster Pytorch Implementation of R-C3D},
    Journal = {https://github.com/sunnyxiaohu/R-C3D.pytorch.git},
    Year = {2018}
} 

@inproceedings{xu2017r,
    title={R-C3D: region convolutional 3d network for temporal activity detection},
    author={Xu, Huijuan and Das, Abir and Saenko, Kate},
    booktitle={IEEE Int. Conf. on Computer Vision (ICCV)},
    pages={5794--5803},
    year={2017}
}