如何定义我要在另一个维度上添加张量的维度? -TensorFlow.js

时间:2020-09-17 18:46:29

标签: javascript tensorflow

我正在建立一个卷积神经网络,并希望在卷积完成后增加偏见。如果.add()尝试广播它,则它会尝试添加到最深的级别。请参见下一个示例:

const output = tf.tensor([
  [
    [0,0],
    [0,0]
  ],
  [
    [1,1],
    [1,1],
  ]
]);

const biases = tf.tensor([1,2]);

const result = output.add(biases);
console.log('Result:');
result.print();

/*
  If I'd be able to specify at which level I'd like to
  add the values, and would specify the outer level,
  it would mean add 1 to the first row, and add 2 to
  the second rows items.
*/
const expected = tf.tensor([
  [
    [1,1],
    [1,1]
  ],
  [
    [3,3],
    [3,3]
  ]
]);
console.log('Expected:');
expected.print();
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>

有办法吗?

0 个答案:

没有答案