For most layers, inference mode is a good default. For data augmentation

layers, though, "do nothing" is a surprising default. It is no longer
necessary to default to the Keras learning phase thanks to changes
in how `training` is propagated in `Layer.__call__`, hence here we can
safely change `training` to a better default of `True`. This makes the layers
easier to use in a tf.data pipeline and generally it makes the debugging
experience less surprising.

PiperOrigin-RevId: 307468108
Change-Id: I0fa75816b18cb054158221c4f93196cfd563b159
This commit is contained in:
Francois Chollet 2020-04-20 13:46:09 -07:00 committed by TensorFlower Gardener
parent 6bfccbd721
commit b592f87bd8
15 changed files with 22 additions and 22 deletions

View File

@ -205,7 +205,7 @@ class RandomCrop(Layer):
self.input_spec = InputSpec(ndim=4)
super(RandomCrop, self).__init__(name=name, **kwargs)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()
@ -370,7 +370,7 @@ class RandomFlip(Layer):
self._rng = make_generator(self.seed)
self.input_spec = InputSpec(ndim=4)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()
@ -493,7 +493,7 @@ class RandomTranslation(Layer):
self.input_spec = InputSpec(ndim=4)
super(RandomTranslation, self).__init__(name=name, **kwargs)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()
@ -771,7 +771,7 @@ class RandomRotation(Layer):
self.input_spec = InputSpec(ndim=4)
super(RandomRotation, self).__init__(name=name, **kwargs)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()
@ -899,7 +899,7 @@ class RandomZoom(Layer):
self.input_spec = InputSpec(ndim=4)
super(RandomZoom, self).__init__(name=name, **kwargs)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()
@ -1035,7 +1035,7 @@ class RandomContrast(Layer):
self.input_spec = InputSpec(ndim=4)
super(RandomContrast, self).__init__(name=name, **kwargs)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()
@ -1113,7 +1113,7 @@ class RandomHeight(Layer):
self._rng = make_generator(self.seed)
super(RandomHeight, self).__init__(name=name, **kwargs)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()
@ -1208,7 +1208,7 @@ class RandomWidth(Layer):
self._rng = make_generator(self.seed)
super(RandomWidth, self).__init__(name=name, **kwargs)
def call(self, inputs, training=None):
def call(self, inputs, training=True):
if training is None:
training = K.learning_phase()

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"

View File

@ -145,7 +145,7 @@ tf_class {
}
member_method {
name: "call"
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'None\'], "
argspec: "args=[\'self\', \'inputs\', \'training\'], varargs=None, keywords=None, defaults=[\'True\'], "
}
member_method {
name: "compute_mask"