35 using namespace KKMLL;
43 kkint32 _featuresIncludedLineNum,
47 delete modelParameters;
48 modelParameters = NULL;
50 if (_parametersLineNum < 0)
52 KKStr errMsg =
"'Parameters' setting was not specified.";
53 _log.Level (-1) << endl << endl <<
"CreateModelParameters ***ERROR*** " << errMsg << endl << endl;
54 FormatErrorsAdd (_sectionLineNum, errMsg);
58 switch (modelingMethod)
67 _log.Level (-1) << endl << endl
68 <<
"TrainingConfiguration2::CreateModelParameters ***ERROR*** Invalid modeling method[" 69 << Model::ModelTypeToStr (modelingMethod) <<
"] selected at this time." << endl
76 bool validParameterFormat =
false;
85 KKStr errMsg =
"Parameter setting is invalid";
86 _log.Level (-1) << endl
87 <<
"TrainingConfiguration2::CreateModelParameters ***ERROR*** " << errMsg << endl
89 FormatErrorsAdd (_parametersLineNum, errMsg);
93 else if (_featuresIncludedLineNum > 0)
105 configFileNameSpecified
(),
108 fvFactoryProducer (NULL),
109 fvFactoryProducerSpecified (
false),
111 mlClassesWeOwnIt (
false),
113 examplesPerClass (0),
114 modelParameters (NULL),
116 noiseTrainingClass (NULL),
118 otherClassLineNum (-1),
121 subClassifiers (NULL),
122 subClassifierNameList (NULL),
124 validateDirectories (
true)
131 bool _validateDirectories,
137 Configuration::Load (effectiveConfigName, log);
139 configFileNameSpecified
= _configFileName;
141 validateDirectories = _validateDirectories;
144 log.Level (-1) << endl
145 <<
"TrainingConfiguration2 ***ERROR*** Format of Configuration File is Invalid." << endl
151 mlClassesWeOwnIt =
true;
153 ValidateConfiguration (log);
154 if (examplesPerClass < 1)
156 log.Level (10) <<
"TrainingConfiguration2 - examplesPerClass not specified. Defaulting to 1300." << endl;
157 examplesPerClass = 1300;
161 log.Level (-1) << endl
162 <<
"TrainingConfiguration2 ***ERROR*** Format of Configuration File is Invalid." << endl
165 else if (rootDir.Empty ())
166 DetermineWhatTheRootDirectoryIs ();
173 FactoryFVProducerPtr _fvFactoryProducer,
174 const KKStr& _parameterStr,
178 configFileNameSpecified
(""),
181 fvFactoryProducer (_fvFactoryProducer),
182 fvFactoryProducerSpecified (
true),
185 mlClassesWeOwnIt (
false),
186 examplesPerClass (0),
187 modelParameters (NULL),
189 noiseTrainingClass (NULL),
191 otherClassLineNum (-1),
194 subClassifiers (NULL),
195 subClassifierNameList (NULL),
197 validateDirectories (
false)
199 if (!fvFactoryProducer)
208 mlClassesWeOwnIt =
true;
211 MLClassList::iterator idx;
212 for (idx = mlClasses->begin (); idx != mlClasses->end (); idx++)
217 trainingClasses.PushOnBack (tc);
228 CreateModelParameters (_parameterStr, selectedFeatures, 1, 1, 1, _log);
231 _log.Level (-1) << endl
232 <<
"TrainingConfiguration2 ***ERROR*** Invalid Parameters." << endl
233 <<
" Parameters[" << _parameterStr <<
"]" << endl
243 FileDescPtr _fileDesc,
244 const KKStr& _parameterStr,
248 configFileNameSpecified
(""),
250 fileDesc (_fileDesc),
251 fvFactoryProducer (NULL),
252 fvFactoryProducerSpecified (
false),
254 mlClassesWeOwnIt (
false),
256 examplesPerClass (0),
257 modelParameters (NULL),
259 noiseTrainingClass (NULL),
261 otherClassLineNum (-1),
264 subClassifiers (NULL),
265 subClassifierNameList (NULL),
267 validateDirectories (
false)
274 mlClassesWeOwnIt =
true;
277 MLClassList::iterator idx;
278 for (idx = mlClasses->begin (); idx != mlClasses->end (); idx++)
283 trainingClasses.PushOnBack (tc);
294 CreateModelParameters (_parameterStr, selectedFeatures, 1, 1, 1, _log);
297 _log.Level (-1) << endl
298 <<
"TrainingConfiguration2 ***ERROR*** Invalid Parameters." << endl
299 <<
" Parameters[" << _parameterStr <<
"]" << endl
309 FileDescPtr _fileDesc,
310 ModelParamPtr _modelParameters,
314 configFileNameSpecified
(""),
316 fileDesc (_fileDesc),
317 fvFactoryProducer (NULL),
318 fvFactoryProducerSpecified (
false),
320 mlClassesWeOwnIt (
false),
322 examplesPerClass (0),
323 modelParameters (_modelParameters),
325 noiseTrainingClass (NULL),
327 otherClassLineNum (-1),
330 subClassifiers (NULL),
331 subClassifierNameList (NULL),
333 validateDirectories (
false)
339 mlClassesWeOwnIt =
true;
342 MLClassList::iterator idx;
343 for (idx = mlClasses->begin (); idx != mlClasses->end (); idx++)
348 trainingClasses.PushOnBack (tc);
366 configFileNameSpecified
(tc.configFileNameSpecified
),
367 configRootName
(tc.configRootName
),
368 fileDesc (tc.fileDesc),
369 fvFactoryProducer (tc.fvFactoryProducer),
370 fvFactoryProducerSpecified (tc.fvFactoryProducerSpecified),
372 mlClassesWeOwnIt (
false),
373 modelingMethod (tc.modelingMethod),
374 examplesPerClass (tc.examplesPerClass),
375 modelParameters (NULL),
376 noiseMLClass (tc.noiseMLClass),
377 noiseTrainingClass (tc.noiseTrainingClass),
378 otherClass (tc.otherClass),
379 otherClassLineNum (tc.otherClassLineNum),
380 rootDir
(tc.rootDir
),
381 rootDirExpanded
(tc.rootDirExpanded
),
382 subClassifiers (NULL),
383 subClassifierNameList (NULL),
385 validateDirectories (tc.validateDirectories)
390 for (x = 0; x < tc.trainingClasses.QueueSize (); x++)
393 trainingClasses.PushOnBack (
new TrainingClass (*trainingClass));
400 mlClassesWeOwnIt =
true;
403 if (tc.modelParameters)
406 if (tc.subClassifiers)
409 TrainingConfiguration2List::const_iterator idx;
410 for (idx = tc.subClassifiers->begin (); idx != tc.subClassifiers->end (); ++idx)
413 subClassifiers->PushOnBack (
new TrainingConfiguration2 (*subClassifier));
422 delete noiseTrainingClass; noiseTrainingClass = NULL;
423 delete modelParameters; modelParameters = NULL;
424 delete subClassifierNameList; subClassifierNameList = NULL;
425 delete subClassifiers; subClassifiers = NULL;
427 if (mlClassesWeOwnIt)
445 if (!fvFactoryProducerSpecified)
448 return fvFactoryProducer;
462 return dynamic_cast<ModelParamOldSVMPtr>(modelParameters);
471 return rootDirExpanded;
478 TrainingClassList::const_iterator idx;
479 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
493 TrainingClassList::const_iterator idx;
497 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
500 numHierarchialLevels = Max (numHierarchialLevels, tc->MLClass ()->NumHierarchialLevels ());
503 return numHierarchialLevels;
510 if (mlClassesWeOwnIt)
517 mlClassesWeOwnIt =
true;
518 TrainingClassList::const_iterator idx;
520 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
523 if (mlClasses->PtrToIdx (ic) < 0)
524 mlClasses->AddMLClass (ic);
533 TrainingClassList::const_iterator idx;
535 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
539 if (classes->PtrToIdx (claassForGivenLevel) < 0)
540 classes->AddMLClass (claassForGivenLevel);
552 log.Level (10) <<
"TrainingConfiguration2::GenerateAConfiguraionForAHierarchialLevel level[" << level <<
"]" << endl;
558 TrainingClassList::const_iterator idx;
560 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
567 hierarchialConfig->SyncronizeMLClassListWithTrainingClassList ();
569 delete hierarchialClassList;
570 return hierarchialConfig;
579 o <<
"[Global]" << endl
580 <<
"MODELING_METHOD = " << ModelTypeToStr (modelingMethod) << endl
581 <<
"ROOT_DIR = " << rootDir << endl
582 <<
"Parameters=" << modelParameters->ToCmdLineStr () << endl;
584 if (examplesPerClass > 0)
585 o <<
"Examples_Per_Class=" << examplesPerClass << endl;
587 if (modelParameters->SelectedFeatures ())
588 o <<
"Features_Included=" << modelParameters->SelectedFeatures ()->ToString () << endl;
590 if (otherClass != NULL)
591 o <<
"OtherClass=" << otherClass->Name () << endl;
595 if (noiseTrainingClass)
597 o <<
"[NOISE_IMAGES]" << endl;
598 o <<
"Class_Name=" << noiseTrainingClass->Name () << endl;
599 for (kkuint32 zed = 0; zed < noiseTrainingClass->DirectoryCount (); ++zed)
600 o <<
"Dir=" << noiseTrainingClass->Directory (zed) << endl;
605 TrainingClassList::const_iterator tcIDX;
606 for (tcIDX = trainingClasses.begin (); tcIDX != trainingClasses.end (); tcIDX++)
610 o <<
"[TRAINING_CLASS]" << endl;
612 o <<
"Class_Name=" << tc->Name () << endl;
613 if (tc->Weight () != 1.0f)
614 o <<
"Weight=" << tc->Weight () << endl;
616 if (tc->CountFactor () > 0.0f)
617 o <<
"Count_Factor=" << tc->CountFactor () << endl;
621 o <<
"Sub_Classifier=" << subClassifier->ConfigRootName () << endl;
631 if (!dirStr.Empty ())
632 o <<
"Dir=" << dirStr << endl;
638 ModelParamOldSVMPtr oldSVMParams = OldSvmParameters ();
644 BinaryClassParmsList::const_iterator idx;
646 for (idx = binaryParms->begin (); idx != binaryParms->end (); idx++)
648 const BinaryClassParmsPtr binaryClass = *idx;
649 o <<
"[TWO_CLASS_PARAMETERS]" << endl;
650 o <<
"CLASS1=" << binaryClass->Class1Name () << endl;
651 o <<
"CLASS2=" << binaryClass->Class2Name () << endl;
652 o <<
"Parameters=" << binaryClass->Param ().ToCmdLineStr () << endl;
653 o <<
"Features_Included=" << binaryClass->SelectedFeatures () << endl;
654 o <<
"Weight=" << binaryClass->Weight () << endl;
667 ofstream o (fileName.Str ());
677 trainingClasses.RootDir (rootDir);
684 delete modelParameters;
703 TrainingClassList::const_iterator idx;
707 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
711 if (classes->PtrToIdx (tc->MLClass ()) < 0)
712 classes->PushOnBack (tc->MLClass ());
724 TrainingClassList::const_iterator idx;
728 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
733 if (classes->PtrToIdx (tc->MLClass ()) < 0)
734 classes->PushOnBack (tc->MLClass ());
739 MLClassList::const_iterator idx2;
740 for (idx2 = subClassifierClasses->begin(); idx2 != subClassifierClasses->end (); ++idx2)
743 if (classes->PtrToIdx (subClass) < 0)
744 classes->PushOnBack (subClass);
746 delete subClassifierClasses;
747 subClassifierClasses = NULL;
759 FileDescPtr _fileDesc,
760 const KKStr& _parameterStr,
764 _log.Level (10) <<
"TrainingConfiguration2::CreateFromFeatureVectorList" << endl;
769 KKStr parameterStr = _parameterStr;
771 parameterStr
= "-m 200 -s 0 -n 0.11 -t 2 -g 0.024717 -c 10 -u 100 -up -mt OneVsOne -sm P";
782 delete mlClasses; mlClasses = NULL;
790 (
const KKStr& _existingConfigFileName,
791 const KKStr& _subDir,
792 FactoryFVProducerPtr _fvFactoryProducer,
798 _log.Level (10) <<
"TrainingConfiguration2::CreateFromDirectoryStructure" << endl
799 <<
" Feature Data from SubDir[" << _subDir <<
"]." << endl
805 if (directoryConfigFileName
.Empty ())
812 if (!_existingConfigFileName
.Empty ())
817 config
->Load (_existingConfigFileName
, 822 if (!(config->FormatGood ()))
835 config
->Load (directoryConfigFileName
, 841 if (!(config->FormatGood ()))
851 if (_fvFactoryProducer != NULL)
855 "=-s 0 -n 0.11 -t 2 -g 0.01507 -c 12 -u 100 -up -mt OneVsOne -sm P", 870 config
->Save (directoryConfigFileName
);
879 KKStr& _errorMessage,
883 _log.Level (10) <<
"TrainingConfiguration2::BuildTrainingClassListFromDirectoryStructure" << endl
884 <<
" Feature Data from SubDir[" << _subDir <<
"]." << endl
891 bool _validFormat =
true;
892 KKStr svmParameterStr =
"-s 0 -n 0.11 -t 2 -g 0.01507 -c 12 -u 100 -up -mt OneVsOne -sm P";
898 delete oldSVMparameters;
899 oldSVMparameters = NULL;
908 while (mlClasses->QueueSize () > 1)
909 mlClasses->PopFromBack ();
912 KKStr subDirUnderRoot =
"";
913 BuildTrainingClassListFromDirectoryEntry (_subDir,
922 TrainingClassList::iterator idx;
924 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
938 delete origTraniningClasses;
939 origTraniningClasses = NULL;
951 log.Level (10) <<
"BuildTrainingClassListFromDirectoryEntry subDir[" << subDir <<
"]" << endl;
959 bool thereAreImageFilesInDir = (imageFilesInDir->QueueSize () > 0);
960 delete imageFilesInDir;
962 if (thereAreImageFilesInDir)
966 subDirs.push_back (subDir);
973 KKStrList::iterator sdIDX = subDirectories->begin ();
974 for (sdIDX = subDirectories->begin (); ((sdIDX != subDirectories->end ()) && successful); ++sdIDX)
976 KKStrPtr subDirName = *sdIDX;
977 KKStr newDirPath =
"";
979 newDirPath
= *subDirName;
982 BuildTrainingClassListFromDirectoryEntry (rootDir, newDirPath, successful, errorMessage, log);
984 delete subDirectories;
995 trainingClasses.PushOnBack (_trainClass);
1022 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1030 KKStr errMsg =
"TrainingConfiguration2::SVMparamREF ***ERROR*** (modelingMethod != mmOldSVM)";
1031 log.Level (-1) << endl << errMsg << endl << endl;
1040 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1056 if (modelParameters)
1066 if (modelParameters)
1074 if (modelParameters)
1084 if (modelParameters)
1092 if (modelParameters)
1102 if (modelParameters)
1134 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1144 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1155 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1164 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1175 if (modelParameters)
1185 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1196 if (modelParameters)
1217 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1231 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1245 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1255 TrainingClassList::iterator idx;
1257 for (idx = _trainingClasses->begin (); idx != _trainingClasses->end (); idx++)
1258 AddATrainingClass (*idx);
1265 if (modelParameters)
1304 if (modelParameters)
1320 if (modelParameters)
1330 examplesPerClass = _examplesPerClass;
1337 return examplesPerClass;
1346 ModelParamOldSVMPtr oldSVMparms = OldSvmParameters ();
1363 delete modelParameters;
1365 examplesPerClass = _examplesPerClass;
1375 errorsFound =
false;
1377 if (!subClassifiers)
1385 subClassifiers->PushOnBack (config);
1386 if (!config->FormatGood ())
1389 const VectorKKStr& errors = config->FormatErrors ();
1390 const VectorInt& lineNums = config->FormatErrorsLineNums ();
1391 kkuint32 zed = Max (errors.size (), lineNums.size ());
1392 for (kkuint32 x = 0; x < zed; ++x)
1393 FormatErrorsAdd (lineNums[x], errors[x]);
1406 kkint32 numOfSettings = NumOfSettings ((kkint32)sectionNum);
1411 kkint32 countFactorLineNum = 0;
1412 kkint32 subClassifierLineNum = 0;
1414 kkint32 sectionLineNum = SectionLineNum (sectionNum);
1418 KKStr subClassifierName;
1419 float weight = 1.0f;
1420 float countFactor = 0.0f;
1422 for (
kkint32 settingNum = 0; settingNum < numOfSettings; ++settingNum)
1424 KKStrConstPtr settingNamePtr = SettingName (sectionNum, settingNum);
1425 if (!settingNamePtr)
1429 KKStrConstPtr setingValuePtr = SettingValue (sectionNum, settingNum, settingLineNum);
1430 KKStr settingValue =
"";
1432 settingValue
= *setingValuePtr;
1436 className
= settingValue;
1437 classNameLineNum = settingLineNum;
1442 subClassifierName
= settingValue;
1443 subClassifierLineNum = settingLineNum;
1449 weightLineNum = settingLineNum;
1455 countFactorLineNum = settingLineNum;
1460 if (!settingValue.Empty ())
1461 directories.push_back (settingValue);
1463 else if (!className.Empty ())
1464 directories.push_back (className);
1468 if (directories.size () < 1)
1470 directories.push_back (className);
1475 KKStr errMsg =
"'TRAINING_CLASS' section, CLASS_NAME not defined.";
1476 log.Level (-1) <<
"ValidateClassConfig " << errMsg << endl;
1477 FormatErrorsAdd (sectionLineNum, errMsg);
1485 bool errorsFound =
false;
1486 subClassifer = ValidateSubClassifier (subClassifierName, errorsFound, log);
1489 KKStr errMsg =
"Sub-Classifier [" + (subClassifierName) +
"] has a format error: " + subClassifer->FileName ();
1490 FormatErrorsAdd (subClassifierLineNum, errMsg);
1491 VectorKKStr subClassifierErrors = subClassifer->FormatErrorsWithLineNumbers ();
1492 VectorKKStr::const_iterator idx;
1493 for (idx = subClassifierErrors.begin (); idx != subClassifierErrors.end (); ++idx)
1494 FormatErrorsAdd (subClassifierLineNum,
" " + subClassifierName +
": " + *idx);
1500 KKStr errMsg =
"Class[" + className
+ "] Invalid Weight Parameter.";
1501 log.Level (-1) <<
"ValidateClassConfig " << errMsg << endl;
1502 FormatErrorsAdd (weightLineNum, errMsg);
1509 if (validateDirectories)
1517 KKStr errMsg =
"Invalid Directory Specified[" + expandedDir
+ "].";
1518 log.Level (-1) << endl <<
"ValidateClassConfig ***ERROR*** " << errMsg << endl << endl;
1519 FormatErrorsAdd (dirLineNum, errMsg);
1521 delete tc; tc = NULL;
1540 KKStr errMsg =
"OtherClass Directory [" + classDirToUse
+ "] does not exist.";
1541 log.Level (-1) << endl <<
"ValidateOtherClass ***ERROR*** " << errMsg << endl << endl;
1542 FormatErrorsAdd (otherClassLineNum, errMsg);
1556 trainingClasses.AddTrainingClass (trainingClass);
1565 kkint32 sectionLineNum = SectionLineNum (sectionNum);
1567 kkint32 featuresIncludedLineNum = 0;
1568 kkint32 featuresExcludedLineNum = 0;
1570 KKStr includedFeaturesStr (SettingValueToStr (sectionNum,
"FEATURES_INCLUDED", featuresIncludedLineNum));
1586 if (!selectedFeatures)
1589 delete selectedFeatures;
1593 return selectedFeatures;
1604 kkint32 sectionLineNum = SectionLineNum (sectionNum);
1607 KKStr modelingMethodStr (SettingValueToStr (sectionNum,
"MODELING_METHOD", methodLineNum));
1610 log.Level (30) <<
"ValidateGlobalSection - ModelingMethod[" << Model::ModelTypeToStr (modelingMethod) <<
"] LineNum[" << methodLineNum <<
"]." << endl;
1614 if (methodLineNum < 0)
1616 KKStr errMsg =
"No Modeling_Method was specified.";
1617 log.Level (-1) << endl
1618 <<
"ValidateGlobalSection ***ERROR*** " << errMsg << endl
1620 FormatErrorsAdd (sectionLineNum, errMsg);
1627 KKStr errMsg =
"Invalid Modeling Method[" + modelingMethodStr
+ "] was specified.";
1628 log.Level (-1) << endl
1629 <<
"ValidateGlobalSection ***ERROR*** " << errMsg << endl
1631 FormatErrorsAdd (methodLineNum, errMsg);
1635 KKStr fvFactoryProducerName (SettingValueToStr (sectionNum,
"FEATURE_COMPUTER", fvFactoryLineNum));
1636 if (fvFactoryLineNum < 0)
1638 fvFactoryProducerSpecified =
false;
1639 if (!fvFactoryProducer)
1642 log.Level (-1) <<
"No Feature-Computer Specified; defaulting to '" << fvFactoryProducer->Name () <<
"'." << endl;
1647 KKStr defaultName =
"None";
1648 if (!fvFactoryProducer)
1651 defaultName
= fvFactoryProducer
->Name ();
1654 if (!factorySpecified)
1656 log.Level (-1) << endl <<
"ValidateGlobalSection ***ERROR*** Factory[" << fvFactoryProducerName <<
"] on lineNum[" << fvFactoryLineNum <<
"] not defined" << endl
1657 <<
" defaulting to: " << defaultName << endl
1659 fvFactoryProducerSpecified =
false;
1663 fvFactoryProducer = factorySpecified;
1664 fvFactoryProducerSpecified =
true;
1668 KKStr rootDirStr (SettingValueToStr (sectionNum,
"ROOT_DIR", rootDirLineNum));
1669 if (rootDirLineNum < 0)
1672 rootDir = osAddSlash (KKMLVariables::TrainingLibrariesDir ()) + osGetRootName (
this->FileName ());
1673 log.Level (10) << endl
1674 <<
"ValidateGlobalSection 'Root_Dir' Was not specified defaulting to[" << rootDir <<
"]" << endl
1679 rootDir
= rootDirStr;
1684 log.Level (-1) << endl
1685 <<
"ValidateGlobalSection ***ERROR*** " << errMsg << endl
1687 FormatErrorsAdd (rootDirLineNum, errMsg);
1692 kkint32 parametersLineNum = -1;
1693 kkint32 featuresIncludedLineNum = -1;
1694 kkint32 examplesPerClassLineNum = -1;
1696 KKStr modelParametersStr = SettingValueToStr (sectionNum,
"Parameters", parametersLineNum);
1697 KKStr featuresIncludedStr = SettingValueToStr (sectionNum,
"Features_Included", featuresIncludedLineNum);
1699 if ((parametersLineNum < 0) && (modelingMethod == Model::ModelTypes::OldSVM))
1700 modelParametersStr = SettingValueToStr (
"Model3",
"Parameters", parametersLineNum);
1702 if ((featuresIncludedLineNum < 0) && (modelingMethod == Model::ModelTypes::OldSVM))
1703 featuresIncludedStr = SettingValueToStr (
"Model3",
"Features_Included", featuresIncludedLineNum);
1705 if (parametersLineNum < 0)
1707 KKStr errMsg =
"'Parameters' setting was not specified.";
1708 log.Level (-1) << endl
1709 <<
"ValidateGlobalSection ***ERROR*** " << errMsg << endl
1711 FormatErrorsAdd (sectionLineNum, errMsg);
1716 featuresIncludedStr
= "All";
1718 bool validFeaturesNums =
false;
1720 if (!validFeaturesNums)
1722 KKStr errMsg =
"Invalid Features_Included[" + featuresIncludedStr
+ "].";
1723 log.Level (-1) << endl
1724 <<
"ValidateGlobalSection ***ERROR*** " << errMsg << endl
1726 FormatErrorsAdd (featuresIncludedLineNum, errMsg);
1731 KKStr examplesPerClassStr = SettingValueToStr (sectionNum,
"Examples_Per_Class", examplesPerClassLineNum);
1732 if (examplesPerClassStr.Empty ())
1733 examplesPerClassStr = SettingValueToStr (sectionNum,
"Images_Per_Class", examplesPerClassLineNum);
1737 examplesPerClassStr = SettingValueToStr (
"Model3",
"Examples_Per_Class", examplesPerClassLineNum);
1738 if (examplesPerClassStr.Empty ())
1739 examplesPerClassStr = SettingValueToStr (
"Model3",
"Images_Per_Class", examplesPerClassLineNum);
1746 examplesPerClass = examplesPerClassStr
.ToInt ();
1748 if (examplesPerClass < 1)
1750 KKStr errMsg =
"Invalid Examples_Per_Class[" + examplesPerClassStr
+ "].";
1751 log.Level (-1) << endl
1752 <<
"ValidateGlobalSection ***ERROR*** " << errMsg << endl
1754 FormatErrorsAdd (examplesPerClassLineNum, errMsg);
1759 CreateModelParameters (modelParametersStr, selFeatures, sectionLineNum, parametersLineNum, featuresIncludedLineNum, log);
1760 if (modelParameters)
1762 if (examplesPerClassLineNum >= 0)
1768 KKStr otherClassName (SettingValueToStr (sectionNum,
"OtherClass", otherClassLineNum));
1769 if (otherClassLineNum >= 0)
1773 KKStr errMsg =
"OtherClass specified but no name provided.";
1774 log.Level (-1) << endl <<
"ValidateGlobalSection ***ERROR*** " << errMsg << endl;
1775 FormatErrorsAdd (examplesPerClassLineNum, errMsg);
1780 ValidateOtherClass (otherClass, otherClassLineNum, log);
1790 if (!modelParameters)
1792 log.Level (-1) <<
"ValidateTwoClassParameters - Global Parameters must be defined first." 1797 kkint32 class1NameLineNum = -1;
1798 kkint32 class2NameLineNum = -1;
1799 kkint32 parameterLinenum = -1;
1802 kkint32 sectionLineNum = SectionLineNum (sectionNum);
1804 KKStr class1Name (SettingValueToStr (sectionNum,
"CLASS1", class1NameLineNum));
1805 KKStr class2Name (SettingValueToStr (sectionNum,
"CLASS2", class2NameLineNum));
1806 KKStr parameterStr (SettingValueToStr (sectionNum,
"PARAMETERS", parameterLinenum));
1807 KKStr weightStr (SettingValueToStr (sectionNum,
"WEIGHT", weightLineNum));
1809 if (class1NameLineNum < 0)
1811 KKStr errMsg =
"'Class1' setting was not defined.";
1812 log.Level (-1) << endl <<
"ValidateTwoClassParameters ***ERROR*** " << errMsg << endl << endl;
1813 FormatErrorsAdd (sectionLineNum, errMsg);
1817 if (class2NameLineNum < 0)
1819 KKStr errMsg =
"'Class2' setting was not defined.";
1820 log.Level (-1) << endl <<
"ValidateTwoClassParameters ***ERROR*** " << errMsg << endl << endl;
1821 FormatErrorsAdd (sectionLineNum, errMsg);
1830 log.Level (20) <<
"ValidateTwoClassParameters LineNum[" << class1NameLineNum <<
"] Class[" << class1Name <<
"] not part of classifier." << endl;
1836 log.Level (20) <<
"ValidateTwoClassParameters LineNum[" << class2NameLineNum <<
"] Class[" << class2Name <<
"] not part of classifier." << endl;
1841 if (!selectedFeatures)
1844 if (!selectedFeatures)
1847 if ((class1NameLineNum > 0) && (!class1))
1849 KKStr errMsg =
"Class[" + class1Name
+ "] is not defined.";
1850 log.Level (-1) << endl <<
"ValidateTwoClassParameters ***ERROR*** " << errMsg << endl << endl;
1851 FormatErrorsAdd (class1NameLineNum, errMsg);
1855 if ((class2NameLineNum > 0) && (!class2))
1857 KKStr errMsg =
"Class[" + class2Name
+ "] is not defined.";
1858 log.Level (-1) << endl <<
"ValidateTwoClassParameters ***ERROR*** " << errMsg << endl << endl;
1859 FormatErrorsAdd (class2NameLineNum, errMsg);
1866 if (class1 && class2)
1868 float weight = 1.0f;
1869 if (!weightStr.Empty ())
1870 weight = (
float)atof (weightStr.Str ());
1872 ModelParamOldSVMPtr oldSvmParameters = OldSvmParameters ();
1873 if (oldSvmParameters)
1879 binaryParam
= tempParam;
1885 delete selectedFeatures;
1894 this->FormatErrorsClear ();
1896 kkint32 numOfSections = NumOfSections ();
1898 for (
kkint32 sectionNum = 0; sectionNum < numOfSections; sectionNum++)
1900 KKStr sectionName (*SectionName (sectionNum));
1903 if (sectionName
== "TRAINING_CLASS")
1905 ValidateTrainingClassConfig (sectionNum, log);
1908 else if (sectionName
== "NOISE_IMAGES")
1910 noiseTrainingClass = ValidateClassConfig (sectionNum, log);
1911 if (noiseTrainingClass)
1913 kkint32 noiseGuaranteedSizeLineNum = -1;
1919 log.Level (-1) <<
"ValidateConfiguration *** Invalid Noise Class Definition ***" 1925 else if (sectionName
== "GLOBAL")
1927 ValidateGlobalSection (sectionNum, log);
1930 else if ((sectionName
== "TWO_CLASS_PARAMETERS") ||
1931 (sectionName
== "TWOCLASSPARAMETERS") ||
1932 (sectionName
== "TWO_CLASSPARAMETERS")
1935 ValidateTwoClassParameters (sectionNum, log);
1939 if (trainingClasses.QueueSize () < 1)
1941 log.Level (-1) << endl <<
"ValidateConfiguration ***ERROR*** No Training Classes defined." << endl;
1946 if (modelParameters == NULL)
1948 log.Level (-1) <<
"ValidateConfiguration ***ERROR*** SVM Parameters not specified." << endl;
1952 if (otherClass != NULL)
1954 if (trainingClasses.LocateByMLClass (otherClass) != NULL)
1956 KKStr errMsg =
"OtherClass[" + otherClass->Name () +
"] was also defined as a TrainingClass.";
1957 log.Level (-1) << endl <<
"ValidateConfiguration ***ERROR*** " << errMsg << endl << endl;
1958 FormatErrorsAdd (otherClassLineNum, errMsg);
1969 return trainingClasses.LocateByMLClassName (className);
1976 while (trainingClasses.QueueSize () > 0)
1978 TrainingClassPtr trainingClass = trainingClasses.PopFromBack ();
1979 delete trainingClass;
1987 ModelParamOldSVMPtr oldSvmParameters = OldSvmParameters ();
1988 if (oldSvmParameters)
1991 else if (modelParameters)
2012 ostream&
KKMLL::operator<< (std::ostream& os,
2028 KKStr otherClassDirName =
"";
2031 otherClassDirName
= otherClass
->Name ();
2038 bool cancelFlag =
false;
2039 bool changesMade =
false;
2055 return otherClassExamples;
2078 bool& changesMadeToTrainingLibraries,
2083 log.Level (10) <<
"TrainingConfiguration2::LoadFeatureDataFromTrainingLibraries - Starting." << endl;
2085 bool errorOccured =
false;
2089 changesMadeToTrainingLibraries =
false;
2100 TrainingClassList::const_iterator tcIDX;
2103 bool changesMadeToThisTrainingClass =
false;
2105 for (tcIDX = trainingClasses.begin (); (tcIDX != trainingClasses.end () && (!cancelFlag) && (!errorOccured)); tcIDX++)
2109 log.Level (20) <<
"LoadFeatureDataFromTrainingLibraries Starting on Class[" << trainingClass->Name () <<
"]." << endl;
2111 FeatureVectorListPtr featureDataThisClass = ExtractFeatures (trainingClass, latestTimeStamp, changesMadeToThisTrainingClass, cancelFlag, log);
2113 if (!featureDataThisClass)
2115 log.Level (-1) << endl
2116 <<
"Error Loading Feature data for class[" << trainingClass->Name () <<
"]." << endl
2118 errorOccured =
true;
2122 if (latestTimeStamp
> latestImageTimeStamp)
2123 latestImageTimeStamp
= latestTimeStamp;
2125 if (changesMadeToThisTrainingClass)
2126 changesMadeToTrainingLibraries =
true;
2129 featureDataThisClass->Owner (
false);
2131 delete featureDataThisClass; featureDataThisClass = NULL;
2136 log.Level (30) <<
"LoadFeatureDataFromTrainingLibraries Loading Noise Class [" << NoiseTrainingClass ()->ExpandedDirectory (rootDir, 0) <<
"]" << endl;
2137 FeatureVectorListPtr noiseFeatureData = ExtractFeatures (
NoiseTrainingClass (), latestTimeStamp, changesMadeToThisTrainingClass, cancelFlag, log);
2138 if (!noiseFeatureData)
2140 log.Level (-1) << endl
2141 <<
"TrainingConfiguration2::LoadFeatureDataFromTrainingLibraries ***ERROR*** Error Loading feature data for Noise Images, Directory[" 2142 << NoiseTrainingClass ()->ExpandedDirectory (rootDir, 0)
2146 delete featureData; featureData = NULL;
2147 errorOccured =
true;
2151 if (latestTimeStamp
> latestImageTimeStamp)
2152 latestImageTimeStamp
= latestTimeStamp;
2154 if (changesMadeToThisTrainingClass)
2155 changesMadeToTrainingLibraries =
true;
2158 noiseFeatureData->Owner (
false);
2159 delete noiseFeatureData; noiseFeatureData = NULL;
2163 if (cancelFlag || errorOccured)
2165 log.Level (-1) <<
"LoadFeatureDataFromTrainingLibraries ***ERROR*** CancelFlag or ErrorOcured set to 'true'." << endl;
2170 log.Level (20) <<
"LoadFeatureDataFromTrainingLibraries Exiting" << endl;
2183 log.Level (30) <<
"TrainingConfiguration2::ExtractFeatures - Extracting Features For Class[" 2184 << trainingClass->Name () <<
"], into file[" 2185 << trainingClass->FeatureFileName () <<
"]." 2191 if (fvFactoryProducer)
2197 log.Level (30) <<
"ExtractFeatures Directory: " << expandedDir << endl;
2219 FeatureVectorList::iterator idx;
2220 for (idx = extractedExamplesThisDir->begin (); idx != extractedExamplesThisDir->end (); ++idx)
2222 FeatureVectorPtr fv = *idx;
2228 extractedExamples
->AddQueue (*extractedExamplesThisDir
);
2229 extractedExamplesThisDir->Owner (
false);
2230 delete extractedExamplesThisDir;
2231 extractedExamplesThisDir = NULL;
2234 log.Level (30) <<
"ExtractFeatures Exiting" << endl;
2235 return extractedExamples;
2262 return configFileName;
2268 KKStr configFileNameWithExtension = configFileName;
2277 return configFileNameWithExtension;
2283 return configFileNameInDefaultDirectory;
2288 return configNameInTrainingModelDir;
2291 return configFileNameInDefaultDirectory;
2306 TrainingClassList::iterator idx;
2310 if (trainingClasses.QueueSize () < 0)
2315 VectorKKStr rootDirParts = osSplitDirectoryPathIntoParts (trainingClasses[0].ExpandedDirectory (rootDir, 0));
2316 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
2324 while (rootDirParts.size () > parts.size ())
2325 rootDirParts.pop_back ();
2328 while (zed < rootDirParts.size ())
2330 if (!(rootDirParts[zed].EqualIgnoreCase (parts[zed])))
2335 while (zed < rootDirParts.size ())
2336 rootDirParts.pop_back ();
2347 for (idx = trainingClasses.begin (); idx != trainingClasses.end (); idx++)
2355 KKStr newTrainClassSubDir =
"";
2356 for (zed = (kkuint32)rootDirParts.size (); zed < (kkuint32)parts.size (); zed++)
2357 newTrainClassSubDir << parts[zed];
2363 for (zed = 0; zed < rootDirParts.size (); zed++)
2364 rootDir << rootDirParts[zed];
2397 TrainingConfiguration2List::const_iterator idx;
2398 for (idx = begin (); idx != end (); ++idx)
2400 TrainingConfiguration2Ptr c = *idx;
2431 const KKStr& configFileName,
2432 bool validateDirectories,
2436 if (!registeredFactories)
2438 log.Level (-1) << endl <<
"TrainingConfiguration2::Manufacture ***ERROR*** registeredFactories == NULL Will construct default 'TrainingConfiguration2' instance." << endl << endl;
2439 TrainingConfiguration2Ptr config =
new TrainingConfiguration2 ();
2440 config->Load (configFileName, validateDirectories, log);
2448 map<KKStr,Factory*>::const_iterator idx;
2449 idx = registeredFactories->find (className);
2450 if (idx == registeredFactories->end ())
2452 log.Level (-1) << endl <<
"TrainingConfiguration2::Manufacture Factory: " << className <<
" Is not defined; will return instance of 'TrainingConfiguration2'." << endl << endl;
2453 newInstance =
new TrainingConfiguration2 ();
2454 newInstance->Load (configFileName, validateDirectories, log);
2458 newInstance = idx->second->Manufacture (configFileName, validateDirectories, log);
2472 if (!registeredFactories)
2474 registeredFactories =
new map<KKStr,Factory*> ();
2475 atexit (FinalCleanUp);
2478 map<KKStr,Factory*>::const_iterator idx;
2479 idx = registeredFactories->find (className);
2480 if (idx == registeredFactories->end ())
2481 registeredFactories->insert (pair<KKStr,Factory*> (className, factory));
2484 cerr << endl <<
"TrainingConfiguration2::RegisterFatory ***ERROR*** 'TrainingConfiguration2::Factory with same name[" << className <<
"]" << endl << endl;
2494 bool validateDirectories,
2499 config
->Load (configFileName
, validateDirectories
, log
);
2507 delete registeredFactories;
2508 registeredFactories = NULL;
2515 if (!configFileNameSpecified.Empty ())
2516 XmlElementKKStr::WriteXML (configFileNameSpecified,
"ConfigFileNameSpecified", o);
2518 if (!configRootName.Empty ())
2519 XmlElementKKStr::WriteXML (configFileNameSpecified,
"ConfigRootName", o);
2521 XmlElementInt32::WriteXML (examplesPerClass,
"ExamplesPerClass", o);
2523 if (fvFactoryProducer)
2524 XmlElementKKStr::WriteXML (fvFactoryProducer->Name (),
"FvFactoryProducer", o);
2531 XmlElementKKStr::WriteXML (Model::ModelTypeToStr (modelingMethod),
"ModelingMethod", o);
2533 if (modelParameters)
2537 XmlElementKKStr::WriteXML (noiseMLClass->Name (),
"NoiseMLClass", o);
2539 if (noiseTrainingClass)
2540 XmlElementTrainingClass::WriteXML (*noiseTrainingClass,
"NoiseTrainingClass", o);
2543 XmlElementKKStr::WriteXML (otherClass->Name (),
"OtherClass", o);
2545 if (!rootDir.Empty ())
2546 XmlElementKKStr::WriteXML (rootDir,
"RootDir", o);
2548 if (!rootDirExpanded.Empty ())
2549 XmlElementKKStr::WriteXML (rootDirExpanded,
"RootDirExpanded", o);
2553 trainingClasses.WriteXML (
"TrainingClasses", o);
2558 TrainingConfiguration2List::const_iterator idx;
2559 for (idx = subClassifiers->begin (); idx != subClassifiers->end (); ++idx)
2562 subClassifierList.push_back (sc->ConfigFileNameSpecified ());
2564 XmlElementVectorKKStr::WriteXML (subClassifierList,
"subClassifiers", o);
2597 bool tokenFound =
true;
2606 if (s && s->Value ())
2608 KKStrConstPtr str = s->Value ();
2609 if (varName.EqualIgnoreCase (
"ConfigFileNameSpecified"))
2610 configFileNameSpecified = *str;
2612 else if (varName.EqualIgnoreCase (
"configRootName"))
2613 configRootName = *str;
2615 else if (varName.EqualIgnoreCase (
"FvFactoryProducer"))
2616 fvFactoryProducer = FactoryFVProducer::LookUpFactory (*str);
2618 else if (varName.EqualIgnoreCase (
"ModelingMethod"))
2619 modelingMethod = Model::ModelTypeFromStr (*str);
2621 else if (varName.EqualIgnoreCase (
"NoiseMLClass"))
2622 noiseMLClass = MLClass::CreateNewMLClass (*str);
2624 else if (varName.EqualIgnoreCase (
"otherClass"))
2625 otherClass = MLClass::CreateNewMLClass (*str);
2627 else if (varName.EqualIgnoreCase (
"RootDir"))
2630 else if (varName.EqualIgnoreCase (
"RootDirExpanded"))
2631 rootDirExpanded = *str;
2644 XmlElementInt32Ptr i =
dynamic_cast<XmlElementInt32Ptr> (e);
2646 examplesPerClass = i->Value ();
2654 if (mlClassesWeOwnIt)
2657 mlClassesWeOwnIt =
true;
2673 delete noiseTrainingClass;
2674 noiseTrainingClass = NULL;
2675 noiseTrainingClass = ntc->TakeOwnership ();
2683 fvFactoryProducerSpecified = vBool
->Value ();
2699 if (xmlTrainClasses)
2701 trainingClasses.DeleteContents ();
2702 while (xmlTrainClasses->QueueSize () > 0)
2704 TrainingClassPtr tc = xmlTrainClasses->PopFromBack ();
2705 trainingClasses.PushOnFront (tc);
2707 delete xmlTrainClasses;
2708 xmlTrainClasses = NULL;
2718 delete subClassifierNameList;
2719 subClassifierNameList = sc->TakeOwnership ();
2744 if (!fvFactoryProducer)
2749 TrainingClassList::iterator idx;
2750 for (idx = trainingClasses.begin (); (idx != trainingClasses.end ()) && (!cancelFlag); ++idx)
2755 bool errorsFound =
false;
2774 fvFactoryProducer = NULL;
2775 if (mlClassesWeOwnIt)
2779 delete noiseTrainingClass; noiseTrainingClass = NULL;
2780 delete subClassifiers; subClassifiers = NULL;
2781 trainingClasses.DeleteContents ();
2786 while (t && (!cancelFlag))
const KKStr & FeatureFileName() const
bool operator>(const DateTime &right) const
virtual void Load(const KKStr &_configFileName, bool _validateDirectories, RunLog &log)
XmlTag(const KKStr &_name, TagTypes _tagType)
void ExampleFileName(const KKStr &_exampleFileName)
Name of source of feature vector, ex: file name of image that the feature vector was computed from...
Base class to all Learning Algorithms.
void AddQueue(const FeatureVectorList &examplesToAdd)
Add the contents of 'examplesToAdd' to the end of this list.
void FeatureFileName(const KKStr &_featureFileName)
virtual double Gamma() const
virtual const svm_parameter & Param() const
bool EqualIgnoreCase(const char *s2) const
virtual KKStr ToCmdLineStr() const
Creates a a Command Line String that represents these parameters.
static TrainingConfiguration2 * CreateFromDirectoryStructure(const KKStr &_existingConfigFileName, const KKStr &_subDir, FactoryFVProducerPtr _fvFactoryProducer, RunLog &_log, bool &_successful, KKStr &_errorMessage)
Will create a instance using a sub-directory tree to drive the TraningClassList.
const BinaryClassParmsListPtr BinaryParmsList() const
KKStr osRemoveExtension(const KKStr &_fullFileName)
void SetBinaryClassFields(MLClassPtr class1, MLClassPtr class2, const SVM233::svm_parameter &_param, const FeatureNumList &_features, float _weight)
void C_Param(double _CCC)
static KKStr ModelTypeToStr(ModelTypes _modelType)
bool osValidDirectory(const KKStr &_name)
const KKStr & ConfigRootName() const
const BinaryClassParmsPtr GetParamtersToUseFor2ClassCombo(MLClassPtr class1, MLClassPtr class2) const
KKStr osGetPathPartOfFile(KKStr fullFileName)
Get the path part of a full file name specification.
TrainingClassPtr LocateByMLClassName(const KKStr &className)
FeatureNumList GetFeatureNums() const
static KKStr TrainingModelsDir()
KKStr & TrimRight(const char *whiteSpaceChars="\n\r\t ")
decision_function svm_train_one(const svm_problem *prob, const svm_parameter *param, double Cp, double Cn, std::set< kkint32 > &BSVIndex)
void AddATrainingClass(TrainingClassPtr _trainClass)
Adds specified Training Class to list taking ownership of it.
Keeps track of selected features.
virtual double C_Param() const
FeatureNumList(FileDescPtr _fileDesc)
const KKStr & Directory(kkuint32 idx) const
TrainingConfiguration2Ptr GenerateAConfiguraionForAHierarchialLevel(kkuint32 level, RunLog &log) const
TrainingClassPtr LocateByDirectory(const KKStr &directory)
virtual void ExamplesPerClass(kkint32 _examplesPerClass)
TrainingClass(const VectorKKStr &_directories, KKStr _name, float _weight, float _countFactor, TrainingConfiguration2Ptr _subClassifier, MLClassList &_mlClasses)
Constructor, Creates a new instance of TrainingClass and populates fields with respective data from p...
void BuildTrainingClassListFromDirectoryStructure(const KKStr &_subDir, bool &_successful, KKStr &_errorMessage, RunLog &_log)
XmlElementBool * XmlElementBoolPtr
SVM_EncodingMethod EncodingMethod() const
MLClassListPtr ExtractListOfClasses() const
void ReadXMLPost(VolConstBool &cancelFlag, RunLog &log)
unsigned __int16 kkuint16
16 bit unsigned integer.
KKStr & operator=(const char *src)
Represents a "Class" in the Machine Learning Sense.
void SetModelParameters(ModelParamPtr _svmParanters, kkint32 _examplesPerClass)
static void WriteXML(const MLClassList &mlClassList, const KKStr &varName, std::ostream &o)
void WriteXMLFields(std::ostream &o) const
To be used by both Base Class and Derived classes to write fields that are specific to 'TrainingConfi...
BinaryClassParmsPtr GetParamtersToUseFor2ClassCombo(MLClassPtr class1, MLClassPtr class2)
FeatureNumList AllFeatures()
Will return a FeatureNumList instance with all features selected.
void SetFeatureNums(const FeatureNumList &features)
const FileDescPtr FileDesc() const
TrainingConfiguration2 * TrainingConfiguration2Ptr
SVM_KernalType KernalType() const
virtual bool NormalizeNominalFeatures() const
bool operator==(const char *rtStr) const
static KKStr GetClassNameFromDirName(const KKStr &subDir)
static FactoryFVProducerPtr LookUpFactory(const KKStr &name)
Returns pointer to existing instance of 'FactoryFVProducer' that was previously registered with 'name...
TrainingConfiguration2List(bool _owner)
virtual void EncodingMethod(EncodingMethodType _encodingMethod)
void SetTrainingClasses(TrainingClassListPtr _trainingClasses)
virtual MLClassPtr LookUpByName(const KKStr &_name) const
Returns a pointer of MLClass object with name (_name); if none in list will then return NULL...
KKStrListPtr osGetListOfImageFiles(KKStr fileSpec)
XmlElementVectorKKStr * XmlElementVectorKKStrPtr
virtual void WriteXML(const KKStr &varName, std::ostream &o) const =0
TrainingConfiguration2Ptr LookUp(const KKStr &rootName) const
Returns the instance that has the same root name as 'rootName' if none found returns NULL...
virtual SVM_MachineType MachineType() const
void Number_of_rounds(int _number_of_rounds)
virtual void C_Param(MLClassPtr class1, MLClassPtr class2, double cParam)
static void WriteXML(const bool b, const KKStr &varName, std::ostream &o)
KKStr operator+(const char *right) const
virtual void Save(std::ostream &o) const
bool EqualIgnoreCase(const KKStr &s2) const
SVM_EncodingMethod EncodingMethod() const
FeatureVectorListPtr LoadFeatureDataFromTrainingLibraries(KKB::DateTime &latestImageTimeStamp, bool &changesMadeToTrainingLibraries, VolConstBool &cancelFlag, RunLog &log)
Load training data from the training library directories.
kkuint32 DirectoryCount() const
void MachineType(SVM_MachineType _machineType)
bool NormalizeNominalFeatures()
virtual ~TrainingConfiguration2()
void SetBinaryClassFields(MLClassPtr class1, MLClassPtr class2, const svm_parameter &_param, FeatureNumListConstPtr _features, float _weight)
unsigned __int32 kkuint32
virtual ModelParamPtr Duplicate() const =0
KKStr osGetFileExtension(KKStr fullFileName)
kkuint32 NumHierarchialLevels() const
const SVMparam & SVMparamREF(RunLog &log) const
KKStr ExpandedDirectory(const KKStr &rootDir, kkuint32 idx)
int Number_of_rounds() const
BinaryClassParmsPtr GetBinaryClassParms(MLClassPtr class1, MLClassPtr class2)
void KernalType(SVM_KernalType _kernalType)
KKStr & operator=(KKStr &&src)
virtual FactoryFVProducerPtr DefaultFeatureVectorProducer(RunLog &runLog) const
Container class for FeatureVector derived objects.
KKB::KKStr osAddSlash(const KKStr &fileSpec)
static Factory * FactoryInstace()
void SelectionMethod(SVM_SelectionMethod _selectionMethod)
void MLClass(MLClassPtr _mlClass)
svm_parameter(KKStr ¶mStr)
static TrainingConfiguration2 * CreateFromFeatureVectorList(FeatureVectorList &_examples, FileDescPtr _fileDesc, const KKStr &_parameterStr, RunLog &_log)
FeatureNumListConstPtr GetFeatureNums(FileDescPtr fileDesc, MLClassPtr class1, MLClassPtr class2) const
KKStr operator+(const char *left, const KKStr &right)
float AvgNumOfFeatures(FeatureVectorListPtr trainExamples) const
void ModelParameters(ModelParamPtr _modelParameters)
float AvgNumOfFeatures() const
void ImagesPerClass(kkint32 _imagesPerClass)
virtual void Gamma(double _gamma)
FeatureNumList * FeatureNumListPtr
XmlElementTrainingClass * XmlElementTrainingClassPtr
KKStr(const KKStr &str)
Copy Constructor.
XmlElement * XmlElementPtr
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
void AddATrainingClass(MLClassPtr _newClass)
Will assume that images for this class will be saved off the RootDirectory using its own name for the...
void SetFeatureNums(MLClassPtr class1, MLClassPtr class2, const FeatureNumList &_features, float _weight=-1)
void AddBinaryClassParms(MLClassPtr class1, MLClassPtr class2, const svm_parameter &_param, FeatureNumListConstPtr _selectedFeatures, float _weight)
Add a Binary parameters using svm_parametr cmd line str. Typically used by TrainingConfiguration.
FeatureFileIO * FeatureFileIOPtr
virtual FeatureVectorListPtr ManufacturFeatureVectorList(bool owner, RunLog &runLog) const
Manufactures a instance of a derived 'FeatureVectorList' class that is appropriate for containing ins...
virtual float A_Param() const
void SetFeatureNums(MLClassPtr class1, MLClassPtr class2, FeatureNumListConstPtr _features, float _weight=-1)
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
SVM_MachineType MachineType() const
static bool ConfigFileExists(const KKStr &_configFileName)
virtual SVM_SelectionMethod SelectionMethod() const
virtual FeatureNumListConstPtr SelectedFeatures() const
XmlTag const * XmlTagConstPtr
void WriteXML(const KKStr &varName, std::ostream &o) const
virtual ModelParamTypes ModelParamType() const =0
MLClassListPtr TakeOwnership()
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
VectorKKStr osSplitDirectoryPathIntoParts(const KKStr &path)
virtual void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
This class encapsulates are the information necessary to build a UsfCasCor class. ...
void SetAllFeatures(FileDescPtr fileDesc)
Selects all features except those flagged as 'IgnoreAttribute' in the associated FileDesc.
virtual float AvgMumOfFeatures() const
static KKStr GetEffectiveConfigFileName(const KKStr &configFileName)
Determine the correct configuration file name.
BinaryClassParmsPtr GetBinaryClassParms(MLClassPtr class1, MLClassPtr class2)
TrainingConfiguration2(MLClassListPtr _mlClasses, FactoryFVProducerPtr _fvFactoryProducer, const KKStr &_parameterStr, RunLog &_log)
Use this one if you want to create a default Configuration object.
void SubClassifier(TrainingConfiguration2Ptr _subClassifier)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
void Upper()
Converts all characters in string to their Upper case equivalents via 'toupper'.
void ExamplesPerClass(kkint32 _examplesPerClass)
void Number_of_rounds(kkint32 _number_of_rounds)
static const KKStr & EmptyStr()
Static method that returns an Empty String.
FeatureNumList GetFeatureNums(MLClassPtr class1, MLClassPtr class2)
Returns features selected for the specified class-pairIf none were specified for that pair will retur...
double C_Param(MLClassPtr class1, MLClassPtr class2) const
General purpose Configuration File manager class.
XmlElementTrainingClassList * XmlElementTrainingClassListPtr
KKStr DirectoryPathForClass(MLClassPtr mlClass) const
Fully expanded directory path for specified class.
This class encapsulates are the information necessary to build a SVMModel class.
static void RegisterFatory(const KKStr &className, Factory *factory)
void RootDir(const KKStr &_rootDir)
const TrainingClassList & TrainingClasses() const
MLClassListPtr ExtractClassList() const
static FeatureNumList AllFeatures(FileDescPtr fileDesc)
Create a FeatureNumList object where all features are selected, except ones that are flagged as Ignor...
KKStr osGetRootNameOfDirectory(KKStr fullDirName)
FeatureNumList(kkuint32 _maxFeatureNum)
virtual const KKStr & VarName() const
KKStr StrFormatInt(kkint32 val, const char *mask)
virtual void SelectedFeatures(FeatureNumListConst &_selectedFeatures)
const KKStr & Name() const
virtual void SelectionMethod(SVM_SelectionMethod _selectionMethod)
KKStr ModelParameterCmdLine() const
const KKStr & Name() const
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
FeatureVectorListPtr LoadOtherClasssExamples(RunLog &runLog)
ModelParamPtr ModelParameters() const
KKStr operator+(const KKStr &right) const
TrainingConfiguration2Ptr SubClassifier() const
const MLClassPtr MLClass() const
TrainingClassList * TrainingClassListPtr
static MLClassPtr CreateNewMLClass(const KKStr &_name, kkint32 _classId=-1)
Static method used to create a new instance of a MLClass object.
KKB::KKStr osSubstituteInEnvironmentVariables(const KKStr &src)
Substitute in the value of the environment variables into 'src'.
void EncodingMethod(SVM_EncodingMethod _encodingMethod)
virtual TrainingConfiguration2Ptr Duplicate() const
SVM_SelectionMethod SelectionMethod() const
virtual void MachineType(SVM_MachineType _machineType)
MLClassList(const MLClassList &_mlClasses)
Copy constructor; will copy list but not own the contents.
Specify where training examples and other related data for a MLClass that is needed to train a classi...
virtual TrainingConfiguration2Ptr Manufacture(const KKStr &_configFileName, bool _validateDirectories, RunLog &_log)
TrainingConfiguration2(const TrainingConfiguration2 &tc)
void Directory(kkuint32 idx, const KKStr &directory)
virtual TrainingConfiguration2Ptr ManufacturTrainingConfiguration() const
Returns a 'TrainingConfiguration2' derived instance.
float AvgNumOfFeatures(FeatureVectorListPtr trainExamples) const
Returns back the class weighted average number of features per training example.
bool osFileExists(const KKStr &_fileName)
KKStrListPtr osGetListOfDirectories(KKStr fileSpec)
FeatureNumList(const KKStr &_featureListStr, bool &_valid)
Constructs a 'FeatureNumList' instance from a string that contains a list of selected features...
void Append(const KKStr &str)
void A_Param(float _aParam)
XmlElementKKStr * XmlElementKKStrPtr
TrainingConfiguration2(MLClassListPtr _mlClasses, FileDescPtr _fileDesc, const KKStr &_parameterStr, RunLog &_log)
Use this one if you want to create a default Configuration object.
virtual kkint32 NumOfFeaturesAfterEncoding(FileDescPtr fileDesc, RunLog &log) const
void WriteXML(std::ostream &o)
KKStr RootDirExpanded() const
FeatureNumListConst * FeatureNumListConstPtr
KKStr & operator=(const KKStr &src)
static Factory * factoryInstace
kkint32 ExamplesPerClass() const
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
bool StartsWith(const KKStr &value) const
MLClassList * MLClassListPtr
KKStr osGetCurrentDirectory()
const TrainingClassPtr NoiseTrainingClass() const
MLClassListPtr ExtractFullHierachyOfClasses() const
void UnDefined(bool _unDefined)
const KKStr & SubClassifierName() const
SVM_KernalType KernalType() const
virtual TokenTypes TokenType()=0
Responsible for creating a FeatureFectorProducer instance.
KKStr osGetRootNameWithExtension(const KKStr &fullFileName)
static TrainingConfiguration2Ptr Manufacture(const KKStr &_className, const KKStr &_configFileName, bool _validateDirectories, RunLog &_log)
virtual double C_Param(MLClassPtr class1, MLClassPtr class2) const
static GrayScaleImagesFVProducerFactory * Factory(RunLog *runLog)
Returns instance of "GrayScaleImagesFVProducerFactory" that is registered with "FactoryFVProducer::Re...
TrainingConfiguration2(MLClassListPtr _mlClasses, FileDescPtr _fileDesc, ModelParamPtr _modelParameters, RunLog &_log)
Creates a configuration file using the parameters specified in '_modelParameters'; does not read from...
svm_parameter & operator=(const svm_parameter &right)
kkint32 Number_of_rounds() const
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
void ParseCmdLine(KKStr _cmdLineStr, bool &_validFormat, RunLog &_log)
KKException(const KKStr &_exceptionStr)
virtual void A_Param(float _prob)
svm_parameter(const svm_parameter ¶meters)
Maintains a list of MLClass instances.
static ModelTypes ModelTypeFromStr(const KKStr &_modelTypeStr)
const VectorKKStr & Directories() const
MLClassListPtr ExtractListOfClassesForAGivenHierarchialLevel(kkuint32 level) const
virtual void C_Param(double _cost)
Will only write the ClassName rather than complete MLClass instances.
XmlTokenPtr ReadXMLBaseToken(XmlTokenPtr t, VolConstBool &cancelFlag, RunLog &log)
virtual FeatureVectorListPtr FeatureDataReSink(FactoryFVProducerPtr _fvProducerFactory, const KKStr &_dirName, const KKStr &_fileName, MLClassPtr _unknownClass, bool _useDirectoryNameForClassName, MLClassList &_mlClasses, VolConstBool &_cancelFlag, bool &_changesMade, KKB::DateTime &_timeStamp, RunLog &_log)
Synchronizes the contents of a feature data file with a directory of images.
void KernalType(SVM_KernalType _kernalType)
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.
Abstract Base class for Machine Learning parameters.
MLClassPtr MLClassForGivenHierarchialLevel(KKB::kkuint16 level) const
TrainingClass * TrainingClassPtr
virtual FileDescPtr FileDesc() const =0
virtual kkint32 ExamplesPerClass() const
virtual const KKStr & VarName() const
#define XmlFactoryMacro(NameOfClass)
void C_Param(MLClassPtr class1, MLClassPtr class2, double cParam)
void EmptyTrainingClasses()
Removes all training classes from the configuration; example use would be to remove all classes and t...
kkint32 NumOfFeaturesAfterEncoding(RunLog &log) const
TrainingClassList * DuplicateListAndContents() const
const KKStr & ExampleFileName() const
Name of file that this FeatureVector was computed from.
virtual SVMparamPtr SvmParameters() const
virtual bool ValidParam() const
void Gamma(double _gamma)
KKStr osGetRootName(const KKStr &fullFileName)
XmlElementMLClassNameList * XmlElementMLClassNameListPtr
DateTime & operator=(const DateTime &right)
FactoryFVProducerPtr FvFactoryProducer(RunLog &log) const
virtual void ParseCmdLine(KKStr _cmdLineStr, bool &_validFormat, RunLog &_log)
virtual FeatureFileIOPtr DefaultFeatureFileIO() const =0
virtual void Save(const KKStr &fileName) const
volatile const bool VolConstBool