在Tensorflow.js中加载转换后的Keras LSTM模型会导致张量形状错误

时间:2018-08-30 09:03:18

标签: python tensorflow keras lstm tensorflowjs-converter

我已经在Keras中定义了一个LSTM模型,并使用"K.jpg"将其转换为Tensorflow.js格式。但是,当尝试在JS中加载Web友好模型时,会导致错误,提示所期望的形状与权重文件中存在的形状不同:

tfjs.converters.save_keras_model

模型定义:

BenchmarkDialog.vue:47 Error: Based on the provided shape, [2,128], the tensor should have 256 values but has 139
at m (tf-core.esm.js:17)
at new t (tf-core.esm.js:17)
at Function.t.make (tf-core.esm.js:17)
at ke (tf-core.esm.js:17)
at i (tf-core.esm.js:17)
at Object.kh [as decodeWeights] (tf-core.esm.js:17)
at tf-layers.esm.js:17
at tf-layers.esm.js:17
at Object.next (tf-layers.esm.js:17)
at o (tf-layers.esm.js:17)

有问题的张量属于model.json中的LSTM层:

model = Sequential()

model.add(LSTM(
    32,
    batch_input_shape=(30, 5, 3),
    return_sequences=True,
    stateful=True,
    activation='tanh',
))
model.add(Dropout(0.25))

model.add(LSTM(
    32,
    return_sequences=True,
    stateful=True,
    activation='tanh',
))
model.add(Dropout(0.25))

model.add(LSTM(
    32,
    return_sequences=False,
    stateful=True,
    activation='tanh',
))
model.add(Dropout(0.25))

model.add(Dense(3, activation='tanh', kernel_initializer='lecun_uniform'))

model.compile(loss='mse', optimizer=Adam())

这里是model.jsonweights fileoriginal keras model,以防它们有用。

对我在这里做错的任何想法吗?

0 个答案:

没有答案