-
Notifications
You must be signed in to change notification settings - Fork 63
[skip benchmarks]Dissected pipeline #1057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nantonzhang
wants to merge
20
commits into
master
Choose a base branch
from
dissected_pipeline
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e6ed39f
initialize the pipeline
nantonzhang c66827c
make the metrics percentage based
nantonzhang 1da4fb2
add stand-alone vggt runner
nantonzhang 58b2080
add scripts for track quality checking
nantonzhang a60c19a
add scripts to the dissected pipeline
nantonzhang 9ae4e35
move necessary functions into this file
nantonzhang 694a42c
add script for eth3dmvs dataset
nantonzhang cff7816
add single partition
nantonzhang 6911e02
add support for camera w/o measurement
nantonzhang d15c5d8
make the script error tolerent
nantonzhang fff1f4f
Merge branch 'master' into dissected_pipeline
nantonzhang 05b85ea
add a traditional tracker
nantonzhang 0582f8f
add colmap tracker
nantonzhang 9779d2e
Merge branch 'master' into dissected_pipeline
nantonzhang 2049acd
Merge branch 'master' into dissected_pipeline
nantonzhang 7e3b870
syn with master
nantonzhang 3fbb76f
Merge branch 'master' into dissected_pipeline
nantonzhang 9cfacc2
rename the file
nantonzhang 95b89fc
Add Pi3 as submodule under thirdparty/Pi3
nantonzhang 0b4eb91
add pi3 in the pipeline
nantonzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,26 @@ | |
| import gtsfm.utils.logger as logger_utils | ||
| import gtsfm.utils.metrics as metric_utils | ||
| from gtsfm.cluster_optimizer import save_metrics_reports | ||
| from gtsfm.evaluation.metrics import GtsfmMetricsGroup | ||
| from gtsfm.evaluation.metrics import GtsfmMetric, GtsfmMetricsGroup | ||
| from gtsfm.utils import align, transform | ||
|
|
||
| logger = logger_utils.get_logger() | ||
|
|
||
|
|
||
| def _is_auc_metric_name(metric_name: str) -> bool: | ||
| return metric_name.startswith("pose_auc_@") | ||
|
|
||
|
|
||
| def _convert_scalar_auc_metrics_to_percent(metrics: List[GtsfmMetric]) -> List[GtsfmMetric]: | ||
| converted_metrics: List[GtsfmMetric] = [] | ||
| for metric in metrics: | ||
| if metric.dim == 0 and _is_auc_metric_name(metric.name) and metric.data is not None: | ||
| converted_metrics.append(GtsfmMetric(metric.name, float(metric.data) * 100.0)) | ||
| else: | ||
| converted_metrics.append(metric) | ||
| return converted_metrics | ||
|
|
||
|
|
||
| def load_poses(colmap_dirpath: str) -> Dict[str, Pose3]: | ||
| """Returns mapping from image filename to associated camera pose.""" | ||
| wTi_list, img_fnames, _, _, _, _ = io_utils.read_scene_data_from_colmap_format(colmap_dirpath) | ||
|
|
@@ -145,7 +159,7 @@ def export_metrics_group_to_csv(metrics_group: GtsfmMetricsGroup, output_path: s | |
| def _format_pose_auc(metrics_group: GtsfmMetricsGroup) -> str: | ||
| auc_parts = [] | ||
| for metric in metrics_group.metrics: | ||
| if not metric.name.startswith("pose_auc_@"): | ||
| if not _is_auc_metric_name(metric.name): | ||
| continue | ||
| if metric.data is None: | ||
| continue | ||
|
|
@@ -154,7 +168,7 @@ def _format_pose_auc(metrics_group: GtsfmMetricsGroup) -> str: | |
| except (TypeError, ValueError): | ||
| continue | ||
| suffix = metric.name.replace("pose_auc_", "") | ||
| auc_parts.append(f"{suffix}={value:.3f}") | ||
| auc_parts.append(f"{suffix}={value:.2f}%") | ||
| return ", ".join(auc_parts) | ||
|
|
||
|
|
||
|
|
@@ -218,11 +232,11 @@ def compare_poses(baseline_dirpath: str, eval_dirpath: str, output_dirpath: str) | |
|
|
||
| rotation_angular_errors = relative_rotation_error_metric.data | ||
| translation_angular_errors = relative_translation_error_metric.data | ||
| metrics.extend( | ||
| metric_utils.compute_pose_auc_metric( | ||
| rotation_angular_errors, translation_angular_errors, save_dir=output_dirpath | ||
| ) | ||
| pose_auc_metrics = metric_utils.compute_pose_auc_metric( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update this method to return percent values? |
||
| rotation_angular_errors, translation_angular_errors, save_dir=output_dirpath | ||
| ) | ||
| pose_auc_metrics = _convert_scalar_auc_metrics_to_percent(pose_auc_metrics) | ||
| metrics.extend(pose_auc_metrics) | ||
|
|
||
| ba_pose_metrics = GtsfmMetricsGroup(name="ba_pose_error_metrics", metrics=metrics) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,32 @@ | |
| logger = logger_utils.get_logger() | ||
|
|
||
|
|
||
| def _is_auc_metric_name(metric_name: str) -> bool: | ||
| return ( | ||
| metric_name.startswith("pose_auc_@") | ||
| or metric_name.startswith("rotation_auc_@") | ||
| or metric_name.startswith("translation_auc_@") | ||
| ) | ||
|
|
||
|
|
||
| def _convert_scalar_auc_metrics_to_percent(metrics: List[GtsfmMetric]) -> List[GtsfmMetric]: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate (but also unnecessary) function |
||
| converted_metrics: List[GtsfmMetric] = [] | ||
| for metric in metrics: | ||
| if metric.dim == 0 and _is_auc_metric_name(metric.name) and metric.data is not None: | ||
| converted_metrics.append(GtsfmMetric(metric.name, float(metric.data) * 100.0)) | ||
| else: | ||
| converted_metrics.append(metric) | ||
| return converted_metrics | ||
|
|
||
|
|
||
| def _build_short_cluster_plot_filename(recon_dir: Path, root: Path) -> str: | ||
| """Build filename as '<cluster>__<recon_name>_camera_centers.png'.""" | ||
| del root # not needed after simplifying naming policy | ||
| cluster_name = recon_dir.parent.name or "cluster" | ||
| recon_name = recon_dir.name or "recon" | ||
| return f"{cluster_name}__{recon_name}_camera_centers.png" | ||
|
|
||
|
|
||
| def _read_images_txt_with_names(images_txt: Path) -> Dict[str, Pose3]: | ||
| """Read poses from COLMAP images.txt keyed by image NAME.""" | ||
| if not images_txt.exists(): | ||
|
|
@@ -200,7 +226,7 @@ def _compute_pose_metrics(baseline_list: List[Pose3], current_aligned_list: List | |
| rotation_auc_values = metric_utils.pose_auc(rotation_angular_errors, thresholds_deg) | ||
| metrics.extend( | ||
| [ | ||
| GtsfmMetric(f"rotation_auc_@{threshold}_deg", auc) | ||
| GtsfmMetric(f"rotation_auc_@{threshold}_deg", float(auc) * 100.0) | ||
| for threshold, auc in zip(thresholds_deg, rotation_auc_values) | ||
| ] | ||
| ) | ||
|
|
@@ -209,15 +235,15 @@ def _compute_pose_metrics(baseline_list: List[Pose3], current_aligned_list: List | |
| translation_auc_values = metric_utils.pose_auc(translation_angular_errors, thresholds_deg) | ||
| metrics.extend( | ||
| [ | ||
| GtsfmMetric(f"translation_auc_@{threshold}_deg", auc) | ||
| GtsfmMetric(f"translation_auc_@{threshold}_deg", float(auc) * 100.0) | ||
| for threshold, auc in zip(thresholds_deg, translation_auc_values) | ||
| ] | ||
| ) | ||
| metrics.extend( | ||
| metric_utils.compute_pose_auc_metric( | ||
| relative_rotation_error_metric.data, relative_translation_error_metric.data, thresholds_deg=thresholds_deg | ||
| ) | ||
| pose_auc_metrics = metric_utils.compute_pose_auc_metric( | ||
| relative_rotation_error_metric.data, relative_translation_error_metric.data, thresholds_deg=thresholds_deg | ||
| ) | ||
| pose_auc_metrics = _convert_scalar_auc_metrics_to_percent(pose_auc_metrics) | ||
| metrics.extend(pose_auc_metrics) | ||
|
|
||
| return GtsfmMetricsGroup(name="ba_pose_error_metrics", metrics=metrics) | ||
|
|
||
|
|
@@ -440,14 +466,14 @@ def _plot_pose_auc_boxplot(auc_values_by_label: Dict[str, List[float]], output_p | |
| ax = fig.add_subplot(111) | ||
| ax.boxplot(data, vert=True, patch_artist=True) | ||
| ax.set_title(title) | ||
| ax.set_ylabel("AUC") | ||
| ax.set_ylabel("AUC (%)") | ||
| ax.set_xticks(range(1, len(labels) + 1)) | ||
| ax.set_xticklabels(labels, rotation=30, ha="right") | ||
| stats_lines = [] | ||
| for label, values in zip(labels, data): | ||
| mean_val = float(np.mean(values)) | ||
| median_val = float(np.median(values)) | ||
| stats_lines.append(f"{label}: mean={mean_val:.3f}, med={median_val:.3f}") | ||
| stats_lines.append(f"{label}: mean={mean_val:.2f}%, med={median_val:.2f}%") | ||
| if stats_lines: | ||
| ax.text( | ||
| 0.02, | ||
|
|
@@ -488,7 +514,7 @@ def _plot_pose_auc_vs_input_images( | |
|
|
||
| ax.set_title("Pose AUC vs input images (all clusters)") | ||
| ax.set_xlabel("input images (current count)") | ||
| ax.set_ylabel("AUC") | ||
| ax.set_ylabel("AUC (%)") | ||
| ax.grid(True, linestyle="--", linewidth=0.5, alpha=0.5) | ||
| ax.legend(loc="best", fontsize=8) | ||
| fig.tight_layout() | ||
|
|
@@ -596,7 +622,7 @@ def _format_auc(metrics_group: GtsfmMetricsGroup, prefix: str) -> str: | |
| except (TypeError, ValueError): | ||
| continue | ||
| suffix = metric.name.replace(f"{prefix}_", "") | ||
| auc_parts.append(f"{suffix}={value:.3f}") | ||
| auc_parts.append(f"{suffix}={value:.2f}%") | ||
| return ", ".join(auc_parts) | ||
|
|
||
|
|
||
|
|
@@ -832,8 +858,7 @@ def main() -> None: | |
| else: | ||
| _print_metrics(str(recon_dir), metrics_group) | ||
| if fig_output_dir is not None: | ||
| safe_name = str(recon_dir).replace(os.sep, "__") | ||
| plot_path = fig_output_dir / f"{safe_name}_camera_centers.png" | ||
| plot_path = fig_output_dir / _build_short_cluster_plot_filename(recon_dir, root) | ||
| pose_auc_text = _format_auc(metrics_group, "pose_auc") | ||
| rotation_auc_text = _format_auc(metrics_group, "rotation_auc") | ||
| translation_auc_text = _format_auc(metrics_group, "translation_auc") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| """Run MegaLoc retrieval + METIS partitioning and persist the visibility graph + cluster tree. | ||
|
|
||
| This script mirrors the image_pairs_generator and graph_partitioner configuration in | ||
| `gtsfm/configs/vggt.yaml`. It loads images, generates a visibility graph, partitions | ||
| the graph with METIS, and saves both the graph and tree under the chosen output root. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import pickle | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import hydra | ||
| from dask.distributed import Client, LocalCluster | ||
| from hydra.utils import instantiate | ||
|
|
||
| import gtsfm.utils.logger as logger_utils | ||
| from gtsfm.common.outputs import OutputPaths, prepare_output_paths | ||
| from gtsfm.graph_partitioner.graph_partitioner_base import GraphPartitionerBase | ||
| from gtsfm.graph_partitioner.single_partitioner import SinglePartitioner | ||
| from gtsfm.loader.loader_base import LoaderBase | ||
| from gtsfm.products.visibility_graph import VisibilityGraph | ||
| from gtsfm.retriever.image_pairs_generator import ImagePairsGenerator | ||
|
|
||
| logger = logger_utils.get_logger() | ||
|
|
||
|
|
||
| def _build_components( | ||
| config_name: str, | ||
| dataset_dir: str, | ||
| images_dir: str | None, | ||
| max_resolution: int | None, | ||
| ) -> tuple[LoaderBase, ImagePairsGenerator, GraphPartitionerBase]: | ||
| overrides: list[str] = [f"loader.dataset_dir={dataset_dir}"] | ||
| if images_dir is not None: | ||
| overrides.append(f"loader.images_dir={images_dir}") | ||
| if max_resolution is not None: | ||
| overrides.append(f"loader.max_resolution={max_resolution}") | ||
|
|
||
| with hydra.initialize_config_module(config_module="gtsfm.configs", version_base=None): | ||
| cfg = hydra.compose(config_name=config_name, overrides=overrides) | ||
|
|
||
| loader: LoaderBase = instantiate(cfg.loader) | ||
| image_pairs_generator: ImagePairsGenerator = instantiate(cfg.image_pairs_generator) | ||
| graph_partitioner: GraphPartitionerBase = instantiate(cfg.graph_partitioner) | ||
| return loader, image_pairs_generator, graph_partitioner | ||
|
|
||
|
|
||
| def _run_retriever( | ||
| client: Client, loader: LoaderBase, image_pairs_generator: ImagePairsGenerator, output_paths: OutputPaths | ||
| ) -> VisibilityGraph: | ||
| start_time = time.time() | ||
| batch_size = image_pairs_generator._batch_size | ||
| transforms = image_pairs_generator.get_preprocessing_transforms() | ||
| image_batch_futures = loader.get_all_descriptor_image_batches_as_futures(client, batch_size, *transforms) | ||
| image_fnames = loader.image_filenames() | ||
|
|
||
| logger.info("🔥 Running image pair retrieval...") | ||
| visibility_graph = image_pairs_generator.run( | ||
| client=client, | ||
| image_batch_futures=image_batch_futures, | ||
| image_fnames=image_fnames, | ||
| plots_output_dir=output_paths.plots, | ||
| ) | ||
|
|
||
| try: | ||
| image_pairs_generator._retriever.save_diagnostics( | ||
| image_fnames=image_fnames, | ||
| pairs=visibility_graph, | ||
| plots_output_dir=output_paths.plots, | ||
| ) | ||
| except Exception as exc: # pragma: no cover - diagnostic path best-effort | ||
| logger.warning("Failed to persist retriever diagnostics: %s", exc) | ||
|
|
||
| logger.info("🚀 Image pair retrieval took %.2f min.", (time.time() - start_time) / 60.0) | ||
| return visibility_graph | ||
|
|
||
|
|
||
| def _save_visibility_graph(graph: VisibilityGraph, output_paths: OutputPaths) -> None: | ||
| try: | ||
| with open(output_paths.results / "visibility_graph.pkl", "wb") as f: | ||
| pickle.dump(graph, f) | ||
| except Exception as exc: | ||
| logger.warning("Failed to serialize visibility graph: %s", exc) | ||
|
|
||
|
|
||
| def _parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser(description="Run MegaLoc+METIS partitioning and save outputs.") | ||
| parser.add_argument( | ||
| "--dataset_dir", | ||
| type=str, | ||
| required=True, | ||
| help="Dataset root containing images/ (Olsson-style loader default).", | ||
| ) | ||
| parser.add_argument( | ||
| "--images_dir", | ||
| type=str, | ||
| default=None, | ||
| help="Optional path to images directory (overrides loader default).", | ||
| ) | ||
| parser.add_argument( | ||
| "--output_root", | ||
| type=str, | ||
| default=str(Path.cwd()), | ||
| help="Root directory to store results (will create output_root/results).", | ||
| ) | ||
| parser.add_argument( | ||
| "--config_name", | ||
| type=str, | ||
| default="vggt_megaloc_phototourism", | ||
| help="Config in gtsfm/configs to load (default: vggt).", | ||
| ) | ||
| parser.add_argument( | ||
| "--max_resolution", | ||
| type=int, | ||
| default=None, | ||
| help="Override loader max resolution (if unset, uses config default).", | ||
| ) | ||
| parser.add_argument( | ||
| "--num_workers", | ||
| type=int, | ||
| default=1, | ||
| help="Number of local Dask workers.", | ||
| ) | ||
| parser.add_argument( | ||
| "--threads_per_worker", | ||
| type=int, | ||
| default=1, | ||
| help="Threads per Dask worker.", | ||
| ) | ||
| parser.add_argument( | ||
| "--worker_memory_limit", | ||
| type=str, | ||
| default="32GB", | ||
| help="Memory limit per worker, e.g. 16GB.", | ||
| ) | ||
| parser.add_argument( | ||
| "--dashboard_address", | ||
| type=str, | ||
| default=":8787", | ||
| help="Dask dashboard address, set to empty string to disable.", | ||
| ) | ||
| parser.add_argument( | ||
| "--single_cluster", | ||
| action="store_true", | ||
| help="Skip METIS and output a single cluster containing all retrieved image pairs.", | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def main() -> None: | ||
| args = _parse_args() | ||
|
|
||
| output_root = Path(args.output_root) | ||
| output_paths = prepare_output_paths(output_root, None) | ||
|
|
||
| loader, image_pairs_generator, graph_partitioner = _build_components( | ||
| config_name=args.config_name, | ||
| dataset_dir=args.dataset_dir, | ||
| images_dir=args.images_dir, | ||
| max_resolution=args.max_resolution, | ||
| ) | ||
|
|
||
| logger.info("🌟 Starting Dask local cluster...") | ||
| cluster = LocalCluster( | ||
| n_workers=args.num_workers, | ||
| threads_per_worker=args.threads_per_worker, | ||
| memory_limit=args.worker_memory_limit, | ||
| dashboard_address=args.dashboard_address, | ||
| ) | ||
|
|
||
| with Client(cluster) as client: | ||
| visibility_graph = _run_retriever(client, loader, image_pairs_generator, output_paths) | ||
|
|
||
| if args.single_cluster: | ||
| logger.info("🔥 Skipping METIS; creating a single cluster with all retrieved pairs...") | ||
| cluster_tree = SinglePartitioner().run(visibility_graph) | ||
| else: | ||
| logger.info("🔥 Running METIS partitioning...") | ||
| cluster_tree = graph_partitioner.run(visibility_graph) | ||
| graph_partitioner.log_partition_details(cluster_tree, output_paths) | ||
| _save_visibility_graph(visibility_graph, output_paths) | ||
|
|
||
| logger.info("✅ Saved visibility_graph.pkl and cluster_tree.pkl under %s", output_paths.results) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just update the AUC code to save it in percent, we dont need this.