Pytorch调用RNN/LSTM/GRU问题

Q1:调用GRU报错

报错代码:
terminate called after throwing an instance of 'c10::CUDAError' what(): CUDA error: an illegal memory access was encountered CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.

检查发现批量大小可能比较大,导致内存溢出。将batch_size从1024 修改为 500

Q2:修改batch大小后仍报错

报错代码:
ValueError: Expected input batch_size (21) to match target batch_size (256).

当时以为batch_size必须是21的倍数,因为笔者的concat_nframe等于21。将其改为420后,仍报错。

参考官方文档:

https://pytorch.org/docs/stable/generated/torch.nn.GRU.html?highlight=nn+gru#torch.nn.GRU

原来的代码为:

self.gru = nn.GRU(
            input_size = 39,
            hidden_size =  hidden_dim,
            num_layers = hidden_layers,
            bidirectional = True,
            dropout= drop_out
        )

由于没有设置batch_first = True,而我输入的数据的第一个维度为batch,导致维度不匹配,固报错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值