Code that accompanies my blog post outlining five video classification methods in Keras and TensorFlow
The five video classification methods:
lrcnnetwork in the code).
See the accompanying blog post for full details: https://medium.com/@harvitronix/five-video-classification-methods-implemented-in-keras-and-tensorflow-99cad29cc0b5
This code requires you have Keras 2 and TensorFlow 1 or greater installed. Please see the
requirements.txt file. To ensure you're up to date, run:
pip install -r requirements.txt
You must also have
ffmpeg installed in order to extract the video files. If
ffmpeg isn't in your system path (ie.
which ffmpeg doesn't return its path, or you're on an OS other than *nix), you'll need to update the path to
First, download the dataset from UCF into the
cd data && wget http://crcv.ucf.edu/data/UCF101/UCF101.rar
Then extract it with
unrar e UCF101.rar.
Next, create folders (still in the data folder) with
mkdir train && mkdir test && mkdir sequences && mkdir checkpoints.
Now you can run the scripts in the data folder to move the videos to the appropriate place, extract their frames and make the CSV file the rest of the code references. You need to run these in order. Example:
Before you can run the
mlp, you need to extract features from the images with the CNN. This is done by running
extract_features.py. On my Dell with a GeFore 960m GPU, this takes about 8 hours. If you want to limit to just the first N classes, you can set that option in the file.
The CNN-only method (method #1 in the blog post) is run from
The rest of the models are run from
train.py. There are configuration options you can set in that file to choose which model you want to run.
The models are all defined in
models.py. Reference that file to see which models you are able to run in
Training logs are saved to CSV and also to TensorBoard files. To see progress while training, run
tensorboard --logdir=data/logs from the project root folder.
I have not yet implemented a demo where you can pass a video file to a model and get a prediction. Pull requests are welcome if you'd like to help out!
Khurram Soomro, Amir Roshan Zamir and Mubarak Shah, UCF101: A Dataset of 101 Human Action Classes From Videos in The Wild., CRCV-TR-12-01, November, 2012.