-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelper_model.py
More file actions
121 lines (81 loc) · 3.52 KB
/
helper_model.py
File metadata and controls
121 lines (81 loc) · 3.52 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import torch
import numpy as np
import torch.nn as nn
class Sandwich(nn.Module):
def __init__(self, dim, outdim=3, bias=False):
super(Sandwich, self).__init__()
self.mlp1 = nn.Conv2d(12, 6, kernel_size=1, bias=bias) #
self.mlp2 = nn.Conv2d(6, 3, kernel_size=1, bias=bias)
self.relu = nn.ReLU()
self.sigmoid = torch.nn.Sigmoid()
def forward(self, input, rays, time=None):
albedo, spec, timefeature = input.chunk(3,dim=1)
specular = torch.cat([spec, timefeature, rays], dim=1) # 3+3 + 5
specular = self.mlp1(specular)
specular = self.relu(specular)
specular = self.mlp2(specular)
result = albedo + specular
result = self.sigmoid(result)
return result
class Sandwichnoact(nn.Module):
def __init__(self, dim, outdim=3, bias=False):
super(Sandwichnoact, self).__init__()
self.mlp1 = nn.Conv2d(12, 6, kernel_size=1, bias=bias)
self.mlp2 = nn.Conv2d(6, 3, kernel_size=1, bias=bias)
self.relu = nn.ReLU()
def forward(self, input, rays, time=None):
albedo, spec, timefeature = input.chunk(3,dim=1)
specular = torch.cat([spec, timefeature, rays], dim=1) # 3+3 + 5
specular = self.mlp1(specular)
specular = self.relu(specular)
specular = self.mlp2(specular)
result = albedo + specular
result = torch.clamp(result, min=0.0, max=1.0)
return result
class Sandwichnoactss(nn.Module):
def __init__(self, dim, outdim=3, bias=False):
super(Sandwichnoactss, self).__init__()
self.mlp1 = nn.Conv2d(12, 6, kernel_size=1, bias=bias)
self.mlp2 = nn.Conv2d(6, 3, kernel_size=1, bias=bias)
self.relu = nn.ReLU()
def forward(self, input, rays, time=None):
albedo, spec, timefeature = input.chunk(3,dim=1)
specular = torch.cat([spec, timefeature, rays], dim=1) # 3+3 + 5
specular = self.mlp1(specular)
specular = self.relu(specular)
specular = self.mlp2(specular)
result = albedo + specular
return result
####### following are also good rgb model but not used in the paper, slower than sandwich, inspired by color shift in hyperreel
# remove sigmoid for immersive dataset
class RGBDecoderVRayShift(nn.Module):
def __init__(self, dim, outdim=3, bias=False):
super(RGBDecoderVRayShift, self).__init__()
self.mlp1 = nn.Conv2d(dim, outdim, kernel_size=1, bias=bias)
self.mlp2 = nn.Conv2d(15, outdim, kernel_size=1, bias=bias)
self.mlp3 = nn.Conv2d(6, outdim, kernel_size=1, bias=bias)
self.sigmoid = torch.nn.Sigmoid()
self.dwconv1 = nn.Conv2d(9, 9, kernel_size=1, bias=bias)
def forward(self, input, rays, t=None):
x = self.dwconv1(input) + input
albeado = self.mlp1(x)
specualr = torch.cat([x, rays], dim=1)
specualr = self.mlp2(specualr)
finalfeature = torch.cat([albeado, specualr], dim=1)
result = self.mlp3(finalfeature)
result = self.sigmoid(result)
return result
def getcolormodel(rgbfuntion):
if rgbfuntion == "sandwich":
rgbdecoder = Sandwich(9,3)
elif rgbfuntion == "sandwichnoact":
rgbdecoder = Sandwichnoact(9,3)
elif rgbfuntion == "sandwichnoactss":
rgbdecoder = Sandwichnoactss(9,3)
else :
return None
return rgbdecoder
def pix2ndc(v, S):
return (v * 2.0 + 1.0) / S - 1.0
def ndc2pix(v, S):
return ((v + 1.0) * S - 1.0) * 0.5