Minor cleanup.

Add default value for getattr(), which will throw AttributeError if object does not have the attribute.

PiperOrigin-RevId: 256270127
This commit is contained in:
Scott Zhu 2019-07-02 17:10:27 -07:00 committed by TensorFlower Gardener
parent 3957de13a5
commit 9e0e23c59f

View File

@ -1928,7 +1928,7 @@ class Model(network.Network):
# If we have re-compiled the loss/weighted metric sub-graphs then create # If we have re-compiled the loss/weighted metric sub-graphs then create
# train function even if one exists already. This is because # train function even if one exists already. This is because
# `_feed_sample_weights` list has been updated on re-copmpile. # `_feed_sample_weights` list has been updated on re-copmpile.
if getattr(self, 'train_function') is None or has_recompiled: if getattr(self, 'train_function', None) is None or has_recompiled:
# Restore the compiled trainable state. # Restore the compiled trainable state.
current_trainable_state = self._get_trainable_state() current_trainable_state = self._get_trainable_state()
self._set_trainable_state(self._compiled_trainable_state) self._set_trainable_state(self._compiled_trainable_state)
@ -1971,7 +1971,7 @@ class Model(network.Network):
# If we have re-compiled the loss/weighted metric sub-graphs then create # If we have re-compiled the loss/weighted metric sub-graphs then create
# test function even if one exists already. This is because # test function even if one exists already. This is because
# `_feed_sample_weights` list has been updated on re-copmpile. # `_feed_sample_weights` list has been updated on re-copmpile.
if getattr(self, 'test_function') is None or has_recompiled: if getattr(self, 'test_function', None) is None or has_recompiled:
inputs = (self._feed_inputs + inputs = (self._feed_inputs +
self._feed_targets + self._feed_targets +
self._feed_sample_weights) self._feed_sample_weights)