【问题标题】:Classify in tensorflowjs在 tensorflowjs 中分类
【发布时间】:2019-09-12 02:47:54
【问题描述】:

按照this tutorial我想在tensorflowjs中加载并使用一个模型,然后使用classify方法对一个输入进行分类。

我像这样加载和执行模型:

const model = await window.tf.loadGraphModel(MODEL_URL);

const threshold = 0.9;
const labelsToInclude = ["test1"];

model.load(threshold, labelsToInclude).then(model2 => {
    model2.classify(["test sentence"])
      .then(predictions => {
    console.log('prediction: ' + predictions);
    return true;
  })
});

但我得到了错误:

TypeError: model2.classify is not a function at App.js:23

如何正确使用tensorflowjs中的classify方法?

【问题讨论】:

    标签: tensorflow tensorflow.js


    【解决方案1】:

    本教程使用特定模型 (toxicity)。它的loadclassify 函数不是Tensorflow.js 模型本身的特性,而是由这个特定模型实现的。

    查看API 了解一般型号支持的功能。如果你加载一个 GraphModel,你想使用model.predict(或execute)函数来执行模型。

    因此,您的代码应如下所示:

    const model = await window.tf.loadGraphModel(MODEL_URL);
    const input = tf.tensor(/* ... */); // whatever a valid tensor looks like for your model
    const predictions = model.predict([input]);
    console.log('prediction: ' + predictions);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 1970-01-01
      • 2023-02-21
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多