TensorflowJS:输出的不同形状

TensorflowJS: different shape for output

我是 Tensorflow 的新手。

我的目标很简单:我有一个 3d 张量作为 input/training 值,我想 "map" 将其转换为 1d 输出张量。

当 运行 我的模型时,我得到一个错误,1d 输出张量不能分配给定义的 [5, 5] 形状:

const model = tf.sequential({
  layers: [
    tf.layers.dense({
      inputShape: [5, 5],
      units: 32,
      activation: "relu"
    }),
    tf.layers.dense({ units: 1, activation: "softmax" }),
  ]
});

output/input可以有不同的形状吗?我希望 3d 张量像 "groups of numbers" 解析为单个(1d 张量)数字。

要将高维张量(高于 1)映射到一维张量,需要在两者之间使用展平层

const model = tf.sequential({
  layers: [
    tf.layers.dense({
      inputShape: [5, 5],
      units: 32,
      activation: "relu"
    }),
    tf.layers.flatten(),
    tf.layers.dense({ units: 1, activation: "softmax" }),
  ]
});