【问题标题】:TensorFlow JS (React Native) empty responseTensorFlow JS (React Native) 空响应
【发布时间】:2020-12-02 19:11:06
【问题描述】:

我在 GCloud AutoML Vision 上训练了一个模型,将其导出为 TensorFlow.js 模型,并在应用程序启动时加载它。查看 model.json,模型肯定需要 224x224 图像。我必须执行 tensor.reshape,因为当我对 [224, 224, 3] 的张量进行预测时,它拒绝了我的张量。

Base64 来自相机。我相信我正确地准备了这张图片,但我无法确定。

const imgBuffer = decodeBase64(base64) // from 'base64-arraybuffer' package
const raw = new Uint8Array(imgBuffer)

const imageTensor = decodeJpeg(raw)
const resizedImageTensor = imageTensor.resizeBilinear([224, 224])
const reshapedImageTensor = resizedImageTensor.reshape([1, 224, 224, 3])

const res = model.predict(reshapedImageTensor)
console.log('response', res)

但我得到的回应似乎并没有太多......

{
   "dataId":{},
   "dtype":"float32",
   "id":293,
   "isDisposedInternal":false,
   "kept":false,
   "rankType":"2",
   "scopeId":5,
   "shape":[
      1,
      1087
   ],
   "size":1087,
   "strides":[
      1087
   ]
}

这种类型的响应是什么意思?是不是我做错了什么?

【问题讨论】:

    标签: tensorflow tensorflow.js


    【解决方案1】:

    您需要使用dataSync()下载模型的实际预测。

    const res = model.predict(reshapedImageTensor);
    const predictions = res.dataSync();
    console.log('Predictions', predictions);
    

    【讨论】:

      猜你喜欢
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-07
      • 2019-06-26
      • 2018-02-20
      • 2021-12-08
      • 1970-01-01
      相关资源
      最近更新 更多