javascript - TensorFlow JS 中的单位和输入形状

标签 javascript tensorflow tensorflow.js

我是 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 in model.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/

相关文章:

添加第二个 GPU 后 TensorFlow 无法工作(CUDNN_STATUS_INTERNAL_ERROR)

javascript - TensorFlow.js 返回类型错误 : Cannot read property 'concat' of undefined when loading models

python - 将 retrain.py 的输出转换为 tensorflow.js

node.js - 预计dense_Dense1_input的形状为 "a",但得到的数组的形状为 "b"

javascript - JSDoc - 记录可能返回任何类型的方法的正确方法?

javascript - 从 XMLHttpRequest 中提取单个元素

Tensorflow tf.map_fn 参数

python - 读取 tfrecord : DecodeError: Error parsing message

javascript - 全屏菜单淡入淡出不适用于 svg 和图像

javascript - YouTube URL 到 Iframe