This python framework provides modular access to common activity recognition models for the use of baseline comparisons between the current state of the art and custom models.
This README will walk you through the process of installing dependencies, downloading and formatting datasets, testing the framework, and expanding the framework to train your own models.
This repository holds the code and models for the paper
M-PACT: Michigan Platform for Activity Classification in Tensorflow, Eric Hofesmann, Madan Ravi Ganesh, and Jason J. Corso, arXiv, April 2018.
ATTENTION: Please cite the arXiv paper introducing this platform when releasing any work that used this code.
Link: https://arxiv.org/abs/1804.05879
Implemented Model's Classification Accuracy:
| Model Architecture |
Dataset (Split 1) |
M-PACT Accuracy (%) |
Original Authors Accuracy (%) |
| I3D |
HMDB51 |
68.10 |
74.80* |
| C3D |
HMDB51 |
51.90 |
50.30* |
| TSN |
HMDB51 |
51.70 |
54.40 |
| ResNet50 + LSTM |
HMDB51 |
43.86 |
43.90 |
|
|
|
|
| I3D |
UCF101 |
92.55 |
95.60* |
| C3D |
UCF101 |
93.66 |
82.30* |
| TSN |
UCF101 |
85.25 |
85.50 |
| ResNet50 + LSTM |
UCF101 |
80.20 |
84.30 |
(*) Indicates that results are shown across all three splits
Table of Contents
Introduction and Setup
Common Datasets:
- HMDB51
- UCF101
- Kinetics
- Moments in Time
Requirements
Hardware and Software:
- Nvidia Graphics Card
- Ubuntu 16.04
- Python 2.7
- Cuda
- Cudnn
- Gflags
Python Dependencies (All can be installed using pip):
Configuring Datasets
In order to use this framework, the datasets will need to be downloaded and formatted correctly. Datasets are not included and must be downloaded and converted to TFRecords format. Converting dataset videos into TFRecords binary files allows for optimized tensorflow data loading and processing.
Methods to import and configure datasets correctly can be found in the section Adding a Dataset.
Using the framework
From the root directory, the training and testing is done through train.py and test.py.
Implemented models can be used if the weights have been acquired.
Download weights and mean files by running the script sh scripts/shell/download_weights.sh.
NOTE: The download links may not work for users in China. Alternative downloads can be found here: http://academictorrents.com/details/dcea7fa53925b31215bd8437d2f0805253d6b00f
and https://app.nihaocloud.com/d/fb0c387c9a644f86b257/
Ex. Train ResNet50+LSTM on HMDB51 using 4 GPUs
python train.py --model resnet --dataset HMDB51 --numGpus 4 --load 0 --size 224 --inputDims 50 --outputDims 51 --seqLength 50 --dropoutRate 0.5 --expName example_1 --numVids 3570 --lr 0.01 --nEpochs 30 --baseDataPath /data --fName trainlist --optChoice adam
The parameters to train are:
python train.py \
--model The model archetecture to be used (i3d, c3d, tsn, resnet) **REQUIRED**
--dataset The dataset to use for training (UCF101, HMDB51) **REQUIRED**
--size Size of the input frame into network, sets both height and width (224 for ResNet, I3D, TSN and 112 for C3D) **REQUIRED**
--inputDims Input dimensions (number of frames to pass into model) **REQUIRED**
--outputDims Output dimensions (number of classes in dataset) **REQUIRED**
--seqLength Sequence length when output from model (50 for ResNet50, 250 for TSN, 1 for I3D and C3D) **REQUIRED**
--expName Experiment name **REQUIRED**
--baseDataPath The path to where all datasets are stored (Ex. For HMDB51, this directory should then contain tfrecords_HMDB51/Split1/trainlist/exampleVidName.tfrecords) **REQUIRED**
--fName Which dataset list to use (trainlist, testlist, vallist) **REQUIRED**
--numGpus Number of GPUs to train on over a single node (default 1)
--train 1 or 0 whether to set up model in testing or training format (default 1)
--load 1 or 0 whether to use the current trained checkpoints with the same experiment_name or to train from random initialized weights
--modelAlpha Optional rsampling factor constant value resampling or initializing other resampling strategies maininly during training.
--inputAlpha Resampling factor for constant value resampling of input video, used mainly for testing models.
--dropoutRate Value indicating proability of keeping inputs of the model's dropout layers. (defaulat 0.5)
--freeze Freeze weights during training of any layers within the model that have the option manually set. (default 0)
--numVids Number of videos to train on within the specified split
--lr Initial learning rate (Default 0.001)
--wd Weight decay value for training layers (Defaults 0.0)
--lossType String defining loss type associated with chosen model (multiple losses are optionally defined in model)
--nEpochs Number of epochs to train over (default 1)
--split Dataset split to use (deafult 1)
--saveFreq Frequency in epochs to save model checkpoints (default 1 aka every epoch)
--returnLayer Which model layers to be returned by the model's inference during testing. ('logits' during training)
--optChoice String indication optimizer choice (Default sgd)
--gradClipValue Value of normalized gradient at which to clip (Default 5.0)
--clipLength Length of clips to cut video into (default -1 indicates using the entire video as one clip)
--videoOffset (none or random) indicating where to begin selecting video clips assuming clipOffset is none
--clipOffset (none or random) indicating if clips are selected sequentially or randomly
--numClips Number of clips to break video into, -1 indicates breaking the video into the maximum number of clips based on clipLength, clipOverlap, and clipOffset
--clipStride Number of frames that overlap between clips, 0 indicates no overlap and -1 indicates clips are randomly selected and not sequential
--batchSize Number of clips to load into the model each step (default 1)
--metricsDir Name of sub directory within experiment to store metrics. Unique directory names allow for parallel testing.
--metricsMethod Which method to use to calculate accuracy metrics. During training only used to set up correct file structure. (avg_pooling, last_frame, svm, svm_train or extract_features)
--preprocMethod Which preprocessing method to use, allows for the use of multiple preprocessing files per model architecture
--randomInit Randomly initialize model weights, not loading from any files (deafult False)
--shuffleSeed Seed integer for random shuffle of files in load_dataset function
--preprocDebugging Boolean indicating whether to load videos and clips in a queue or to load them directly for debugging. Errors in preprocessing setup will not show up properly otherwise (Default 0)
--loadedCheckpoint Specify the step of the saved model checkpoint that will be loaded for testing. Defaults to most recently saved checkpoint.
--gpuList List of GPU IDs to be used
--gradClipValue Value of normalized gradient at which to clip.
--lrboundary List of boundary epochs at which lr will be updated
--lrvalues List of lr multiplier values, length of list must equal lrboundary
--loadWeights String which can be used to specify the default weights to load.
--verbose Boolean switch to display all print statements or not
The parameters to test are: