Search code examples
c#.netcntk

CNTK.GPU Managed C# Eval API: System.Runtime.InteropServices.SEHException when calling outputVal.CopyVariableValueTo


I have trained a model that labels a sequence by grabbing the label of the last word in the sequence:

Sequential([
            Embedding(emb_dim),
            cntk.ops.sequence.last(Recurrence(LSTM(hidden_dim), go_backwards=False)), 
            Dense(num_labels)
        ])

where num_labels = 8

I am using the GPU library from here https://github.com/Microsoft/CNTK/wiki/NuGet-Package to consume the model from C# (CNTK v2.0.beta8.0):

Variable outputVar = modelFunc.Outputs.Single(); 
var outputDataMap = new Dictionary<Variable, Value>();
outputDataMap.Add(outputVar, null);
modelFunc.Evaluate(inputDataMap, outputDataMap, device);
Value outputVal = outputDataMap[outputVar];

And outputVal is: Dimensions: Count = 3 Rank: 3 TotalSize: 8

while outputVar is: Dimensions: Count = 1 Rank: 1 TotalSize: 8

Is the above correct? I would expect that outputVar and outputVal would be of the same Dimensions/Rank/TotalSize. Also, how can I extract the class returned? Basically what C# type should I use for outputData? I tried the two nested lists as in the example on github but without any luck. outputVal.CopyVariableValueTo(outputVar, outputData);

Thank you


Solution

  • CopyVariableValueTo copies the data stored in the Value object into the provided buffer, either in the dense (the buffer is List>) or one-hot vector format (the buffer is List>). The one-hot vector format as output requires that each sample has only 1 non-zero value. If the output contains multiple non-zeor values, you should use the dense output. More details about API are here.

    Thanks, Zhou