I'm trying to train/create my own classifier, I attached this code to main camera and I didn't got any response from the console nor getting any errors. Or I just doing it the wrong way?
public class VisualRecog : MonoBehaviour{
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("cpu", m_positiveExamplesPath);
if (!m_VisualRecognition.TrainClassifier(OnTrainClassifier, "compClassifier", 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!");
}
}
}
by the way here is the link of the Unity SDK. Thanks!
If m_positiveExamplesPath
and m_negativeExamplesPath
are not valid path, you will get exception that says:
DirectoryNotFoundException: Could not find a part of the path
If your did not setup your credentials then you will get the error:
No API Key was found!
Those two problems are eliminated .
It takes about 10
seconds to get a reply from IBM server when you run this code. Please wait for at-least 15
seconds for a reply. The wait time actually depends on how big your cpu_positive_examples.zip and negative_examples.zip files are. Sometimes, it can take few minutes.
I didnt got any response from the console nor getting any errors.
The problem is from the Log
function. If you look closely, you will realize that IBM is using Log.Debug
instead of Debug.Log
. IBM's Log.Debug
comes from the IBM.Watson.DeveloperCloud.Logging
namespace and it doesn't show in the Editor Console tab. I can't tell if this is a bug or a feature but replacing all the Log.Debug
with Debug.Log
should fix your problem.
I got a reply with the code below within 10 seconds(Used Debug.Log
):
private VisualRecognition m_VisualRecognition = new VisualRecognition();
void Start()
{
string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip";
string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip";
Dictionary<string, string> positiveExamples = new Dictionary<string, string>();
positiveExamples.Add("giraffe", positiveExamplesPath);
if (!m_VisualRecognition.TrainClassifier(OnTrainClassifier, "unity-test-classifier-example", positiveExamples, negativeExamplesPath))
Debug.Log("Train classifier failed!");
}
private void OnTrainClassifier(GetClassifiersPerClassifierVerbose classifier, string data)
{
if (classifier != null)
{
Debug.Log("Classifier is training! " + classifier);
}
else
{
Debug.Log("Failed to train classifier!" + data);
}
}
If you are using Log.Debug()
, initialize the reactors in the beginning of your Start()
or Awake()
functions using
LogSystem.InstallDefaultReactors();
Alternatively, like Programmer says, use Unity's Debug.Log()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.