【问题标题】:How to reshape image sequence for LSTM如何为 LSTM 重塑图像序列
【发布时间】:2019-01-02 12:50:34
【问题描述】:

我正在尝试设置一个 RNN 来估计两个图像之间的移动。 我目前有一组 5000 张灰度图像,这些图像是在移动时相机指向地面拍摄的。我想使用 LSTM 建立一个 RNN,估计当前图像和前一个图像之间的移动。

目前图像 (64x64x1) 只是排列在一个 numpy 数组中:

image1
image2
image3
...

我猜我需要重新排列数组,以便有两个时间步:

image1 image2
image2 image3
image3 image4
...

那么我如何重塑数组,以便我可以将其用作 LSTM 的输入,具有两个时间步长?

【问题讨论】:

  • lst = lst.reshape((len(lst)+1)//2, 2)lst = lst.reshape(2500, 2)
  • 但这会产生一个长度为 2500 的列表,而我想要一个长度为 4999 的数组,因为图像会在整个过程中重新出现。例如,您可以在我的问题中看到 image2 存在于两行中。在第 1 和第 2 行中,图像 3 出现在第 1 行中。 2和3等
  • 哦,抱歉,我没看到:>

标签: python opencv machine-learning keras lstm


【解决方案1】:

我用 numpy 构建了一个小例子。

impot numpy as np

lst = np.array(range(10))
lst
Out[56]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

lst = np.vstack((lst[:-1], lst[1:]))

# Getting the list with shape (2, len(lst)-1)
lst
Out[60]: 
array([[0, 1, 2, 3, 4, 5, 6, 7, 8],
       [1, 2, 3, 4, 5, 6, 7, 8, 9]])

# Getting the list with shape (len(lst)-1, 2)
lst = lst.T
lst
Out[61]: 
array([[0, 1],
       [1, 2],
       [2, 3],
       [3, 4],
       [4, 5],
       [5, 6],
       [6, 7],
       [7, 8],
       [8, 9]])

如果您需要获取“第二个”列表的深层副本,您可以使用

lst2 = lst[1:].copy()

【讨论】:

    【解决方案2】:
    train_images = []
    for cnt, img in images:
        if cnt > 0:
            image_pairs = []
            image_pairs.append(np.array(prev_img))
            image_pairs.append(np.array(img))
            train_images.append(image_pairs)
         prev_img = img
    

    在我问之前我会开始思考。

    【讨论】:

    • 查看我给你的例子。
    猜你喜欢
    • 1970-01-01
    • 2019-09-07
    • 2021-09-23
    • 1970-01-01
    • 2022-01-14
    • 2023-01-23
    • 2018-02-20
    • 1970-01-01
    • 2018-06-05
    相关资源
    最近更新 更多