Hi, you initialized a layer inside your forward call.



 randinoo:

out2 = nn.AvgPool2d(out2)


Here is a way to deal with that:
import torch.nn as nn
import torch

class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.cnn1 = nn.Conv1d(1,3, 4)
        self.batchnorm1= nn.BatchNorm1d(3)
        self.maxpool1 = nn.MaxPool1d(3)
        self.fc1 = nn.Linear(12, 10)
        self.batchnorm2 = nn.BatchNorm1d(3)
        self.pool = nn.AvgPool2d(2)
        self.fc2 = nn.Linear(6, 4)
        self.relu = nn.ReLU()
        self.flatten = nn.Flatten()
    def forward(self,x):
        out1 = self.cnn1(x)
        out = self.batchnorm1(out1)
        out = self.relu(out)
        out = self.maxpool1(out)
        out = self.flatten(out)
        out = self.fc1(out)
        out2 = self.batchnorm2(out1)
        out2 = self.relu(out2)
        out2 = self.pool(out2)
        out2 = self.fc2(out2)
        out2 = self.flatten(out2)
        #print(out.shape, out2.shape)
        out=torch.cat((out,out2), dim =1)
        return out
m = Model()
x = torch.rand(10,1, 15)
m(x).shape == (10,14)