简体   繁体   中英

How can i speed up my model training process using tensorflow and keras

My batch size = 128 number of epochs = 15

Single epoch takes 4 hours to complete the task, so the full training process takes a huge time. In my case, I need to increase the speed of my model training process to save my weight values how can I do this

# Training Process
results = model.fit_generator(generate_batch(orig_train, forg_train, batch_sz),
                              steps_per_epoch = num_train_samples//batch_sz,
                              epochs = 15,
                              validation_data = generate_batch(orig_val, forg_val, batch_sz),
                              validation_steps = num_val_samples//batch_sz,
                              callbacks = callbacks)

and my callback array defined as follows,

callbacks = [
    EarlyStopping(patience=12, verbose=1),
    ReduceLROnPlateau(factor=0.1, patience=5, min_lr=0.000001, verbose=1),
    ModelCheckpoint('./Weights/model-weight-{epoch:03d}.h5', verbose=1, save_weights_only=True)
]

There are two things you can do:

  1. Switch on XLA.
import tensorflow as tf

tf.config.optimizer.set_jit(True)
  1. Switch on mixed precision.
from tensorflow.keras.mixed_precision import experimental as mixed_precision
policy = mixed_precision.Policy('mixed_float16')
mixed_precision.set_policy(policy)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM