RuntimeError: fractional_max_pool2d_backward_out_cuda failed with error code 0

在深度学习模型中遇到反向传播错误:'RuntimeError: fractional_max_pool2d_backward_out_cuda failed with error code 0'。通过在permute操作后应用contiguous()函数,确保张量的连续性,从而解决了这个问题。
摘要由CSDN通过智能技术生成
class DeepWise_MaxPool(nn.MaxPool1d):
    def __init__(self, channels):
        super(DeepWise_MaxPool, self).__init__(channels)

    def forward(self, input):
        n, c, h, w = input.size()
        input = input.view(n, c, h * w).permute(0, 2, 1)
        pooled = torch.nn.functional.max_pool1d(input, self.kernel_size, self.stride, 
             self.padding, self.dilation, self.ceil_mode, self.return_indices)
        _, _, c = pooled.size()
        pooled = pooled.permute(0, 2, 1)
        return pooled.view(n, c, h, w)

在模型中使用该类作为基本结构的一部分时,网络反向传播报错,使用contiguous()将permute()操作之后的tensor变为连续。

Returns a contiguous in memory tensor containing the same data as self tensor. If self tensor is already in the specified memory format, this function returns the self tensor
class DeepWise_MaxPool(nn.MaxPool1d)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值