cvg / Hierarchical-Localization

Visual localization made easy with hloc
Apache License 2.0
3.13k stars 581 forks source link

Check failed: bundle_adjuster.Solve(&reconstruction) #177

Open YouyangShen opened 2 years ago

YouyangShen commented 2 years ago

Hi, @Skydes. I am trying my own feature extractor and matcher on Aachen dataset by following the pipeline. When I run triangulation, I have this problem as below: I look it up in the issues and you labeled this as a bug in https://github.com/cvg/Hierarchical-Localization/issues/20#issuecomment-694864147. In the messages below, while it run triangulation, it load 0 matches. Do you have any idea how to fix it?

[2022/04/03 11:03:47 hloc INFO] Importing features into the database...
100%|██████████████████████████████████████████████████████████████████████████████| 4328/4328 [00:41<00:00, 105.54it/s]
[2022/04/03 11:04:28 hloc INFO] Importing matches into the database...
100%|████████████████████████████████████████████████████████████████████████████| 85515/85515 [09:24<00:00, 151.50it/s]
[2022/04/03 11:13:53 hloc INFO] Performing geometric verification of the matches...

==============================================================================
Custom feature matching
==============================================================================

Matching block [1/47] in 0.016s
Matching block [2/47] in 0.015s
Matching block [3/47] in 0.015s
Matching block [4/47] in 0.014s
Matching block [5/47] in 0.015s
Matching block [6/47] in 0.016s
Matching block [7/47] in 0.015s
Matching block [8/47] in 0.014s
Matching block [9/47] in 0.016s
Matching block [10/47] in 0.015s
Matching block [11/47] in 0.014s
Matching block [12/47] in 0.015s
Matching block [13/47] in 0.015s
Matching block [14/47] in 0.014s
Matching block [15/47] in 0.014s
Matching block [16/47] in 0.016s
Matching block [17/47] in 0.014s
Matching block [18/47] in 0.014s
Matching block [19/47] in 0.015s
Matching block [20/47] in 0.015s
Matching block [21/47] in 0.015s
Matching block [22/47] in 0.015s
Matching block [23/47] in 0.016s
Matching block [24/47] in 0.016s
Matching block [25/47] in 0.015s
Matching block [26/47] in 0.015s
Matching block [27/47] in 0.015s
Matching block [28/47] in 0.015s
Matching block [29/47] in 0.016s
Matching block [30/47] in 0.015s
Matching block [31/47] in 0.015s
Matching block [32/47] in 0.015s
Matching block [33/47] in 0.016s
Matching block [34/47] in 0.017s
Matching block [35/47] in 0.016s
Matching block [36/47] in 0.018s
Matching block [37/47] in 0.017s
Matching block [38/47] in 0.016s
Matching block [39/47] in 0.018s
Matching block [40/47] in 0.016s
Matching block [41/47] in 0.016s
Matching block [42/47] in 0.017s
Matching block [43/47] in 0.021s
Matching block [44/47] in 0.019s
Matching block [45/47] in 0.017s
Matching block [46/47] in 0.018s
Matching block [47/47] in 0.008s
Elapsed time: 0.030 [minutes]
[2022/04/03 11:13:55 hloc INFO] Running 3D triangulation...
Loading cameras... 4328 in 0.004s
Loading matches... 0 in 0.004s
Loading images... 4328 in 0.005s (connected 0)
Building correspondence graph... in 0.000s (ignored 0)

==============================================================================
Retriangulation
==============================================================================

  => Completed observations: 0
  => Merged observations: 0
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0403 11:13:58.770174  4382 pipeline.cc:237] Check failed: bundle_adjuster.Solve(&reconstruction)
*** Check failure stack trace: ***
jobscript.sh: line 17:  4382 Aborted                 python -m hloc.pipelines.Aachen.pipeline_changed --outputs ./outputs/aachen
sarlinpe commented 2 years ago

The error message seems unrelated to the issue that you link. Can you please add a breakpoint in import_matches and check that the matches are correct? https://github.com/cvg/Hierarchical-Localization/blob/e8ea8a25b297bae2e058abfb294335219d9f55ad/hloc/triangulation.py#L75-L79 You can also compute statistics on the number of keypoints and matches per image or read the database to check the matches:

from hloc.utils.viz import plot_images, plot_matches
from hloc.utils.database import COLMAPDatabase, pair_id_to_image_ids, blob_to_array
db = COLMAPDatabase.connect('path/to/database.db')
keypoints = {
    i: blob_to_array(data, np.float32, (r, c))[:, :2]
    for i, r, c, data in db.execute('SELECT * FROM keypoints')}
matches = {
    pair_id_to_image_ids(pid): blob_to_array(data, np.uint32, (r, c)
    for pid, r, c, data in db.execute('SELECT pair_id, rows, cols, data FROM two_view_geometries')
    if data is not None}
for id0, id1 in list(matches)[::5][:10]:
    assert id1 > id0
    m = matches[id0, id1]
    plot_images([read_image(image_dir / rec.images[i].name) for i in (id0, id1)], titles=[len(m), ''])
    plot_matches(keypoints[id0][m[:, 0]], keypoints[id1][m[:, 1]])