Reputation: 585
This is just a C++ programming syntax question (I think). I have 192 floats in a structure like:
std::vector outputData(192);
I want to call the built-in Softmax function in the CNTKLibrary on this 192x1 vector -- the documentation in the header file is:
/// Create an instance of the CNTK built-in softmax operation on specified tensor input operand CNTK_API FunctionPtr Softmax(const Variable& operand, const std::wstring& name = L"");
How do I do that? I guess first I get the function pointer, and then I apply it, but I don't understand what the syntax would be. Something like this...
// Grab Softmax Function pointer
FunctionPtr SoftmaxFuncPtr = Softmax(outputData); // how to cast arg?
// How to evaluate this FuntionPtr?
SoftmaxFuncPtr->eval(); // WAG - I have no idea...
Where does result of computation go?
Thanks if you can give me some hints...
Upvotes: 0
Views: 211
Reputation: 556
First you need to define a Variable for the input of Softmax, something like:
auto inputVar = InputVariable(DimensionsOfInput, DataType::Float, L"InputSoftMax");
Then, you build a Composite Function using Softmax, like
FunctionPtr SoftmaxFuncPtr = Softmax(inputVar, L"SoftMax");
auto EvalFuncPtr = AsComposite(SoftmaxFuncPtr, L"EvalSoftMax");
After that , construct input and output map to prepare data for evaluation and then call Forward() or Evaluate() to execute evaluation on the input data and get output result.
The sample MultiThreadsEvaluationWithNewFunction() in EvalMultithreads.cpp showcases how to create a new function for evaluation. The page describes how to use these samples. The function there contains multiple layers and supports evaluation using multi-threads, so it might have some code which is not required for your case. And the sample is still using low-level APIs to manipulate input and output data, and we have also high-level convenient methods, like Value::CreateBatch/Sequence/BatchOfSequence(), Value::CopyVariableValueTo() to help you prepare input/output data without knowing low-level details. The CNTKLibrary.h has description of these APIS too.
Please let us know any questions you have. Thanks,
Upvotes: 1