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)
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))
如果要用Python计算模型,请参见here。如果你想用其他语言,比如C++ +C,你可以在Model Evalaution页面中找到细节。在
谢谢
我是通过以下方式得到的:
其中
[[1,238,4,4990,7223,1357,2]]
是词汇索引的序列(基本上是训练所依据的序列,50466
是词汇的大小。在不太可能,当你在CNTK中训练你的模型时,你不需要使用create_reader/Minibatch工具。主要是因为测试/生产文件通常非常小。模型评估实际上非常简单:
相关问题 更多 >
编程相关推荐