如何控制tensorflow js中的输出范围
How to control range of output in tensorflow js
我有这个型号:
const hidden = tf.layers.dense({
units: 8,
inputShape: [58, 8, 8],
activation: 'sigmoid'
});
const output = tf.layers.dense({
units: 1,
activation: 'softmax'
});
var model = tf.sequential({
layers: [
hidden,
output
]
});
现在我希望输出在 -1 和 1 范围内,我该如何实现?
激活函数决定了输出。 'sigmoid' 适用于 0 到 1 输出,'tanh' 适用于 -1 到 1,但是您选择使用通常用于 multi-class 分类的 'softmax'。无论您何时做出预测,您都可以将这些值重新映射到另一个数组。
我有这个型号:
const hidden = tf.layers.dense({
units: 8,
inputShape: [58, 8, 8],
activation: 'sigmoid'
});
const output = tf.layers.dense({
units: 1,
activation: 'softmax'
});
var model = tf.sequential({
layers: [
hidden,
output
]
});
现在我希望输出在 -1 和 1 范围内,我该如何实现?
激活函数决定了输出。 'sigmoid' 适用于 0 到 1 输出,'tanh' 适用于 -1 到 1,但是您选择使用通常用于 multi-class 分类的 'softmax'。无论您何时做出预测,您都可以将这些值重新映射到另一个数组。