Custom Models

Clarifai makes it easy to customize and repurpose existing models.

You do not need many images to get started. We recommend starting with 10 and adding more as needed. Before you train your first model you will have needed to create an application and select a base workflow.

Add images with concepts

To get started training your own model, you must first add images that already contain the concepts you want your model to see.

import com.clarifai.grpc.api.*;
import com.clarifai.grpc.api.status.*;

// Insert here the initialization code as outlined on this page:
// https://docs.clarifai.com/api-guide/api-overview/api-clients#client-installation-instructions

MultiInputResponse postInputsResponse = stub.postInputs(
    PostInputsRequest.newBuilder()
        .addInputs(
            Input.newBuilder()
                .setData(
                    Data.newBuilder()
                        .setImage(
                            Image.newBuilder()
                                .setUrl("https://samples.clarifai.com/puppy.jpeg")
                                .setAllowDuplicateUrl(true)
                        )
                        .addConcepts(Concept.newBuilder().setId("charlie").setValue(1))
                        .addConcepts(Concept.newBuilder().setId("our_wedding").setValue(0))
                )
        )
        .addInputs(
            Input.newBuilder()
                .setData(
                    Data.newBuilder()
                        .setImage(
                            Image.newBuilder()
                                .setUrl("https://samples.clarifai.com/wedding.jpg")
                                .setAllowDuplicateUrl(true)
                        )
                        .addConcepts(Concept.newBuilder().setId("our_wedding").setValue(1))
                        .addConcepts(Concept.newBuilder().setId("charlie").setValue(0))
                        .addConcepts(Concept.newBuilder().setId("cat").setValue(0))
                )
        )
        .build()
);

if (postInputsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
    for (Input input : postInputsResponse.getInputsList()) {
        System.out.println("Input " + input.getId() + " status: ");
        System.out.println(input.getStatus() + "\n");
    }

    throw new RuntimeException("Post inputs failed, status: " + postInputsResponse.getStatus());
}