(C#) The type of 1st parameter "arguments" of the function Trainer.TestMinibatch()
I'm copying the python example CNTK 105 to a C# version. The example implements a simple autoencoder.
When it comes to the Error Testing part, I use the trainter.TestMinibatch function.
# We are loading test data in batches specified by test_minibatch_size
# Each data point in the minibatch is a MNIST digit image of 784 dimensions
# with one pixel per dimension that we will encode / decode with the
# trained model.
data = reader_test.next_minibatch(test_minibatch_size,
input_map = test_input_map)
# Specify the mapping of input variables in the model to actual
# minibatch data to be tested with
eval_error = trainer.test_minibatch(data)
In the above Python version, The type of 1st parameter seems to be the same as the return type of the function MinibatchSource.GetNextMinibatch(). But in the C# version, when I do it in the same way, I get an ERROR, which saying "Cannot convert the type from UnorderedMapStreamInfomationMinibatchData to UnorderedMapVariableMinibatchData".
Then, how can I get or build a UnorderedMapVariableMinibatchData object? Or is there a different way from the python version in using the Trainer class?
@sconan32 thanks for trying CNTK C#. We still need to work on high level C# API to ensure that it matches python API. Before that, an easier way will be to try out C# examples first.
for example, this usage: trainer.TrainMinibatch(new Dictionary<Variable, MinibatchData>() { { imageInput, minibatchData[imageStreamInfo] }, { labelsVar, minibatchData[labelStreamInfo] } }, device);
@liqunfu Thank you for the reply.
I tried the above sample after I had read the C# examples.
Yes. The TrainMinibatch() method can work with a dictionary perfectly. But all of the TestMinibatch() method's overloads don't receive a dictionary as the parameter.
Here are all the TestMinibatch() declaration:
public double TestMinibatch(UnorderedMapVariableMinibatchData arguments); public double TestMinibatch(UnorderedMapVariableValuePtr arguments, DeviceDescriptor computeDevice, bool distributed); public double TestMinibatch(UnorderedMapVariableValuePtr arguments, DeviceDescriptor computeDevice); public double TestMinibatch(UnorderedMapVariableValuePtr arguments); public double TestMinibatch(UnorderedMapVariableMinibatchData arguments, UnorderedMapVariableValuePtr outputsToFetch, DeviceDescriptor computeDevice); public double TestMinibatch(UnorderedMapVariableMinibatchData arguments, UnorderedMapVariableValuePtr outputsToFetch); public double TestMinibatch(UnorderedMapVariableValuePtr arguments, UnorderedMapVariableValuePtr outputsToFetch, DeviceDescriptor computeDevice, bool distributed); public double TestMinibatch(UnorderedMapVariableValuePtr arguments, UnorderedMapVariableValuePtr outputsToFetch, DeviceDescriptor computeDevice); public double TestMinibatch(UnorderedMapVariableValuePtr arguments, UnorderedMapVariableValuePtr outputsToFetch); public double TestMinibatch(UnorderedMapVariableMinibatchData arguments, DeviceDescriptor computeDevice, bool distributed); public double TestMinibatch(UnorderedMapVariableMinibatchData arguments, DeviceDescriptor computeDevice); public double TestMinibatch(UnorderedMapVariableMinibatchData arguments, UnorderedMapVariableValuePtr outputsToFetch, DeviceDescriptor computeDevice, bool distributed);`
Is there a workaround in calling the TestMinibatch method?
I do it like this ,and it works well for me :
void UnorderedMapVariableMinibatchData AsUnorderedMapVariableMinibatchData(IDictionary<Variable, MinibatchData> input) { UnorderedMapVariableMinibatchData data = new UnorderedMapVariableMinibatchData(); foreach (var kv in input) { data.Add(kv.Key, kv.Value); } return data; }
trainer.TestMinibatch(AsUnorderedMapVariableMinibatchData(inputDataMap), device);
It's possible to do this by manually adding the entries, but in the latest version (mid 2021), there's still the argument disparity.
It would be great if IDictionary was accepted.