我是 TensorflowJS 和 ML 的新手。在API Reference中,以下代码为there .
const model = tf.sequential();
// First layer must have an input shape defined.
model.add(tf.layers.dense({units: 32, inputShape: [50]}));
// Afterwards, TF.js does automatic shape inference.
model.add(tf.layers.dense({units: 4}));
// Inspect the inferred shape of the model's output, which equals
// `[null, 4]`. The 1st dimension is the undetermined batch dimension; the
// 2nd is the output size of the model's last layer.
console.log(JSON.stringify(model.outputs[0].shape));
我想知道的是,
什么是inputShape
?
什么是自动形状?
既然unit
指的是数据集的属性,为什么在model.add(tf.layers.dense({units: 4}))
行。 (该层在 model.add(tf.layers.dense({units: 32, inputShape: [50]}))
中将 unit
定义为 32)因为 sequential()
一层的输出是下一层的输入,单位不是一定要一样吗?
最佳答案
What is
inputShape
?
它是一个包含张量维度的数组,在运行神经网络时用作输入。
What is the automatic shape?
它只是使用之前图层的输出形状。在这种情况下 [32]
因为之前的层是一个具有 32 个单元的密集层。
Since the unit referred to attributes of the data set, why unit set to 4 in
model.add(tf.layers.dense({units: 4}))
line. (the layer defined the unit as 32 inmodel.add(tf.layers.dense({units: 32, inputShape: [50]})))
Since sequential()'s outputs of one layer are the inputs to the next layer, the aren't the units must be same?
单位定义了密集层的输出形状。在这种情况下,神经网络应该有 4 个输出,所以最后一层必须有 4 个单元。输出形状和输入形状不必相同,因为每个神经元的输出(其数量是输出形状)是根据前一层的所有神经元(输出)计算的。 (在致密层的情况下)
关于javascript - TensorFlow JS 中的单位和输入形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50269445/