CNTK
CNTK copied to clipboard
Issue saving and reading function named using Function.SetName
In the .NET API, Function
exposes a method SetName
, which, I presume, is intended to give a name to a Function
.
However, when I use it to name a model, save it, and load the model from file, the corresponding name doesn't seem to be found. As an example, in the MNISTClassifier.cs
example, if instead of creating and naming the classifierOutput:
classifierOutput = CreateMLPClassifier(device, numClasses, hiddenLayerDim, scaledInputclassifierName);
I modify the code slightly to name classifierOutput
after creating it, along these lines:
classifierOutput = CreateMLPClassifier(device, numClasses, hiddenLayerDim, scaledInput);
classifierOutput.SetName(classifierName);
... then the training phases works successfully, but validation fails here, suggesting that the name in question cannot be found in the file:
var labelOutput = model.Outputs.Single(o => o.Name == outputName);
Am I doing something wrong here, or is this a bug? I would really like to be able to separate creating and naming of functions, which would make composability of layers much cleaner. As an illustration of what I have in mind, if SetName
worked as expected, I could do something like this in F#:
let named (name:string) (f:Function) =
f.SetName name
f
createLayer (some arguments)
|> named "layer 1"
|> createLayer (some arguments)
|> named "layer 2"
import cntk as C
# Define your model layers with named variables
input_var = C.input_variable(...)
layer1 = C.layers.Dense(...)(input_var)
layer2 = C.layers.Dense(...)(layer1)
output = C.layers.Dense(..., name="output_layer")(layer2)
# You can now access the 'output' variable by name