Skip to content

Finish EarlyStopping #1020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2023
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
2 changes: 1 addition & 1 deletion src/TensorFlowNET.Core/Keras/Layers/ILayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface ILayer: IWithTrackable, IKerasConfigable
List<IVariableV1> TrainableVariables { get; }
List<IVariableV1> TrainableWeights { get; }
List<IVariableV1> NonTrainableWeights { get; }
List<IVariableV1> Weights { get; }
List<IVariableV1> Weights { get; set}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a semicolon in the end ;

Shape OutputShape { get; }
Shape BatchInputShape { get; }
TensorShapeConfig BuildInputShape { get; }
Expand Down
6 changes: 2 additions & 4 deletions src/TensorFlowNET.Keras/Callbacks/Earlystopping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void on_epoch_end(int epoch, Dictionary<string, float> epoch_logs)
// Restore the weights after first epoch if no progress is ever made.
if (_restore_best_weights && _best_weights == null)
{
_best_weights = _parameters.Model.TrainableWeights;
_best_weights = _parameters.Model.Weights;
}
_wait += 1;

Expand All @@ -103,9 +103,7 @@ public void on_epoch_end(int epoch, Dictionary<string, float> epoch_logs)
Console.WriteLine($"Restoring model weights from the end of the best epoch: {_best_epoch + 1}");
}
}
// Because loading the weight variable into the model has not yet been implemented, so Earlystopping can't load best_weight yet.
// TODO(Wanglongzhi2001): implement it.
// _parameters.Model.load_weights(best_weights);
_parameters.Model.Weights = _best_weights;
}
}
public void on_train_end()
Expand Down