【发布时间】:2023-02-18 08:03:52
【问题描述】:
我正在使用 tfjs-node 在我的 Node.js 应用程序中加载模型和预测结果。它提供了不错的结果,但对于某些图像,显示了以下错误:
Error when checking : expected input to have shape [null,300,300,3] but got array with shape [1,300,300,4].
加载和预测结果的代码:
const loadModel = async (imagePath) => {
const image = fs.readFileSync(imagePath);
let tensor = tf.node.decodeImage(image);
const resizedImage = tensor.resizeNearestNeighbor([300, 300]);
const batchedImage = resizedImage.expandDims(0);
const input = batchedImage.toFloat().div(tf.scalar(255));
const model = await tf.loadLayersModel(
process.env.ML_MODEL_PATH || "file://./ml-model/model.json"
);
let predictions = await model.predict(input).data();
predictions = Array.from(predictions);
};
如何解决这个问题?谢谢。
【问题讨论】:
标签: tensorflow tensorflow.js tfjs-node