python - 如何将时间分布式层与卷积层一起使用?

标签 python python-3.x tensorflow keras conv-neural-network

我正在尝试构建一个非常基本的自动驾驶汽车转向角预测问题。我有一个以 30fps 拍摄的视频,我已将其转换为大约 50000 个图像(即大约 25 分钟的镜头),并且我正在尝试预测转向角度的目标。

我尝试使用一些基本的卷积层,但我得到的 MSE 非常糟糕。所以,我正在尝试使用 CNN + RNN 来改进我的模型。因为我的数据是时间分布的,所以使用 RNN 是有意义的。

我不知道如何使用 TimeDistributed LayerLSTM 来实现此目的。我基本上使用下面这样的东西,我有每个形状的图像宽度,高度, channel =(200,66,3)

img_height = 66
img_width = 200
channels = 3

input_l = Input(shape=(img_height, img_width, channels))
x = layers.Conv2D(128, kernel_size=(5, 5))(input_l)
x = layers.Conv2D(256, kernel_size=(5, 5))(x)
x = Flatten()(x)
out = Dense(1)(x)
model = Model(inputs=input_l, outputs=out)
model.summary()

据我所知,TimeDistributedLayer 需要 4 个维度才能工作,但我的每个图像的形状为 (200, 66, 3),如何将每个图像转换为四个维度。我不知 Prop 体如何使用它。我读过几篇文章,但没有一篇谈到这一点。

如何将时间分布式层与 LSTM 合并到此架构中?任何人都可以提供有关如何实现它的示例代码。

最佳答案

TimeDistributed 图层假定维度 1 是时间维度(时间步长),因此您需要向图像数据添加时间维度。类似于:

from keras import layers
from keras import models

time_steps = 10
img_height = 66
img_width = 200
channels = 3

input_l = layers.Input(shape=(time_steps, img_height, img_width, channels))
x = layers.TimeDistributed( layers.Conv2D( 32, kernel_size=(5, 5) ) ) (input_l)
x = layers.TimeDistributed( layers.Conv2D(256, kernel_size=(5, 5)) ) (x)
x = layers.Flatten()(x)
out = layers.Dense(1)(x)
model = models.Model(inputs=input_l, outputs=out)
model.summary()

我希望这会有所帮助。

关于python - 如何将时间分布式层与卷积层一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58632160/

相关文章:

Python : pygame. key.get_pressed 不起作用

python - 有没有一个程序可以缩短这个时间?

python-3.x - 异常 : Layout must be a dash component or a function that returns a dash component

c++ - 如何通过 C++ API 为 tflite 提供多维输入

python - 如何在 Keras 中调整(插值)张量?

python - 根据标签关联图像的最佳方法

python - Pandas map 函数返回 'NaN'

python - 在最小化中使用 CALLABLE 函数时,“numpy.ndarray”对象不可调用

python - 如何使用 Python 3 获取 Google 搜索结果?

python - 规范化遗漏波兰语字符