} /* DialogTimer_Tick */ private void CreateTuningFeatureFiles() { tuningThreadRunning = true; PicesDataBase.ThreadInit(); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Started"); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Creating Destination Directory"); String destinationDirectory = OSservices.AddSlash(DestinationDirectory.Text) + OSservices.GetRootName(modelName); OSservices.CreateDirectoryPath(destinationDirectory); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Loading feature data for Model[" + modelName + "]"); config = new PicesTrainingConfigManaged(modelName, runLog); if (!config.Valid()) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Model[" + modelName + "] is invalid."); tuningThreadFailed = true; tuningThreadDone = true; tuningThreadRunning = false; return; } bool changesMade = false; PicesFeatureVectorList data = config.LoadFeatureDataFromTrainingLibraries(changesMade); if (data == null) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Model[" + modelName + "] Could not load Feature Data."); tuningThreadFailed = true; tuningThreadDone = true; tuningThreadRunning = false; return; } if (tuningThreadCancelReq) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Process Canceled."); tuningThreadDone = true; tuningThreadRunning = false; return; } AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Feature Data Loaded."); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Checking that Depth Data Exists."); MakeSureDepthFieldIsIncluded(data); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Splitting into separate files."); PicesFeatureVectorList trainData = new PicesFeatureVectorList(); PicesFeatureVectorList testData = new PicesFeatureVectorList(); PicesFeatureVectorList validationData = new PicesFeatureVectorList(); PicesClassList classes = data.ExtractListOfClasses(); if (classes == null) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Could not extract list of classes from data."); tuningThreadFailed = true; tuningThreadDone = true; tuningThreadRunning = false; return; } foreach (PicesClass c in classes) { int trainCount = 0; int testCount = 0; int validationCount = 0; PicesFeatureVectorList examplesForClass = data.ExtractExamplesForAGivenClass(c); int n = examplesForClass.Count; AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Processing Class[" + c.Name + "] Count[" + n + "]"); trainCount = (int)((float)n * trainingDataPercentage / 100.0f + 0.5f); if (trainingDataMaxImagesPerClass > 0) { if (trainCount > trainingDataMaxImagesPerClass) { trainCount = trainingDataMaxImagesPerClass; } } if (validationDataPercentage == 0.0f) { testCount = n - trainCount; } else { testCount = (int)((float)n * testDataPercentage / 100.0f + 0.5f); } validationCount = n - (trainCount + testCount); examplesForClass.RandomizeOrder(); int validationStart = trainCount + testCount; int testStart = trainCount; for (int idx = 0; idx < n; idx++) { PicesFeatureVector fv = examplesForClass[idx]; if (idx >= validationStart) { validationData.Add(fv); } else if (idx >= testStart) { testData.Add(fv); } else { trainData.Add(fv); } } if (tuningThreadCancelReq) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Process Canceled."); break; } } if (!tuningThreadCancelReq) { AddMsgToDialogMsgQueue("\n\n" + DateTime.Now.ToShortTimeString() + " Stratifying Data"); PicesFeatureVectorList trainDataStratified = trainData.StratifyAmoungstClasses(numOfFolds); PicesFeatureVectorList testDataStratified = testData.StratifyAmoungstClasses(numOfFolds); PicesFeatureVectorList validationDataStratified = validationData.StratifyAmoungstClasses(numOfFolds); String rootName = OSservices.AddSlash(destinationDirectory) + OSservices.GetRootName(modelName); if ((trainDataStratified.Count > 0) && (!tuningThreadCancelReq)) { trainDataFileName = rootName + "_Train.data"; AddMsgToDialogMsgQueue("Saving Training Data[" + trainDataFileName + "]"); trainDataStratified.Save(trainDataFileName, "", runLog); } if ((testDataStratified.Count > 0) && (!tuningThreadCancelReq)) { testDataFileName = rootName + "_Test.data"; AddMsgToDialogMsgQueue("Saving Test Data[" + testDataFileName + "]"); testDataStratified.Save(testDataFileName, "", runLog); } if ((validationDataStratified.Count > 0) && (!tuningThreadCancelReq)) { validationDataFileName = rootName + "_Validation.data"; AddMsgToDialogMsgQueue("Saving Validation Data[" + validationDataFileName + "]"); validationDataStratified.Save(validationDataFileName, "", runLog); } } AddMsgToDialogMsgQueue("\n\n"); if (tuningThreadCancelReq) { AddMsgToDialogMsgQueue("Process *** CANCELED ***."); } else { AddMsgToDialogMsgQueue("Process Completed."); } PicesDataBase.ThreadEnd(); tuningThreadDone = true; tuningThreadRunning = false; } /* CreateTuningFeatureFiles */
} /* DialogTimer_Tick */ private void CreateFeatureDataFileThread() { savingThreadRunning = true; PicesDataBase.ThreadInit(); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Started"); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Loading feature data for Model[" + modelName + "]"); config = new PicesTrainingConfigManaged(modelName, runLog); if (!config.Valid()) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Model[" + modelName + "] is invalid."); savingThreadFailed = true; savingThreadDone = true; savingThreadRunning = false; return; } bool changesMade = false; PicesFeatureVectorList data = config.LoadFeatureDataFromTrainingLibraries(changesMade); if (data == null) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Model[" + modelName + "] Count not load Feature Data."); savingThreadFailed = true; savingThreadDone = true; savingThreadRunning = false; return; } if (savingThreadCancelReq) { AddMsgToDialogMsgQueue("\n\n"); AddMsgToDialogMsgQueue("Process Canceled."); savingThreadDone = true; savingThreadRunning = false; return; } AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Feature Data Loaded."); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Checking that Depth Data Exists."); MakeSureDepthFieldIsIncluded(data); AddMsgToDialogMsgQueue(DateTime.Now.ToShortTimeString() + " Splitting into separate files."); if (!savingThreadCancelReq) { data.Save(destinationFileName, FileFormat.Text, runLog); } AddMsgToDialogMsgQueue("\n\n"); if (savingThreadCancelReq) { AddMsgToDialogMsgQueue("Process *** CANCELED ***."); } else { AddMsgToDialogMsgQueue("Process Completed."); } PicesDataBase.ThreadEnd(); savingThreadDone = true; savingThreadRunning = false; } /* CreateFeatureDataFileThread */