PyNVVL:一个用于NVIDIA Video Loader (NVVL) 的CuPy Python包装器
项目描述
PyNVVL
PyNVVL是NVIDIA Video Loader (NVVL) 的一个薄包装器NVIDIA Video Loader (NVVL)。这个包允许您直接将视频加载到GPU内存中,并以零拷贝的方式将其作为CuPy ndarrays访问。PyNVVL的预构建二进制文件包括NVVL本身,因此您不需要安装NVVL。
要求
- CUDA 8.0, 9.0, 9.1或9.2
- Python 2.7.6+,3.4.7+,3.5.1+或3.6.0+
- CuPy v4.5.0
测试环境
- Ubuntu 16.04
- Python 2.7.6+,3.4.7+,3.5.1+和3.6.0+
- CUDA 8.0,9.0,9.1和9.2
安装预构建二进制文件
请根据您的CUDA版本选择正确的包。
# [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
用法
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')
此视频是来自 Moments-In-Time 数据集的 flickr-2-6-3-3-5-2-7-6-5626335276_4.mp4
。
请注意,裁剪是在缩放之后进行的。在上面的示例中,NVVL首先从256 x 256缩放到512 x 512,然后裁剪区域 [60:60 + 385, 0:512]。有关转换选项的更多信息,请参阅下一节。
VideoLoader选项
在创建NVVLVideoLoader
对象时,请指定GPU设备ID。您还可以通过构造函数的log_level
参数指定日志级别。
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'.
转换选项
pynvvl.NVVLVideoLoader.read_sequence
可以接受一些选项来指定色彩空间、数值范围以及您想要对视频执行哪些转换。
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.
如何构建
使用Docker构建wheel
要求
- Docker
- nvidia-docker (v1/v2)
bash docker/build_wheels.sh
不使用Docker设置开发环境
setup.py
脚本会查找必要的库。
要求:以下库在LIBRARY_PATH
中可用。
- libnvvl.so
- libavformat.so.57
- libavfilter.so.6
- libavcodec.so.57
- libavutil.so.55
您可以在nvvl
存储库中构建libnvvl.so
。遵循nvvl
库的说明。必须将build
目录放在LIBRARY_PATH
中。
其他三个库在Ubuntu 16.04中以软件包的形式提供。它们安装在/usr/lib/x86_64-linux-gnu
下,因此它们也必须在LIBRARY_PATH
中。
python setup.py develop
python setup.py bdist_wheel
项目详情
关闭
哈希值 for pynvvl_cuda91-0.0.3a2-cp36-cp36m-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d46a564862bc9126ec5e6c4d4d07ada1a5c0758988c616e1dc5239d3e5266ef4 |
|
MD5 | ada585dd24fce3917c3801f025447f40 |
|
BLAKE2b-256 | e7b9fb1675f3a87675d9ef02446435813825a0b0dd84f39b79eeec6d75e73c85 |
关闭
哈希值 for pynvvl_cuda91-0.0.3a2-cp35-cp35m-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 017ec9364c3161849990215e95bcc557c17ea81d9cd02f6efe099a37b28a9e19 |
|
MD5 | 3576aa11aab7c2d6c4e8fb1986fcecb4 |
|
BLAKE2b-256 | 76d2838b5db61d5cf7322bd5c6eb4c8caaf02170a5f5a029be850ec1ee5d76c3 |
关闭
哈希值 for pynvvl_cuda91-0.0.3a2-cp34-cp34m-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 824a43cb3338415e622c1d0e711d79b958e0f31920dcaabc5bcb9afdd92ed1a4 |
|
MD5 | 97b7ef04cd2216f3a44162bdff44cd6e |
|
BLAKE2b-256 | 2c5146540cc57d52a732962ac27a8df1623232c8f6bf51007f0dca81433b2fa0 |
关闭
哈希值用于pynvvl_cuda91-0.0.3a2-cp27-cp27mu-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3eb54a5180768965121945064501cf8b0f29ceda44cba73405c277ad3acf13f5 |
|
MD5 | 87f8cca77d766809792f7ba733c43383 |
|
BLAKE2b-256 | e2e2b56e41b6bc2991ee873a9435e7e0e34b76c0763338f127d9ffe5ff673710 |