Advertisement
alseambusher

Full1

Aug 8th, 2019
12,472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import skvideo.io
  2. import skvideo.datasets
  3. import tensorflow as tf
  4. from tensorflow.keras.applications.resnet50 import ResNet50
  5. from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
  6.  
  7. # enabling eager execution for easier explanation
  8. tf.enable_eager_execution()
  9.  
  10. model = ResNet50(weights='imagenet')
  11.  
  12. reader = skvideo.io.FFmpegReader(skvideo.datasets.bigbuckbunny(),
  13.                              inputdict={},
  14.                              outputdict={})
  15. def gen_frames():
  16.     for frame in reader.nextFrame():
  17.         yield frame
  18.  
  19. dataset = tf.data.Dataset.from_generator(gen_frames, tf.int64)
  20.  
  21. def preprocess(frames):
  22.     x = tf.image.resize_bilinear(frames, [224, 224])
  23.     x = preprocess_input(x)
  24.     return x
  25.  
  26. dataset = dataset.batch(64).map(preprocess, 10).prefetch(1)
  27.  
  28. for value in dataset:
  29.     print(decode_predictions(model.predict(value.numpy())))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement