【问题标题】:TimeDistributed(Flatten()) gives the same output shape in KerasTimeDistributed(Flatten()) 在 Keras 中给出相同的输出形状
【发布时间】:2017-11-03 04:41:52
【问题描述】:

我在 Keras 中有以下模型,但 TimeDistributed(Flatten())(x) 不起作用,它的形状与输出相同。我在 Windows 10 上使用带有 Tensorflow 后端和 Python 3.5.3 的最新版本的 Keras。我做错了什么吗?有其他解决方案吗?

rnn_size = 128

input_tensor = Input((width, height, 3))

x = input_tensor

x = Convolution2D(32, 3, 3, activation='relu', input_shape=[width, height, 3])(x)
x = Convolution2D(32, 3, 3, activation='relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)

x = Convolution2D(32, 3, 3, activation='relu')(x)
x = Convolution2D(32, 3, 3, activation='relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)

x = Convolution2D(32, 3, 3, activation='relu')(x)
x = Convolution2D(32, 3, 3, activation='relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)

conv_shape = x.get_shape()
x = Reshape(target_shape = (int(conv_shape [1]), int(conv_shape[2] * conv_shape[3])))(x)

x = Dense(32, activation='relu')(x)

x = GRU(rnn_size, return_sequences=True, init='he_normal', name='gru1')(x)

x = TimeDistributed(Flatten())(x)
x = TimeDistributed(Dropout(0.25))(x)
x = TimeDistributed(Dense(n_class, init='he_normal', activation='softmax'))(x)

model = Model(input = [input_tensor], output = [x])

model.compile(loss='categorical_crossentropy', optimizer='adadelta')

【问题讨论】:

    标签: python-3.x tensorflow deep-learning keras recurrent-neural-network


    【解决方案1】:

    最新的 keras 发行版对我有用(Ubuntu 16.04)。 如果 Win10 的发行版没有,请升级 keras 到 github 版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 2022-10-20
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2021-07-15
      相关资源
      最近更新 更多