我有一个视频数据集,我将每个视频划分为一组帧,并将每个视频存储到一个列表中,然后将该列表存储在一个数组中,所以现在我有了一个列表数组,每个列表都是一个视频,如何将每个视频传递给网络以及如何将序列长度设置为每个视频的列表
提示:每个视频都有不同的长度
这是我的RNN代码
# Create RNN Model
class RNNModel(nn.Module):
def __init__(self, input_dim, hidden_dim, layer_dim,
output_dim):
super(RNNModel, self).__init__()
# Number of hidden dimensions
self.hidden_dim = hidden_dim
# Number of hidden layers
self.layer_dim = layer_dim
# RNN
self.rnn = nn.RNN(input_dim, hidden_dim, layer_dim,
batch_first=True,
nonlinearity='relu')
# Readout layer
self.fc = nn.Linear(hidden_dim, output_dim)
def forward(self, x):
# Initialize hidden state with zeros
h0 = Variable(torch.zeros(self.layer_dim, x.size(0),
self.hidden_dim))
# One time step
out, hn = self.rnn(x, h0)
out = self.fc(out[:, -1, :])
return out