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,导致维度不匹配,固报错