(I'm using Tensorflow 1.8.0 ...)
The documentation from Keras on how to save a model mentions no difference between saving a sequential model vs. one created from the functional API. But, all of the following blocks of code fail:
import tensorflow as tf
net = tf.keras.models.Model()
net.save('file')
or
import tensorflow as tf
net = tf.keras.models.Model()
print(net.to_json())
or
import tensorflow as tf
net = tf.keras.models.Model()
print(net.to_yaml())
or
import tensorflow as tf
net = tf.keras.models.Model()
print(net.get_config())
They raise a NotImplementedError
. In the Keras module, the relevant lines are
if not self._is_graph_network:
raise NotImplementedError
which shows up in .save
and get_config
(the latter is also called by to_json
and to_yaml
.
The only thing that DOES work is the following
import tensorflow as tf
net = tf.keras.models.Model()
net.save_weights('file')
in which case the weights are saved successfully and can be successfully loaded with net.load_weights
.
However, replacing the second line of the above blocks of code, net = tf.keras.models.Model()
, with net = tf.keras.models.Sequential()
, making net a sequential model, allows everything above to work.
Is it really not possible to save the structure of a Keras model made with the functional API (using Model
rather than Sequential
)? Right now, can we only save weights?
Of course its possible to save Model, all your examples have an empty Model, whcih makes no sense to save. Keras' author simply did not implement that case.
If you test with a non-empty Model you will see that saving works perfectly. We use it every day.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With