in src/models.py [0:0]
def __init__(self, D=8, W=256, n_in=None, n_out=4, skips=[4], use_viewdirs=False, net_idx=None, config=None):
"""
"""
super(NeRF, self).__init__()
self.net_idx = net_idx
self.D = D
self.W = W
self.skips = skips
if 'auto' in skips[0]:
self.skips = [4]
else:
self.skips = [int(x) for x in self.skips]
self.name = f"NeRF{self.net_idx}({W}x{D}{self.skips})"
self.input_ch = 3
self.input_ch_views = 3
self.output_ch = n_out
if config.posEnc and config.posEnc[net_idx] and "RayMarch" in config.inFeatures[net_idx]:
if config.posEnc[net_idx] == "nerf":
freq = config.posEncArgs[net_idx].split("-")
self.input_ch = (int(freq[0])) * 6 + 3
self.input_ch_views = (int(freq[1])) * 6 + 3
self.use_viewdirs = use_viewdirs
self.pts_linears = nn.ModuleList(
[nn.Linear(self.input_ch, W)] + [nn.Linear(W, W) if i not in self.skips else nn.Linear(W + self.input_ch, W) for i in
range(D - 1)])
### Implementation according to the official code release (https://github.com/bmild/nerf/blob/master/run_nerf_helpers.py#L104-L105)
self.views_linears = nn.ModuleList([nn.Linear(self.input_ch_views + W, W // 2)])
### Implementation according to the paper
# self.views_linears = nn.ModuleList(
# [nn.Linear(input_ch_views + W, W//2)] + [nn.Linear(W//2, W//2) for i in range(D//2)])
if use_viewdirs:
self.feature_linear = nn.Linear(W, W)
self.alpha_linear = nn.Linear(W, 1)
self.rgb_linear = nn.Linear(W // 2, 3)
else:
self.output_linear = nn.Linear(W, self.output_ch)
for i, l in enumerate(self.pts_linears):
nn.init.kaiming_normal_(l.weight)
for i, l in enumerate(self.views_linears):
nn.init.kaiming_normal_(l.weight)