我在Keras中定义了一个LSTM模型,并使用 tfjs.converters.save_keras_model 将其转换为Tensorflow.js格式 . 但是当尝试在JS中加载Web友好模型时,会导致错误,表示预期不同于weight文件中存在的形状:

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 = 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.json中的LSTM层:

{"name": "lstm_1/kernel", "shape": [2, 128], "dtype": "float32"}

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

关于我在这里做错了什么的想法?