Skip to content

fix(colmap_utils): handle 'images/'-prefixed keys in image_rename_map#3760

Open
dparikh79 wants to merge 1 commit into
nerfstudio-project:mainfrom
dparikh79:fix/3759-colmap-image-rename-map-keyerror
Open

fix(colmap_utils): handle 'images/'-prefixed keys in image_rename_map#3760
dparikh79 wants to merge 1 commit into
nerfstudio-project:mainfrom
dparikh79:fix/3759-colmap-image-rename-map-keyerror

Conversation

@dparikh79
Copy link
Copy Markdown

Summary

Fixes #3759.

colmap_to_json looks up im_data.name in image_rename_map at colmap_utils.py:453. The map is built in images_to_nerfstudio_dataset.py:78 as a.relative_to(self.data).as_posix(). When --data points at a directory that contains an images/ subdirectory (a common layout for users running COLMAP externally and then ns-process-data images --skip-colmap), the keys end up prefixed with images/ while COLMAP's im_data.name is the bare path. The result is a KeyError before transforms.json is 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 --data in an images/ directory.

Change

nerfstudio/process_data/colmap_utils.py: accept both key forms in the image_rename_map lookup. Bare name takes priority (preserves the existing happy-path behavior for --data pointing directly at the image dir); falls back to the images/-prefixed variant. If neither is present, raise a clear KeyError with the candidate keys and a sample of the map so users can diagnose alternative layouts instead of getting a bare KeyError from dict.__getitem__.

Test plan

New regression test test_process_images_data_parent_skip_colmap in tests/process_data/test_process_images.py. It mirrors the existing test_process_images_skip_colmap setup but:

  • Saves images to tmp_path/images/, exactly like the existing test.
  • Passes data=tmp_path (the parent of images/) to ImagesToNerfstudioDataset, instead of data=tmp_path/"images" which the existing test uses.

That single difference is what triggers #3759. The test fails on main without this fix (KeyError inside cmd.main() before transforms.json exists) and passes with the fix.

  • Added the regression test.
  • Code-read the call graph from images_to_nerfstudio_dataset.py:77-94 (rename-map producer) through colmap_converter_to_nerfstudio_dataset.py:136-141 (caller) into colmap_utils.py:451-454 (consumer) to confirm the producer/consumer key format mismatch.
  • Could not run pytest locally: nerfstudio's full install pulls heavy deps (jaxtyping, av, comet_ml, ipywidgets, jupyterlab). I am relying on CI to run the existing 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

  • Bare name key in map: dict.__getitem__ semantics unchanged.
  • images/-prefixed key in map: previously raised KeyError, now resolved.
  • Neither key in map: previously raised KeyError with no context, now raises KeyError naming 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.

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
@dparikh79
Copy link
Copy Markdown
Author

Quick note on the failing build check: all three pytest failures (test_process_images_skip_colmap, test_process_images_recursively_skip_colmap, and my new test_process_images_data_parent_skip_colmap) fail at the same line inside write_points3D_binary when constructing the mock Point3D with error=np.array([0]). The two existing tests are unchanged by this PR and the last Core Tests run on main (sha dab57f5e, 2026-05-03) also reports conclusion=failure, so this looks like a pre-existing numpy-version regression in the test fixture, not a regression from this PR.

Happy to either (a) leave this PR alone and let the test fix land separately, or (b) include a one-line fix here (error=np.array([0.0]) -> error=0.0 or similar in the three test setups) if a maintainer prefers a single PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

colmap_to_json KeyError

1 participant