CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

The problems of function 'load()'

Open Maokui-He opened this issue 9 years ago • 3 comments

I saved a model z defined as follow with file name 'z.model' , then I want to load the model I trained for test. There are some problems. The model I defined: def create_model(features): with C.layers.default_options(init = C.glorot_uniform()): r = C.layers.Dense(num_output_classes, activation = None)(features) return r z = create_model(input/255.0) ... z.save("z.model") #after training

load the madel: #actually I don't know how to load the model from cntk.ops.functions import Function z = Function.load("z.model") #then create a trainer using same parameters with before

Here comes problems: Selected GPU[0] Tesla K20m as the process wide default device. Traceback (most recent call last): File "test.py", line 70, in eval_error = trainer.test_minibatch(data) File "/usr/local/lib/python2.7/dist-packages/cntk/train/trainer.py", line 223, in test_minibatch return super(Trainer, self).test_minibatch(arguments, device) File "/usr/local/lib/python2.7/dist-packages/cntk/cntk_py.py", line 2770, in test_minibatch return _cntk_py.Evaluator_test_minibatch(self, *args) ValueError: Values for 1 required arguments 'Input('Input3', [#], [784])', that the requested output(s) 'Output('aggregateEvalMetric', [], []), Output('Block45_Output_0', [#], [1])' depend on, have not been provided.

I just want know the way I loading the model is correct?

Maokui-He avatar Oct 04 '17 14:10 Maokui-He

Actually, this code comes from https://cntk.ai/pythondocs/CNTK_103B_MNIST_LogisticRegression.html to practice saving and loading models, I add the code after training model(before evaluation) as follows: z.save("z.model") z = Function.load("z.model") loss = C.cross_entropy_with_softmax(z, label) label_error = C.classification_error(z, label) learning_rate = 0.2 lr_schedule = C.learning_rate_schedule(learning_rate, C.UnitType.minibatch) learner = C.sgd(z.parameters, lr_schedule) trainer = C.Trainer(z, (loss, label_error), [learner])

Maokui-He avatar Oct 04 '17 14:10 Maokui-He

This might be a model compatibility issue. Did you train your model with an older version of CNTK?

cha-zhang avatar Oct 13 '17 01:10 cha-zhang

given this issue hasn't been updated for a long period. I am closing this issue. Please open a new issue if your questions hasn't been answered.

sayanpa avatar Nov 07 '17 02:11 sayanpa