Example #1
0
    def forward(self, x: Tensor) -> Tensor:
        x = self.conv(x)
        x = x.view(-1, 512 * 2 * 2)

        x = self.linear(x)

        return x
Example #2
0
 def forward(self, x: Tensor) -> Tensor:
     x = self.bn1(self.fc1(x)).relu()
     x = self.bn2(self.fc2(x)).relu()
     x = x.view(-1, 16, self.img_size_h, self.img_size_w)
     x = self.up1(self.cbn1(self.conv1(x)).relu())
     if self.dataset == 'CelebA':
         x = self.up2(self.cbn2(self.conv2(x)).relu())
     x = self.cbn3(self.conv3(x)).relu()
     x = self.conv4(x).sigmoid()
     return x
Example #3
0
 def forward(self, x: Tensor) -> Tuple[Tensor]:
     x = self.down1(self.cbn1(self.conv1(x)).relu())
     if self.dataset == 'CelebA':
         x = self.down2(self.cbn2(self.conv2(x)).relu())
     x = self.cbn3(self.conv3(x)).relu()
     x = x.view(-1, 16*self.img_size_h*self.img_size_w)
     x = self.bn1(self.fc1(x)).relu()
     d = self.out_d(x).sigmoid()
     q_cat = self.out_q_cat(x)
     q_non_cat_mean, q_non_cat_logvar = self.out_q_non_cat_mean(x), self.out_q_non_cat_logvar(x)
     return d, q_cat, q_non_cat_mean, q_non_cat_logvar
Example #4
0
    def forward(self, img: Tensor, labels: int):
        """Forward pass of the Discriminator.

        Args:
            img: the image that should be classified in fake or real.
            labels: the label of the image.

        Returns:

        """
        d_in = torch.cat(
            (img.view(img.size(0), -1), self.label_embedding(labels)), -1)
        score = self.model(d_in)
        return score
Example #5
0
    def forward(self, input: Tensor, mask: Tensor = None, hx: Tuple[Tensor, Tensor] = None) -> Tuple[Tensor, Tensor]:
        batch_size = input.size(0) if self.batch_first else input.size(1)
        if hx is None:
            num_directions = 2 if self.bidirectional else 1
            hx = input.new_zeros((self.num_layers * num_directions, batch_size, self.hidden_size))
            hx = (hx, hx)

        func = rnn_f.autograd_var_masked_rnn(num_layers=self.num_layers,
                                             batch_first=self.batch_first,
                                             bidirectional=self.bidirectional,
                                             lstm=True)

        self.reset_noise(batch_size)

        output, hidden = func(input, self.all_cells, hx, None if mask is None else mask.view(mask.size() + (1,)))
        return output, hidden
Example #6
0
    def forward(self, x: Tensor) -> Tensor:
        y: Tensor = self.conv1(x)

        x = self.conv128(y)
        x += y

        y = self.conv128to256(x)

        x = self.conv256(y)
        x += y

        y = self.conv256to512(x)

        x = self.conv512(y)
        x += y

        x = x.view(-1, 512 * 4 * 4)

        return self.linear(x)
Example #7
0
    def forward(self, x: Tensor) -> Tensor:
        x = self.conv(x)
        x = x.view(-1, 256 * 3 * 3)
        x = self.linear(x)

        return x
 def forward(self, x: Tensor) -> Tensor:
     x = self.conv(x)
     x = x.view(-1, 512 * 4 * 4)  # -1 means infer this dimension
     x = self.linear(x)
     return x