Pytorch中 bidirectional=True,Tensor的大小变化

rnn = nn.RNN(input_size=4,hidden_size=3,num_layers=2,batch_first=True, bidirectional = True)
input = torch.randn(1,5,4)
output , h_n = rnn(input)
print(output.shape)
print(h_n.shape)


#----输出结果----------
input.Size([1, 5, 4])
output.Size([1, 5, 6]) # hidden_size 要乘以2
h_n.Size([4, 1, 3]) # num_layers 要乘以2

seq_len = 1  num_layers = 2 hidden_size = 3 input_size = 4 btach_size = 5

  

posted @ 2022-04-25 09:04  华小电  阅读(311)  评论(0编辑  收藏  举报