diff options
author | Jordan Gong <jordan.gong@protonmail.com> | 2021-04-04 17:44:23 +0800 |
---|---|---|
committer | Jordan Gong <jordan.gong@protonmail.com> | 2021-04-04 17:44:23 +0800 |
commit | 6f3dd9109b8ae7b37e3373d844a6c406d83c2b35 (patch) | |
tree | a530221dfef3100a236c4091c3d0c15ea636d9e5 /models/auto_encoder.py | |
parent | 6a8824e4fb8bdd1f3e763b78b765830788415cfb (diff) | |
parent | 85627d4cfb495453a7c28b3f131b84b1038af674 (diff) |
Merge branch 'disentangling_only' into disentangling_only_py3.8disentangling_only_py3.8
Diffstat (limited to 'models/auto_encoder.py')
-rw-r--r-- | models/auto_encoder.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/models/auto_encoder.py b/models/auto_encoder.py index b1d51ef..61622eb 100644 --- a/models/auto_encoder.py +++ b/models/auto_encoder.py @@ -112,7 +112,7 @@ class Decoder(nn.Module): x = torch.cat((f_appearance, f_canonical, f_pose), dim=1) x = self.fc(x) x = x.view(-1, self.feature_channels * 8, self.h_0, self.w_0) - x = F.relu(x, inplace=True) + x = F.leaky_relu(x, 0.2, inplace=True) x = self.trans_conv1(x) x = self.trans_conv2(x) x = self.trans_conv3(x) @@ -124,6 +124,7 @@ class Decoder(nn.Module): class AutoEncoder(nn.Module): def __init__( self, + num_class: int, channels: int = 3, frame_size: Tuple[int, int] = (64, 48), feature_channels: int = 64, @@ -134,8 +135,9 @@ class AutoEncoder(nn.Module): feature_channels, embedding_dims) self.decoder = Decoder(embedding_dims, feature_channels, self.encoder.feature_size, channels) + self.classifier = BasicLinear(embedding_dims[1], num_class) - def forward(self, x_c1_t2, x_c1_t1=None, x_c2_t2=None): + def forward(self, x_c1_t2, x_c1_t1=None, x_c2_t2=None, y=None): n, t, c, h, w = x_c1_t2.size() # x_c1_t2 is the frame for later module x_c1_t2_ = x_c1_t2.view(n * t, c, h, w) @@ -162,6 +164,9 @@ class AutoEncoder(nn.Module): cano_cons_loss = torch.stack([ F.mse_loss(f_c_c1_t1[:, i, :], f_c_c1_t2[:, i, :]) + F.mse_loss(f_c_c1_t2[:, i, :], f_c_c2_t2[:, i, :]) + + F.cross_entropy(self.classifier( + F.leaky_relu(f_c_c1_t2[:, i, :], 0.2) + ), y) for i in range(t) ]).mean() |