如何评估使用样本SequenceClassification代码训练的CNTK模型

时间:2017-06-25 20:23:16

标签: python cntk

3 个答案:

答案 0 :(得分:1)

如果您想在Python中评估模型,请参阅页面here。如果您想在其他语言中使用您的模型,例如C ++ / C#,您可以在Model Evalaution页面找到详细信息。

谢谢,

答案 1 :(得分:1)

我按照以下方式得到了它:

import cntk as C
from cntk.ops.functions import load_model # Note this
...
...
# saved the model after epochs
for i in range(500):
    mb = reader.next_minibatch(minibatch_size, input_map=input_map)
    trainer.train_minibatch(mb)
    classifier_output.save("model.dnn") # Note this
...
...
# loading the model
model = load_model("model.dnn") # Note this

# converted sentence to numbers and given as sequence
predScores = model(C.Value.one_hot([[1,238,4,4990,7223,1357,2]], 50466)) # Note this
predClass = np.argmax(predScores)
print(predClass)

其中[[1,238,4,4990,7223,1357,2]]是词汇中单词索引的序列(基本上是发生训练的序列,50466是词汇的大小。

答案 2 :(得分:0)

不太可能在CNTK中训练模型时,不需要使用 create_reader / Minibatch 工具。主要是因为测试/生产文件通常很小。模型评估实际上非常简单:

import cntk as C
import pandas as pd
import numpy as np

model = C.load_model(path_to_where_the_model_is_saved) # load your CNTK model

ds = pd.read_csv(filename, delimiter=",") # load your data of course
                                          # we are assuming all data come 
                                          # together in a single matrix

X = ds.values[:,0:28].astype('float32') # ensures the right type for CNTK
Y = ds.values[:,28].astype('float32')   # last column is the label

X= X / 255 # perform any necessary transformation if any

pred = model(X) # evaluate your test data

pred[pred > 0.5]=1
pred[pred!=1]=0
maxa=np.mean(Y==pred)

print("Accuracy {} ".format(maxa*100.0))
相关问题