将 keras 后端从 theano 更改为 tensorflow 时出现 TypeError

TypeError on changing keras backend from theano to tensorflow

我正在尝试为 https://github.com/baidu-research/ba-dls-deepspeech/ 使用 tensorflow 后端。 model.py 中的 compile_gru_model 函数在更改后端时会出现 TypeError。

# Main acoustic input
acoustic_input = Input(shape=(None, input_dim), name='acoustic_input')

# Setup the network
conv_1d = Convolution1D(nodes, conv_context, name='conv1d',
                        border_mode=conv_border_mode,
                        subsample_length=conv_stride, init=initialization,
                        activation='relu')(acoustic_input)
if batch_norm:
    output = BatchNormalization(name='bn_conv_1d', mode=2)(conv_1d)
else:
    output = conv_1d

for r in range(recur_layers):
    output = GRU(nodes, activation='relu',
                 name='rnn_{}'.format(r + 1), init=initialization,
                 return_sequences=True)(output)
    if batch_norm:
        bn_layer = BatchNormalization(name='bn_rnn_{}'.format(r + 1),
                                      mode=2)
        output = bn_layer(output)

在运行 GRU层,报错:

TypeError: Expected int32, got <tf.Variable 'rnn_1_W_z_1:0' shape=(1024, 1024) dtype=float32_ref> of type 'Variable' instead.

即使使用 K.cast() 将输入转换为 int32,错误仍然存​​在。此代码适用于 theano 后端。

张量流版本:1.1.0
Keras 版本:1.1.2

如有任何帮助,我们将不胜感激。谢谢!

郑重声明,问题已通过升级到 keras 2.0.4 得到解决。