Skip to content

Commit

Permalink
make sure colmap-formatted files are sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
senselessdev1 authored and senselessdev1 committed Aug 16, 2023
1 parent bfabf5a commit ab54930
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
9 changes: 6 additions & 3 deletions .github/scripts/execute_single_benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ fi
if [ "$LOADER_NAME" == "olsson-loader" ]; then
python gtsfm/runner/run_scene_optimizer_olssonloader.py \
--dataset_root $DATASET_ROOT \
--config_name ${CONFIG_NAME}.yaml \
--config_name unified \
--correspondence_generator_config_name ${CONFIG_NAME} \
--max_frame_lookahead $MAX_FRAME_LOOKAHEAD \
--max_resolution ${MAX_RESOLUTION} \
${SHARE_INTRINSICS_ARG} \
Expand All @@ -61,7 +62,8 @@ elif [ "$LOADER_NAME" == "colmap-loader" ]; then
python gtsfm/runner/run_scene_optimizer_colmaploader.py \
--images_dir ${IMAGES_DIR} \
--colmap_files_dirpath $COLMAP_FILES_DIRPATH \
--config_name ${CONFIG_NAME}.yaml \
--config_name unified \
--correspondence_generator_config_name ${CONFIG_NAME} \
--max_frame_lookahead $MAX_FRAME_LOOKAHEAD \
--max_resolution ${MAX_RESOLUTION} \
${SHARE_INTRINSICS_ARG} \
Expand All @@ -70,7 +72,8 @@ elif [ "$LOADER_NAME" == "colmap-loader" ]; then
elif [ "$LOADER_NAME" == "astrovision" ]; then
python gtsfm/runner/run_scene_optimizer_astrovision.py \
--data_dir $DATASET_ROOT \
--config_name ${CONFIG_NAME}.yaml \
--config_name unified \
--correspondence_generator_config_name ${CONFIG_NAME} \
--max_frame_lookahead $MAX_FRAME_LOOKAHEAD \
--max_resolution ${MAX_RESOLUTION} \
${SHARE_INTRINSICS_ARG} \
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
config_dataset_info:
[
# config dataset lookahead img-extension source loader max-res share-intrinsics
[unified, door-12, 10, JPG, test_data, olsson-loader, 1296, true],
[unified, door-12, 10, JPG, test_data, olsson-loader, 1296, true],
[unified, skydio-8, 10, jpg, gdrive , colmap-loader, 760, true],
[unified, skydio-8, 10, jpg, gdrive, colmap-loader, 760, true],
[unified, skydio-32, 10, jpg, gdrive, colmap-loader, 760, true],
[unified, skydio-32, 10, jpg, gdrive, colmap-loader, 760, true],
[unified, palace-fine-arts-281, 10, jpg, wget, olsson-loader, 320, true],
[unified, notre-dame-20, 10, jpg, gdrive, colmap-loader, 760, false],
[unified, 2011205_rc3, 10, png, wget, astrovision, 1024, true],
[unified, 2011205_rc3, 10, png, wget, astrovision, 1024, true],
[unified, gerrard-hall-100, 10, jpg, wget, colmap-loader, 760, true],
[unified, gerrard-hall-100, 10, jpg, wget, colmap-loader, 760, true],
[unified, south-building-128, 10, jpg, wget, colmap-loader, 760, true],
[unified, south-building-128, 10, jpg, wget, colmap-loader, 760, true],
[sift, door-12, 10, JPG, test_data, olsson-loader, 1296, true],
[lightglue, door-12, 10, JPG, test_data, olsson-loader, 1296, true],
[sift, skydio-8, 10, jpg, gdrive , colmap-loader, 760, true],
[lightglue, skydio-8, 10, jpg, gdrive, colmap-loader, 760, true],
[sift, skydio-32, 10, jpg, gdrive, colmap-loader, 760, true],
[lightglue, skydio-32, 10, jpg, gdrive, colmap-loader, 760, true],
[sift, palace-fine-arts-281, 10, jpg, wget, olsson-loader, 320, true],
[lightglue, notre-dame-20, 10, jpg, gdrive, colmap-loader, 760, false],
[sift, 2011205_rc3, 10, png, wget, astrovision, 1024, true],
[lightglue, 2011205_rc3, 10, png, wget, astrovision, 1024, true],
[sift, gerrard-hall-100, 10, jpg, wget, colmap-loader, 760, true],
[lightglue, gerrard-hall-100, 10, jpg, wget, colmap-loader, 760, true],
[sift, south-building-128, 10, jpg, wget, colmap-loader, 760, true],
[lightglue, south-building-128, 10, jpg, wget, colmap-loader, 760, true],
]
defaults:
run:
Expand Down
16 changes: 15 additions & 1 deletion gtsfm/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,20 @@ def read_images_txt(fpath: str) -> Tuple[Optional[List[Pose3]], Optional[List[st
wTi_list.append(wTi)
img_fnames.append(img_fname)

return wTi_list, img_fnames
# TODO(johnwlambert): Re-order tracks for COLMAP-formatted .bin files.
wTi_list_sorted, img_fnames_sorted = sort_image_filenames_lexigraphically(wTi_list, img_fnames)

return wTi_list_sorted, img_fnames_sorted


def sort_image_filenames_lexigraphically(wTi_list: List[Pose3], img_fnames: List[str]) -> Tuple[List[Pose3], List[str]]:
"""Sort a list of camera poses according to provided image file names."""
sorted_idxs = sorted(range(len(img_fnames)), key=lambda i: img_fnames[i])

wTi_list_sorted = [wTi_list[i] for i in sorted_idxs]
img_fnames_sorted = [img_fnames[i] for i in sorted_idxs]

return wTi_list_sorted, img_fnames_sorted


def write_images(gtsfm_data: GtsfmData, images: List[Image], save_dir: str) -> None:
Expand Down Expand Up @@ -503,6 +516,7 @@ def read_scene_data_from_colmap_format(

if any(x is None for x in [wTi_list, img_fnames, calibrations, point_cloud, rgb]):
raise RuntimeError("One or more of the requested model data products was not found.")
print(f"Loaded {len(wTi_list)} cameras with {point_cloud.shape[0]} points.")
return wTi_list, img_fnames, calibrations, point_cloud, rgb


Expand Down
22 changes: 22 additions & 0 deletions tests/utils/test_io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,28 @@ def test_json_roundtrip(self) -> None:
self.assertEqual(data_from_json["data"][0], None)
np.testing.assert_allclose(data["data"][1:], data_from_json["data"][1:])

def test_sort_image_filenames_lexigraphically(self) -> None:
"""Tests that 5 image-camera pose pairs are sorted jointly according tp file name."""
wTi_list = [
Pose3(Rot3(), np.array([0,0,34])),
Pose3(Rot3(), np.array([0,0,35])),
Pose3(Rot3(), np.array([0,0,36])),
Pose3(Rot3(), np.array([0,0,28])),
Pose3(Rot3(), np.array([0,0,37]))
]
img_fnames = ['P1180334.JPG', 'P1180335.JPG', 'P1180336.JPG', 'P1180328.JPG', 'P1180337.JPG']

wTi_list_sorted, img_fnames_sorted = io_utils.sort_image_filenames_lexigraphically(wTi_list, img_fnames)

expected_img_fnames_sorted = ['P1180328.JPG', 'P1180334.JPG', 'P1180335.JPG', 'P1180336.JPG', 'P1180337.JPG']
self.assertEqual(img_fnames_sorted, expected_img_fnames_sorted)

self.assertEqual(wTi_list_sorted[0].translation()[2], 28)
self.assertEqual(wTi_list_sorted[1].translation()[2], 34)
self.assertEqual(wTi_list_sorted[2].translation()[2], 35)
self.assertEqual(wTi_list_sorted[3].translation()[2], 36)
self.assertEqual(wTi_list_sorted[4].translation()[2], 37)


if __name__ == "__main__":
unittest.main()

0 comments on commit ab54930

Please sign in to comment.