TimeDistributed(Flatten())在Keras中提供相同的输出形状

时间:2017-06-01 21:47:18

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

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

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')

1 个答案:

答案 0 :(得分:0)

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