I am trying to get the shape of the conv2 layer so that i can build a linear layer with that shape.
class PostConvNet(nn.Module):
“”"
Post Convolutional Network (mel → mel)
“”"
def init(self, num_hidden, num_input_layers):
“”"
:param num_hidden: dimension of hidden
"""
super(PostConvNet, self).__init__()
self.conv1 = nn.Conv1d(in_channels=hp.num_mels * hp.outputs_per_step,
out_channels=num_hidden,
kernel_size=16,
padding=4,
)
self.conv_list = nn.Sequential(*[nn.Conv1d(in_channels=768,
out_channels=768,
kernel_size=16,
padding=4,
) for _ in range(3)])
self.conv2 = nn.Conv1d(in_channels=num_hidden,
out_channels=hp.num_mels * hp.outputs_per_step,
kernel_size=16,
padding=4)
self.shape = self.conv2.shape[1]
self.convLinear = nn.Linear(in_features=num_input_layers, out_features=self.shape)
self.pre_batchnorm = nn.BatchNorm1d(num_hidden)
self.batch_norm_list = clones(nn.BatchNorm1d(num_hidden), 3)
self.dropout1 = nn.Dropout(p=0.1)
self.dropout_list = nn.ModuleList([nn.Dropout(p=0.1) for _ in range(3)])
def forward(self, input_, mask=None):
input_ = self.conv1(input_)
input_1 = self.conv_list(input_)
input_2 = self.conv2(input_1)
input_ = self.convLinear(in_features=input_.shape(1), out_features=input_2.shape(1))(input_)
return input_
My problem is i want to build a linear layer whose out_features are the shape of the conv2 layer