Skip to content

Commit

Permalink
Enables EvalWrapper to evaluate network without model (albeit still r…
Browse files Browse the repository at this point in the history
…equiring input)
  • Loading branch information
gaizkan committed Mar 17, 2016
1 parent d919edf commit 2487e48
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CNTK.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions Examples/Other/Simple2d/Config/AddOperatorConstant.cntk
Original file line number Diff line number Diff line change
@@ -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"
]
28 changes: 28 additions & 0 deletions Examples/Other/Simple2d/Config/AddOperatorConstantNoInput.cntk
Original file line number Diff line number Diff line change
@@ -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"
]
7 changes: 5 additions & 2 deletions Source/EvalDll/CNTKEval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -85,8 +86,10 @@ void CNTKEval<ElemType>::CreateNetwork(const std::string& networkDescription)
{
ConfigParameters config;
config.Parse(networkDescription);
auto netBuilder = make_shared<NDLBuilder<ElemType>>(config);
m_net = netBuilder->BuildNetworkFromDescription();
auto networkFactory = GetNetworkFactory<ConfigParameters, ElemType>(config);
DEVICEID_TYPE deviceId = DeviceFromConfig(config);

m_net = networkFactory(deviceId);
if (m_net == nullptr)
{
// TODO: Throw appropriate exception
Expand Down
2 changes: 2 additions & 0 deletions Source/EvalDll/EvalDll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
<ClInclude Include="CNTKEval.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\CNTK\BrainScript\BrainScriptEvaluator.cpp" />
<ClCompile Include="..\CNTK\BrainScript\BrainScriptParser.cpp" />
<ClCompile Include="..\Common\Config.cpp" />
<ClCompile Include="..\Common\Eval.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
Expand Down
9 changes: 9 additions & 0 deletions Source/EvalDll/EvalDll.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<ClCompile Include="..\Common\ExceptionWithCallStack.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\CNTK\BrainScript\BrainScriptEvaluator.cpp">
<Filter>BrainScript</Filter>
</ClCompile>
<ClCompile Include="..\CNTK\BrainScript\BrainScriptParser.cpp">
<Filter>BrainScript</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="EvalReader.h" />
Expand Down Expand Up @@ -69,5 +75,8 @@
<Filter Include="For External Use">
<UniqueIdentifier>{fa8ec6d7-8998-44f0-bddb-cb4dffc5ec0b}</UniqueIdentifier>
</Filter>
<Filter Include="BrainScript">
<UniqueIdentifier>{eff3a7b6-ad84-4438-9422-1b66077cfded}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Source/Extensibility/CSEvalClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CNTK>/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<float> outputs;
Expand All @@ -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
Expand Down

0 comments on commit 2487e48

Please sign in to comment.