输入和输出到Pytorch中的LSTMS

发布于 2025-01-18 10:17:37 字数 172 浏览 1 评论 0原文

我想在Pytorch中实现LSTM,因为我的数据是时间序列数据,即视频框架以进行心率检测,我正在为LSTMS的输入和输出尺寸而苦苦挣扎。在考虑时间步骤,隐藏状态等时,在Pytorch中LSTMS的输入非常令人困惑 我来自CNN的输出是“ 2批256帧”,现在是LSTMS的输入 批次是2 功能= 256 输出也是256帧的2批次。

I want to implement lstms with CNN in pytorch as my data is a time series data i.e. frames of video for heart rate detection, I am struggling with the input and output dimensions for lstms what and how i should properly configure the dimensions/parameters/arguments at input of lstms in pytorch as its quite confusing when considering time steps, hidden state etc.
my output from CNN is “2 batches of 256 frames”, which is now the input to lstms
batch is 2
features =256
the output is also a batch of 2 with 256 frames.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彩虹直至黑白 2025-01-25 10:17:37

通常,顺序数据的输入形状采用(batch_size, seq_len, num_features)的形式。根据您的解释,我假设您的输入格式为 (2, 256),其中 2 是批量大小,256 是标量(一维张量)的序列长度。因此,您应该通过 inputs.unsqueeze(2) 将输入重塑为 (2, 256, 1)

要声明和使用 LSTM 模型,只需尝试

from torch import nn

model = nn.LSTM(
    input_size=1, # 1-dimensional features
    batch_first=True, # batch is the first (zero-th) dimension
    hidden_size=some_hidden_size, # maybe 64, 128, etc.
    num_layers=some_num_layers, # maybe 1 or 2
    proj_size=1, # output should also be 1-dimensional
)
outputs, (hidden_state, cell_state) = model(inputs)

Generally, the input shape of sequential data takes the form (batch_size, seq_len, num_features). Based on your explanation, I assume your input is of the form (2, 256), where 2 is the batch size and 256 is the sequence length of scalars (1-dimensional tensor). Therefore, you should reshape your input to be (2, 256, 1) by inputs.unsqueeze(2).

To declare and use an LSTM model, simply try

from torch import nn

model = nn.LSTM(
    input_size=1, # 1-dimensional features
    batch_first=True, # batch is the first (zero-th) dimension
    hidden_size=some_hidden_size, # maybe 64, 128, etc.
    num_layers=some_num_layers, # maybe 1 or 2
    proj_size=1, # output should also be 1-dimensional
)
outputs, (hidden_state, cell_state) = model(inputs)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文