diff --git a/nerfstudio/field_components/encodings.py b/nerfstudio/field_components/encodings.py index 652d387f5..6e0158654 100644 --- a/nerfstudio/field_components/encodings.py +++ b/nerfstudio/field_components/encodings.py @@ -274,18 +274,18 @@ class HashEncoding(Encoding): self.hash_table_size = 2**log2_hashmap_size levels = torch.arange(num_levels) - growth_factor = np.exp((np.log(max_res) - np.log(min_res)) / (num_levels - 1)) + growth_factor = np.exp((np.log(max_res) - np.log(min_res)) / (num_levels - 1)) if num_levels > 1 else 1 self.scalings = torch.floor(min_res * growth_factor**levels) self.hash_offset = levels * self.hash_table_size - self.hash_table = torch.rand(size=(self.hash_table_size * num_levels, features_per_level)) * 2 - 1 - self.hash_table *= hash_init_scale - self.hash_table = nn.Parameter(self.hash_table) self.tcnn_encoding = None + self.hash_table = torch.empty(0) if implementation == "tcnn" and not TCNN_EXISTS: print_tcnn_speed_warning("HashEncoding") - elif implementation == "tcnn": + implementation = "torch" + + if implementation == "tcnn": encoding_config = { "otype": "HashGrid", "n_levels": self.num_levels, @@ -301,6 +301,10 @@ class HashEncoding(Encoding): n_input_dims=3, encoding_config=encoding_config, ) + elif implementation == "torch": + self.hash_table = torch.rand(size=(self.hash_table_size * num_levels, features_per_level)) * 2 - 1 + self.hash_table *= hash_init_scale + self.hash_table = nn.Parameter(self.hash_table) if self.tcnn_encoding is None: assert (