I am using CNTK.GPU v2.2.0 and saved a model using the following method:
model.Save(modelFilePath);
Now I want to load it again and e.g. continue training or just evaluate samples. I can see two ways how this could be possible. One way works, but is impracticable. The second one does not work.
I build the whole structure of my neural network from scratch again and then I call the following method on it:
model.Restore(modelFilePath);
Indeed, this works.
I create my model using the following static method:
Function.Load(modelFilePath, DeviceDescriptor.GPUDevice(0));
This does not work.
After these actions I just create a trainer for the model, create a minibatchSource and try to train the model the same way I did before I saved the model.
But with the second strategy I get the following exception:
System.ArgumentOutOfRangeException: 'Values for 1 required arguments 'Input('features', [28 x 28 x 1], [, #])', that the requested output(s) 'Output('aggregateLoss', [], []), Output('lossFunction', [1], [, #]), Output('aggregateEvalMetric', [], [])' depend on, have not been provided.
[CALL STACK]
> CNTK::Internal:: UseSparseGradientAggregationInDataParallelSGD
- CNTK::Function:: Forward
- CNTK:: CreateTrainer
- CNTK::Trainer:: TotalNumberOfSamplesSeen
- CNTK::Trainer:: TrainMinibatch (x2)
- CSharp_CNTK_Trainer_TrainMinibatch__SWIG_0
- 00007FFA34AE8967 (SymFromAddr() error: The specified module could not be found.)
It says that the input features have not been provided. I am using the input when training and when creating the model by scratch:
var input = CNTKLib.InputVariable(_imageDimension, DataType.Float, _featureName);
var scaledInput = CNTKLib.ElementTimes(Constant.Scalar<float>(0.002953125f, _device), input);
...
So I thought I would have to replace the input of the loaded model with the one I create for training, and use when I create the model by scratch - although the input is not different. But I stuck at trying this because I could not retrieve the input of the model object, which I would need for replacement (I think).
model.FindByName(inputLayerName);
just returns null, although I clearly can see that the name matches with the layer name in the model's "Inputs" List in the debugger.
In consequence I do not know how to properly load a saved model. I hope someone can help me.