我正在尝试使用tfds.features.Video在tensorflow 2中解码视频,以使输出为“ tf.uint8类型的tf.Tensor,形状为[num_frames,高度,宽度,通道]”:
import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_datasets as tfds
df_trains= pd.DataFrame()
df_trains['video_files']= ['aa.mp4']
files_ds = tf.data.Dataset.from_tensor_slices(df_trains.video_files)
video_class = tfds.features.Video(shape=(None, 1080, 1920,3), encoding_format='png', ffmpeg_extra_args=())
a= video_class.decode_example(files_ds)
但是它会产生以下错误:"AssertionError: Feature Video can only be decoded when defined as top-level feature, through info.features.decode_example()"
我无法解决,请在这方面提供帮助。
您不能那样使用“ tfds.features.Video”。 “ tfds.features.Video”通常与“ tfds.builder”或“ tfds.load”一起使用。因此,当您使用tfds_download_dataset时,您会感到自在,但难以使用custum数据集。
features = tfds.features.FeaturesDict({
'video': tfds.features.Video(shape=(None, 1080, 1920,3)),
})
tfds.load(..., decoders=features, ...)
但是“ tfds.features.Video”可以通过使my_dataset包含您的数据来使用。但是,这很烦人。所以cv2比这更好。