如何为单个输出MLP设计Tensorflow Js模型?



我正在尝试使用 Tensorflow Js 实现和测试单个输出 MLP,其中我的数据如下所示:

dataset = [[x_1, x_2, ..., x_n, y], ...]

这是我的代码:

for (var i = 0; i < dataset.length; ++i) {
x[i] = dataset[i].slice(0, inputLength);
y[i] = dataset[i][inputLength];
}
const xTrain = tf.tensor2d(x.slice(1));
const yTrain = tf.tensor1d(y.slice(1));
const model = tf.sequential();
model.add(tf.layers.dense({inputShape: [inputLength], units: 10}));
model.add(tf.layers.dense({units: 1}));
const learningRate = 0.1;
const optimizer = tf.train.sgd(learningRate);
model.compile({loss: 'meanSquaredError', optimizer});
return model.fit(
xTrain,
yTrain,
{
batchSize: 10,
epochs: 5
}
)

问题是我的模型没有收敛,我在每一步都得到了损失函数null值。另外,请注意,我知道我可以使用多元回归来解决这个问题,但我想将结果与 MLP 进行比较。

我想知道是否有人可以帮助我解决这个问题。

model.fit()中使用的 x/y 张量的维度必须比模型第一层/最后一层的形状多 1 个,以表示多个训练数据集,因此 GPU 加速的批量训练是可能的。

模型的另一个问题是高learningRate(相对于训练值的大小(,这会阻止模型收敛,因为它跳过了最优解并失控。

降低learningRate或将学习值归一化为较低的量级。

最新更新