How to solve the two layers of CNN dimension

Viewed 119

Now,I am learning CNN for nlp, some time ago, I tried to modify the code from Yoon Kim's github repo. I tried to add a layer of convolution in the model.py.

However, I encountered a dimension problem, in other words, making the output of the first convolutional layer the input of the second convolutional layer, yields the message that the dimensions do not fit.

Can anyone help me to so solve it?

# one layer
self.conv13 = nn.Conv2d(Ci, 100, (3, D))
self.conv14 = nn.Conv2d(Ci, 100, (4, D))
self.conv15 = nn.Conv2d(Ci, 100, (5, D))

# two layer
self.conv23 = nn.Conv2d(100, Co, (D, Co))
self.conv24 = nn.Conv2d(100, Co, (D, Co))
self.conv25 = nn.Conv2d(100, Co, (D, Co))

x1 = self.conv(x, self.conv13) #(N,Co)
print("convvv", x1)

# two layer
if self.args.cuda:
    self.conv23 = [model.cuda() for model in self.conv23]
    self.conv24 = [model.cuda() for model in self.conv24]
    self.conv25 = [model.cuda() for model in self.conv25]

x1 = x1.unsqueeze(1)
x4 = self.conv(x1, self.conv23) #(N,Co)
x = self.pool(x4)
0 Answers
Related