CNTK / Python:如何从training_session / CheckpointConfig加载已保存的模型

时间:2017-04-03 06:33:43

标签: python deep-learning cntk

我在CheckpointConfig中使用了training_session,它生成了2个文件(model_file(没有扩展名)和model_file.ckp)。然后,我使用load_model加载生成的文件(没有扩展名)。

现在,我如何使用此加载的模型来评估新输入?

loaded_model = load_model(model_path)
loaded_model.eval(test_x)

我在上面尝试过,但是我收到了这个错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-27-92b81f195f09> in <module>()
      1 test_x, test_y = generate_minibatch((1, 128, 128), 1)
----> 2 pred = loaded_model.eval(test_x)
      3 
      4 print(pred.shape)
      5 

/root/anaconda3/envs/cntk-py35/lib/python3.5/site-packages/cntk/cntk_py.py in <lambda>(self, name)
   1341     for _s in [IDictionarySerializable]:
   1342         __swig_getmethods__.update(getattr(_s, '__swig_getmethods__', {}))
-> 1343     __getattr__ = lambda self, name: _swig_getattr(self, Function, name)
   1344 
   1345     def _backward(self, state, rootGradientValues, backPropagatedGradientValuesForInputs):

/root/anaconda3/envs/cntk-py35/lib/python3.5/site-packages/cntk/cntk_py.py in _swig_getattr(self, class_type, name)
     81     if method:
     82         return method(self)
---> 83     raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
     84 
     85 

AttributeError: 'Function' object has no attribute 'eval'

我确认load_model.eval(test_x)使用save_model时工作正常。

0 个答案:

没有答案