MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / trainClassifier

Method trainClassifier

ml/src/svm_wrapper.cpp:225–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223};
224
225bool
226pcl::SVMTrain::trainClassifier()
227{
228 if (training_set_.empty()) {
229 // to be sure to have loaded the training set
230 PCL_ERROR("[pcl::%s::trainClassifier] Training data not set!\n",
231 getClassName().c_str());
232 return false;
233 }
234
235 scaleFactors(training_set_, scaling_);
236 adaptInputToLibSVM(training_set_, prob_);
237
238 const char* error_msg;
239 error_msg = svm_check_parameter(&prob_, &param_);
240
241 // initialize gamma parameter
242
243 if (param_.gamma == 0 && scaling_.max > 0)
244 param_.gamma = 1.0 / scaling_.max;
245
246 if (error_msg) {
247 PCL_ERROR("[pcl::%s::trainClassifier] %s\n", getClassName().c_str(), error_msg);
248 // fprintf (stderr, "ERROR: %s\n", error_msg);
249 exit(1);
250 }
251
252 if (cross_validation_) {
253 doCrossValidation();
254 }
255 else {
256 auto* out = reinterpret_cast<SVMModel*>(svm_train(&prob_, &param_));
257 if (out == nullptr) {
258 PCL_ERROR("[pcl::%s::trainClassifier] Error taining the classifier model.\n",
259 getClassName().c_str());
260 return false;
261 }
262 model_ = *out;
263 model_.scaling = scaling_.obj;
264 free(out);
265 }
266
267 return true;
268}
269
270bool
271pcl::SVM::loadProblem(const char* filename, svm_problem& prob)

Callers

nothing calls this directly

Calls 4

svm_check_parameterFunction · 0.85
svm_trainFunction · 0.85
getClassNameFunction · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected