cvg / pixel-perfect-sfm

Pixel-Perfect Structure-from-Motion with Featuremetric Refinement (ICCV 2021, Best Student Paper Award)
Apache License 2.0
1.29k stars 132 forks source link

[HOW TO] Serialize References obtained during BA #74

Closed ThomasParistech closed 1 year ago

ThomasParistech commented 1 year ago

I first run a triangulation with Bundle Adjustment on my PixSfM model and then call the QueryLocalizer to localize an image within it.

However, (for specific reasons) I need to do this in two separate Python runs but want to avoid the computational cost of re-extracting the features references at the QueryLocalizer init.

Here's what I do:

reconstruction, outputs = refiner.triangulation(...

...

reconstruction = pycolmap.Reconstruction(model_folder)
feature_manager_path = Path(model_folder) / "s2dnet_featuremaps_sparse.h5"
dense_features = load_features_from_cache(feature_manager_path)
localizer = QueryLocalizer(reconstruction, conf, dense_features=dense_features)

I'd prefer to use the constructor below directly to skip the redundant extraction. But I don't see how to serialize the references I got during triangulation: outputs["BA"]["references"]

QueryLocalizer(conf, reconstruction, references=references)

The bindings don't provide a constructor for "Reference" and its attributes aren't pickable.

Do you have any advice?

Many thanks :)

Phil26AT commented 1 year ago

Hi @ThomasParistech,

indeed this use case is not supported atm, but would be great to have. I think this should be quite simple to implement, just make reference a dataclass (like here), add a setter for Reference.descriptor, and then implement loading/writing references from a separate .h5 file in python. If you have time to implement this please submit a PR, otherwise I can have a look into it soon.

ThomasParistech commented 1 year ago

Thanks for the fast reply, Sounds great. To be honest I posted the issue just before one week off. I'll have a look when I come back :)

ThomasParistech commented 1 year ago

Hi @Phil26AT, I submitted a PR: https://github.com/cvg/pixel-perfect-sfm/pull/76