Remove LoadModel from eval and force use of CreateNetwork instead.
Update description in CSEvalClient to clarify the purpose of the program
This commit is contained in:
Родитель
2d462d3d1b
Коммит
ead48bef6d
|
@ -1,5 +1,5 @@
|
|||
# deviceId=-1 for CPU, >=0 for GPU devices, "auto" chooses the best GPU, or CPU if no usable GPU is available
|
||||
deviceId = 0
|
||||
deviceId = -1
|
||||
|
||||
command = Add_Operator_Constant
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# deviceId=-1 for CPU, >=0 for GPU devices, "auto" chooses the best GPU, or CPU if no usable GPU is available
|
||||
deviceId = 0
|
||||
deviceId = -1
|
||||
|
||||
command = Add_Operator_Constant
|
||||
|
||||
|
|
|
@ -95,13 +95,6 @@ Eval<ElemType>::~Eval()
|
|||
}
|
||||
}
|
||||
|
||||
// LoadModel - load a model from the specified path
|
||||
// modelFileName - file holding the model to load
|
||||
template <class ElemType>
|
||||
void Eval<ElemType>::LoadModel(const std::wstring& modelFileName)
|
||||
{
|
||||
m_eval->LoadModel(modelFileName);
|
||||
}
|
||||
|
||||
// CreateNetwork - create the network from the specified description
|
||||
// networkDescription - network description
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
virtual void Init(const std::string& config) = 0;
|
||||
virtual void Destroy() = 0;
|
||||
|
||||
virtual void LoadModel(const std::wstring& modelFileName) = 0;
|
||||
virtual void CreateNetwork(const std::string& networkDescription) = 0;
|
||||
virtual void GetNodeDimensions(std::map<std::wstring, size_t>& dimensions, NodeGroup nodeGroup) = 0;
|
||||
virtual void StartEvaluateMinibatchLoop(const std::wstring& outputNodeName) = 0;
|
||||
|
@ -84,10 +83,6 @@ public:
|
|||
Eval(const std::string& config);
|
||||
virtual ~Eval();
|
||||
|
||||
// LoadModel - load a model from the specified path
|
||||
// modelFileName - file holding the model to load
|
||||
virtual void LoadModel(const std::wstring& modelFileName);
|
||||
|
||||
// CreateNetwork - create a network based on the network description
|
||||
// networkDescription - network description
|
||||
virtual void CreateNetwork(const std::string& networkDescription);
|
||||
|
|
|
@ -46,11 +46,6 @@ void CNTKEval<ElemType>::Init(const std::string& config)
|
|||
{
|
||||
m_start = 0;
|
||||
m_config.Parse(config);
|
||||
if (m_config.Exists("modelPath"))
|
||||
{
|
||||
std::wstring path = m_config("modelPath");
|
||||
LoadModel(path);
|
||||
}
|
||||
size_t nThreads = m_config("numCPUThreads", "1");
|
||||
CPUMatrix<ElemType>::SetNumThreads(nThreads);
|
||||
|
||||
|
@ -69,16 +64,6 @@ void CNTKEval<ElemType>::Destroy()
|
|||
delete this;
|
||||
}
|
||||
|
||||
// LoadModel - load a model from the specified path
|
||||
// modelFileName - file holding the model to load
|
||||
template <class ElemType>
|
||||
void CNTKEval<ElemType>::LoadModel(const std::wstring& modelFileName)
|
||||
{
|
||||
DEVICEID_TYPE deviceId = DeviceFromConfig(m_config);
|
||||
fprintf(stderr, "DeviceID=%d\n", (int) deviceId);
|
||||
m_net = ComputationNetwork::CreateFromFile<ElemType>(deviceId, modelFileName);
|
||||
}
|
||||
|
||||
// CreateNetwork - create a network based on the network description
|
||||
// networkDescription - network description
|
||||
template <class ElemType>
|
||||
|
@ -86,13 +71,13 @@ void CNTKEval<ElemType>::CreateNetwork(const std::string& networkDescription)
|
|||
{
|
||||
ConfigParameters config;
|
||||
config.Parse(networkDescription);
|
||||
auto networkFactory = GetNetworkFactory<ConfigParameters, ElemType>(config);
|
||||
DEVICEID_TYPE deviceId = DeviceFromConfig(config);
|
||||
|
||||
m_net = networkFactory(deviceId);
|
||||
std::vector<wstring> outputNodeNames;
|
||||
m_net = GetModelFromConfig<ConfigParameters, ElemType>(config, outputNodeNames);
|
||||
|
||||
if (m_net == nullptr)
|
||||
{
|
||||
// TODO: Throw appropriate exception
|
||||
LogicError("Unable to construct network from description");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,6 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
// LoadModel - load a model from the specified path
|
||||
// modelFileName - file holding the model to load
|
||||
virtual void LoadModel(const std::wstring& modelFileName);
|
||||
|
||||
// CreateNetwork - create a network based on the network description
|
||||
// networkDescription - network description
|
||||
virtual void CreateNetwork(const std::string& networkDescription);
|
||||
|
|
|
@ -14,19 +14,19 @@ using System.Net.Configuration;
|
|||
namespace Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Program for running model evaluations using the CLIWrapper
|
||||
/// Program for demonstrating how to run model evaluations using the CLIWrapper
|
||||
/// </summary>
|
||||
/// <description>
|
||||
/// This program is a managed client using the CLIWrapper to run the model evaluator in CTNK.
|
||||
/// It uses one of the examples provided in CNTK for evaluating the model associated with the example.
|
||||
/// There are four cases shown in this program related to model loading/network creation and evaluation.
|
||||
/// The first two use the trained model from one of the examples provided in the CNTK source code.
|
||||
/// In order to run this program the model must already exist in the example. To create the model,
|
||||
/// first run the example in <CNTK>/Examples/Image/MNIST. Once the model file 01_OneHidden is created,
|
||||
/// you can run this client.
|
||||
/// This example also shows evaluating a network without first training the model. This is accomplished
|
||||
/// by creating the network and evaluating a single forward pass.
|
||||
/// This client also shows two methods for obtaining the output results from the evaluation, the first as
|
||||
/// return values from the Evaluate method call (which only returns a single layer output), and the second
|
||||
/// by passing the allocated output layers to the evaluate method.
|
||||
/// The last two cases show how to evaluate a network without first training the model. This is accomplished
|
||||
/// by building the network and evaluating a single forward pass.
|
||||
/// This program also shows how to obtaining the output results from the evaluation, either as the default output layer,
|
||||
/// or by specifying one or more layers as outputs.
|
||||
/// </description>
|
||||
class Program
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ namespace Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient
|
|||
|
||||
// Load model
|
||||
string modelFilePath = Path.Combine(Environment.CurrentDirectory, @"..\Output\Models\01_OneHidden");
|
||||
model.LoadModel(modelFilePath);
|
||||
model.CreateNetwork(string.Format("deviceId=-1\nmodelPath=\"{0}\"", modelFilePath));
|
||||
|
||||
// Generate random input values in the appropriate structure and size
|
||||
var inputs = GetDictionary("features", 28*28, 255);
|
||||
|
@ -118,7 +118,7 @@ namespace Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient
|
|||
|
||||
// Load model
|
||||
string modelFilePath = Path.Combine(Environment.CurrentDirectory, @"..\Output\Models\01_OneHidden");
|
||||
model.LoadModel(modelFilePath);
|
||||
model.CreateNetwork(string.Format("deviceId=-1\nmodelPath=\"{0}\"", modelFilePath));
|
||||
|
||||
// Generate random input values in the appropriate structure and size
|
||||
var inputs = GetDictionary("features", 28*28, 255);
|
||||
|
@ -158,7 +158,7 @@ namespace Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient
|
|||
using (var model = new IEvaluateModelManagedF())
|
||||
{
|
||||
// Initialize model evaluator
|
||||
model.Init("deviceId=0");
|
||||
model.Init("deviceId=-1");
|
||||
|
||||
// Create the network
|
||||
string networkDescription = GetFileContents(Path.Combine(workingDirectory, @"AddOperatorConstant.cntk"));
|
||||
|
@ -200,7 +200,7 @@ namespace Microsoft.MSR.CNTK.Extensibility.Managed.CSEvalClient
|
|||
using (var model = new IEvaluateModelManagedF())
|
||||
{
|
||||
// Initialize model evaluator
|
||||
model.Init("deviceId=0");
|
||||
model.Init("deviceId=-1");
|
||||
|
||||
// Create the network
|
||||
string networkDescription = GetFileContents(Path.Combine(workingDirectory, @"AddOperatorConstantNoInput.cntk"));
|
||||
|
|
|
@ -88,27 +88,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Loads a model file</summary>
|
||||
/// <param name="modelFileName">The model file name to load</param>
|
||||
void LoadModel(String^ modelFileName)
|
||||
{
|
||||
if (m_eval == nullptr)
|
||||
{
|
||||
throw gcnew ObjectDisposedException("Object has been disposed.");
|
||||
}
|
||||
|
||||
pin_ptr<const WCHAR> stdModelPath = PtrToStringChars(modelFileName);
|
||||
|
||||
try
|
||||
{
|
||||
m_eval->LoadModel(stdModelPath);
|
||||
}
|
||||
catch (const exception& ex)
|
||||
{
|
||||
throw GetCustomException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Creates a network based from the network description in the configuration</summary>
|
||||
/// <param name="networkDescription">The configuration file containing the network description</param>
|
||||
void CreateNetwork(String^ networkDescription)
|
||||
|
@ -446,7 +425,6 @@ void emit()
|
|||
f.Evaluate(nullptr, nullptr);
|
||||
f.Evaluate(nullptr, "", 0);
|
||||
f.Evaluate("", 0);
|
||||
f.LoadModel("");
|
||||
f.CreateNetwork("");
|
||||
|
||||
IEvaluateModelManagedD d;
|
||||
|
@ -454,7 +432,6 @@ void emit()
|
|||
d.Evaluate(nullptr, nullptr);
|
||||
d.Evaluate(nullptr, "", 0);
|
||||
d.Evaluate("", 0);
|
||||
d.LoadModel("");
|
||||
d.CreateNetwork("");
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,8 @@ void DoCommand(const ConfigParameters& configRoot)
|
|||
Eval<ElemType> eval(config);
|
||||
|
||||
auto dataReader = make_shared<DataReader>(readerConfig);
|
||||
eval.LoadModel(modelPath);
|
||||
string strPath(modelPath.begin(), modelPath.end());
|
||||
eval.CreateNetwork(strPath);
|
||||
dataReader->StartMinibatchLoop(mbSize, 0, epochSize);
|
||||
eval.StartEvaluateMinibatchLoop(outputName);
|
||||
while (dataReader->GetMinibatch(inputMatrices))
|
||||
|
|
Загрузка…
Ссылка в новой задаче