I am a new hand of Deep learning. trying to learn about textCNN. but the model give me the runtime error:
Traceback (most recent call last):
File "/root/.vscode/extensions/ms-python.python-2019.2.5558/pythonFiles/ptvsd_launcher.py", line 45, in <module>
main(ptvsdArgs)
File "/root/.vscode/extensions/ms-python.python-2019.2.5558/pythonFiles/lib/python/ptvsd/__main__.py", line 357, in main
run()
File "/root/.vscode/extensions/ms-python.python-2019.2.5558/pythonFiles/lib/python/ptvsd/__main__.py", line 257, in run_file
runpy.run_path(target, run_name='__main__')
File "/etc/miniconda3/envs/DL/lib/python3.6/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/etc/miniconda3/envs/DL/lib/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/etc/miniconda3/envs/DL/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/document/A01/mian.py", line 32, in <module>
output=cnn(b_x)
File "/etc/miniconda3/envs/DL/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/root/document/A01/textCNN.py", line 44, in forward
output=self.out(x)
File "/etc/miniconda3/envs/DL/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/etc/miniconda3/envs/DL/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 55, in forward
return F.linear(input, self.weight, self.bias)
File "/etc/miniconda3/envs/DL/lib/python3.6/site-packages/torch/nn/functional.py", line 1026, in linear
output = input.matmul(weight.t())
RuntimeError: size mismatch, m1: [2048 x 1], m2: [2048 x 1] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:2070
the textCNN model is:
class textCNN(nn.Module):
def __init__(self):
super(textCNN,self).__init__()
self.embedding=nn.Embedding(config.NUM_EMBED,config.EMBED_DIM)
self.conv1=nn.Sequential(
nn.Conv2d(in_channels=1,out_channels=16,kernel_size=5,stride=1,padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
)
self.conv2=nn.Sequential(
nn.Conv2d(in_channels=16,out_channels=32,kernel_size=5,stride=1,padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
)
self.conv3=nn.Sequential(
nn.Conv2d(in_channels=32,out_channels=64,kernel_size=5,stride=1,padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2,padding=1)
)
self.conv4=nn.Sequential(
nn.Conv2d(in_channels=64,out_channels=128,kernel_size=5,stride=1,padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
)
self.out=nn.Linear(2048,1)
def forward(self,x):
x=self.embedding(x)
x=x.view(16,1,10,10)
x=self.conv1(x)
x=self.conv2(x)
x=self.conv3(x)
x=self.conv4(x)
x.view(x.size(0),-1)
output=self.out(x)
return output
they are the same size, right? why it give me this error?