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

Function test_adaptive_computation_time_network

dlib/test/dnn.cpp:1442–1488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1440// ----------------------------------------------------------------------------------------
1441
1442 void test_adaptive_computation_time_network()
1443 {
1444 print_spinner();
1445
1446 // Test with a simple network containing ACT layer
1447 using net_type = tag1<act<input<matrix<float>>>>;
1448 net_type net;
1449
1450 // Create test data
1451 std::vector<matrix<float>> training_images;
1452 const int seq_len = 4, d_model = 3;
1453
1454 matrix<float> sample(seq_len, d_model);
1455 dlib::rand rnd(54321);
1456
1457 for (int i = 0; i < 10; ++i)
1458 {
1459 for (int r = 0; r < seq_len; ++r)
1460 for (int c = 0; c < d_model; ++c)
1461 sample(r, c) = rnd.get_random_gaussian();
1462 training_images.push_back(sample);
1463 }
1464
1465 // Convert to tensor and run forward pass
1466 resizable_tensor input_tensor;
1467 net.to_tensor(&training_images[0], &training_images[0] + training_images.size(), input_tensor);
1468
1469 // Forward pass
1470 net.forward(input_tensor);
1471
1472 // Get output and verify dimensions
1473 const tensor& output = net.get_output();
1474 DLIB_TEST(output.num_samples() == training_images.size());
1475 DLIB_TEST(output.nr() == seq_len);
1476 DLIB_TEST(output.nc() == d_model);
1477
1478 // Access the ACT layer for statistics
1479 auto& act_layer = layer<tag1>(net).subnet().layer_details();
1480 dlog << LINFO << "Network ACT ponder cost: " << act_layer.get_ponder_cost();
1481 dlog << LINFO << "Network ACT average steps: " << act_layer.get_average_steps();
1482
1483 // Verify reasonable statistics
1484 DLIB_TEST(act_layer.get_ponder_cost() >= 0.0f && act_layer.get_ponder_cost() <= 1.0f);
1485 DLIB_TEST(act_layer.get_average_steps() >= 1.0f);
1486
1487 dlog << LINFO << "ACT network tests completed successfully";
1488 }
1489
1490// ----------------------------------------------------------------------------------------
1491

Callers 1

run_testsMethod · 0.85

Calls 11

print_spinnerFunction · 0.85
get_random_gaussianMethod · 0.80
get_ponder_costMethod · 0.80
get_average_stepsMethod · 0.80
push_backMethod · 0.45
to_tensorMethod · 0.45
sizeMethod · 0.45
forwardMethod · 0.45
num_samplesMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45

Tested by

no test coverage detected