【发布时间】:2017-10-29 10:12:00
【问题描述】:
我正在尝试将 tensorflow 后端用于 https://github.com/baidu-research/ba-dls-deepspeech/ 。 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
任何帮助将不胜感激。谢谢!
【问题讨论】:
-
Related stackoverflow.com/questions/41813665/…,由 Tensorflow 中的 API 更改引起。需要降级 tensorflow 或升级 Keras
标签: python tensorflow speech-recognition keras