Tensorflow JS 删除张量中的一个维度
Tensorflow JS remove a dimension in a tensor
我创建了我的第一个模型,但预测的格式不正确。我如何删除预测输出的维度(或更改我的最后一层以获得正确的维度)?
const actualYs = [1,2,3] // The shape of my values Y
const predictions = [[1],[2],[3]] // The shape of my predictions
// My last layer looks like this:
model.add(tf.layers.dense({ units: 1, useBias: true }))
所以以我有限的理解。我也许可以删除 predictions
的维度或更改最后一层?但是我已经设置了 1
,所以不确定我还能设置什么。
如果这有帮助,这是我的实际 console.log
MY Y VALUES
Tensor
[0.0862738, 0.0862553, 0.0861815, ..., 0.0054516, 0.0043004, 0.0037461]
PREDICTIONS
Tensor
[[0.1690691],
[0.1659686],
[0.1698797],
...,
[0.1118171],
[0.1092742],
[0.1096415]]
我希望预测看起来像我的实际 Y 值。
提前致谢。
reshape
或squeeze
都可以使用
const x = tf.tensor([[1],[2],[3]] ).reshape([-1]);
// or
const x = tf.tensor([[1],[2],[3]] ).squeeze();
我创建了我的第一个模型,但预测的格式不正确。我如何删除预测输出的维度(或更改我的最后一层以获得正确的维度)?
const actualYs = [1,2,3] // The shape of my values Y
const predictions = [[1],[2],[3]] // The shape of my predictions
// My last layer looks like this:
model.add(tf.layers.dense({ units: 1, useBias: true }))
所以以我有限的理解。我也许可以删除 predictions
的维度或更改最后一层?但是我已经设置了 1
,所以不确定我还能设置什么。
如果这有帮助,这是我的实际 console.log
MY Y VALUES
Tensor
[0.0862738, 0.0862553, 0.0861815, ..., 0.0054516, 0.0043004, 0.0037461]
PREDICTIONS
Tensor
[[0.1690691],
[0.1659686],
[0.1698797],
...,
[0.1118171],
[0.1092742],
[0.1096415]]
我希望预测看起来像我的实际 Y 值。
提前致谢。
reshape
或squeeze
都可以使用
const x = tf.tensor([[1],[2],[3]] ).reshape([-1]);
// or
const x = tf.tensor([[1],[2],[3]] ).squeeze();