• This repository has been archived on 26/Oct/2020
  • Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Python wrapper of NVIDIA Video Loader (NVVL) with CuPy for fast video loading with Python

PyNVVL

pypi-pynvvl-cuda80 pypi-pynvvl-cuda90 pypi-pynvvl-cuda91 pypi-pynvvl-cuda92 GitHub license

PyNVVL is a thin wrapper of NVIDIA Video Loader (NVVL). This package enables you to load videos directly to GPU memory and access them as CuPy ndarrays with zero copy. The pre-built binaries of PyNVVL include NVVL itself, so you do not need to install NVVL.

Requirements

  • CUDA 8.0, 9.0, 9.1, or 9.2
  • Python 2.7.6+, 3.4.7+, 3.5.1+, or 3.6.0+
  • CuPy v4.5.0

Tested Environment

  • Ubuntu 16.04
  • Python 2.7.6+, 3.4.7+, 3.5.1+, and 3.6.0+
  • CUDA 8.0, 9.0, 9.1, and 9.2

Install the pre-built binary

Please choose a right package depending on your CUDA version.

# [For CUDA 8.0]
pip install pynvvl-cuda80

# [For CUDA 9.0]
pip install pynvvl-cuda90

# [For CUDA 9.1]
pip install pynvvl-cuda91

# [For CUDA 9.2]
pip install pynvvl-cuda92

Usage

import pynvvl
import matplotlib.pyplot as plt

# Create NVVLVideoLoader object
loader = pynvvl.NVVLVideoLoader(device_id=0, log_level='error')

# Show the number of frames in the video
n_frames = loader.frame_count('examples/sample.mp4')
print('Number of frames:', n_frames)

# Load a video and return it as a CuPy array
video = loader.read_sequence(
    'examples/sample.mp4',
    horiz_flip=True,
    scale_height=512,
    scale_width=512,
    crop_y=60,
    crop_height=385,
    crop_width=512,
    scale_method='Linear',
    normalized=True
)

print(video.shape)  # => (91, 3, 385, 512): (n_frames, channels, height, width)
print(video.dtype)  # => float32

# Get the first frame as numpy array
frame = video[0].get()
frame = frame.transpose(1, 2, 0)

plt.imshow(frame)
plt.savefig('examples/sample.png')

This video is flickr-2-6-3-3-5-2-7-6-5626335276_4.mp4 from the Moments-In-Time dataset.

Note that cropping is performed after scaling. In the above example, NVVL performs scaling up from 256 x 256 to 512 x 512 first, then cropping the region [60:60 + 385, 0:512]. See the following section to know more about the transformation options.

VideoLoader options

Please specify the GPU device id when you create a NVVLVideoLoader object. You can also specify the logging level with the argument log_level for the constructor of NVVLVideoLoader.

Wrapper of NVVL VideoLoader

    Args:
        device_id (int): Specify the device id used to load a video.
        log_level (str): Logging level which should be either 'debug',
            'info', 'warn', 'error', or 'none'.
            Logs with levels >= log_level is shown. The default is 'warn'.

Transformation Options

pynvvl.NVVLVideoLoader.read_sequence can take some options to specify the color space, the value range, and what transformations you want to perform to the video.

Loads the video from disk and returns it as a CuPy ndarray.

    Args:
        filename (str): The path to the video.
        frame (int): The initial frame number of the returned sequence.
            Default is 0.
        count (int): The number of frames of the returned sequence.
            If it is None, whole frames of the video are loaded.
        channels (int): The number of color channels of the video.
            Default is 3.
        scale_height (int): The height of the scaled video.
            Note that scaling is performed before cropping.
            If it is 0 no scaling is performed. Default is 0.
        scale_width (int): The width of the scaled video.
            Note that scaling is performed before cropping.
            If it is 0, no scaling is performed. Default is 0.
        crop_x (int): Location of the crop within the scaled frame.
            Must be set such that crop_y + height <= original height.
            Default is 0.
        crop_y (int): Location of the crop within the scaled frame.
            Must be set such that crop_x + width <= original height.
            Default is 0.
        crop_height (int): The height of cropped region of the video.
            If it is None, no cropping is performed. Default is None.
        crop_width (int): The width of cropped region of the video.
            If it is None, no cropping is performed. Default is None.
        scale_method (str): Scaling method. It should be either of
            'Nearest' or 'Lienar'. Default is 'Linear'.
        horiz_flip (bool): Whether horizontal flipping is performed or not.
            Default is False.
        normalized (bool): If it is True, the values of returned video is
            normalized into [0, 1], otherwise the value range is [0, 255].
            Default is False.
        color_space (str): The color space of the values of returned video.
            It should be either 'RGB' or 'YCbCr'. Default is 'RGB'.
        chroma_up_method (str): How the chroma channels are upscaled from
            yuv 4:2:0 to 4:4:4. It should be 'Linear' currently.
        out (cupy.ndarray): Alternate output array where place the result.
            It must have the same shape and the dtype as the expected
            output, and its order must be C-contiguous.

