Support tensors for validation_data in fit #8388
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our usecase it is convenient to read both our validation data and training data from TFRecords and so as raw tensorflow tensors. Tensors as input is supported through a combination of compile + fit calls. This merge request adds support for Tensors in validation_data
Not sure what conversation this is a part of, there are a few conversations hovering around using TFRecords (e.g. #6928 and #8287)
The first one is quite involved and this approach might well have already been suggested but here's my attempt anyway.
Basic idea is that we check to see whether the validation data is tensors in the
training.Model#fit
function. If it is, we construct a new Model instance in place and use it to:The supported use case is:
The code above has the effect of reading the validation tensors twice and outputting the correct metrics etc
While I'm here, an aside:
Upon closer inspection I noticed
validation_steps
was already specified, but the current behaviour seemed strange. It would seem if your specifyvalidation_steps
without settingvalidation_data
the inputX
andY
in the example above would be readvalidation_steps
times. I suppose one possible use case would be the careful construction of theX
andY
tensors such that they contained all training examples followed by validation examples with precise use ofsteps_per_epoch
andvalidation_steps
to make sure the right data is read at the right time. It feels like this would be tricky to pull off at best