Tensorflow.js TypeError: Cannot read property 'arraySync' of undefined

Tensorflow.js TypeError: Cannot read property 'arraySync' of undefined

我在 dataSync 和 arraySync 上都遇到了这个错误。定义模型并检索结果。

正在执行的代码:

  const result = await faceLandmarkModel.executeAsync({
     Placeholder: images_pl
  });
  console.log(result[0]);
  const emb_values = result[0].dataSync();

张量对象:

Tensor {
 kept: false, 
 isDisposedInternal: false, 
 shape: Array(4), 
 dtype: "float32", 
 size: 716130,
 dataId: {},
 dtype: "float32",
 id: 123347
 isDisposedInternal: false,
 kept: false
 rankType: "4"
 scopeId: 283898
 shape: (4) [1, 365, 654, 3]
 strides: (3) [716130, 1962, 3]
 }

有人知道吗?非常感谢任何帮助。

您必须先下载张量,然后才能访问其中的数组

result.dataSync()[0]

模型接收到的张量不是数组,我也用错了模型。抱歉,这不是一个小问题 :)