MCPcopy Create free account
hub / github.com/Sin3DM/Sin3DM / AutoEncoderGroupSkip

Class AutoEncoderGroupSkip

src/encoding/networks.py:124–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122
123
124class AutoEncoderGroupSkip(nn.Module):
125 def __init__(self, geo_feat_channels, tex_feat_channels, feat_channel_up, mlp_hidden_channels, mlp_hidden_layers, use_tex=True, tex_channels=3, posenc=0) -> None:
126 super().__init__()
127 self.use_tex = use_tex
128
129 self.geo_encoder = nn.Conv3d(1, geo_feat_channels, kernel_size=4, stride=2, padding=1, bias=True)
130 if use_tex:
131 self.tex_encoder = nn.Conv3d(tex_channels + 1, tex_feat_channels, kernel_size=4, stride=2, padding=1, bias=True)
132 out_channels = geo_feat_channels + tex_feat_channels if use_tex else geo_feat_channels
133 self.norm = nn.InstanceNorm2d(out_channels)
134
135 self.geo_feat_dim = geo_feat_channels
136 self.tex_feat_dim = tex_feat_channels
137
138 self.geo_convs = TriplaneGroupResnetBlock(
139 geo_feat_channels, feat_channel_up, ks=5, input_norm=False, input_act=False
140 )
141 self.geo_decoder = DecoderMLPSkipConcat(feat_channel_up, 1, mlp_hidden_channels, mlp_hidden_layers)
142
143 if use_tex:
144 self.tex_convs = TriplaneGroupResnetBlock(
145 tex_feat_channels, feat_channel_up, ks=5, input_norm=False, input_act=False
146 )
147 self.tex_decoder = DecoderMLPSkipConcat(feat_channel_up, tex_channels, mlp_hidden_channels, mlp_hidden_layers, posenc=posenc)
148
149 self.register_buffer("aabb", torch.tensor([-1, -1, -1, 1, 1, 1], dtype=torch.float32))
150
151 def geo_parameters(self):
152 return list(self.geo_encoder.parameters()) + list(self.geo_convs.parameters()) + list(self.geo_decoder.parameters())
153
154 def tex_parameters(self):
155 return list(self.tex_encoder.parameters()) + list(self.tex_convs.parameters()) + list(self.tex_decoder.parameters())
156
157 def reset_aabb(self, aabb):
158 print("set net aabb:", aabb)
159 if not isinstance(aabb, torch.Tensor):
160 aabb = torch.tensor(aabb, dtype=torch.float32)
161 # self.register_buffer("aabb", aabb.to(self.encoder.weight.device))
162 self.aabb = aabb.to(self.geo_encoder.weight.device)
163
164 def encode(self, vol):
165 geo_feat = self.geo_encoder(vol[:, :1])
166 if self.use_tex:
167 tex_feat = self.tex_encoder(vol)
168 vol_feat = torch.cat([geo_feat, tex_feat], dim=1)
169 else:
170 vol_feat = geo_feat
171
172 xy_feat = vol_feat.mean(dim=4)
173 xz_feat = vol_feat.mean(dim=3)
174 yz_feat = vol_feat.mean(dim=2)
175
176 xy_feat = (self.norm(xy_feat) * 0.5).tanh()
177 xz_feat = (self.norm(xz_feat) * 0.5).tanh()
178 yz_feat = (self.norm(yz_feat) * 0.5).tanh()
179
180 return [xy_feat, xz_feat, yz_feat]
181

Callers 1

get_networksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected