Check that the model has been initialized
@@ -21,6 +21,7 @@ class Model(tf.keras.layers.Layer):
super(Model, self).__init__()
self.examples_inputter = examples_inputter
self.params = {}
+ self.initialized = False
self._frozen_layers = False
@property
@@ -77,11 +78,17 @@ class Model(tf.keras.layers.Layer):
params = {}
self.params.update(params)
self.examples_inputter.initialize(data_config)
+ self.initialized = True
def build(self, input_shape):
self.examples_inputter.build(input_shape)
self.built = True
+ def __call__(self, *args, **kwargs): # pylint: disable=arguments-differ
+ if not self.initialized:
+ raise ValueError("The model should be first initialized with initialize()")
+ return super(Model, self).__call__(*args, **kwargs)
+
@abc.abstractmethod
def call(self, features, labels=None, training=None, step=None): # pylint: disable=arguments-differ
"""Runs the model.
