3
votes

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?

EDIT

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!

2

2 Answers

4
votes

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>
0
votes

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!