| 223 | }; |
| 224 | |
| 225 | bool |
| 226 | pcl::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_, ¶m_); |
| 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_, ¶m_)); |
| 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 | |
| 270 | bool |
| 271 | pcl::SVM::loadProblem(const char* filename, svm_problem& prob) |
nothing calls this directly
no test coverage detected