ConvLSTM2D 在 keras 或 tensorflow 中的 Conv2D 层之后
ConvLSTM2D after a Conv2D layer in keras or tensorflow
过程是这样的:
x(batch, time, w, h, c)
=> Reshape
=> (batch*time, w, h, c)
=> Conv2D => Reshape => (batch,time, w, h, c')
=> ConvLstm2d => ...
tf.keras.layers.Reshape
只能重塑 non-batch_size 部分,我无法从之前的重塑尺寸 (batch*time,w,h,c)
.
中提取 time
有没有合适的方法来实现这样的模型?
你是对的,tf.keras
不支持批量维度重塑 - 如果你需要一个可以做到这一点的层,并且仍然使用 tf.keras
只需编写一个自定义层
class BatchAwareReshape(tf.keras.layers.Layer):
def __init__(self, shape, **kwargs):
super().__init__(**kwargs)
self._shape = shape
def call(self, inputs):
return tf.reshape(inputs, self._shape)
由于 tf.reshape
知道批量维度,您现在可以在模型中调用层 BatchAwareReshape(shape=(batch*time, w, h, c))
,它会起作用。
过程是这样的:
x(batch, time, w, h, c)
=> Reshape
=> (batch*time, w, h, c)
=> Conv2D => Reshape => (batch,time, w, h, c')
=> ConvLstm2d => ...
tf.keras.layers.Reshape
只能重塑 non-batch_size 部分,我无法从之前的重塑尺寸 (batch*time,w,h,c)
.
中提取 time
有没有合适的方法来实现这样的模型?
你是对的,tf.keras
不支持批量维度重塑 - 如果你需要一个可以做到这一点的层,并且仍然使用 tf.keras
只需编写一个自定义层
class BatchAwareReshape(tf.keras.layers.Layer):
def __init__(self, shape, **kwargs):
super().__init__(**kwargs)
self._shape = shape
def call(self, inputs):
return tf.reshape(inputs, self._shape)
由于 tf.reshape
知道批量维度,您现在可以在模型中调用层 BatchAwareReshape(shape=(batch*time, w, h, c))
,它会起作用。