尝试使用tensorflow.js创建LSTM模型时遇到了一个问题,但我不断遇到此错误:
Uncaught (in promise) Error: Layer lstmLayer is not connected, no input to return.
我不确定它是怎么发生的。我尝试以几种不同的方式更改代码,但总是会回到该错误。我只是似乎无法弄清楚问题出在什么地方,在添加LSTM层之前,它工作得很好。我不是Tensorflow的javascript版本的佼佼者,因此任何指针都将大有帮助。我只是想让它工作,所以我可以继续对其进行更改,以更好地完成我想要的事情。
createModel() {
return tf.tidy(() => {
const inputLayer = tf.input({
shape: [this.memoryLength, this.inputNodes],
name: "inputLayer"
});
const lstmLayer = tf.layers.lstm({
units: 8,
returnSequences: true,
name: "lstmLayer"
}).apply(inputLayer);
const hiddenLayer1 = tf.layers.dense({
units: this.hiddenNodes1,
activation: 'sigmoid',
name: "hiddenLayer1"
}).apply(lstmLayer);
const dropout1 = tf.layers.dropout({
rate: 0.2,
name: "dropout1"
}).apply(hiddenLayer1);
const flattenLayer = tf.layers.flatten({
name: "flattenLayer"
}).apply(dropout1);
const hiddenLayer2 = tf.layers.dense({
units: this.hiddenNodes2,
activation: 'sigmoid',
name: "hiddenLayer2"
}).apply(flattenLayer);
const dropout2 = tf.layers.dropout({
rate: 0.2,
name: "dropout2"
}).apply(hiddenLayer2);
const hiddenLayer3 = tf.layers.dense({
units: this.hiddenNodes3,
activation: 'sigmoid',
name: "hiddenLayer3"
}).apply(flattenLayer);
const dropout3 = tf.layers.dropout({
rate: 0.2,
name: "dropout3"
}).apply(hiddenLayer3);
const outputLayer1 = tf.layers.dense({
units: this.inputNodes,
activation: 'softmax',
name: "outputLayer1"
}).apply(dropout2);
const outputLayer2 = tf.layers.dense({
units: this.outputNodes,
activation: 'softmax',
name: "outputLayer2"
}).apply(dropout3);
const model = tf.model({
inputs: [inputLayer],
outputs: [outputLayer1, outputLayer2],
name: "model"
});
model.summary();
return model;
});
}