is this code right? class StyleTransformer(nn.Module): def init(self, inputdim,…
- User
is this code right?
class StyleTransformer(nn.Module): def init(self, input_dim, num_heads, num_layers, style_dim): super(StyleTransformer, self).init() self.fc1 = nn.Linear(input_dim, style_dim) self.encoder_layer = nn.TransformerEncoderLayer(d_model=style_dim, nhead=num_heads, batch_first=True) self.transformer_encoder = nn.TransformerEncoder(self.encoder_layer, num_layers=num_layers) self.activation = nn.ReLU() self.fc2 = nn.Linear(style_dim, input_dim)
codedef forward(self, src, mask): output = self.fc1(output) output = self.transformer_encoder(src, src_key_padding_mask=mask) # Берем среднее по всем эмбеддингам изображений одного стиля output = torch.mean(output, dim=1) output = self.activation(output) output = self.fc2(output) return output - Assistant
Your code for the
StyleTransformerclass has a few issues that need to be addressed for it to function correctly. I'll walk you through the necessary corrections: