Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import tensorflow as tf
  2. ke = tf.keras
  3.  
  4. import numpy as np
  5.  
  6. import glob
  7.  
  8. def preprocessing(fn):
  9. binary = tf.read_file(fn)
  10. audio = tf.contrib.ffmpeg.decode_audio(binary)
  11. # ... etc.
  12. return audio
  13.  
  14. list_of_audio_files = glob.glob('*.wav')
  15.  
  16. # Could be:
  17. dataset = tf.data.Dataset().from_tensor_slices(list_of_audio_files)
  18. # or:
  19. dataset = tf.data.Dataset().from_tensor_slices((list_of_mix_files, list_of_source_files))
  20. # or:
  21. dataset = tf.data.Dataset().from_tensor_slices(np.random.uniform(-1, 1, [1000, 100]))
  22. # or some other way, there are multiple (see api reference).
  23.  
  24. # Do preprocessing:
  25. dataset = dataset.map(preprocessing)
  26.  
  27. dataset = dataset
  28. .batch(512) # Select batch size.
  29. .repeat() # Don't stop getting data when iterated through once (necessary for model.fit).
  30. .prefetch(100) # Prefetch to ram (there's some other command for prefetching to gpu can't remember).
  31.  
  32. model = ke.Sequential(...)
  33. model.fit(dataset)
  34.  
  35. # You can also get the tf tensors for a batch directly from a data.dataset.
  36. test_dataset = tf.data.Dataset().from_tensor_slices(np.random.uniform(-1, 1, [1000, 100]))
  37. test_iterator = test_dataset.make_initializable_iterator()
  38. next_batch = test_iterator.get_next()
  39.  
  40. # And maybe grab the model outputs for the test data.
  41. test_output = model(next_batch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement