From 2487e48d5f699da6de9d7b2608769532eb7ec2a9 Mon Sep 17 00:00:00 2001 From: Gaizka Navarro Date: Wed, 16 Mar 2016 16:36:25 +0100 Subject: [PATCH] Enables EvalWrapper to evaluate network without model (albeit still requiring input) --- CNTK.sln | 3 ++ .../Simple2d/Config/AddOperatorConstant.cntk | 28 +++++++++++++++++++ .../Config/AddOperatorConstantNoInput.cntk | 28 +++++++++++++++++++ Source/EvalDll/CNTKEval.cpp | 7 +++-- Source/EvalDll/EvalDll.vcxproj | 2 ++ Source/EvalDll/EvalDll.vcxproj.filters | 9 ++++++ Source/Extensibility/CSEvalClient/Program.cs | 4 +-- 7 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 Examples/Other/Simple2d/Config/AddOperatorConstant.cntk create mode 100644 Examples/Other/Simple2d/Config/AddOperatorConstantNoInput.cntk diff --git a/CNTK.sln b/CNTK.sln index a6e97b73ad13..81ddcd8dabd2 100644 --- a/CNTK.sln +++ b/CNTK.sln @@ -544,11 +544,14 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NdlExamples", "NdlExamples", "{FC573A62-6DAE-40A4-8153-520C8571A007}" ProjectSection(SolutionItems) = preProject Examples\Other\NdlExamples\AddOperator.ndl = Examples\Other\NdlExamples\AddOperator.ndl + Examples\Other\NdlExamples\AddOperatorConstant.ndl = Examples\Other\NdlExamples\AddOperatorConstant.ndl Examples\Other\NdlExamples\NDLExamples.ndl = Examples\Other\NdlExamples\NDLExamples.ndl EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{1E37CE40-556D-4693-B58C-F8D4CE349BB7}" ProjectSection(SolutionItems) = preProject + Examples\Other\Simple2d\Config\AddOperatorConstant.cntk = Examples\Other\Simple2d\Config\AddOperatorConstant.cntk + Examples\Other\Simple2d\Config\AddOperatorConstantNoInput.cntk = Examples\Other\Simple2d\Config\AddOperatorConstantNoInput.cntk Examples\Other\Simple2d\Config\Multigpu.cntk = Examples\Other\Simple2d\Config\Multigpu.cntk Examples\Other\Simple2d\Config\Simple.cntk = Examples\Other\Simple2d\Config\Simple.cntk EndProjectSection diff --git a/Examples/Other/Simple2d/Config/AddOperatorConstant.cntk b/Examples/Other/Simple2d/Config/AddOperatorConstant.cntk new file mode 100644 index 000000000000..729d683498cd --- /dev/null +++ b/Examples/Other/Simple2d/Config/AddOperatorConstant.cntk @@ -0,0 +1,28 @@ +# deviceId=-1 for CPU, >=0 for GPU devices, "auto" chooses the best GPU, or CPU if no usable GPU is available +deviceId = 0 + +command = Add_Operator_Constant + +precision = "float" +traceLevel = 1 +outputNodeNames = AddResult + +####################################### +# NETWORK CONFIG # +####################################### + +# Notation xxx:yyy*n:zzz is equivalent to xxx, then yyy repeated n times, then zzz +# Example: 10:20*3:5 is equivalent to 10:20:20:20:5 +run=NDLNetworkBuilder +NDLNetworkBuilder=[ + features = Input(1) + v2 = Constant(1) + ol = Plus(features, v2) + + FeatureNodes=(features) + OutputNodes=(ol) + ] + +Add_Operator_Constant = [ + action = "write" +] \ No newline at end of file diff --git a/Examples/Other/Simple2d/Config/AddOperatorConstantNoInput.cntk b/Examples/Other/Simple2d/Config/AddOperatorConstantNoInput.cntk new file mode 100644 index 000000000000..2d3abeb4c813 --- /dev/null +++ b/Examples/Other/Simple2d/Config/AddOperatorConstantNoInput.cntk @@ -0,0 +1,28 @@ +# deviceId=-1 for CPU, >=0 for GPU devices, "auto" chooses the best GPU, or CPU if no usable GPU is available +deviceId = -1 + +command = Add_Operator_Constant + +precision = "float" +traceLevel = 1 +outputNodeNames = AddResult + +####################################### +# NETWORK CONFIG # +####################################### + +# Notation xxx:yyy*n:zzz is equivalent to xxx, then yyy repeated n times, then zzz +# Example: 10:20*3:5 is equivalent to 10:20:20:20:5 +run=NDLNetworkBuilder +NDLNetworkBuilder=[ + v1 = Constant(1) + v2 = Constant(2) + ol = Plus(v1, v2) + + FeatureNodes=(v1) + OutputNodes=(ol) + ] + +Add_Operator_Constant = [ + action = "write" +] \ No newline at end of file diff --git a/Source/EvalDll/CNTKEval.cpp b/Source/EvalDll/CNTKEval.cpp index d976fb11c53c..845fc218cb5d 100644 --- a/Source/EvalDll/CNTKEval.cpp +++ b/Source/EvalDll/CNTKEval.cpp @@ -8,6 +8,7 @@ #include "stdafx.h" #define EVAL_EXPORTS // creating the exports here #include "Eval.h" +#include "Actions.h" #include "CNTKEval.h" #include "CPUMatrix.h" // for SetNumThreads() #include "SimpleOutputWriter.h" @@ -85,8 +86,10 @@ void CNTKEval::CreateNetwork(const std::string& networkDescription) { ConfigParameters config; config.Parse(networkDescription); - auto netBuilder = make_shared>(config); - m_net = netBuilder->BuildNetworkFromDescription(); + auto networkFactory = GetNetworkFactory(config); + DEVICEID_TYPE deviceId = DeviceFromConfig(config); + + m_net = networkFactory(deviceId); if (m_net == nullptr) { // TODO: Throw appropriate exception diff --git a/Source/EvalDll/EvalDll.vcxproj b/Source/EvalDll/EvalDll.vcxproj index 63b64bbd149e..d178f4387ba4 100644 --- a/Source/EvalDll/EvalDll.vcxproj +++ b/Source/EvalDll/EvalDll.vcxproj @@ -140,6 +140,8 @@ + + true diff --git a/Source/EvalDll/EvalDll.vcxproj.filters b/Source/EvalDll/EvalDll.vcxproj.filters index d4443aba6c31..94297da72c19 100644 --- a/Source/EvalDll/EvalDll.vcxproj.filters +++ b/Source/EvalDll/EvalDll.vcxproj.filters @@ -26,6 +26,12 @@ Common + + BrainScript + + + BrainScript + @@ -69,5 +75,8 @@ {fa8ec6d7-8998-44f0-bddb-cb4dffc5ec0b} + + {eff3a7b6-ad84-4438-9422-1b66077cfded} + \ No newline at end of file diff --git a/Source/Extensibility/CSEvalClient/Program.cs b/Source/Extensibility/CSEvalClient/Program.cs index f84f0a2b1b81..c1c6063371da 100644 --- a/Source/Extensibility/CSEvalClient/Program.cs +++ b/Source/Extensibility/CSEvalClient/Program.cs @@ -147,7 +147,7 @@ private static void EvaluateNetworkSingleLayer() { // The examples assume the executable is running from the data folder // We switch the current directory to the data folder (assuming the executable is in the /x64/Debug|Release folder - string workingDirectory = Path.Combine(initialDirectory, @"..\..\Examples\Other\NDlExamples"); + string workingDirectory = Path.Combine(initialDirectory, @"..\..\Examples\Other\Simple2d\Config"); Environment.CurrentDirectory = initialDirectory; List outputs; @@ -158,7 +158,7 @@ private static void EvaluateNetworkSingleLayer() model.Init("deviceId=0"); // Create the network - string networkDescription = GetFileContents(Path.Combine(workingDirectory, @"AddOperator.ndl")); + string networkDescription = GetFileContents(Path.Combine(workingDirectory, @"AddOperatorConstant.cntk")); model.CreateNetwork(networkDescription); // Generate random input values in the appropriate structure and size