简体   繁体   English

如何在Tensorflow中为视频序列构建多层LSTM?

[英]How to build a multi-layer LSTM in Tensorflow for a video sequence?

I want to build a 3 layer LSTM in tensorflow for video analysis. 我想在Tensorflow中构建一个三层LSTM用于视频分析。 I read some examples online, but still confusing. 我在网上阅读了一些示例,但仍然令人困惑。 Could anyone help to write a concise code snippet to do a task as below: 任何人都可以帮助编写简洁的代码段来完成以下任务:

Input: 5 consecutive video frames in 240X320 dimension 输入:240X320尺寸的5个连续视频帧

Output: 5 scalars 输出:5个标量

Thank you so much. 非常感谢。

Basically you have to prepare you frames for the sequence. 基本上,您必须为序列准备帧。 You should have a vector like (Batch_size, sequence_length = 5, features = 240*320). 您应该有一个矢量,例如(Batch_size,sequence_length = 5,features = 240 * 320)。 Then create your 3 Stacked LSTM using: 然后使用以下命令创建3个堆叠的LSTM:

layer1 = rnn.BasicLSTMCell(number_lstm_units)
layer2 = rnn.BasicLSTMCell(number_lstm_units)
layer3 = rnn.BasicLSTMCell(number_lstm_units)

Group the cells and pass it to a Multi RNN Cell: 对单元进行分组,并将其传递到多RNN单元:

cells = [layer1, layer2, layer3]
multirnn = rnn.MultiRNNCell(cells)

Then with your flattened vector of features you only have to pass each element though the LSTM 然后,使用扁平化的特征向量,您只需通过LSTM传递每个元素

for feature in your_flattened_vector:
    lstm_output, state = cell(feature,state)

You will have an output of the same size as your input. 您将获得与输入大小相同的输出。

For additional info check the API here . 有关其他信息,请在此处查看API。

Hope it helped. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM