Javascript 如何从节点中的TensorFlow.js获取最可能的类名

Javascript 如何从节点中的TensorFlow.js获取最可能的类名,javascript,node.js,tensorflow,mobilenet,image-classification,Javascript,Node.js,Tensorflow,Mobilenet,Image Classification,我想做什么:我想从使用mobileNet的TensorFlow.js图像分类中获得概率最高的类名。我想将类名作为字符串获取 问题:我不知道如何将类名分离为字符串。有这个命令吗?或者你知道我如何解决我的问题吗 我的代码: theAi(); async function theAi() { const tf = require('@tensorflow/tfjs'), mobilenet = require('@tensorflow-models/mobilenet'),

我想做什么:我想从使用mobileNet的TensorFlow.js图像分类中获得概率最高的类名。我想将类名作为字符串获取

问题:我不知道如何将类名分离为字符串。有这个命令吗?或者你知道我如何解决我的问题吗

我的代码:

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 }
]
和输出:

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 }
]

因此,在本例中,我希望得到字符串(“链邮件,环邮件,邮件,链甲,链甲,环甲,环甲”)。

这是一个纯javascript问题。如果你得到这个结果,你可以搜索m 最大值:

const maxClass=result.reduce(函数(上一个,当前){
收益率(上一个概率>当前概率)?上一个:当前;
})[“类名”];

您好,请您看一下: