MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / StrandEncoder1dCNNWN

Class StrandEncoder1dCNNWN

models/strand_codec.py:112–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111
112class StrandEncoder1dCNNWN(nn.Module):
113 def __init__(self, do_vae, out_channels=128, num_pts=256):
114 super(StrandEncoder1dCNNWN, self).__init__()
115
116 self.do_vae = do_vae
117 self.num_pts = num_pts
118
119 # self.training = False
120
121
122 in_channels = 0
123 in_channels += 3 # 3 for xyz
124 in_channels += 3 # 3 for dirs
125
126
127 self.cnn_encoder = torch.nn.Sequential(
128 Conv1dWN_v2(in_channels, 64, kernel_size=4, stride=2, padding=1, padding_mode='replicate'),torch.nn.SiLU(),
129 Conv1dWN_v2(64, 64, kernel_size=4, stride=2, padding=1, padding_mode='replicate'), torch.nn.SiLU(),
130 Conv1dWN_v2(64, 128, kernel_size=4, stride=2, padding=1, padding_mode='replicate'), torch.nn.SiLU(),
131 Conv1dWN_v2(128, 128, kernel_size=4, stride=2, padding=1, padding_mode='replicate'), torch.nn.SiLU(),
132 Conv1dWN_v2(128, 256, kernel_size=4, stride=2, padding=1, padding_mode='replicate'), torch.nn.SiLU(),
133 Conv1dWN_v2(256, 256, kernel_size=4, stride=2, padding=1, padding_mode='replicate'), torch.nn.SiLU(),
134 )
135
136
137 self.aggregate_towards_mean = torch.nn.Sequential(
138 LinearWN_v2(256 * 4, 512), torch.nn.SiLU(),
139 )
140 self.pred_mean = LinearWN_v2(512, out_channels)
141
142 self.aggregate_towards_logstd = torch.nn.Sequential(
143 LinearWN_v2(256 * 4, 512), torch.nn.SiLU(),
144 )
145 self.pred_logstd = LinearWN_v2(512, out_channels)
146
147
148 self.apply(lambda x: kaiming_init(x, False, nonlinearity="silu"))
149 kaiming_init(self.pred_mean, True)
150 kaiming_init(self.pred_logstd, True)
151
152
153 self.tanh = torch.nn.Tanh()
154
155
156 def forward(self, gt_dict):
157
158 points=gt_dict["strand_positions"]
159 dirs=gt_dict["strand_directions"]
160
161 #points
162 points = points.permute(0, 2, 1) ## nr_strands, xyz, 100
163 nr_strands = points.shape[0]
164 #dirs
165 last_dir = dirs[:, -1:, :]
166 dirs = torch.cat([dirs, last_dir],1) # make the direction nr_strands, 100, 3
167 dirs = dirs.permute(0, 2, 1)
168
169 per_point_features = torch.cat([points, dirs] ,1)

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected