【发布时间】:2021-10-19 04:14:49
【问题描述】:
我在输入大小为 48、48、1 的 React Native 中使用我训练有素的模型。输入值是 rgb 图像。所以我尝试将图像转换为 tensor3d,然后转换为灰度并调整其大小。但是在调整模型大小后总是给出相同的预测值。我不明白我的代码哪里出了问题。我的模型精度还可以。
const imageDataArrayBuffer = await response.arrayBuffer();
const imageData = new Uint8Array(imageDataArrayBuffer);
let imageTensor = decodeJpeg(imageData).resizeBilinear([48,48]).reshape([48,48,3])
//let imag=imageTensor
imageTensor=tf.ones([48,48,3])
rgb_weights=[0.2989, 0.5870, 0.1140]
imageTensor = tf.mul(imageTensor, rgb_weights)
imageTensor = tf.sum(imageTensor, -1)
imageTensor = tf.expandDims(imageTensor, -1)
imageTensor=imageTensor.resizeBilinear([48,48]).reshape([-1,48,48,1])
let result = await model.predict(imageTensor).data()
alert("Result " +result)
【问题讨论】:
标签: python react-native rgb tensorflow.js grayscale