/** Train SVM classifier using data from 'data_file' and save trained model to 'model_file' */ void TrainClassifier(const string& data_file, const string& model_file, bool sse_on) { // List of image file names and its labels TFileList file_list; // Structure of images and its labels TDataSet data_set; // Structure of features of images and its labels TFeatures features; // Model which would be trained TModel model; // Parameters of classifier TClassifierParams params; // Load list of image file names and its labels LoadFileList(data_file, &file_list); // Load images LoadImages(file_list, &data_set); // Extract features from images ExtractFeatures(data_set, &features, sse_on); // PLACE YOUR CODE HERE // You can change parameters of classifier here params.C = 0.01; TClassifier classifier(params); // Train classifier classifier.Train(features, &model); // Save model to file model.Save(model_file); // Clear dataset structure ClearDataset(&data_set); }
HOGFeatureClassifier::TModel OptimizeThresholdsInModel(const string &images_list, const string& model_file, RecognitionStatistics &stat) { TModel model; model.Load(model_file); float model_threshold = ImageRecognition::FindOptimalThresholdForModel(images_list, model, stat); model.setModelThreshold(model_threshold); model.Save(model_file); return model; }