Closed GaijinOtohp closed 1 year ago
Hello, very thanks for your suggestion. In TensorFlow.NET, it uses a single bool expression to represent self.monitor_op
rather than np.greater
and np.less
that used in tensorflow. And it seems like the reason trigers this bug is that there lacks of parts corresponding to the following code in tensorflow:
if self.monitor_op == np.greater:
self.min_delta *= 1
else:
self.min_delta *= -1
I will fix it, and you can refer to the implemention in tensorflow: https://github.com/tensorflow/tensorflow/blob/879a5e37eb350f556debec3cd5c9b6dcb8809318/tensorflow/python/keras/callbacks.py#L1702
Hello, I have commit a PR to solve this problem. #1180 If there still exist some problem, please tell me. ^_^
Can this issue be closed?
Yes. The bug is fixed. It can be closed.
Description
loss
value is not improved by at least_min_delta
.loss
reaches_base_line
which should infer to the optimal value (the threshold to the desired loss value).Reproduction Steps
Known Workarounds
Suggested fix to the bug
Tensorflow.Keras.Callbacks.EarlyStopping.cs
:bool less_op = (monitor_value - _min_delta) < reference_value;
--->
bool less_op = (monitor_value + _min_delta) < reference_value;
Why:
since
_min_delta
is always positive, andmonitor_value
is a slight improvement ofreference_value
, then(monitor_value - _min_delta) < reference_value
will always be true. Therefore, it keeps resetting_wait
to 0.The suggestion to earlystopping using _baseline
Tensorflow.Keras.Callbacks.EarlyStopping.cs
:if (_baseline == 0f || _is_improvement(current, _baseline))
--->
if (_baseline == 0f || _is_improvement(_baseline, current))
Why:
We should check if the current improved
loss
is less than_baseline
. If yes then do not reset_wait
to 0.Configuration and Other Information
No response