| 69 | self.create_embedding_fn() |
| 70 | |
| 71 | def create_embedding_fn(self): |
| 72 | embed_fns = [] |
| 73 | d = self.kwargs['input_dims'] |
| 74 | out_dim = 0 |
| 75 | if self.kwargs['include_input']: |
| 76 | embed_fns.append(lambda x : x) |
| 77 | out_dim += d |
| 78 | |
| 79 | max_freq = self.kwargs['max_freq_log2'] |
| 80 | self.N_freqs = self.kwargs['num_freqs'] |
| 81 | |
| 82 | if self.kwargs['log_sampling']: |
| 83 | freq_bands = 2.**torch.linspace(0., max_freq, steps=self.N_freqs) # tensor([ 1., 2., 4., 8., 16., 32., 64., 128., 256., 512.]) |
| 84 | else: |
| 85 | freq_bands = torch.linspace(2.**0., 2.**max_freq, steps=self.N_freqs) |
| 86 | |
| 87 | for freq in freq_bands: # 10 iters for 3D location, 4 iters for 2D direction |
| 88 | for p_fn in self.kwargs['periodic_fns']: |
| 89 | embed_fns.append(lambda x, p_fn=p_fn, freq=freq : p_fn(x * freq)) |
| 90 | out_dim += d |
| 91 | self.embed_fns = embed_fns |
| 92 | self.out_dim = out_dim |
| 93 | |
| 94 | def embed(self, inputs): |
| 95 | # inputs [65536, 3] |