Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #adjust learning rate policy by callbacks
  2. def scheduler(epoch):
  3. if epoch == 5:
  4. model.lr.set_value(.02)
  5. return model.lr.get_value()
  6.  
  7. change_lr = LearningRateScheduler(scheduler)
  8.  
  9. model.fit(x_embed, y, nb_epoch=1, batch_size = batch_size, show_accuracy=True,
  10. callbacks=[chage_lr])
  11.  
  12. #adapt gpu memory usage when using tensorflow as backend
  13. import os
  14. import tensorflow as tf
  15. import keras.backend.tensorflow_backend as KTF
  16.  
  17. def get_session(gpu_fraction=0.3):
  18. '''Assume that you have 6GB of GPU memory and want to allocate ~2GB'''
  19.  
  20. num_threads = os.environ.get('OMP_NUM_THREADS')
  21. gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=gpu_fraction)
  22.  
  23. if num_threads:
  24. return tf.Session(config=tf.ConfigProto(
  25. gpu_options=gpu_options, intra_op_parallelism_threads=num_threads))
  26. else:
  27. return tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
  28.  
  29. KTF.set_session(get_session())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement