在 Tensorflow.js 中输出大张量的所有值
Outputting all values of an large tensor in Tensorflow.js
我有一个 [174,48]
维张量,我想输出 all(不以类似于 this 值的方式压缩它们进入浏览器中的开发人员控制台。我如何才能做到这一点?
例子
const tensor = tf.tensor([[1, 2], [3, 4]]);
console.log(JSON.stringify(tensor.arraySync())); // [[1,2],[3,4]]
tensor.arraySync()
creates a nested array of the tensor. JSON.stringify
然后用于将数组转换为字符串,然后再打印到控制台。
备选方案
或者,您可以使用 tensor.dataSync()
,其中 returns 单个维度的数据而不是嵌套数组。
这两个函数还有一个不阻塞 UI 的异步版本,这对大张量特别有用:
我有一个 [174,48]
维张量,我想输出 all(不以类似于 this 值的方式压缩它们进入浏览器中的开发人员控制台。我如何才能做到这一点?
例子
const tensor = tf.tensor([[1, 2], [3, 4]]);
console.log(JSON.stringify(tensor.arraySync())); // [[1,2],[3,4]]
tensor.arraySync()
creates a nested array of the tensor. JSON.stringify
然后用于将数组转换为字符串,然后再打印到控制台。
备选方案
或者,您可以使用 tensor.dataSync()
,其中 returns 单个维度的数据而不是嵌套数组。
这两个函数还有一个不阻塞 UI 的异步版本,这对大张量特别有用: