use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier in project java-sdk by watson-developer-cloud.
the class VisualRecognition method createClassifier.
/**
* Create a classifier.
*
* Train a new multi-faceted classifier on the uploaded image data. Create your custom classifier with positive or
* negative examples. Include at least two sets of examples, either two positive example files or one positive and one
* negative file. You can upload a maximum of 256 MB per call. Encode all names in UTF-8 if they contain non-ASCII
* characters (.zip and image file names, and classifier and class names). The service assumes UTF-8 encoding if it
* encounters non-ASCII characters.
*
* @param createClassifierOptions the {@link CreateClassifierOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Classifier}
*/
public ServiceCall<Classifier> createClassifier(CreateClassifierOptions createClassifierOptions) {
Validator.notNull(createClassifierOptions, "createClassifierOptions cannot be null");
String[] pathSegments = { "v3/classifiers" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
multipartBuilder.addFormDataPart("name", createClassifierOptions.name());
// Classes
for (String className : createClassifierOptions.classNames()) {
String dataName = className + "_positive_examples";
File positiveExamples = createClassifierOptions.positiveExamplesByClassName(className);
RequestBody body = RequestUtils.fileBody(positiveExamples, "application/octet-stream");
multipartBuilder.addFormDataPart(dataName, positiveExamples.getName(), body);
}
if (createClassifierOptions.negativeExamples() != null) {
RequestBody negativeExamplesBody = RequestUtils.inputStreamBody(createClassifierOptions.negativeExamples(), "application/octet-stream");
multipartBuilder.addFormDataPart("negative_examples", createClassifierOptions.negativeExamplesFilename(), negativeExamplesBody);
}
builder.body(multipartBuilder.build());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class));
}
Aggregations