title: Resume Training tf.keras Tensorboard
body: <p>I encountered some problems when I continued training my model and visualized the progress on tensorboard.</p>
  
  <p><a href="https://i.stack.imgur.com/GsdB7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GsdB7.png" alt="Tensorboard Training Visualization"></a></p>
  
  <p>My question is how do I resume training from the same step without specifying any epoch manually? If possible, simply by loading the saved model, it somehow could read the <code>global_step</code> from the optimizer saved and continue training from there.</p>
  
  <p>I have provided some codes below to reproduce similar errors.</p>
  
  <pre><code>import tensorflow as tf
  from tensorflow.keras.callbacks import TensorBoard
  from tensorflow.keras.models import load_model
  
  mnist = tf.keras.datasets.mnist
  
  (x_train, y_train),(x_test, y_test) = mnist.load_data()
  x_train, x_test = x_train / 255.0, x_test / 255.0
  
  model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(512, activation=tf.nn.relu),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation=tf.nn.softmax)
  ])
  model.compile(optimizer='adam',
                loss='sparse_categorical_crossentropy',
                metrics=['accuracy'])
  
  model.fit(x_train, y_train, epochs=10, callbacks=[Tensorboard()])
  model.save('./final_model.h5', include_optimizer=True)
  
  del model
  
  model = load_model('./final_model.h5')
  model.fit(x_train, y_train, epochs=10, callbacks=[Tensorboard()])
  </code></pre>
  
  <p>You can run the <code>tensorboard</code> by using the command:</p>
  
  <pre><code>tensorboard --logdir ./logs
  </code></pre>