CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

How to use on c/c++

Open seokhoonboo opened this issue 10 years ago • 5 comments

i want to use model and action commands on c/c++

is there any samples?

seokhoonboo avatar Mar 15 '16 08:03 seokhoonboo

Hi seokhoonboo,

Please take a look at the CNTKCore\EvalDLL, Extensibility\EvalWrapper, and Extensibility\CSEvalClient. The EvalDll provides some functionality for evaluating models. The EvalWrapper is consumer/wrapper of the EvalDLL (which shows how to use the EvalDLL). The CSEvalClient is a C# client using the EvalWrapper.

We don't have a full API yet for all actions.

Thanks,

Gaizka

gaizkan avatar Mar 15 '16 13:03 gaizkan

eh... i already saw that. so i tried like below

#include <Windows.h> #include "ExceptionWithCallStack.h" #include "Eval.h" #include <Basics.h> #pragma comment(lib,"EvalDll.lib") using namespace Microsoft::MSR::CNTK; int _tmain(int argc, _TCHAR* argv[]) { Eval model("C:/Users/dspl/Downloads/CNTK-master/Examples/Image/MNIST/Config/01_OneHidden.cntk"); model.LoadModel(L"C:/Users/dspl/Downloads/CNTK-master/Examples/Image/MNIST/Config/01_OneHidden.cntk");

return 0;

}

but it occurs "unresolved external symbol error LoadModel,Eval,~Eval" Do I need to override the functions?

other way, i tried below

#define CPUONLY #include <EvalDll/CNTKEval.cpp> #include <ExceptionWithCallStack.cpp>

using namespace Microsoft::MSR::CNTK;

int _tmain(int argc, _TCHAR* argv[]) {

CNTKEval<float> model;

model.Init("C:/Users/dspl/Downloads/CNTK-master/Examples/Image/MNIST/Config/01_OneHidden.cntk"); model.LoadModel(L"Models/01_OneHidden");

return 0;

} It works;;; So I use?

seokhoonboo avatar Mar 15 '16 13:03 seokhoonboo

The second method should work fine. As you can infer from the interface IEvaluateModel, you are limited to those functions. in your example:

std::map<std::wstring, std::vector> inputs; std::map<std::wstring, std::vector> outputs; { allocate inputs and output } model.Evaluate(inputs, outputs)

will evaluate inputs against the model and provide the results in the outputs

Best regards,

gaizkan avatar Mar 15 '16 14:03 gaizkan

Sorry, formatting went wrong... std::map<std::wstring, std::vector<ElemType>*> inputs; std::map<std::wstring, std::vector<ElemType>*> outputs; {allocate inputs and outputs structures} model.Evaluate(inputs, outputs) Extract values from outputs

gaizkan avatar Mar 15 '16 14:03 gaizkan

Simple sample for c++ model loading https://github.com/dmandreev/simplestcntkapp

dmandreev avatar Mar 21 '16 23:03 dmandreev