Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. IMG = 128
  2. a = "/content/gdrive/My Drive/Colab Notebooks/"
  3. def preprocess_train(img, label):
  4. img = tf.cast(img, tf.float32)
  5. img = img / 255 - 0.5
  6. img = tf.image.resize(img, (IMG, IMG))
  7.  
  8. return img, label
  9.  
  10. batch_size = 100
  11.  
  12. data_train = np.load(a+"train-1.npy", allow_pickle=True)
  13. for i in range(2, 5):
  14. t = np.load(a+f"./train-{i}.npy", allow_pickle=True)
  15. data_train = np.concatenate([data_train, t])
  16.  
  17. def train_gen():
  18. for img, label in data_train[int(len(data_train) * val_size):]:
  19. img = img[..., None] # [batch, w, h, channels]
  20. yield img, char_to_id[label]
  21.  
  22. ds_train = tf.data.Dataset.from_generator(train_gen,
  23. output_types=(tf.float32, tf.int32),
  24. output_shapes=((None,None,1), ())
  25. ).map(preprocess_train, num_parallel_calls=-1).prefetch(-1).shuffle(1024).batch(batch_size).repeat()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement