Reputation: 85
I have already classified images against IBMs preconfigured classifier.
Now I try to create and then use my own classifier (called "Santa") to identify images of Santa Clause:
VisualRecognition service = new VisualRecognition(VisualRecognition.VERSION_DATE_2016_05_19);
service.setApiKey("***************");
File santa = new File("src/images/Santa.zip");
File notSanta = new File("src/images/NotSanta.zip");
CreateClassifierOptions classifierOptions = new CreateClassifierOptions.Builder()
.classifierName("Santa").addClass("Santa", santa).negativeExamples(notSanta).build();
VisualClassifier santaClassifier = service.createClassifier(classifierOptions).execute();
List<String> classifierIds = new ArrayList<String>();
classifierIds.add(santaClassifier.getId());
ClassifyImagesOptions classifyOptionsSanta = new ClassifyImagesOptions.Builder()
.classifierIds(classifierIds)
.images(new File ("src/images/lilSanta.png")).build();
VisualClassification resultSanta = service.classify(classifyOptionsSanta).execute();
System.out.println(resultSanta);
But then I get this answer:
{
"images_processed": 0,
"images": [
{
"classifiers": [],
"image": "lilSanta.png"
}
]
}
Why are there zero images processed and no classifiers in the answer? What am I doing wrong?
I created the classifier by using Curl now and waited for it to be fully trained. Then i noted the Classifier-ID and now I can easily use Java for that. I also used 50 pictures now. Thank you for your help!
Upvotes: 3
Views: 348
Reputation: 85
I created the classifier by using Curl now and waited for it to be fully trained. Then i noted the Classifier-ID and now I can easily use Java for that. I also used 50 pictures now. Thank you for your help!
Upvotes: 0
Reputation: 23663
images_processed
is zero because the service won't charge you for using a custom classifier. The parameter is intended to be used as a way to calculate how much the API call will cost.
Your code looks OK. I did some minor changes and reduced the threshold(0.5
by default):
VisualRecognition service = new VisualRecognition(VisualRecognition.VERSION_DATE_2016_05_19);
service.setApiKey("***************");
CreateClassifierOptions classifierOptions = new CreateClassifierOptions.Builder()
.classifierName("Santa")
.addClass("Santa", new File("src/images/Santa.zip"))
.negativeExamples(new File("src/images/NotSanta.zip"))
.build();
VisualClassifier santaClassifier = service.createClassifier(classifierOptions).execute();
ClassifyImagesOptions classifyOptionsSanta = new ClassifyImagesOptions.Builder()
.classifierIds(santaClassifier.getId())
.images(new File ("src/images/lilSanta.png"))
.threshold(0.0)
.build();
VisualClassification resultSanta = service.classify(classifyOptionsSanta).execute();
System.out.println(resultSanta);
Make sure you are sending 50 Santa and non-Santa images.
I've found that when I create the zip using a mac I get some extra __MACOX
files in. Check the zip file using unzip
unzip -l <zip-file>
Upvotes: 4