CNTK python API:如何从经过训练的模型中获取预测? [英] CNTK python API: How to get predictions from the trained model?

查看:172
本文介绍了CNTK python API:如何从经过训练的模型中获取预测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个训练有素的模型,正在使用 CNTK.load_model()函数加载。我正在看CNTK git repo上的 MNIST教程作为模型评估代码的参考。我创建了一个数据读取器(这是一个 MinibatchSource 对象),并尝试运行 model.eval(mb),其中 mb = minibatch_source.next_minibatch(...)(类似于此答案

I have a trained model which I am loading using CNTK.load_model() function. I was looking at the MNIST Tutorial on the CNTK git repo as reference for model evaluation code. I have created a data reader (which is a MinibatchSource object) and trying to run model.eval(mb) where mb = minibatch_source.next_minibatch(...) (Similar to this answer)

但是,我收到以下错误消息

But, I'm getting the following error message

Traceback (most recent call last):
    File "LID_test.py", line 162, in <module>
        test_and_evaluate()
    File "LID_test.py", line 159, in test_and_evaluate
        predictions = model.eval(mb)
    File "/home/t-asbahe/anaconda3/envs/cntk-py35/lib/python3.5/site-packages/cntk/ops/functions.py", line 228, in eval
        _, output_map = self.forward(arguments, self.outputs, device=device, as_numpy=as_numpy)
    File "/home/t-asbahe/anaconda3/envs/cntk-py35/lib/python3.5/site-packages/cntk/utils/swig_helper.py", line 62, in wrapper
        result = f(*args, **kwds)
    File "/home/t-asbahe/anaconda3/envs/cntk-py35/lib/python3.5/site-packages/cntk/ops/functions.py", line 354, in forward
        None, device)
    File "/home/t-asbahe/anaconda3/envs/cntk-py35/lib/python3.5/site-packages/cntk/utils/__init__.py", line 393, in sanitize_var_map
        if len(arguments) < len(op_arguments):
TypeError: object of type 'Variable' has no len()

我的模型中没有名为'Variable' input_variable ,并且我看不到出现此错误的任何原因。

I have no input_variable named 'Variable' in my model and I don't see any reason to get this error.

PS:我的输入是稀疏输入(一次性)

P.S.: My inputs are sparse inputs (one-hots)

推荐答案

您有一些选择:


  • 将一组数据作为numpy数组传递(在CNTK 202教程中的实例),其中

  • Pass a set of data as numpy array (instance in CNTK 202 tutorial) where onehot data is passed in as a numpy array.

pred = model.eval({model.arguments [0]:[onehot]})

pred = model.eval({model.arguments[0]:[onehot]})

读取小批量数据并将其传递给eval函数

Read the minibatch data and pass it to the eval function

eval_input_map = {输入:reader_eval.streams.features} < br>
eval_data = reader_eval.next_minibatch(eval_minibatch_size,
input_map = eval_input_map)
mydata = eval_data [input] .value
预测= model.eval(mydata)

eval_input_map = { input : reader_eval.streams.features }
eval_data = reader_eval.next_minibatch(eval_minibatch_size, input_map = eval_input_map) mydata = eval_data[input].value predicted= model.eval(mydata)

这篇关于CNTK python API:如何从经过训练的模型中获取预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