I created a Sequential model using tf.keras as follows:
model = tf.keras.Sequential() model.add(tf.keras.layers.Dense(8, input_dim=4)) model.add(tf.keras.layers.Dense(3, activation=tf.nn.softmax)) opt = tf.train.AdamOptimizer(learning_rate=0.001) model.compile(optimizer=opt, loss="categorical_crossentropy", metrics=["accuracy"]) model.summary() After that, I created a training process using train_on_batch:
EPOCHS=50 for epoch in range(EPOCHS): for metrics, labels in dataset: # Calculate training loss and accuracy tr_loss, tr_accuracy = model.train_on_batch(metrics, labels) When I try to save the model, I receive a warning. I can't understand why, because I included the optimizer as part of the model.compile:
tf.keras.models.save_model( model, "./model/iris_model.h5", overwrite=True, include_optimizer=True ) WARNING:tensorflow:TensorFlow optimizers do not make it possible to access optimizer attributes or optimizer state after instantiation. As a result, we cannot save the optimizer as part of the model save file.You will have to compile your model again after loading it. Prefer using a Keras optimizer instead (see keras.io/optimizers).
The TF version I used is 1.9.0-rc2.