我使用this链接解码图像并获得3d张量。代码如下:
const tf = require('@tensorflow/tfjs');
let node = require('@tensorflow/tfjs-node');
const { Image } = require('image-js');
async function getImage() {
let image = await Image.load('/path/to/image.jpg');
return image;
}
async function loadModel() {
let m = await tf.loadLayersModel('path/to/model.json')
return m;
}
let model = loadModel();
model.then(async function (res) {
const img = await getImage();
const imgTensor = node.decodeImage(img, 1, 'int32', false);
console.log(imgTensor);
}, function (err) {
console.log(err);
});
当我使用node.decodeImage()时,我得到UnhandledPromiseRejectionWarning: TypeError: node.decodeImage is not a function
。如果我使用tf.node.decodeImage(),则会得到UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'decodeImage' of undefined
。我在做什么错了?
答案 0 :(得分:0)
哦,我的错误,正确的格式如下:node.node.decodeImage(...)