0

我已经按照安装 SDK 和配置服务凭证的步骤进行操作。问题是我无法训练自己的分类器。我收到此错误:No overload for method 'TrainClassifier' takes 5 arguments

void Start()
{
    string m_positiveExamplesPath = Application.dataPath + "/testData/cpu_positive_examples.zip";
    string m_negativeExamplesPath = Application.dataPath + "/testData/negative_examples.zip";
    if(!m_VisualRecognition.TrainClassifier("components", "cpu", m_positiveExamplesPath, m_negativeExamplesPath, OnTrainClassifier))
        Log.Debug("ExampleVisualRecognition", "Train classifier failed!");
}

private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier)
{

    if(classifier != null)
    {
        Log.Debug("ExampleVisualRecognition", "Classifier is training! " + classifier);
    }
    else
    {
        Log.Debug("ExampleVisualRecognition", "Failed to train classifier!");
    }
}

是 GitHub 中 SDK 的链接。谢谢!

4

1 回答 1

1

您从示例页面复制了该代码,但看起来该页面上的所有内容都已过时。它需要由 IBM 更新。

该类VisualRecognition有 2 个重载TrainClassifier

public bool TrainClassifier(OnTrainClassifier callback, string classifierName, Dictionary<string, string> positiveExamples, string negativeExamplesPath = default(string), string mimeType = "application/zip", string customData = default(string))

public bool TrainClassifier(OnTrainClassifier callback, string classifierName, Dictionary<string, byte[]> positiveExamplesData, byte[] negativeExamplesData = null, string mimeType = "application/zip", string customData = default(string))

SDK 就在您面前。下次遇到这样的错误时,选择函数,右键单击Go To Definition。它将向您显示函数的重载,然后您将能够在其中传递正确的参数。

在此处输入图像描述

你的代码应该是这样的:

private VisualRecognition m_VisualRecognition = new VisualRecognition();

void Start()
{
    string m_positiveExamplesPath = Application.dataPath + "/testData/cpu_positive_examples.zip";
    string m_negativeExamplesPath = Application.dataPath + "/testData/negative_examples.zip";

    Dictionary<string, string> positiveExamples = new Dictionary<string, string>();
    positiveExamples.Add("giraffe", m_positiveExamplesPath);

    if (!m_VisualRecognition.TrainClassifier(OnTrainClassifier, "unity-test-classifier-example", positiveExamples, m_negativeExamplesPath))
        Log.Debug("ExampleVisualRecognition", "Train classifier failed!");
}

private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier, string data)
{

    if (classifier != null)
    {
        Log.Debug("ExampleVisualRecognition", "Classifier is training! " + classifier);
    }
    else
    {
        Log.Debug("ExampleVisualRecognition", "Failed to train classifier!");
    }
}

如果您需要任何其他示例,请不要示例页面中获取。从插件附带的示例文件夹中获取它。

于 2017-01-08T17:38:37.627 回答