0

我正在按照 CNTKLibrary-2.0 示例编写一个简单的案例来检查小批量版本的评估。代码如下所示。但是当我调用“评估”函数时,我得到了访问冲突异常。有关此类异常的任何见解。

const string outputName = "r1";
const string inputName = "qu1fea";
var inputDataMap = new Dictionary<Variable, Value>();

// Load the model.
Function modelFunc = Function.LoadModel("D:/deep_cross/ModelEvaluation_cpp/models/dfsr.cn", device);
Console.WriteLine(modelFunc.Outputs.Count);
for (int i = 0; i < modelFunc.Outputs.Count; i++)
{
    Console.WriteLine(modelFunc.Outputs[i].GetName());
}

// Get output variable based on name
Variable outputVar = modelFunc.Outputs.Where(variable => string.Equals(variable.Name, outputName)).Single();

// Get input variable. The model has only one single input.
// The same way described above for output variable can be used here to get input variable by name.
Console.WriteLine(modelFunc.Arguments.Count);
for (int i = 0; i < modelFunc.Arguments.Count; i++)
{
    Console.WriteLine(modelFunc.Arguments[i].GetName());
}
Variable inputVar = modelFunc.Arguments.Where(Variable => string.Equals(Variable.Name, inputName)).Single();
var outputDataMap = new Dictionary<Variable, Value>();
Value inputVal, outputVal;
List<List<float>> outputBuffer;

// Get shape data for the input variable
NDShape inputShape = inputVar.Shape;

// Create Value for the batch data.
inputVal = Value.CreateBatch(inputVar.Shape, samples, device);

// Create input data map.
inputDataMap.Add(inputVar, inputVal);

// Create ouput data map. Using null as Value to indicate using system allocated memory.
// Alternatively, create a Value object and add it to the data map.
outputDataMap.Add(outputVar, null);

// Evaluate the model against the batch input
modelFunc.Evaluate(inputDataMap, outputDataMap, device);

// Retrieve the evaluation result.
outputBuffer = new List<List<float>>();
outputVal = outputDataMap[outputVar];
outputVal.CopyVariableValueTo(outputVar, outputBuffer);

// Output result
PrintOutput(outputVar.Shape.TotalSize, outputBuffer);  
4

1 回答 1

0

该异常是由一个错误引起的,该错误现已修复。我们刚刚发布了 CNTK Nuget 包 2.0-Beta9.0。你能试一试吗?

带来不便敬请谅解。

谢谢,

于 2017-01-20T17:21:22.050 回答