fix(colmap_utils): handle 'images/'-prefixed keys in image_rename_map#3760
fix(colmap_utils): handle 'images/'-prefixed keys in image_rename_map#3760dparikh79 wants to merge 1 commit into
Conversation
colmap_to_json looks up im_data.name (the bare relative name COLMAP was given) in image_rename_map. The map is built by images_to_nerfstudio_dataset.py:78 as keys relative to self.data. When --data points at a directory that contains an images/ subdirectory (a common layout for users running COLMAP externally with --skip-colmap), keys end up prefixed with "images/" while im_data.name is bare, producing a KeyError. Accept both key forms. Bare name takes priority; if not present, try the "images/"-prefixed variant. If neither is present, raise a KeyError with the candidate keys and a sample of the rename map so users can diagnose alternative layouts. Regression test in tests/process_data/test_process_images.py mirrors the existing test_process_images_skip_colmap setup but passes data=tmp_path (the parent of images/) instead of data=tmp_path/"images". The test fails without the fix and passes with it. Fixes nerfstudio-project#3759
|
Quick note on the failing Happy to either (a) leave this PR alone and let the test fix land separately, or (b) include a one-line fix here ( |
Summary
Fixes #3759.
colmap_to_jsonlooks upim_data.nameinimage_rename_mapatcolmap_utils.py:453. The map is built inimages_to_nerfstudio_dataset.py:78asa.relative_to(self.data).as_posix(). When--datapoints at a directory that contains animages/subdirectory (a common layout for users running COLMAP externally and thenns-process-data images --skip-colmap), the keys end up prefixed withimages/while COLMAP'sim_data.nameis the bare path. The result is aKeyErrorbeforetransforms.jsonis written.The reporter's repro uses a cube-rig layout (
<data>/images/rig1/{front,back,left,right,up,down}/...); the same bug surfaces with any layout where the images live one level below--datain animages/directory.Change
nerfstudio/process_data/colmap_utils.py: accept both key forms in theimage_rename_maplookup. Bare name takes priority (preserves the existing happy-path behavior for--datapointing directly at the image dir); falls back to theimages/-prefixed variant. If neither is present, raise a clearKeyErrorwith the candidate keys and a sample of the map so users can diagnose alternative layouts instead of getting a bareKeyErrorfromdict.__getitem__.Test plan
New regression test
test_process_images_data_parent_skip_colmapintests/process_data/test_process_images.py. It mirrors the existingtest_process_images_skip_colmapsetup but:tmp_path/images/, exactly like the existing test.data=tmp_path(the parent ofimages/) toImagesToNerfstudioDataset, instead ofdata=tmp_path/"images"which the existing test uses.That single difference is what triggers #3759. The test fails on
mainwithout this fix (KeyError insidecmd.main()beforetransforms.jsonexists) and passes with the fix.images_to_nerfstudio_dataset.py:77-94(rename-map producer) throughcolmap_converter_to_nerfstudio_dataset.py:136-141(caller) intocolmap_utils.py:451-454(consumer) to confirm the producer/consumer key format mismatch.test_process_images_*cases plus the new regression test. The fix is minimal and the regression test is a copy-paste-and-tweak of the existing test in the same file.Behavior summary
namekey in map:dict.__getitem__semantics unchanged.images/-prefixed key in map: previously raisedKeyError, now resolved.KeyErrorwith no context, now raisesKeyErrornaming both attempted keys + a sample of the map.AI Assistance Disclosure
Diagnosis and the patch were drafted with Claude assistance. I traced the call graph against the repo, confirmed the key-format mismatch by reading both the producer and consumer, and reviewed every changed line. I am the human contributor accountable for this PR.