gpt4 book ai didi

node.js - 隐式形状不能是小数

转载 作者:行者123 更新时间:2023-12-04 09:06:55 25 4
gpt4 key购买 nike

我正在尝试在 TensorFlow 中创建一个标签。
这是 image在下面的代码中。

async function main(){
const model = await mobilenet.load();
const classifier = await knnClassifier.create();
const buf = fs.readFileSync('./41.png');
const decode = tfnode.node.decodeImage(buf);
console.log(decode)
return new Promise(async resolve => {
const embedding = model.infer(
decode,
false
);
classifier.addExample(
embedding,
'rong'
)
})
}
我收到了这个错误:
(node:17992) UnhandledPromiseRejectionWarning: Error: The implicit shape can't be a fractional number. Got 200704 / 150528
这是当我 console.log() 解码时:
Tensor {
kept: false,
isDisposedInternal: false,
shape: [ 475, 475, 4 ],
dtype: 'int32',
size: 902500,
strides: [ 1900, 4 ],
dataId: {},
id: 264,
rankType: '3',
scopeId: 311
}

最佳答案

我昨晚遇到了和你一样的问题。我想知道为什么它不适用于 PNG 图像,但 JPG 图像可以正常工作。事实证明,它有事情要做number of channels从缓冲区解码图像时使用。
当我们使用 decodeImage函数( reference ),它使用 3 个 channel 用于 JPG,4 个 channel 用于 PNG。但是,该模型需要 3 个 channel 。解码图像后,我们可以明确告诉 decodeImage使用 3 个 channel 来解码所有类型的图像。
修改后的代码如下所示:

async function main() {
const model = await mobilenet.load();
const classifier = await knnClassifier.create();
const buf = fs.readFileSync('./41.png');
const decode = tfnode.node.decodeImage(buf, 3);

return new Promise(async resolve => {
const embedding = model.infer(decode, false);
classifier.addExample(embedding, 'rong');
})
}
decodeImage现在接受第二个参数,指示在图像解码期间要使用的 channel 数。

关于node.js - 隐式形状不能是小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63421470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com