SciSharp / TensorFlow.NET

.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
https://scisharp.github.io/tensorflow-net-docs
Apache License 2.0
3.23k stars 517 forks source link

[BUG Report]: v0.150.0 breaks multi-input models fit #1211

Closed Utanapishtim31 closed 11 months ago

Utanapishtim31 commented 11 months ago

Description

Before TensorFlow.NET v0.150.0 in order to train a multi-input model, I used the method Model.fit(IEnumerable x, NDArray y, ...) with validation_data as a tuple (IEnumerable, NDArray). The enumeration IEnumerable of validation_data contains the several inputs of the model.

With v0.150.0, the tuple is implicitly cast to a ValidationDataPack but this cast keeps only the first NDArray of the validation_data.Item1 enumeration:

public ValidationDataPack((IEnumerable<NDArray>, NDArray) validation_data)
{
    this.val_x = validation_data.Item1.ToArray()[0]; <-- incompatible with multi-input!
    this.val_y = validation_data.Item2;
}

The call to Model.evaluate() in Model.FitInternal() then obviously fails since the validation data format does not match the model inputs anymore.

Reproduction Steps

The problem is obvious.

Known Workarounds

Maybe use the method Model.fit(IDatasetV2 dataset, ..., IDatasetV2 validation_data), but how do I create an IDatasetV2 from a tuple (IEnumerable, NDArray) ?

Configuration and Other Information

TensorFlow.NET 0.150.0 TensorFlow.Keras 0.15.0 Windows 11

Wanglongzhi2001 commented 11 months ago

I'm so sorry for this bug, really thank you for this issue. You can use the use v0.110.4 for now, and I will fix it as soon as possible.