MCPcopy Create free account
hub / github.com/davisking/dlib / do_test

Function do_test

dlib/test/sequence_segmenter.cpp:178–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176
177 template <bool use_BIO_model, bool use_high_order_features, bool allow_negative_weights>
178 void do_test()
179 {
180 dlog << LINFO << "use_BIO_model: "<< use_BIO_model;
181 dlog << LINFO << "use_high_order_features: "<< use_high_order_features;
182 dlog << LINFO << "allow_negative_weights: "<< allow_negative_weights;
183
184 std::vector<std::vector<unsigned long> > samples;
185 std::vector<std::vector<std::pair<unsigned long,unsigned long> > > segments;
186 make_dataset2( samples, segments, 100);
187
188 print_spinner();
189 typedef unigram_extractor<use_BIO_model,use_high_order_features,allow_negative_weights> fe_type;
190
191 fe_type fe_temp;
192 fe_type fe_temp2;
193 structural_sequence_segmentation_trainer<fe_type> trainer(fe_temp2);
194 trainer.set_c(5);
195 trainer.set_num_threads(1);
196
197
198 sequence_segmenter<fe_type> labeler = trainer.train(samples, segments);
199
200 print_spinner();
201
202 const std::vector<std::pair<unsigned long, unsigned long> > predicted_labels = labeler(samples[1]);
203 const std::vector<std::pair<unsigned long, unsigned long> > true_labels = segments[1];
204 /*
205 for (unsigned long i = 0; i < predicted_labels.size(); ++i)
206 cout << "["<<predicted_labels[i].first<<","<<predicted_labels[i].second<<") ";
207 cout << endl;
208 for (unsigned long i = 0; i < true_labels.size(); ++i)
209 cout << "["<<true_labels[i].first<<","<<true_labels[i].second<<") ";
210 cout << endl;
211 */
212
213 DLIB_TEST(predicted_labels.size() > 0);
214 DLIB_TEST(predicted_labels.size() == true_labels.size());
215 for (unsigned long i = 0; i < predicted_labels.size(); ++i)
216 {
217 DLIB_TEST(predicted_labels[i].first == true_labels[i].first);
218 DLIB_TEST(predicted_labels[i].second == true_labels[i].second);
219 }
220
221
222 matrix<double> res;
223
224 res = cross_validate_sequence_segmenter(trainer, samples, segments, 3);
225 dlog << LINFO << "cv res: "<< res;
226 DLIB_TEST(min(res) > 0.98);
227 make_dataset2( samples, segments, 100);
228 res = test_sequence_segmenter(labeler, samples, segments);
229 dlog << LINFO << "test res: "<< res;
230 DLIB_TEST(min(res) > 0.98);
231
232 print_spinner();
233
234 ostringstream sout;
235 serialize(labeler, sout);

Callers

nothing calls this directly

Calls 14

make_dataset2Function · 0.85
print_spinnerFunction · 0.85
test_sequence_segmenterFunction · 0.85
serializeFunction · 0.70
deserializeFunction · 0.70
minFunction · 0.50
colmFunction · 0.50
set_cMethod · 0.45
set_num_threadsMethod · 0.45
trainMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected