Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tf_keras/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,20 +1423,20 @@ def __init__(
if mode == "min":
self.monitor_op = np.less
if self.best is None:
self.best = np.Inf
self.best = np.inf
elif mode == "max":
self.monitor_op = np.greater
if self.best is None:
self.best = -np.Inf
self.best = -np.inf
else:
if "acc" in self.monitor or self.monitor.startswith("fmeasure"):
self.monitor_op = np.greater
if self.best is None:
self.best = -np.Inf
self.best = -np.inf
else:
self.monitor_op = np.less
if self.best is None:
self.best = np.Inf
self.best = np.inf

if self.save_freq != "epoch" and not isinstance(self.save_freq, int):
raise ValueError(
Expand Down Expand Up @@ -2112,7 +2112,7 @@ def on_train_begin(self, logs=None):
# Allow instances to be re-used
self.wait = 0
self.stopped_epoch = 0
self.best = np.Inf if self.monitor_op == np.less else -np.Inf
self.best = np.inf if self.monitor_op == np.less else -np.inf
self.best_weights = None
self.best_epoch = 0

Expand Down Expand Up @@ -3115,10 +3115,10 @@ def _reset(self):
self.mode == "auto" and "acc" not in self.monitor
):
self.monitor_op = lambda a, b: np.less(a, b - self.min_delta)
self.best = np.Inf
self.best = np.inf
else:
self.monitor_op = lambda a, b: np.greater(a, b + self.min_delta)
self.best = -np.Inf
self.best = -np.inf
self.cooldown_counter = 0
self.wait = 0

Expand Down
4 changes: 2 additions & 2 deletions tf_keras/mixed_precision/autocast_variable_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,13 @@ def test_assign_stays_in_true_dtype(self, distribution):
# same float16 value.
self.evaluate(x.assign(1.0 + small_tensor))
self.assertEqual(1.0, self.evaluate(x.value()))
self.assertEqual(1.0 + small_val, self.evaluate(x))
self.assertEqual(1.0 + np.float64(small_val), self.evaluate(x))

self.evaluate(x.assign(1.0))
with autocast_variable.enable_auto_cast_variables(tf.float16):
self.evaluate(x.assign_add(small_tensor))
self.assertEqual(1.0, self.evaluate(x.value()))
self.assertEqual(1.0 + small_val, self.evaluate(x))
self.assertEqual(1.0 + np.float64(small_val), self.evaluate(x))

def test_thread_local_autocast_dtype(self):
x = get_var(1.0, tf.float32)
Expand Down
2 changes: 1 addition & 1 deletion tf_keras/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ def pad_sequences(
maxlen = np.max(lengths)

is_dtype_str = np.issubdtype(dtype, np.str_) or np.issubdtype(
dtype, np.unicode_
dtype, np.str_
)
if isinstance(value, str) and dtype != object and not is_dtype_str:
raise ValueError(
Expand Down