Skip to content

Commit

Permalink
Add round half up mode to colmap
Browse files Browse the repository at this point in the history
  • Loading branch information
yzslab committed Jul 5, 2024
1 parent 662c79c commit 4f9b2cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ You can use `utils/image_downsample.py` to downsample your images, e.g. 4x downs
--data.parser.down_sample_factor 4 \
...
```

Rounding mode is specified by `--data.parser.down_sample_rounding_model`. Available values are `floor`, `round`, `round_half_up`, `ceil`. Default is `round`.

* Load large dataset without OOM
```bash
... fit \
Expand Down
10 changes: 8 additions & 2 deletions internal/dataparsers/colmap_dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Colmap(DataParserConfig):

down_sample_factor: int = 1

down_sample_rounding_model: Literal["floor", "round", "ceil"] = "round"
down_sample_rounding_model: Literal["floor", "round", "round_half_up", "ceil"] = "round"

def instantiate(self, path: str, output_path: str, global_rank: int) -> DataParser:
return ColmapDataParser(path, output_path, global_rank, self)
Expand All @@ -68,6 +68,9 @@ def __init__(self, path: str, output_path: str, global_rank: int, params: Colmap
self.global_rank = global_rank
self.params = params

def _round_half_up(self, i: torch.Tensor):
return torch.floor(i + 0.5)

def detect_sparse_model_dir(self) -> str:
if os.path.isdir(os.path.join(self.path, "sparse", "0")):
return os.path.join(self.path, "sparse", "0")
Expand Down Expand Up @@ -344,7 +347,10 @@ def get_outputs(self) -> DataParserOutputs:

# recalculate intrinsics if down sample enabled
if self.params.down_sample_factor != 1:
rounding_func = getattr(torch, self.params.down_sample_rounding_model)
if self.params.down_sample_rounding_model == "round_half_up":
rounding_func = self._round_half_up
else:
rounding_func = getattr(torch, self.params.down_sample_rounding_model)
down_sampled_width = rounding_func(width.to(torch.float) / self.params.down_sample_factor)
down_sampled_height = rounding_func(height.to(torch.float) / self.params.down_sample_factor)
width_scale_factor = down_sampled_width / width
Expand Down
8 changes: 2 additions & 6 deletions utils/eval_mipnerf360.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@


def start(command: str, scene: str, extra_args: list = None):
down_sample_rounding_model = "ceil"
if scene == "garden":
down_sample_rounding_model = "round"

arg_list = [
"python",
"main.py",
Expand All @@ -31,7 +27,7 @@ def start(command: str, scene: str, extra_args: list = None):
"--data.parser", "Colmap",
"--data.parser.down_sample_factor", "4",
"--data.parser.split_mode", "experiment",
"--data.parser.down_sample_rounding_model", down_sample_rounding_model,
"--data.parser.down_sample_rounding_model", "round_half_up",
"--cache_all_images",
"--logger", "wandb",
"--output", os.path.join("outputs", args.project),
Expand All @@ -43,7 +39,7 @@ def start(command: str, scene: str, extra_args: list = None):
if extra_args is not None:
arg_list += extra_args

subprocess.call(arg_list)
return subprocess.call(arg_list)


with tqdm(scenes) as t:
Expand Down

0 comments on commit 4f9b2cd

Please sign in to comment.