Nlp 没有Maxpool2d时显示Maxpool2d错误

Nlp 没有Maxpool2d时显示Maxpool2d错误,nlp,pytorch,Nlp,Pytorch,我运行以下代码来训练一个神经网络,它包含一个具有最大池的CNN和两个完全连接的层: 类网络(nn.Module): 定义初始大小(自、语音大小、嵌入大小): 手电筒。手动种子(0) 超级(网络,自我)。\uuuu初始化 self.word\u embeddings=nn.Embedding(声音大小,嵌入大小) self.conv1=nn.Conv1d(嵌入大小,64,3) self.drop1=nn.Dropout(0.5) self.max_pool1=nn.MaxPool1d(2) sel

我运行以下代码来训练一个神经网络,它包含一个具有最大池的CNN和两个完全连接的层:

类网络(nn.Module):
定义初始大小(自、语音大小、嵌入大小):
手电筒。手动种子(0)
超级(网络,自我)。\uuuu初始化
self.word\u embeddings=nn.Embedding(声音大小,嵌入大小)
self.conv1=nn.Conv1d(嵌入大小,64,3)
self.drop1=nn.Dropout(0.5)
self.max_pool1=nn.MaxPool1d(2)
self.flat1=nn.flatte()
self.fc1=nn.线性(64*99100)
self.fc2=nn.线性(100,1)
def转发(自我,句子):
嵌入=self.word\u嵌入(句子).permute(0,2,1)
conv1=F.relu(self.conv1(嵌入))
drop1=自.drop1(conv1)
max_pool1=self.max_pool1(drop1)
flat1=自flat1(最大值为1)
fc1=F.relu(自fc1(平面1))
fc2=火炬乙状体(自身fc2(fc1))
返回fc2
net=net(声音大小、嵌入大小)
纪元=10
net.cuda()
标准=nn.BCELoss()
optimizer=optim.Adam(net.parameters(),lr=0.001)
加载器=数据加载器(系列,批量大小=32)
net.train()
对于范围内的历元(历元):
进度=tqdm_笔记本(加载器,离开=假)
对于输入,目标在建:
净零度梯度()
输出=净(输入到(设备))
损耗=标准(输出、目标到(设备))
loss.backward()
optimizer.step()
打印(丢失)
我得到以下错误(错误跟踪已更新,包括完整跟踪):

/usr/local/lib/python3.6/dist packages/torch/nn/modules/loss.py:498:UserWarning:不推荐使用与输入大小(torch.size([32,1])不同的目标大小(torch.size([32])。请确保尺寸相同。
返回F.binary\u cross\u熵(输入,目标,权重=自身权重,缩减=自身缩减)
---------------------------------------------------------------------------
运行时错误回溯(上次最近调用)
在()
33对于输入,目标在建:
34净零度梯度()
--->35输出=净(输入到(设备))
36损耗=标准(输出、目标到(设备))
37.损失向后()
5帧
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in_max_pool1d(输入、内核大小、步幅、填充、扩展、ceil_模式、返回索引)
455 stride=torch.jit.annotate(列表[int],]
456返回火炬最大直径1d(
-->457输入、内核大小、步幅、填充、扩展、ceil_模式)
458
459 max\u pool1d=布尔值\u分派(
运行时错误:带有索引的max\U pool2d\U out\U cuda\U帧失败,错误代码为0

我的代码中没有任何Maxpool2ds!有人能帮我解决这个问题吗?

请发布错误消息的全部跟踪信息。@Shai我更新了代码max pool 1d似乎在幕后运行一些2d代码。
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py:498: UserWarning: Using a target size (torch.Size([32])) that is different to the input size (torch.Size([32, 1])) is deprecated. Please ensure they have the same size.
  return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-3c8a885417ba> in <module>()
     33     for inputs, target in progress:
     34         net.zero_grad()
---> 35         output = net(inputs.to(device))
     36         loss = criterion(output, target.to(device))
     37         loss.backward()

5 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in _max_pool1d(input, kernel_size, stride, padding, dilation, ceil_mode, return_indices)
    455         stride = torch.jit.annotate(List[int], [])
    456     return torch.max_pool1d(
--> 457         input, kernel_size, stride, padding, dilation, ceil_mode)
    458 
    459 max_pool1d = boolean_dispatch(

RuntimeError: max_pool2d_with_indices_out_cuda_frame failed with error code 0