Nathan Nau
Nathan Nau

Reputation: 83

model.fit with dictionary in tensorflow.net

How use model.fit with dictionary (string, tensor) for input named in tensorflow.net

The two implement function is : public void fit(NDArray x, NDArray y, int batch_size = -1, int epochs = 1, int verbose = 1, float validation_split = 0f, bool shuffle = true, int initial_epoch = 0, int max_queue_size = 10, int workers = 1, bool use_multiprocessing = false) and public void fit(IDatasetV2 dataset, IDatasetV2 validation_data = null, int batch_size = -1, int epochs = 1, int verbose = 1, float validation_split = 0f, bool shuffle = true, int initial_epoch = 0, int max_queue_size = 10, int workers = 1, bool use_multiprocessing = false)

Maybe IDatasetV2 support Dictionary but I don't know how...

Thank you

Upvotes: 0

Views: 593

Answers (1)

LOST
LOST

Reputation: 3249

I don't think this functionality is available in TensorFlow.NET.

You can do it using LostTech.TensorFlow (proprietary) like this:

var inputA = tf.keras.Input(name: "A", shape: 1);
var inputB = tf.keras.Input(name: "B", shape: 1);

var inputs = tf.concat(new[] { inputA, inputB }, axis: 1);

var output = new Dense(1).__call__(inputs);

var model = new Model(kwargs: new {
    inputs = new[] { inputA, inputB },
    outputs = output,
}.AsKwArgs());

model.compile(
    optimizer: new AdamOptimizer(),
    loss: "mse");

model.fit(
    x: new Dictionary<string, ndarray> {
        ["A"] = new float[] { 1 }.ToNumPyArray(),
        ["B"] = new float[] { 2 }.ToNumPyArray(),
    }.ToPyDict(),
    y: new float[] { 3 }.ToNumPyArray(),
    epochs: 10
);

Disclaimer: I am the main LostTech.TensorFlow developer.

Upvotes: -1

Related Questions