|
4 | 4 |
|
5 | 5 | #include "colmap/controllers/matcher_cache.h" |
6 | 6 | #include "colmap/feature/aliked.h" |
| 7 | +#include "colmap/feature/flexglue.h" |
| 8 | +#include "colmap/feature/sift.h" |
| 9 | +#include "colmap/feature/utils.h" |
7 | 10 | #include "colmap/scene/synthetic.h" |
8 | 11 | #include "colmap/sensor/models.h" |
| 12 | +#include "colmap/util/cuda.h" |
9 | 13 | #include "colmap/util/testing.h" |
10 | 14 |
|
11 | 15 | #include <functional> |
@@ -333,19 +337,140 @@ TEST(FeatureMatcherController, SetupPropagatesMatcherCreationErrors) { |
333 | 337 | matching_options.aliked->lightglue.model_path = |
334 | 338 | (data.test_dir / "missing_model.onnx").string(); |
335 | 339 | TwoViewGeometryOptions geometry_options; |
| 340 | +#ifdef COLMAP_ONNX_ENABLED |
| 341 | + const std::string expected_message = "missing_model.onnx"; |
| 342 | +#else |
| 343 | + const std::string expected_message = "requires ONNX support"; |
| 344 | +#endif |
336 | 345 | { |
337 | 346 | FeatureMatcherController controller( |
338 | 347 | matching_options, geometry_options, data.cache); |
339 | 348 | // The worker fails to create the matcher. Setup rethrows its error, and |
340 | 349 | // the controller then destructs without terminating. |
341 | | -#ifdef COLMAP_ONNX_ENABLED |
342 | | - const std::string expected_message = "missing_model.onnx"; |
343 | | -#else |
344 | | - const std::string expected_message = "requires ONNX support"; |
345 | | -#endif |
346 | 350 | EXPECT_THAT(ThrownMessage([&]() { controller.Setup(); }), |
347 | 351 | testing::HasSubstr(expected_message)); |
348 | 352 | } |
| 353 | + |
| 354 | + // Also test SharedFeatureMatcher error propagation across multiple sibling |
| 355 | + // workers: only the creator worker rethrows on Wait(), while sibling workers |
| 356 | + // signal invalid setup and join without throwing. |
| 357 | + { |
| 358 | + JobQueue<FeatureMatcherData> input_queue; |
| 359 | + JobQueue<FeatureMatcherData> output_queue; |
| 360 | + auto shared_matcher = std::make_shared<SharedFeatureMatcher>(); |
| 361 | + std::vector<std::unique_ptr<FeatureMatcherWorker>> workers; |
| 362 | + workers.reserve(3); |
| 363 | + for (int w = 0; w < 3; ++w) { |
| 364 | + workers.push_back( |
| 365 | + std::make_unique<FeatureMatcherWorker>(matching_options, |
| 366 | + geometry_options, |
| 367 | + data.cache, |
| 368 | + &input_queue, |
| 369 | + &output_queue, |
| 370 | + shared_matcher, |
| 371 | + /*is_shared_creator=*/w == 0)); |
| 372 | + } |
| 373 | + for (auto& worker : workers) { |
| 374 | + worker->Start(); |
| 375 | + } |
| 376 | + EXPECT_FALSE(workers[0]->CheckValidSetup()); |
| 377 | + EXPECT_THAT(ThrownMessage([&]() { workers[0]->Wait(); }), |
| 378 | + testing::HasSubstr(expected_message)); |
| 379 | + for (size_t w = 1; w < workers.size(); ++w) { |
| 380 | + EXPECT_FALSE(workers[w]->CheckValidSetup()); |
| 381 | + EXPECT_NO_THROW(workers[w]->Wait()); |
| 382 | + } |
| 383 | + } |
| 384 | + |
| 385 | +#ifdef COLMAP_CUDA_ENABLED |
| 386 | + if (GetNumCudaDevices() > 0) { |
| 387 | + FeatureMatchingOptions flexglue_options(FeatureMatcherType::FLEXGLUE); |
| 388 | + flexglue_options.use_gpu = true; |
| 389 | + flexglue_options.gpu_index = "0"; |
| 390 | + flexglue_options.num_threads = 2; |
| 391 | + flexglue_options.flexglue->image_path = data.test_dir.string(); |
| 392 | + flexglue_options.flexglue->num_workers_per_gpu = 3; |
| 393 | + flexglue_options.flexglue->descriptor_model_path = |
| 394 | + (data.test_dir / "missing_model.onnx").string(); |
| 395 | + FeatureMatcherController controller( |
| 396 | + flexglue_options, geometry_options, data.cache); |
| 397 | + EXPECT_THAT(ThrownMessage([&]() { controller.Setup(); }), |
| 398 | + testing::HasSubstr(expected_message)); |
| 399 | + } |
| 400 | +#endif |
| 401 | +} |
| 402 | + |
| 403 | +TEST(FeatureMatcherController, SharedFeatureMatcherWorkersMatchPairs) { |
| 404 | + auto data = CreateTestData(4); |
| 405 | + data.database->ClearMatches(); |
| 406 | + data.database->ClearTwoViewGeometries(); |
| 407 | + std::vector<FeatureDescriptors> normalized_descriptors; |
| 408 | + normalized_descriptors.reserve(data.image_ids.size()); |
| 409 | + for (const image_t image_id : data.image_ids) { |
| 410 | + FeatureDescriptors desc = data.database->ReadDescriptors(image_id); |
| 411 | + FeatureDescriptorsFloatData float_desc = desc.ToFloat().data; |
| 412 | + L2NormalizeFeatureDescriptors(&float_desc); |
| 413 | + desc.data = FeatureDescriptorsToUnsignedByte(float_desc); |
| 414 | + normalized_descriptors.push_back(std::move(desc)); |
| 415 | + } |
| 416 | + data.database->ClearDescriptors(); |
| 417 | + for (size_t i = 0; i < data.image_ids.size(); ++i) { |
| 418 | + data.database->WriteDescriptors(data.image_ids[i], |
| 419 | + normalized_descriptors[i]); |
| 420 | + } |
| 421 | + data.cache = std::make_shared<FeatureMatcherCache>(100, data.database); |
| 422 | + |
| 423 | + FeatureMatchingOptions matching_options = DefaultMatchingOptions(); |
| 424 | + matching_options.skip_geometric_verification = true; |
| 425 | + // Brute-force SIFT avoids SiftCPUFeatureMatcher's non-thread-safe index |
| 426 | + // cache so the shared matcher is safe across concurrent workers. |
| 427 | + matching_options.sift->cpu_brute_force_matcher = true; |
| 428 | + TwoViewGeometryOptions geometry_options; |
| 429 | + JobQueue<FeatureMatcherData> input_queue; |
| 430 | + JobQueue<FeatureMatcherData> output_queue; |
| 431 | + auto shared_matcher = std::make_shared<SharedFeatureMatcher>(); |
| 432 | + |
| 433 | + std::vector<std::unique_ptr<FeatureMatcherWorker>> workers; |
| 434 | + workers.reserve(3); |
| 435 | + for (int w = 0; w < 3; ++w) { |
| 436 | + workers.push_back( |
| 437 | + std::make_unique<FeatureMatcherWorker>(matching_options, |
| 438 | + geometry_options, |
| 439 | + data.cache, |
| 440 | + &input_queue, |
| 441 | + &output_queue, |
| 442 | + shared_matcher, |
| 443 | + /*is_shared_creator=*/w == 0)); |
| 444 | + workers.back()->Start(); |
| 445 | + } |
| 446 | + for (auto& worker : workers) { |
| 447 | + ASSERT_TRUE(worker->CheckValidSetup()); |
| 448 | + } |
| 449 | + |
| 450 | + const auto pairs = AllPairs(data.image_ids); |
| 451 | + for (const auto& [id1, id2] : pairs) { |
| 452 | + FeatureMatcherData job; |
| 453 | + job.image_id1 = id1; |
| 454 | + job.image_id2 = id2; |
| 455 | + ASSERT_TRUE(input_queue.Push(std::move(job))); |
| 456 | + } |
| 457 | + |
| 458 | + for (size_t i = 0; i < pairs.size(); ++i) { |
| 459 | + auto out = output_queue.Pop(); |
| 460 | + ASSERT_TRUE(out.IsValid()); |
| 461 | + EXPECT_EQ(out.Data().error, nullptr); |
| 462 | + EXPECT_FALSE(out.Data().matches.empty()); |
| 463 | + } |
| 464 | + |
| 465 | + input_queue.Wait(); |
| 466 | + for (auto& worker : workers) { |
| 467 | + worker->Stop(); |
| 468 | + } |
| 469 | + input_queue.Stop(); |
| 470 | + output_queue.Stop(); |
| 471 | + for (auto& worker : workers) { |
| 472 | + worker->Wait(); |
| 473 | + } |
349 | 474 | } |
350 | 475 |
|
351 | 476 | TEST(FeatureMatcherController, MatchSkipGeometricVerification) { |
|
0 commit comments