All Projects → ferreirafabio → Video2tfrecord

ferreirafabio / Video2tfrecord

Licence: mit
Easily convert RGB video data (e.g. .avi) to the TensorFlow tfrecords file format for training e.g. a NN in TensorFlow. This implementation allows to limit the number of frames per video to be stored in the tfrecords.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Video2tfrecord

Opticalflow visualization
Python optical flow visualization following Baker et al. (ICCV 2007) as used by the MPI-Sintel challenge
Stars: ✭ 183 (+33.58%)
Mutual labels:  opencv, optical-flow
Attendace management system
In this system we can fill attendance by face recognition
Stars: ✭ 135 (-1.46%)
Mutual labels:  opencv
Skindetector
A Python based skin detection system using OpenCV
Stars: ✭ 130 (-5.11%)
Mutual labels:  opencv
Smoothstream
Webcam, PiCamera streaming over the network with Python made easy.
Stars: ✭ 133 (-2.92%)
Mutual labels:  opencv
Robin
RObust document image BINarization
Stars: ✭ 131 (-4.38%)
Mutual labels:  opencv
Jest Vue Preprocessor
Preprocessor that allows importing of .vue files in jest tests
Stars: ✭ 133 (-2.92%)
Mutual labels:  preprocessor
Leagueai
LeagueAI software framework for League of Legends that provides information about the state of the game based on Image Recognition using OpenCV and Pytorch.
Stars: ✭ 128 (-6.57%)
Mutual labels:  opencv
Gesture Recognition
✋ Recognizing "Hand Gestures" using OpenCV and Python.
Stars: ✭ 136 (-0.73%)
Mutual labels:  opencv
Arflow
The official PyTorch implementation of the paper "Learning by Analogy: Reliable Supervision from Transformations for Unsupervised Optical Flow Estimation".
Stars: ✭ 134 (-2.19%)
Mutual labels:  optical-flow
Preprocessor
A future-facing CSS preprocessor (used by SUIT CSS)
Stars: ✭ 132 (-3.65%)
Mutual labels:  preprocessor
Native Opencv Android Template
A tutorial for setting up OpenCV 4.5.0 (and other 4.x.y version) for Android in Android Studio with Native Development Kit (NDK) support.
Stars: ✭ 131 (-4.38%)
Mutual labels:  opencv
Opentrack
Head tracking software for MS Windows, Linux, and Apple OSX
Stars: ✭ 1,950 (+1323.36%)
Mutual labels:  opencv
Lidar camera calibration
Light-weight camera LiDAR calibration package for ROS using OpenCV and PCL (PnP + LM optimization)
Stars: ✭ 133 (-2.92%)
Mutual labels:  opencv
Multiverse
Dataset, code and model for the CVPR'20 paper "The Garden of Forking Paths: Towards Multi-Future Trajectory Prediction". And for the ECCV'20 SimAug paper.
Stars: ✭ 131 (-4.38%)
Mutual labels:  video-understanding
Stylus
Expressive, robust, feature-rich CSS language built for nodejs
Stars: ✭ 10,817 (+7795.62%)
Mutual labels:  preprocessor
Netdef models
Repository for different network models related to flow/disparity (ECCV 18)
Stars: ✭ 130 (-5.11%)
Mutual labels:  optical-flow
Vision landing
Precision landing using visual targets
Stars: ✭ 131 (-4.38%)
Mutual labels:  opencv
Yolo Powered robot vision
Stars: ✭ 133 (-2.92%)
Mutual labels:  opencv
Vidgear
A High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features 🔥
Stars: ✭ 2,048 (+1394.89%)
Mutual labels:  opencv
Node Camera
Access and stream web camera in nodejs using opencv and websockets.
Stars: ✭ 135 (-1.46%)
Mutual labels:  opencv

Downloads

Description

Easily convert RGB video data (e.g. tested with .avi and .mp4) to the TensorFlow tfrecords file format for training e.g. a NN in TensorFlow. Due to common hardware/GPU RAM limitations in Deep Learning, this implementation allows to limit the number of frames per video to be stored in the tfrecords or to simply use all video frames. The code automatically chooses the frame step size s.t. there is an equal separation distribution of the individual video frames.

The implementation offers the option to include Optical Flow (currently OpenCV's calcOpticalFlowFarneback) as an additional channel to the tfrecords data (it can be easily extended in this regard, for example, by exchanging the currently used Optical Flow algorithm with a different one). Acompanying the code, we've also added a small example with two .mp4 files from which two tfrecords batches are created (1 video per tfrecords file). To access the examples, make sure to use the GitHub repo instead of the pip package.

This implementation was created during a research project and grew historically. Therefore, we invite users encountering bugs to pull-request fixes.

Installation

run the following command:

pip install video2tfrecord 

Writing (video) to tfrecord

After installing the package, you execute the following exemplary command to start the video-to-tfrecord conversion:

from video2tfrecord import convert_videos_to_tfrecord

convert_videos_to_tfrecord(source_path, destination_path, n_videos_in_record, n_frames_per_video, "*.avi") 

while n_videos_in_record being the number of videos in one single tfrecord file, n_frames_per_video being the number of frames to be stored per video and source_path containing your .avi video files. Set n_frames_per_video="all" if you want all video frames to be stored in the tfrecord file (keep in mind that tfrecord can become very large).

Reading from tfrecord

see test.py for an example

Manual installation

If you want to set up your installation manually, use the install scripts provided in the repository.

The package has been successfully tested with:

  • Python 3.4, 3.5 and 3.6
  • tensorflow 1.5.0
  • opencv-python 3.4.0.12
  • numpy 1.14.0

OpenCV troubleshooting

If you encounter issues with OpenCV (e.g. because you use a different version), you can build OpenCV locally from the repository [1] (e.g. refer to StackOverflow thread under [2]). Make sure to use the specified version as in different versions there might be changes to functions within the OpenCV framework.

Parameters and storage details

By adjusting the parameters at the top of the code you can control:

  • input dir (containing all the video files)
  • output dir (to which the tfrecords should be saved)
  • resolution of the images
  • video file suffix (e.g. *.avi) as RegEx(!include asterisk!)
  • number of frames per video that are actually stored in the tfrecord entries (can be smaller than the real number of frames)
  • image color depth
  • if optical flow should be added as a 4th channel
  • number of videos a tfrecords file should contain

The videos are stored as features in the tfrecords. Every video instance contains the following data/information:

  • feature[path] (as byte string while path being "blobs/i" with 0 <= i <=number of images per video)
  • feature['height'] (while height being the image height, e.g. 128)
  • feature['width'] (while width being the image width, e.g. 128)
  • feature['depth'] (while depth being the image depth, e.g. 4 if optical flow used)

Future work:

  • supervised learning: allow to include a label file (e.g. .csv) that specifies the relationship <videoid> to <label> in each row and store label information in the records
  • use compression mode in TFRecordWriter (options = tf.python_io.TFRecordOptions(tf.python_io.TFRecordCompressionType.GZIP))
  • improve documentation
  • add the option to use all video frames instead of just a subset (use n_frames_per_video="all")
  • write small exemplary script for loading the tfrecords + meta-data into a TF QueueRunner (see test.py)
  • replace Farneback optical flow with a more sophisticated method, say dense trajectories
  • Question to users: would it make sense to offer video2tfrecord as a web service (i.e. upload videos, get tfrecords back)?

Additional contributors: Jonas Rothfuss (https://github.com/jonasrothfuss/)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].