How to build

Build wheels using Docker:

Requirements:

  • Docker
  • nvidia-docker (v1/v2)
bash docker/build_wheels.sh

Setup development environment without Docker:

The setup.py script searches for necessary libraries.

Requirements: the following libraries should be available in LIBRARY_PATH.

  • libnvvl.so
  • libavformat.so.57
  • libavfilter.so.6
  • libavcodec.so.57
  • libavutil.so.55

You can build libnvvl.so in the nvvl repository. Follow the instructions of nvvl library. The build directory must be in LIBRARY_PATH.

The other three libraries are available as packages in Ubuntu 16.04. They are installed under /usr/lib/x86_64-linux-gnu, so they must be in LIBRARY_PATH as well.

python setup.py develop
python setup.py bdist_wheel

More Repositories

1

deeppose

DeepPose implementation in Chainer
Python
401
star
2

chainer-faster-rcnn

Object Detection with Faster R-CNN in Chainer
Python
291
star
3

ssai-cnn

Semantic Segmentation for Aerial / Satellite Images with Convolutional Neural Networks including an unofficial implementation of Volodymyr Mnih's methods
Python
262
star
4

caltech-pedestrian-dataset-converter

Download Caltech Pedestrian Dataset and convert them for Python users without using MATLAB
Python
200
star
5

chainer-cifar10

Various CNN models for CIFAR10 with Chainer
Python
138
star
6

chainer-handson

CAUTION: This is not maintained anymore. Visit https://github.com/chainer-community/chainer-colab-notebook/
Jupyter Notebook
87
star
7

chainer-pspnet

PSPNet in Chainer
Python
76
star
8

chainer-fast-rcnn

Chainer folk of Fast R-CNN (Object Detection Method)
Python
52
star
9

chainer-siamese

Siamese Network implementation using Chainer
Python
40
star
10

chainer-imagenet-vgg

Python
34
star
11

chainer-nri

Reproduction work of "Neural Relational Inference for Interacting Systems" in Chainer
Python
31
star
12

ssai

Semantic Segmentation for Aerial Imagery using Convolutional Neural Network
Python
28
star
13

chainer-svm

Support Vector Machine (SVM) implementation using Chainer
Python
26
star
14

chainer-notebooks

Jupyter notebooks for Chainer hands-on
Jupyter Notebook
24
star
15

tfchain

Run a static part of the computational graph written in Chainer with Tensorflow
Python
20
star
16

chainer-conv-vis

Convolution filter visualization tool for VGG-net using Chainer
Python
17
star
17

SOINN_CPP

SOINN implementation with C++
C++
16
star
18

dlibss

Python wrapper of selective search like algorithm in dlib
C++
15
star
19

pybing

A Python wrapper of OpenCV implementation of BING Objectness
C++
15
star
20

homebrew-caffe

[THIS PROJECT HAS BEEN DEPRECATED. BECAUSE NOW CUDA SUPPORTS libc++] Caffe (Convolutional Architecture for Fast Feature Embedding) related formulae for OSX 10.9
Ruby
15
star
21

ofChainer

Python
12
star
22

chainercmd

Command Line Tools for Chainer
Python
9
star
23

TicTacToe

Reinforcement Learning - TicTacToe
Ruby
9
star
24

intel-chainer

6
star
25

burn-captions

Burn captions (.srt) into videos
Python
5
star
26

2Kinects

Use 2 Kinects with OpenNI, Capture IR images from both kinects.
C++
4
star
27

animeface

Python
3
star
28

marlo-handson

Python
3
star
29

deeplab-public-ver2

This is fork of https://bitbucket.org/aquariusjay/deeplab-public-ver2
C++
3
star
30

CMA-ES

C++
2
star
31

DepthSenseSample

C++
2
star
32

chainermn-on-azure

Shell
2
star
33

chainer-mdn

Mixture Density Network with Chainer
Python
2
star
34

wakapata

Python
1
star
35

cvmodules

Python
1
star
36

OSCSample

OpenSoundControl Library Test on Qt 4.8.0
C++
1
star
37

MeanShiftTracking

C++
1
star
38

KinectV2Rec

Save Color, Depth, IR images from Kinect for Windows V2 into different movie files
C++
1
star
39

blog

Jupyter Notebook
1
star
40

openmpi-cuda-bins

Pre-built binaries of OpenMPI w/ CUDA & verbs options
Dockerfile
1
star
41

ofOpenNI2

OpenNI2 & NiTE2 with openFrameworks (OSX Mountain Lion)
C++
1
star
42

NeuralNetwork

NeuralNetwork sample (back propagation)
C++
1
star
43

CuPy-cuDF-cuML

Use CuPy ndarray with cuDF/cuML functions
Jupyter Notebook
1
star
44

KinectFromPCL

PCLのOpenNIGrabberを使ってKinectからテクスチャ付き点群データを取得して表示するサンプル
C++
1
star
45

Qt3DSample

C++
1
star