From b42bc6ee8448496f11e03e5c9a881d3655caf945 Mon Sep 17 00:00:00 2001 From: Francois Chollet Date: Thu, 24 May 2018 14:58:15 -0700 Subject: [PATCH] Raise ValueError when calling model.summary() before it is built PiperOrigin-RevId: 197959372 --- tensorflow/python/keras/engine/network.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tensorflow/python/keras/engine/network.py b/tensorflow/python/keras/engine/network.py index 6e818ec..6db4147 100644 --- a/tensorflow/python/keras/engine/network.py +++ b/tensorflow/python/keras/engine/network.py @@ -1428,7 +1428,15 @@ class Network(base_layer.Layer): It will be called on each line of the summary. You can set it to a custom function in order to capture the string summary. + + Raises: + ValueError: if `summary()` is called before the model is built. """ + if not self.built: + raise ValueError('This model has never been called, thus its weights ' + 'have not yet been created, so no summary can be ' + 'displayed. Build the model first ' + '(e.g. by calling it on some data).') print_layer_summary(self, line_length=line_length, positions=positions, -- 2.7.4