我想做的事:我想用mobileNet从TensorFlow.js图像分类中得到概率最高的className。我想将类名作为字符串。
问题:我不知道如何将类名隔离为字符串。有这个命令吗?或者你知道我该如何解决我的问题吗?
我的代码:
theAi();
async function theAi() {
const tf = require('@tensorflow/tfjs'),
mobilenet = require('@tensorflow-models/mobilenet'),
tfnode = require('@tensorflow/tfjs-node'),
fs = require('fs-extra');
const imageBuffer = await fs.readFile("./jesus.jpg"),
tfimage = tfnode.node.decodeImage(imageBuffer),
mobilenetModel = await mobilenet.load();
const results = await mobilenetModel.classify(tfimage);
console.log(results);
};
和输出:
[
{
className: 'chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour',
probability: 0.5979475378990173
},
{ className: 'vestment', probability: 0.14261281490325928 },
{ className: 'fountain', probability: 0.03441018983721733 }
]
所以在这种情况下,我想得到字符串('chain mail, ring mail, mail, chain armor, chain armour, ring armour, ring armour')。