我正在按照 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);