From 771955e2b8be98a0b38fada41bd67f663397c87d Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 9 Oct 2018 15:18:21 -0700 Subject: Raises an appropriate error if `add_weight` is called on a Keras network. PiperOrigin-RevId: 216432358 --- tensorflow/python/keras/engine/network.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tensorflow/python/keras/engine/network.py b/tensorflow/python/keras/engine/network.py index 5969fea2b2..266c48d304 100644 --- a/tensorflow/python/keras/engine/network.py +++ b/tensorflow/python/keras/engine/network.py @@ -432,6 +432,27 @@ class Network(base_layer.Layer): 'assign variables to attributes and they will show up in the weights ' 'and variables properties.') + def add_weight(self, + name, + shape, + dtype=None, + initializer=None, + regularizer=None, + trainable=None, + constraint=None, + partitioner=None, + use_resource=None, + synchronization=variables.VariableSynchronization.AUTO, + aggregation=variables.VariableAggregation.NONE, + **kwargs): + if self._is_graph_network: + raise NotImplementedError('`add_weight` is not supported on Networks.') + else: + raise NotImplementedError( + '`add_weight` is not supported on Networks. However, you may ' + 'assign variables to attributes and they will show up in the weights ' + 'and variables properties.') + def add_loss(self, *args, **kwargs): if context.executing_eagerly(): raise NotImplementedError('`add_loss` is not supported on Networks ' -- cgit v1.2.3