dmlc / decord

An efficient video loader for deep learning with smart shuffling that's super easy to digest
Apache License 2.0
1.89k stars 161 forks source link

Decord reader does not work with tf.Data.Dataset.from_generator #67

Open douglas125 opened 4 years ago

douglas125 commented 4 years ago

Hello;

I would like to use tf.Data to process some video frames but I can't get Decord to work with from_generator. Versions: Decord: 0.3.9 tf: 2.2.0

Here's some minimal code to reproduce the issue. Any help is appreciated.

from decord import VideoReader
from decord import cpu, gpu
import tensorflow as tf

# use whatever video here e.g. http://file.all-free-download.com/downloadfiles/footage/traffic_jam_new_work_street_583.zip
vr = VideoReader('traffic_jam_new_work_street_583.mp4', ctx=cpu(0))
def frame_gen_decord():
    for k in range(len(vr)):
        sample = vr.next().asnumpy()
        yield sample

g = frame_gen_decord()
x = next(g)
h, w, c = x.shape

dataset = tf.data.Dataset.from_generator(
    frame_gen_decord,
    output_types=(tf.int32),
    output_shapes=(tf.TensorShape([h, w, c]))
)

# this throws an error
for frame in dataset.take(1):
    x = frame
zhreshold commented 4 years ago

@douglas125 Have you tried setting the output format to be tensorflow?

For example

import decord
decord.bridge.set_bridge('tensorflow')
douglas125 commented 4 years ago

I have not. I'll do that and post the results.