本文整理汇总了C++中ConfigParameters::Exists方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigParameters::Exists方法的具体用法?C++ ConfigParameters::Exists怎么用?C++ ConfigParameters::Exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigParameters
的用法示例。
在下文中一共展示了ConfigParameters::Exists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void HTKMLFWriter<ElemType>::InitFromConfig(const ConfigRecordType& writerConfig)
{
m_tempArray = nullptr;
m_tempArraySize = 0;
m_overflowWarningCount = 0;
vector<wstring> scriptpaths;
vector<wstring> filelist;
size_t numFiles;
size_t firstfilesonly = SIZE_MAX; // set to a lower value for testing
m_verbosity = writerConfig(L"verbosity", 2);
m_overflowValue = writerConfig(L"overflowValue", 50);
m_maxNumOverflowWarning = writerConfig(L"maxNumOverflowWarning", 10);
vector<wstring> outputNames = writerConfig(L"outputNodeNames", ConfigRecordType::Array(stringargvector()));
if (outputNames.size() < 1)
RuntimeError("writer needs at least one outputNodeName specified in config");
int counter = 0;
foreach_index (i, outputNames) // inputNames should map to node names
{
ConfigParameters thisOutput = writerConfig(outputNames[i]);
if (thisOutput.Exists("dim"))
udims.push_back(thisOutput(L"dim"));
else
RuntimeError("HTKMLFWriter::Init: writer need to specify dim of output");
if (thisOutput.Exists("file"))
scriptpaths.push_back(thisOutput(L"file"));
else if (thisOutput.Exists("scpFile"))
scriptpaths.push_back(thisOutput(L"scpFile"));
else
RuntimeError("HTKMLFWriter::Init: writer needs to specify scpFile for output");
if (thisOutput.Exists("Kaldicmd"))
{
kaldicmd.push_back(thisOutput(L"Kaldicmd"));
kaldi::BaseFloatMatrixWriter wfea;
feature_writer.push_back(wfea);
feature_writer[i].Open(msra::strfun::utf8(kaldicmd[counter]));
}
outputNameToIdMap[outputNames[i]] = i;
outputNameToDimMap[outputNames[i]] = udims[i];
wstring type = thisOutput(L"type", "Real");
if (type == L"Real")
{
outputNameToTypeMap[outputNames[i]] = OutputTypes::outputReal;
}
else
{
throw std::runtime_error("HTKMLFWriter::Init: output type for writer output expected to be Real");
}
counter++;
}
示例2: CreateTransforms
// Create transformers based on the configuration, i.e.
// deserializers = [
// [
// type = "ImageDataDeserializer"
// module = "ImageReader"
// input = [
// features = [
//----> transforms = [
// [type = "Crop"]:[type = "Scale"]...
void CompositeDataReader::CreateTransforms(const ConfigParameters& deserializerConfig)
{
std::string defaultModule = deserializerConfig("module");
if (!deserializerConfig.Exists("input"))
return;
const ConfigParameters& inputs = deserializerConfig("input");
for (const pair<string, ConfigParameters>& section : inputs)
{
ConfigParameters inputBody = section.second;
// Trying to find transforms in the input section of the config.
if (inputBody.find("transforms") == inputBody.end())
continue;
std::wstring inputName = Microsoft::MSR::CNTK::ToFixedWStringFromMultiByte(section.first);
// Read transformers in order and appending them to the transformer pipeline.
argvector<ConfigParameters> transforms = inputBody("transforms");
for (size_t j = 0; j < transforms.size(); ++j)
{
ConfigParameters p = transforms[j];
p.Insert("precision", deserializerConfig("precision"));
TransformerPtr transformer = CreateTransformer(p, defaultModule, std::wstring());
m_transforms.push_back(Transformation{ transformer, inputName });
}
// Let's add a cast transformer by default. It is noop if the type provided by others is float
// or double, but will do a proper cast if the type is uchar.
auto cast = CreateTransformer(inputBody, defaultModule, std::wstring(L"Cast"));
m_transforms.push_back(Transformation{ cast, inputName });
}
}
示例3: DoEdit
void DoEdit(const ConfigParameters& config)
{
// BrainScript editing
if (config.Exists(L"BrainScriptNetworkBuilder"))
{
bool makeMode = config(L"makeMode", true);
wstring outputPathname = config(L"outputModelPath");
// in makeMode, if output file exists, we are done
if (makeMode && File::Exists(outputPathname))
{
LOGPRINTF(stderr, "'%ls' exists, skipping. Specify makeMode=false to force executing the action.\n", outputPathname.c_str());
return;
}
DEVICEID_TYPE deviceId = DeviceFromConfig(config);
let createNetworkFn = GetNetworkFactory<ConfigParameters, ElemType>(config);
let net = createNetworkFn(deviceId);
net->Save(outputPathname);
LOGPRINTF(stderr, "\nModel with %d nodes saved as '%ls'.\n", (int)net->GetTotalNumberOfNodes(), outputPathname.c_str());
return;
}
// legacy model editing
wstring editPath = config(L"editPath");
wstring ndlMacros = config(L"ndlMacros", "");
NDLScript<ElemType> ndlScript;
if (!ndlMacros.empty())
{
ndlScript.LoadConfigFile(ndlMacros);
}
MELScript<ElemType> melScript;
melScript.LoadConfigFileAndResolveVariables(editPath, config);
}
示例4: DoWriteOutput
void DoWriteOutput(const ConfigParameters& config)
{
ConfigParameters readerConfig(config(L"reader"));
readerConfig.Insert("randomize", "None"); // we don't want randomization when output results
DataReader testDataReader(readerConfig);
ConfigArray minibatchSize = config(L"minibatchSize", "2048");
intargvector mbSize = minibatchSize;
size_t epochSize = config(L"epochSize", "0");
if (epochSize == 0)
{
epochSize = requestDataSize;
}
vector<wstring> outputNodeNamesVector;
let net = GetModelFromConfig<ConfigParameters, ElemType>(config, L"outputNodeNames", outputNodeNamesVector);
// set tracing flags
net->EnableNodeTracing(config(L"traceNodeNamesReal", ConfigParameters::Array(stringargvector())),
config(L"traceNodeNamesCategory", ConfigParameters::Array(stringargvector())),
config(L"traceNodeNamesSparse", ConfigParameters::Array(stringargvector())));
SimpleOutputWriter<ElemType> writer(net, 1);
if (config.Exists("writer"))
{
ConfigParameters writerConfig(config(L"writer"));
bool writerUnittest = writerConfig(L"unittest", "false");
DataWriter testDataWriter(writerConfig);
writer.WriteOutput(testDataReader, mbSize[0], testDataWriter, outputNodeNamesVector, epochSize, writerUnittest);
}
else if (config.Exists("outputPath"))
{
wstring outputPath = config(L"outputPath");
WriteFormattingOptions formattingOptions(config);
bool nodeUnitTest = config(L"nodeUnitTest", "false");
writer.WriteOutput(testDataReader, mbSize[0], outputPath, outputNodeNamesVector, formattingOptions, epochSize, nodeUnitTest);
}
else
InvalidArgument("write command: You must specify either 'writer'or 'outputPath'");
}
示例5: wmain
int wmain(int argc, wchar_t* argv[])
{
try
{
ConfigParameters config;
ConfigParameters::ParseCommandLine(argc, argv, config);
// get the command param set they want
wstring logpath = config("stderr", L"");
ConfigArray command = config("command", "train");
// dump config info
fprintf(stderr, "command: ");
for (int i = 0; i < command.size(); i++)
{
fprintf(stderr, "%s ", command[i].c_str());
}
// run commands
std::string type = config("precision", "float");
// accept old precision key for backward compatibility
if (config.Exists("type"))
type = config("type", "float");
fprintf(stderr, "\nprecision = %s\n", type.c_str());
if (type == "float")
DoCommand<float>(config);
else if (type == "double")
DoCommand<double>(config);
else
RuntimeError("invalid precision specified: %s", type.c_str());
}
catch (std::exception& err)
{
fprintf(stderr, "EXCEPTION occurred: %s", err.what());
Microsoft::MSR::CNTK::DebugUtil::PrintCallStack();
#ifdef _DEBUG
DebugBreak();
#endif
return -1;
}
catch (...)
{
fprintf(stderr, "Unknown ERROR occurred");
Microsoft::MSR::CNTK::DebugUtil::PrintCallStack();
#ifdef _DEBUG
DebugBreak();
#endif
return -1;
}
return 0;
}
示例6: TestBing
void TestBing(const ConfigParameters& config)
{
if (!config.Exists("train.set"))
{
std::cout<<"USAGE: cn.exe train.set featureDim networkDescription learnRatesPerMB mbSize epochSize maxEpochs outdir test.set test.set.size"<<endl;
exit(0);
}
size_t vdim = config("featureDim");
size_t udim = 1;
vector<wstring> filepaths;
filepaths.push_back(config("train.set"));
DataReader<ElemType> dataReader(vdim, udim, filepaths, config);
ConfigArray layerSizes(config("networkDescription"));
SimpleNetworkBuilder<ElemType> netBuilder(layerSizes, TrainingCriterion::SquareError, EvalCriterion::SquareError, L"Sigmoid", true, false, false, &dataReader);
ConfigArray learnRatesPerMB(config("learnRatesPerMB"));
ConfigArray mbSize(config("mbSize"));
size_t epochSize = config("epochSize");
size_t maxEpochs = config("maxEpochs");
float momentumPerMB = 0.9;//0.9f;
std::string outDir = config("outdir");
wstring modelPath = wstring(msra::strfun::utf16(outDir)).append(L"\\bingranknet.dnn");
SimpleSGD<ElemType> sgd(learnRatesPerMB, mbSize, epochSize, maxEpochs, modelPath, momentumPerMB);
sgd.Train(netBuilder, dataReader, true);
std::cout<<std::endl<<std::endl<<std::endl<<std::endl<<"Testing ..... "<<std::endl;
// test
vector<wstring> testfilepaths;
testfilepaths.push_back( config("test.set"));
size_t testSize = config("test.set.size");
DataReader<ElemType> testDataReader(vdim, udim, testfilepaths, config);
wstring finalNetPath = modelPath.append(L".").append(to_wstring(maxEpochs-1));
SimpleEvaluator<ElemType> eval(netBuilder.LoadNetworkFromFile(finalNetPath, false));
eval.Evaluate(testDataReader, 1024, (finalNetPath.append(L".results.txt")).c_str(),testSize);
}
示例7: wmainOldCNTKConfig
//.........这里部分代码省略.........
#if 1 // keep the ability to do it how it was done before 1.8; delete if noone needs it anymore
let useOldWay = ProgressTracing::GetTimestampingFlag(); // enable it when running in our server farm
if (useOldWay)
{
for (int i = 0; i < command.size(); i++) // append all 'command' entries
{
logpath += L"_";
logpath += (wstring)command[i];
}
logpath += L".log"; // append .log
}
if (paralleltrain && useOldWay)
{
std::wostringstream oss;
oss << mpi->CurrentNodeRank();
logpath += L"rank" + oss.str();
}
else
#endif
// for MPI workers except main, append .rankN
if (paralleltrain && mpi->CurrentNodeRank() != 0)
logpath += msra::strfun::wstrprintf(L".rank%d", mpi->CurrentNodeRank());
RedirectStdErr(logpath);
if (traceLevel == 0)
PrintBanner(argc, argv, timestamp); // repeat simple banner into log file
}
// full config info
if (traceLevel > 0)
{
PrintBuiltInfo();
PrintGpuInfo();
}
#ifdef _DEBUG
if (traceLevel > 0)
{
// This simply merges all the different config parameters specified (eg, via config files or via command line directly),
// and prints it.
fprintf(stderr, "\nConfiguration, Raw:\n\n");
LOGPRINTF(stderr, "%s\n", rawConfigString.c_str());
// Same as above, but all variables are resolved. If a parameter is set multiple times (eg, set in config, overridden at command line),
// All of these assignments will appear, even though only the last assignment matters.
fprintf(stderr, "\nConfiguration After Variable Resolution:\n\n");
LOGPRINTF(stderr, "%s\n", config.ResolveVariables(rawConfigString).c_str());
}
#endif
SetMathLibTraceLevel(traceLevel);
// This outputs the final value each variable/parameter is assigned to in config (so if a parameter is set multiple times, only the last
// value it is set to will appear).
if (traceLevel > 0)
{
fprintf(stderr, "\nConfiguration After Processing and Variable Resolution:\n\n");
config.dumpWithResolvedVariables();
LOGPRINTF(stderr, "Commands:");
for (int i = 0; i < command.size(); i++)
fprintf(stderr, " %s", command[i].c_str());
fprintf(stderr, "\n");
}
// run commands
std::string type = config(L"precision", "float");
// accept old precision key for backward compatibility
if (config.Exists("type"))
InvalidArgument("CNTK: Use of 'type' parameter is deprecated, it is called 'precision' now.");
if (traceLevel > 0)
{
LOGPRINTF(stderr, "precision = \"%s\"\n", type.c_str());
}
if (type == "float")
DoCommands<float>(config, mpi);
else if (type == "double")
DoCommands<double>(config, mpi);
else
RuntimeError("CNTK: Invalid precision string: \"%s\", must be \"float\" or \"double\"", type.c_str());
// if completed then write a doneFile if requested
if (!doneFile.empty())
{
FILE* fp = fopenOrDie(doneFile.c_str(), L"w");
fprintf(fp, "Successfully finished at %s on %s\n", TimeDateStamp().c_str(), GetHostName().c_str());
fcloseOrDie(fp);
}
if (ProgressTracing::GetTimestampingFlag())
{
LOGPRINTF(stderr, "__COMPLETED__\n"); // running in server environment which expects this string
}
else
fprintf(stderr, "COMPLETED.\n");
fflush(stderr);
return EXIT_SUCCESS;
}
示例8: wmainOldCNTKConfig
int wmainOldCNTKConfig(int argc, wchar_t* argv[]) // called from wmain which is a wrapper that catches & repots Win32 exceptions
{
ConfigParameters config;
std::string rawConfigString = ConfigParameters::ParseCommandLine(argc, argv, config);
// get the command param set they want
wstring logpath = config(L"stderr", L"");
// [1/26/2015 erw, add done file so that it can be used on HPC]
wstring DoneFile = config(L"DoneFile", L"");
ConfigArray command = config(L"command", "train");
// paralleltrain training
g_mpi = nullptr;
bool paralleltrain = config(L"parallelTrain", "false");
if (paralleltrain)
{
g_mpi = new MPIWrapper();
}
g_shareNodeValueMatrices = config(L"shareNodeValueMatrices", false);
TracingGPUMemoryAllocator::SetTraceLevel(config(L"traceGPUMemoryAllocations", 0));
if (logpath != L"")
{
for (int i = 0; i < command.size(); i++)
{
logpath += L"_";
logpath += (wstring) command[i];
}
logpath += L".log";
if (paralleltrain)
{
std::wostringstream oss;
oss << g_mpi->CurrentNodeRank();
logpath += L"rank" + oss.str();
}
RedirectStdErr(logpath);
}
PrintBuiltInfo(); // this one goes to log file
std::string timestamp = TimeDateStamp();
// dump config info
fprintf(stderr, "running on %s at %s\n", GetHostName().c_str(), timestamp.c_str());
fprintf(stderr, "command line: \n");
for (int i = 0; i < argc; i++)
{
fprintf(stderr, "%s ", WCharToString(argv[i]).c_str());
}
// This simply merges all the different config parameters specified (eg, via config files or via command line directly),
// and prints it.
fprintf(stderr, "\n\n>>>>>>>>>>>>>>>>>>>> RAW CONFIG (VARIABLES NOT RESOLVED) >>>>>>>>>>>>>>>>>>>>\n");
fprintf(stderr, "%s\n", rawConfigString.c_str());
fprintf(stderr, "<<<<<<<<<<<<<<<<<<<< RAW CONFIG (VARIABLES NOT RESOLVED) <<<<<<<<<<<<<<<<<<<<\n");
// Same as above, but all variables are resolved. If a parameter is set multiple times (eg, set in config, overriden at command line),
// All of these assignments will appear, even though only the last assignment matters.
fprintf(stderr, "\n>>>>>>>>>>>>>>>>>>>> RAW CONFIG WITH ALL VARIABLES RESOLVED >>>>>>>>>>>>>>>>>>>>\n");
fprintf(stderr, "%s\n", config.ResolveVariables(rawConfigString).c_str());
fprintf(stderr, "<<<<<<<<<<<<<<<<<<<< RAW CONFIG WITH ALL VARIABLES RESOLVED <<<<<<<<<<<<<<<<<<<<\n");
// This outputs the final value each variable/parameter is assigned to in config (so if a parameter is set multiple times, only the last
// value it is set to will appear).
fprintf(stderr, "\n>>>>>>>>>>>>>>>>>>>> PROCESSED CONFIG WITH ALL VARIABLES RESOLVED >>>>>>>>>>>>>>>>>>>>\n");
config.dumpWithResolvedVariables();
fprintf(stderr, "<<<<<<<<<<<<<<<<<<<< PROCESSED CONFIG WITH ALL VARIABLES RESOLVED <<<<<<<<<<<<<<<<<<<<\n");
fprintf(stderr, "command: ");
for (int i = 0; i < command.size(); i++)
{
fprintf(stderr, "%s ", command[i].c_str());
}
// run commands
std::string type = config(L"precision", "float");
// accept old precision key for backward compatibility
if (config.Exists("type"))
{
type = config(L"type", "float");
}
fprintf(stderr, "\nprecision = %s\n", type.c_str());
if (type == "float")
{
DoCommands<float>(config);
}
else if (type == "double")
{
DoCommands<double>(config);
}
else
{
RuntimeError("invalid precision specified: %s", type.c_str());
}
// still here , write a DoneFile if necessary
//.........这里部分代码省略.........
示例9: if
TextConfigHelper::TextConfigHelper(const ConfigParameters& config)
{
if (!config.ExistsCurrent(L"input"))
{
RuntimeError("CNTKTextFormatReader configuration does not contain \"input\" section.");
}
const ConfigParameters& input = config(L"input");
if (input.empty())
{
RuntimeError("CNTKTextFormatReader configuration contains an empty \"input\" section.");
}
string precision = config.Find("precision", "float");
if (AreEqualIgnoreCase(precision, "double"))
{
m_elementType = ElementType::tdouble;
}
else if (AreEqualIgnoreCase(precision, "float"))
{
m_elementType = ElementType::tfloat;
}
else
{
RuntimeError("Not supported precision '%s'. Expected 'double' or 'float'.", precision.c_str());
}
StreamId id = 0;
map<string, wstring> aliasToInputMap;
for (const pair<string, ConfigParameters>& section : input)
{
ConfigParameters input = section.second;
wstring name = msra::strfun::utf16(section.first);
if (!input.ExistsCurrent(L"dim") || !input.ExistsCurrent(L"format"))
{
RuntimeError("Input section for input '%ls' does not specify all the required parameters, "
"\"dim\" and \"format\".", name.c_str());
}
StreamDescriptor stream;
stream.m_id = id++;
stream.m_name = name;
stream.m_sampleDimension = input(L"dim");
string type = input(L"format");
if (AreEqualIgnoreCase(type, "dense"))
{
stream.m_storageType = StorageType::dense;
}
else if (AreEqualIgnoreCase(type, "sparse"))
{
stream.m_storageType = StorageType::sparse_csc;
if (stream.m_sampleDimension > numeric_limits<IndexType>::max())
{
RuntimeError("Sample dimension (%" PRIu64 ") for sparse input '%ls'"
" exceeds the maximum allowed value (%" PRIu64 ").\n",
stream.m_sampleDimension, name.c_str(), (size_t)numeric_limits<IndexType>::max());
}
}
else
{
RuntimeError("'format' parameter must be set either to 'dense' or 'sparse'.");
}
// alias is optional
if (input.ExistsCurrent(L"alias"))
{
stream.m_alias = input(L"alias");
if (stream.m_alias.empty())
{
RuntimeError("Alias value for input '%ls' is empty.", name.c_str());
}
}
else
{
stream.m_alias = section.first;
}
if (aliasToInputMap.find(stream.m_alias) != aliasToInputMap.end())
{
RuntimeError("Alias %s is already mapped to input %ls.",
stream.m_alias.c_str(), aliasToInputMap[stream.m_alias].c_str());
}
else
{
aliasToInputMap[stream.m_alias] = stream.m_name;
}
stream.m_elementType = m_elementType;
m_streams.push_back(stream);
}
m_filepath = msra::strfun::utf16(config(L"file"));
if (config.Exists(L"randomize"))
{
wstring randomizeString = config.CanBeString(L"randomize") ? config(L"randomize") : wstring();
if (!_wcsicmp(randomizeString.c_str(), L"none"))
//.........这里部分代码省略.........
示例10: TestConfiguration
void TestConfiguration(const ConfigParameters& configBase)
{
ConfigParameters configMacros = configBase("macroExample");
for (auto iterMacro = configMacros.begin(); iterMacro != configMacros.end(); iterMacro++)
{
std::map<std::string, ConfigValue> paramsMap;
ConfigParameters configCN = iterMacro->second;
if (configCN.Exists("parameters"))
{
ConfigArray params = configCN("parameters");
for (int i = 0; i < params.size(); ++i)
paramsMap[params[i]] = ConfigValue("uninitialized");
}
ConfigParameters configNodes = configCN("NodeList");
for (auto iter = configNodes.begin();
iter != configNodes.end(); iter++)
{
std::wstring nodeName;
nodeName = msra::strfun::utf16(iter->first);
ConfigArray configNode = iter->second;
std::string opName = configNode[0];
if (IsParameter(paramsMap, opName))
{
;
}
if (opName == "InputValue" && configNode.size() >= 2)
{
size_t rows = 0;
if (!IsParameter(paramsMap, configNode[1]))
rows = configNode[1];
}
else if (opName == "LearnableParameter" && configNode.size() >= 3)
{
size_t rows = 0;
if (!IsParameter(paramsMap, configNode[1]))
rows = configNode[1];
size_t cols = 0;
if (!IsParameter(paramsMap, configNode[2]))
cols = configNode[2];
bool learningRateMultiplier = 0;
bool init = false;
ConfigArray initData;
// look for optional parameters
for (int i = 3; i < configNode.size(); ++i)
{
bool needsGradient = false;
ConfigParameters configParam = configNode[i];
if (configParam.Exists("learningRateMultiplier")) // TODO: should this be a test for 'true' rather than Exists()?
needsGradient = (float)configParam("learningRateMultiplier") > 0? true : false;
else if (configParam.Exists("init"))
{
init = true;
initData = configParam["init"];
}
}
// if initializing, do so now
if (init)
{
bool uniform = true;
ElemType initValueScale = 1;
size_t inputSize = cols;
if (initData.size() > 0)
initValueScale = initData[0];
if (initData.size() > 1)
uniform = EqualCI(initData[1], "uniform");
}
}
}
// now link up all the nodes
configNodes = configCN("Relation");
for (auto iter = configNodes.begin(); iter != configNodes.end(); iter++)
{
std::wstring nodeName = msra::strfun::utf16(iter->first);
ConfigArray configNode = iter->second;
int numChildren = (int) configNode.size();
for (int i = 0; i < numChildren; ++i)
{
std::wstring nodeName = configNode[i];
}
}
ConfigParameters configRoots = configCN("RootNodes");
ConfigArray configNode = configRoots("FeatureNodes");
for (size_t i = 0; i < configNode.size(); i++)
{
std::wstring nodeName = configNode[i];
}
if (configRoots.Exists("LabelNodes"))
{
configNode = configRoots("LabelNodes");
for (size_t i = 0; i < configNode.size(); i++)
{
std::wstring nodeName = configNode[i];
}
}
//.........这里部分代码省略.........
示例11: DoWriteOutput
void DoWriteOutput(const ConfigParameters& config)
{
ConfigParameters readerConfig(config(L"reader"));
readerConfig.Insert("traceLevel", config(L"traceLevel", "0"));
readerConfig.Insert("randomize", "None"); // we don't want randomization when output results
DataReader testDataReader(readerConfig);
DEVICEID_TYPE deviceId = DeviceFromConfig(config);
ConfigArray minibatchSize = config(L"minibatchSize", "2048");
wstring modelPath = config(L"modelPath");
intargvector mbSize = minibatchSize;
size_t epochSize = config(L"epochSize", "0");
if (epochSize == 0)
{
epochSize = requestDataSize;
}
ConfigArray outputNodeNames = config(L"outputNodeNames", "");
vector<wstring> outputNodeNamesVector;
// Note this is required since the user might specify OutputNodeNames in the config, so don't use CreateFromFile,
// instead we build the network ourselves.
auto net = make_shared<ComputationNetwork>(deviceId);
net->Read<ElemType>(modelPath);
if (outputNodeNames.size() > 0)
{
net->OutputNodes().clear();
for (int i = 0; i < outputNodeNames.size(); ++i)
{
outputNodeNamesVector.push_back(outputNodeNames[i]);
net->OutputNodes().emplace_back(net->GetNodeFromName(outputNodeNames[i]));
}
}
net->CompileNetwork();
SimpleOutputWriter<ElemType> writer(net, 1);
if (config.Exists("writer"))
{
ConfigParameters writerConfig(config(L"writer"));
bool bWriterUnittest = writerConfig(L"unittest", "false");
DataWriter testDataWriter(writerConfig);
writer.WriteOutput(testDataReader, mbSize[0], testDataWriter, outputNodeNamesVector, epochSize, bWriterUnittest);
}
else if (config.Exists("outputPath"))
{
wstring outputPath = config(L"outputPath");
// gather additional formatting options
typename decltype(writer)::WriteFormattingOptions formattingOptions;
if (config.Exists("format"))
{
ConfigParameters formatConfig(config(L"format"));
if (formatConfig.ExistsCurrent("type")) // do not inherit 'type' from outer block
{
string type = formatConfig(L"type");
if (type == "real") formattingOptions.isCategoryLabel = false;
else if (type == "category") formattingOptions.isCategoryLabel = true;
else InvalidArgument("write: type must be 'real' or 'category'");
if (formattingOptions.isCategoryLabel)
formattingOptions.labelMappingFile = (wstring)formatConfig(L"labelMappingFile", L"");
}
formattingOptions.transpose = formatConfig(L"transpose", formattingOptions.transpose);
formattingOptions.prologue = formatConfig(L"prologue", formattingOptions.prologue);
formattingOptions.epilogue = formatConfig(L"epilogue", formattingOptions.epilogue);
formattingOptions.sequenceSeparator = formatConfig(L"sequenceSeparator", formattingOptions.sequenceSeparator);
formattingOptions.sequencePrologue = formatConfig(L"sequencePrologue", formattingOptions.sequencePrologue);
formattingOptions.sequenceEpilogue = formatConfig(L"sequenceEpilogue", formattingOptions.sequenceEpilogue);
formattingOptions.elementSeparator = formatConfig(L"elementSeparator", formattingOptions.elementSeparator);
formattingOptions.sampleSeparator = formatConfig(L"sampleSeparator", formattingOptions.sampleSeparator);
formattingOptions.precisionFormat = formatConfig(L"precisionFormat", formattingOptions.precisionFormat);
}
writer.WriteOutput(testDataReader, mbSize[0], outputPath, outputNodeNamesVector, formattingOptions, epochSize);
}
else
InvalidArgument("write command: You must specify either 'writer'or 'outputPath'");
}
示例12: wmainOldCNTKConfig
// ---------------------------------------------------------------------------
// main() for old CNTK config language
// ---------------------------------------------------------------------------
// called from wmain which is a wrapper that catches & repots Win32 exceptions
int wmainOldCNTKConfig(int argc, wchar_t* argv[])
{
ConfigParameters config;
std::string rawConfigString = ConfigParameters::ParseCommandLine(argc, argv, config); // get the command param set they want
bool timestamping = config(L"timestamping", false);
if (timestamping)
{
ProgressTracing::SetTimestampingFlag();
}
// get the command param set they want
wstring logpath = config(L"stderr", L"");
// [1/26/2015 erw, add done file so that it can be used on HPC]
wstring DoneFile = config(L"DoneFile", L"");
ConfigArray command = config(L"command", "train");
// paralleltrain training
shared_ptr<Microsoft::MSR::CNTK::MPIWrapper> mpi;
bool paralleltrain = config(L"parallelTrain", "false");
if (paralleltrain)
mpi = MPIWrapper::GetInstance(true /*create*/);
g_shareNodeValueMatrices = config(L"shareNodeValueMatrices", false);
TracingGPUMemoryAllocator::SetTraceLevel(config(L"traceGPUMemoryAllocations", 0));
if (logpath != L"")
{
for (int i = 0; i < command.size(); i++)
{
logpath += L"_";
logpath += (wstring) command[i];
}
logpath += L".log";
if (paralleltrain)
{
std::wostringstream oss;
oss << mpi->CurrentNodeRank();
logpath += L"rank" + oss.str();
}
RedirectStdErr(logpath);
}
PrintBuiltInfo(); // this one goes to log file
std::string timestamp = TimeDateStamp();
// dump config info
fprintf(stderr, "\n");
LOGPRINTF(stderr, "Running on %s at %s\n", GetHostName().c_str(), timestamp.c_str());
LOGPRINTF(stderr, "Command line: \n");
for (int i = 0; i < argc; i++)
fprintf(stderr, "%*s%ls", i > 0 ? 2 : 0, "", argv[i]); // use 2 spaces for better visual separability
fprintf(stderr, "\n\n");
#if 1 //def _DEBUG
// This simply merges all the different config parameters specified (eg, via config files or via command line directly),
// and prints it.
fprintf(stderr, "\n\n");
LOGPRINTF(stderr, ">>>>>>>>>>>>>>>>>>>> RAW CONFIG (VARIABLES NOT RESOLVED) >>>>>>>>>>>>>>>>>>>>\n");
LOGPRINTF(stderr, "%s\n", rawConfigString.c_str());
LOGPRINTF(stderr, "<<<<<<<<<<<<<<<<<<<< RAW CONFIG (VARIABLES NOT RESOLVED) <<<<<<<<<<<<<<<<<<<<\n");
// Same as above, but all variables are resolved. If a parameter is set multiple times (eg, set in config, overridden at command line),
// All of these assignments will appear, even though only the last assignment matters.
fprintf(stderr, "\n");
LOGPRINTF(stderr, ">>>>>>>>>>>>>>>>>>>> RAW CONFIG WITH ALL VARIABLES RESOLVED >>>>>>>>>>>>>>>>>>>>\n");
LOGPRINTF(stderr, "%s\n", config.ResolveVariables(rawConfigString).c_str());
LOGPRINTF(stderr, "<<<<<<<<<<<<<<<<<<<< RAW CONFIG WITH ALL VARIABLES RESOLVED <<<<<<<<<<<<<<<<<<<<\n");
// This outputs the final value each variable/parameter is assigned to in config (so if a parameter is set multiple times, only the last
// value it is set to will appear).
fprintf(stderr, "\n");
LOGPRINTF(stderr, ">>>>>>>>>>>>>>>>>>>> PROCESSED CONFIG WITH ALL VARIABLES RESOLVED >>>>>>>>>>>>>>>>>>>>\n");
config.dumpWithResolvedVariables();
LOGPRINTF(stderr, "<<<<<<<<<<<<<<<<<<<< PROCESSED CONFIG WITH ALL VARIABLES RESOLVED <<<<<<<<<<<<<<<<<<<<\n");
#endif
LOGPRINTF(stderr, "Commands:");
for (int i = 0; i < command.size(); i++)
fprintf(stderr, " %s", command[i].c_str());
fprintf(stderr, "\n");
// run commands
std::string type = config(L"precision", "float");
// accept old precision key for backward compatibility
if (config.Exists("type"))
InvalidArgument("CNTK: Use of 'type' parameter is deprecated, it is called 'precision' now.");
LOGPRINTF(stderr, "Precision = \"%s\"\n", type.c_str());
if (type == "float")
DoCommands<float>(config, mpi);
else if (type == "double")
DoCommands<double>(config, mpi);
//.........这里部分代码省略.........