#8488·tfjs

`restoreBestWeights` support request.

Author: PLtierCreated Jan 8, 2025Updated Jun 30, 2026
Labelstype:featurestat:contributions welcome

System information

  • TensorFlow.js version (you are using): 4.22.0
  • Are you willing to contribute it (Yes/No): Yes, I almost sent the PR before I read you would issue first (though there is a TODO)

Describe the feature and the current behavior/state.

I’d like to implement earlyStopping's restoreBestWeights parameter equivalent to python TF version. It’s been denoted in code, but it’s been unsupported.

Will this change the current api? How?

It will almost no change it. There is already restoreBestWeights parameter denoted in code and documentation, it’s just unsupported.

Who will benefit with this feature?

Anyone who wants to prevent resource waste and overfitting. Although there has been no Github issue, there was a TODO in code so there must have been a will for future implementation. I personally wanted to implement it for my browser extension which uses tfjs so that it uses less resources when training.

Any Other info.

You can see my proposed change code here: diff PLtier/tfjs at restore-best-weights. In tfjs-layers it passes almost every test - per 107 I had a few timeouts on my 2019 Mac. I'd like very much to contribute.