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

Function test_loss_dot

dlib/test/dnn.cpp:5335–5371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5333// ----------------------------------------------------------------------------------------
5334
5335 void test_loss_dot()
5336 {
5337 print_spinner();
5338
5339 std::vector<matrix<float,0,1>> samples;
5340 std::vector<matrix<float,0,1>> labels;
5341
5342 const matrix<float> proj = matrix_cast<float>(randm(2,3));
5343 for (int i = 0; i < 128; ++i)
5344 {
5345 // The task is going to be to learn the matrix proj. So we make our
5346 // training data thusly:
5347 matrix<float,0,1> x = matrix_cast<float>(randm(3,1));
5348 matrix<float,0,1> y = normalize(proj*x);
5349 samples.push_back(x);
5350 labels.push_back(y);
5351 }
5352
5353 using net_type = loss_dot<
5354 l2normalize<fc_no_bias<2,
5355 input<matrix<float,0,1>>
5356 >>>;
5357
5358 net_type net;
5359 dnn_trainer<net_type> trainer(net, sgd(1e-4, 0.9));
5360 trainer.set_learning_rate(0.01);
5361 trainer.set_min_learning_rate(0.0000001);
5362 trainer.set_mini_batch_size(128);
5363 trainer.set_max_num_epochs(50000);
5364 trainer.train(samples, labels);
5365
5366
5367 for (size_t i = 0; i < samples.size(); ++i)
5368 {
5369 DLIB_TEST(std::abs(1-dot(net(samples[i]),labels[i])) < 0.001);
5370 }
5371 }
5372
5373// ----------------------------------------------------------------------------------------
5374

Callers 1

run_testsMethod · 0.85

Calls 13

print_spinnerFunction · 0.85
absFunction · 0.85
set_learning_rateMethod · 0.80
set_min_learning_rateMethod · 0.80
set_mini_batch_sizeMethod · 0.80
set_max_num_epochsMethod · 0.80
randmFunction · 0.70
normalizeFunction · 0.50
sgdClass · 0.50
dotFunction · 0.50
push_backMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected