From 0433b3757de0e4ae41737f2adad771aefc2f659e Mon Sep 17 00:00:00 2001 From: wangdapao666 <583087864@qq.com> Date: Sun, 19 Mar 2023 14:47:34 +0800 Subject: [PATCH] Add an Stop_training attribute --- src/TensorFlowNET.Core/Keras/Engine/IModel.cs | 2 +- src/TensorFlowNET.Keras/Callbacks/Earlystopping.cs | 2 +- src/TensorFlowNET.Keras/Engine/Model.cs | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/TensorFlowNET.Core/Keras/Engine/IModel.cs b/src/TensorFlowNET.Core/Keras/Engine/IModel.cs index 3928ef5f..6b2eb186 100644 --- a/src/TensorFlowNET.Core/Keras/Engine/IModel.cs +++ b/src/TensorFlowNET.Core/Keras/Engine/IModel.cs @@ -79,5 +79,5 @@ public interface IModel : ILayer IKerasConfig get_config(); - void set_stopTraining_true(); + bool Stop_training { get;set; } } diff --git a/src/TensorFlowNET.Keras/Callbacks/Earlystopping.cs b/src/TensorFlowNET.Keras/Callbacks/Earlystopping.cs index 1e0418dc..13db771d 100644 --- a/src/TensorFlowNET.Keras/Callbacks/Earlystopping.cs +++ b/src/TensorFlowNET.Keras/Callbacks/Earlystopping.cs @@ -95,7 +95,7 @@ public class EarlyStopping: ICallback if (_wait >= _paitence && epoch > 0) { _stopped_epoch = epoch; - _parameters.Model.set_stopTraining_true(); + _parameters.Model.Stop_training = true; if (_restore_best_weights && _best_weights != null) { if (_verbose > 0) diff --git a/src/TensorFlowNET.Keras/Engine/Model.cs b/src/TensorFlowNET.Keras/Engine/Model.cs index c1d29f59..7d4640af 100644 --- a/src/TensorFlowNET.Keras/Engine/Model.cs +++ b/src/TensorFlowNET.Keras/Engine/Model.cs @@ -39,6 +39,12 @@ namespace Tensorflow.Keras.Engine set => optimizer = value; } + public bool Stop_training + { + get => stop_training; + set => stop_training = value; + } + public Model(ModelArgs args) : base(args) { @@ -145,10 +151,5 @@ namespace Tensorflow.Keras.Engine return children; } - - void IModel.set_stopTraining_true() - { - stop_training = true; - } } }