Raise ValueError when calling model.summary() before it is built
authorFrancois Chollet <fchollet@google.com>
Thu, 24 May 2018 21:58:15 +0000 (14:58 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Thu, 24 May 2018 22:00:58 +0000 (15:00 -0700)
PiperOrigin-RevId: 197959372

tensorflow/python/keras/engine/network.py

index 6e818ec..6db4147 100644 (file)
@@ -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,