【发布时间】:2020-09-01 13:45:23
【问题描述】:
假设我有一个这样的张量:
let myTensor = tf.tensor([
[1,2,3],
[4,5,6],
[7,8,9]
]);
根据 Tensorflow.js API 文档,我可以使用 tf.node.encodePng 将张量转换为 PNG。文档声称其参数是这样的:
参数:
image(Tensor3D) 形状为 [高度、宽度、通道] 的 3-D uint8 张量。compression(数字)一个可选的整数。默认为 -1。压缩级别。可选
在这种情况下,我假设我可以像这样将我的张量编码为 PNG:
let myImage = await tf.node.encodePng(myTensor.cast("uint8"));
但是,这会导致以下崩溃:
Uncaught Error: Failed to cast to unknown dtype uint8
at cast_ (.../node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:5093:15)
at Object.cast (.../ingester/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4186:29)
at Tensor.cast (.../ingester/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:2181:26)
根据documentation for the cast method,uint8 不是张量的有效类型。
如何将float32 类型的 2D 张量转换为 PNG 图像?
【问题讨论】:
标签: javascript node.js tensorflow tensor tensorflow.js