实验方法

  1. Hyp-NeRF
1
2
3
if encoding == 'hashgrid':
from gridencoder import GridEncoder
encoder = GridEncoder(input_dim=input_dim, num_levels=num_levels, level_dim=level_dim, base_resolution=base_resolution, log2_hashmap_size=log2_hashmap_size, desired_resolution=desired_resolution, gridtype='hash', align_corners=align_corners, num_instances=num_instances)
  1. R2L
1

  1. GRAM-HD
1
2
3
## upsamping 上采样
self.num_upconvs = int(np.log2(scale_factor))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## patch-gan -->  discriminator()

class GramEncoderPatchDiscriminator(Discriminator):
def __init__(self, img_size, img_channels=3, norm_layer=nn.BatchNorm2d):
super().__init__()
self.img_size = img_size
self.img_size_log2 = int(np.log2(img_size))

self.layers = nn.ModuleList([])
for i in range(13 - self.img_size_log2, 12):
self.layers.append(ResidualCoordConvBlock(int(min(400, 2**i)), int(min(400, 2**(i+1))),
downsample=True))
self.fromRGB = AdapterBlock(img_channels, int(min(400, 2**(13 - self.img_size_log2))))
self.final_layer = nn.Conv2d(400, 1 + 2, 2)

# patch-gan
self.patchgan = NLayerDiscriminator(img_channels, min(64, int(2**(14-self.img_size_log2))),
max(3,self.img_size_log2-6), norm_layer=norm_layer)

def forward(self, input):
x = self.fromRGB(input)
for layer in self.layers:
x = layer(x)

x = self.final_layer(x).reshape(x.shape[0], -1)

prediction = x[..., 0:1]
position = x[..., 1:]

patch = self.patchgan(input).reshape(x.shape[0], -1)

return prediction, position, patch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class NLayerDiscriminator(nn.Module):
"""Defines a PatchGAN discriminator"""

def __init__(self, input_nc, ndf=64, n_layers=3, norm_layer=nn.BatchNorm2d):
"""Construct a PatchGAN discriminator
Parameters:
input_nc (int) -- the number of channels in input images
ndf (int) -- the number of filters in the last conv layer
n_layers (int) -- the number of conv layers in the discriminator
norm_layer -- normalization layer
"""
super(NLayerDiscriminator, self).__init__()
if type(norm_layer) == functools.partial: # no need to use bias as BatchNorm2d has affine parameters
use_bias = norm_layer.func == nn.InstanceNorm2d
else:
use_bias = norm_layer == nn.InstanceNorm2d

kw = 4
padw = 1
sequence = [nn.Conv2d(input_nc, ndf, kernel_size=kw, stride=2, padding=padw), nn.LeakyReLU(0.2, True)]
nf_mult = 1
nf_mult_prev = 1
for n in range(1, n_layers): # gradually increase the number of filters
nf_mult_prev = nf_mult
nf_mult = min(2 ** n, 8)
sequence += [
nn.Conv2d(ndf * nf_mult_prev, ndf * nf_mult, kernel_size=kw, stride=2, padding=padw,
bias=use_bias),
norm_layer(ndf * nf_mult),
nn.LeakyReLU(0.2, True)
]

nf_mult_prev = nf_mult
nf_mult = min(2 ** n_layers, 8)
sequence += [
nn.Conv2d(ndf * nf_mult_prev, ndf * nf_mult, kernel_size=kw, stride=1, padding=padw, bias=use_bias),
norm_layer(ndf * nf_mult),
nn.LeakyReLU(0.2, True)
]

# output 1 channel prediction map
sequence += [nn.Conv2d(ndf * nf_mult, 1, kernel_size=kw, stride=1, padding=padw)]
self.model = nn.Sequential(*sequence)

def forward(self, input):
"""Standard forward."""
return self.model(input)


实验方法
http://seulqxq.top/posts/9364/
作者
SeulQxQ
发布于
2024年3月2日
许可协议