Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import skvideo.io
- import skvideo.datasets
- import tensorflow as tf
- from tensorflow.keras.applications.resnet50 import ResNet50
- from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
- # enabling eager execution for easier explanation
- tf.enable_eager_execution()
- model = ResNet50(weights='imagenet')
- reader = skvideo.io.FFmpegReader(skvideo.datasets.bigbuckbunny(),
- inputdict={},
- outputdict={})
- def gen_frames():
- for frame in reader.nextFrame():
- yield frame
- dataset = tf.data.Dataset.from_generator(gen_frames, tf.int64)
- def preprocess(frames):
- x = tf.image.resize_bilinear(frames, [224, 224])
- x = preprocess_input(x)
- return x
- dataset = dataset.batch(64).map(preprocess, 10).prefetch(1)
- for value in dataset:
- print(decode_predictions(model.predict(value.numpy())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement