Warm tip: This article is reproduced from stackoverflow.com, please click
keras tensorflow tensorflow2.0

How to input 5D tensor to keras model.fit

发布于 2020-03-27 15:46:55

I am utilizing tensorflow ver 2, tensorflow.keras.

A model I made is in a sequence of tf.keras.Conv2D ( which requires 4D input tensor (samples, rows, cols, channels)

then tf.keras.convLSTM2D (which requires 5D input tensor (samples, time, rows, cols, channels).

Because of this reason, I made an input with 5D tensor (samples, time, rows, cols, channels) but it can't be fed into tf.keras.Conv2D at the beginning when I implement model.fit(train_data, train_data... )

Is there any way to make model.fit to take 5D tensor?

Questioner
Brian Lee
Viewed
153
Orphee Faucoz 2020-01-31 17:20

You need to implement TimeDistributed conv2D as in :

x_conv = tf.keras.layers.TimeDistributed(tf.keras.layers.Conv2D(filters=filters,
                                                                kernel_size=kernel_size,
                                                                strides=strides,
                                                                padding='same',
                                                                kernel_initializer='he_normal'))(x)

This way the layers understand that you're giving 4D input over timestep