训练自己的分类器IBM Watson Visual Recognition Unity3d

时间:2017-01-08 14:46:32

标签: c# unity3d watson visual-recognition

我已经按照安装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!");
    }
}

Here是GitHub中SDK的链接。谢谢!

1 个答案:

答案 0 :(得分:1)

您从example page复制了该代码,但看起来该页面上的所有内容都已过时。它需要由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。下次出现这样的错误时,选择该功能,右键单击转到定义。它将向您显示函数的重载,然后您将能够在其中传递正确的参数。

enter image description here

您的代码应该是这样的:

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!");
    }
}

如果您还需要其他任何示例,不要example page获取该示例。从插件附带的示例文件夹中获取它。