import torch
import torch.nn as nn
# RNN模型
'''
第一个参数:input_size(输入张量x的维度)
第二个参数:hidden_size(隐藏层维度,隐藏层的神经元个数)
第三个参数:num_layer(隐藏层的数量)
'''
rnn = nn.RNN(5, 6, 1)
'''
第一个参数:sequence_length(输入序列长度)
其中sequence_length代表时间步,代表了RNN内部的细胞数量
第二个参数:batch_size(批次的样本数量)
第三个参数:input_size(输入张量的维度)
'''
input = torch.randn(3, 8, 5)
'''
第一个参数:num_layer * num_direction(层数*网络方向)
第二个参数:batch_size(批次的样本数)
第三个参数:hidden_size(隐藏层的维度, 隐藏层神经元的个数)
'''
h0 = torch.randn(1, 8, 6)
output, hn = rnn(input, h0)
print(h0)
print(h0.shape) # torch.Size([1, 8, 6])
print(input)
print(input.shape) # torch.Size([3, 8, 5])
RNN各个参数含义
于 2022-01-13 17:24:25 首次发布