def forward_noise(self, tilde_h):
# z_pre will be used in the decoder cost
z_pre = self.linear(tilde_h)
z_pre_norm = self.bn_normalize(z_pre)
# Add noise
noise = np.random.normal(loc=0.0, scale=self.noise_level, size=z_pre_norm.size())
if self.use_cuda:
noise = Variable(torch.cuda.FloatTensor(noise))
else:
noise = Variable(torch.FloatTensor(noise))
# tilde_z will be used by decoder for reconstruction
tilde_z = z_pre_norm + noise
# store tilde_z in buffer
self.buffer_tilde_z = tilde_z
z = self.bn_gamma_beta(tilde_z)
h = self.activation(z)
return h
评论列表
文章目录