CNTKLibrary-2.0" System.AccessViolationException:尝试读取或写入受保护的内存。 "

时间:2017-01-18 18:55:06

标签: c# cntk

我正在按照CNTKLibrary-2.0示例编写一个简单的案例来检查评估的minibatch版本。代码看起来像以下方式。但是当我打电话给"评估"时,我收到了访问冲突异常。功能。关于此类例外的任何见解。

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);  

1 个答案:

答案 0 :(得分:0)

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

很抱歉给您带来不便。

谢谢,

相关问题