Search in sources :

Example 1 with AutoMlImageClassificationInputs

use of com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs in project java-aiplatform by googleapis.

the class ValueConverterTest method testValueConverterFromValueWithBadInputs.

@Test
public void testValueConverterFromValueWithBadInputs() throws InvalidProtocolBufferException {
    JsonObject testBadJsonInputs = new JsonObject();
    testBadJsonInputs.addProperty("wrong_key", "some_value");
    Value.Builder badValueBuilder = Value.newBuilder();
    JsonFormat.parser().merge(testBadJsonInputs.toString(), badValueBuilder);
    final Value testBadValueInputs = badValueBuilder.build();
    assertThrows(InvalidProtocolBufferException.class, new ThrowingRunnable() {

        @Override
        public void run() throws Throwable {
            AutoMlImageClassificationInputs actualBadInput = (AutoMlImageClassificationInputs) ValueConverter.fromValue(AutoMlImageClassificationInputs.newBuilder(), testBadValueInputs);
        }
    });
}
Also used : AutoMlImageClassificationInputs(com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs) Value(com.google.protobuf.Value) JsonObject(com.google.gson.JsonObject) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 2 with AutoMlImageClassificationInputs

use of com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs in project java-aiplatform by googleapis.

the class ValueConverterTest method testValueConverterToValue.

@Test
public void testValueConverterToValue() throws InvalidProtocolBufferException {
    AutoMlImageClassificationInputs testObjectInputs = AutoMlImageClassificationInputs.newBuilder().setModelType(ModelType.CLOUD).setBudgetMilliNodeHours(8000).setMultiLabel(true).setDisableEarlyStopping(false).build();
    Value actualConvertedValue = ValueConverter.toValue(testObjectInputs);
    Struct actualStruct = actualConvertedValue.getStructValue();
    assertEquals(3, actualStruct.getFieldsCount());
    Collection<Object> innerFields = actualStruct.getAllFields().values();
    Collection<MapEntry> fieldEntries = (Collection<MapEntry>) innerFields.toArray()[0];
    MapEntry actualBoolValueEntry = null;
    MapEntry actualStringValueEntry = null;
    MapEntry actualNumberValueEntry = null;
    for (MapEntry entry : fieldEntries) {
        String key = entry.getKey().toString();
        if (key.equals("multiLabel")) {
            actualBoolValueEntry = entry;
        } else if (key.equals("modelType")) {
            actualStringValueEntry = entry;
        } else if (key.equals("budgetMilliNodeHours")) {
            actualNumberValueEntry = entry;
        }
    }
    Value actualBoolValue = (Value) actualBoolValueEntry.getValue();
    assertEquals(testObjectInputs.getMultiLabel(), actualBoolValue.getBoolValue());
    Value actualStringValue = (Value) actualStringValueEntry.getValue();
    assertEquals("CLOUD", actualStringValue.getStringValue());
    Value actualNumberValue = (Value) actualNumberValueEntry.getValue();
    // protobuf stores int64 values as strings rather than numbers
    long actualNumber = Long.parseLong(actualNumberValue.getStringValue());
    assertEquals(testObjectInputs.getBudgetMilliNodeHours(), actualNumber);
}
Also used : MapEntry(com.google.protobuf.MapEntry) AutoMlImageClassificationInputs(com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs) Value(com.google.protobuf.Value) Collection(java.util.Collection) JsonObject(com.google.gson.JsonObject) Struct(com.google.protobuf.Struct) Test(org.junit.Test)

Example 3 with AutoMlImageClassificationInputs

use of com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs in project java-aiplatform by googleapis.

the class ValueConverterTest method testValueConverterFromValue.

@Test
public void testValueConverterFromValue() throws InvalidProtocolBufferException {
    JsonObject testJsonInputs = new JsonObject();
    testJsonInputs.addProperty("multi_label", true);
    testJsonInputs.addProperty("model_type", "CLOUD");
    testJsonInputs.addProperty("budget_milli_node_hours", 8000);
    Value.Builder valueBuilder = Value.newBuilder();
    JsonFormat.parser().merge(testJsonInputs.toString(), valueBuilder);
    Value testValueInputs = valueBuilder.build();
    AutoMlImageClassificationInputs actualInputs = (AutoMlImageClassificationInputs) ValueConverter.fromValue(AutoMlImageClassificationInputs.newBuilder(), testValueInputs);
    assertEquals(8000, actualInputs.getBudgetMilliNodeHours());
    assertEquals(true, actualInputs.getMultiLabel());
    assertEquals(ModelType.CLOUD, actualInputs.getModelType());
}
Also used : AutoMlImageClassificationInputs(com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs) Value(com.google.protobuf.Value) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 4 with AutoMlImageClassificationInputs

use of com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs in project java-aiplatform by googleapis.

the class CreateTrainingPipelineImageClassificationSample method createTrainingPipelineImageClassificationSample.

static void createTrainingPipelineImageClassificationSample(String project, String trainingPipelineDisplayName, String datasetId, String modelDisplayName) throws IOException {
    PipelineServiceSettings pipelineServiceSettings = PipelineServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PipelineServiceClient pipelineServiceClient = PipelineServiceClient.create(pipelineServiceSettings)) {
        String location = "us-central1";
        String trainingTaskDefinition = "gs://google-cloud-aiplatform/schema/trainingjob/definition/" + "automl_image_classification_1.0.0.yaml";
        LocationName locationName = LocationName.of(project, location);
        AutoMlImageClassificationInputs autoMlImageClassificationInputs = AutoMlImageClassificationInputs.newBuilder().setModelType(ModelType.CLOUD).setMultiLabel(false).setBudgetMilliNodeHours(8000).setDisableEarlyStopping(false).build();
        InputDataConfig trainingInputDataConfig = InputDataConfig.newBuilder().setDatasetId(datasetId).build();
        Model model = Model.newBuilder().setDisplayName(modelDisplayName).build();
        TrainingPipeline trainingPipeline = TrainingPipeline.newBuilder().setDisplayName(trainingPipelineDisplayName).setTrainingTaskDefinition(trainingTaskDefinition).setTrainingTaskInputs(ValueConverter.toValue(autoMlImageClassificationInputs)).setInputDataConfig(trainingInputDataConfig).setModelToUpload(model).build();
        TrainingPipeline trainingPipelineResponse = pipelineServiceClient.createTrainingPipeline(locationName, trainingPipeline);
        System.out.println("Create Training Pipeline Image Classification Response");
        System.out.format("Name: %s\n", trainingPipelineResponse.getName());
        System.out.format("Display Name: %s\n", trainingPipelineResponse.getDisplayName());
        System.out.format("Training Task Definition %s\n", trainingPipelineResponse.getTrainingTaskDefinition());
        System.out.format("Training Task Inputs: %s\n", trainingPipelineResponse.getTrainingTaskInputs());
        System.out.format("Training Task Metadata: %s\n", trainingPipelineResponse.getTrainingTaskMetadata());
        System.out.format("State: %s\n", trainingPipelineResponse.getState());
        System.out.format("Create Time: %s\n", trainingPipelineResponse.getCreateTime());
        System.out.format("StartTime %s\n", trainingPipelineResponse.getStartTime());
        System.out.format("End Time: %s\n", trainingPipelineResponse.getEndTime());
        System.out.format("Update Time: %s\n", trainingPipelineResponse.getUpdateTime());
        System.out.format("Labels: %s\n", trainingPipelineResponse.getLabelsMap());
        InputDataConfig inputDataConfig = trainingPipelineResponse.getInputDataConfig();
        System.out.println("Input Data Config");
        System.out.format("Dataset Id: %s", inputDataConfig.getDatasetId());
        System.out.format("Annotations Filter: %s\n", inputDataConfig.getAnnotationsFilter());
        FractionSplit fractionSplit = inputDataConfig.getFractionSplit();
        System.out.println("Fraction Split");
        System.out.format("Training Fraction: %s\n", fractionSplit.getTrainingFraction());
        System.out.format("Validation Fraction: %s\n", fractionSplit.getValidationFraction());
        System.out.format("Test Fraction: %s\n", fractionSplit.getTestFraction());
        FilterSplit filterSplit = inputDataConfig.getFilterSplit();
        System.out.println("Filter Split");
        System.out.format("Training Filter: %s\n", filterSplit.getTrainingFilter());
        System.out.format("Validation Filter: %s\n", filterSplit.getValidationFilter());
        System.out.format("Test Filter: %s\n", filterSplit.getTestFilter());
        PredefinedSplit predefinedSplit = inputDataConfig.getPredefinedSplit();
        System.out.println("Predefined Split");
        System.out.format("Key: %s\n", predefinedSplit.getKey());
        TimestampSplit timestampSplit = inputDataConfig.getTimestampSplit();
        System.out.println("Timestamp Split");
        System.out.format("Training Fraction: %s\n", timestampSplit.getTrainingFraction());
        System.out.format("Validation Fraction: %s\n", timestampSplit.getValidationFraction());
        System.out.format("Test Fraction: %s\n", timestampSplit.getTestFraction());
        System.out.format("Key: %s\n", timestampSplit.getKey());
        Model modelResponse = trainingPipelineResponse.getModelToUpload();
        System.out.println("Model To Upload");
        System.out.format("Name: %s\n", modelResponse.getName());
        System.out.format("Display Name: %s\n", modelResponse.getDisplayName());
        System.out.format("Description: %s\n", modelResponse.getDescription());
        System.out.format("Metadata Schema Uri: %s\n", modelResponse.getMetadataSchemaUri());
        System.out.format("Metadata: %s\n", modelResponse.getMetadata());
        System.out.format("Training Pipeline: %s\n", modelResponse.getTrainingPipeline());
        System.out.format("Artifact Uri: %s\n", modelResponse.getArtifactUri());
        System.out.format("Supported Deployment Resources Types: %s\n", modelResponse.getSupportedDeploymentResourcesTypesList());
        System.out.format("Supported Input Storage Formats: %s\n", modelResponse.getSupportedInputStorageFormatsList());
        System.out.format("Supported Output Storage Formats: %s\n", modelResponse.getSupportedOutputStorageFormatsList());
        System.out.format("Create Time: %s\n", modelResponse.getCreateTime());
        System.out.format("Update Time: %s\n", modelResponse.getUpdateTime());
        System.out.format("Labels: %sn\n", modelResponse.getLabelsMap());
        PredictSchemata predictSchemata = modelResponse.getPredictSchemata();
        System.out.println("Predict Schemata");
        System.out.format("Instance Schema Uri: %s\n", predictSchemata.getInstanceSchemaUri());
        System.out.format("Parameters Schema Uri: %s\n", predictSchemata.getParametersSchemaUri());
        System.out.format("Prediction Schema Uri: %s\n", predictSchemata.getPredictionSchemaUri());
        for (ExportFormat exportFormat : modelResponse.getSupportedExportFormatsList()) {
            System.out.println("Supported Export Format");
            System.out.format("Id: %s\n", exportFormat.getId());
        }
        ModelContainerSpec modelContainerSpec = modelResponse.getContainerSpec();
        System.out.println("Container Spec");
        System.out.format("Image Uri: %s\n", modelContainerSpec.getImageUri());
        System.out.format("Command: %s\n", modelContainerSpec.getCommandList());
        System.out.format("Args: %s\n", modelContainerSpec.getArgsList());
        System.out.format("Predict Route: %s\n", modelContainerSpec.getPredictRoute());
        System.out.format("Health Route: %s\n", modelContainerSpec.getHealthRoute());
        for (EnvVar envVar : modelContainerSpec.getEnvList()) {
            System.out.println("Env");
            System.out.format("Name: %s\n", envVar.getName());
            System.out.format("Value: %s\n", envVar.getValue());
        }
        for (Port port : modelContainerSpec.getPortsList()) {
            System.out.println("Port");
            System.out.format("Container Port: %s\n", port.getContainerPort());
        }
        for (DeployedModelRef deployedModelRef : modelResponse.getDeployedModelsList()) {
            System.out.println("Deployed Model");
            System.out.format("Endpoint: %s\n", deployedModelRef.getEndpoint());
            System.out.format("Deployed Model Id: %s\n", deployedModelRef.getDeployedModelId());
        }
        Status status = trainingPipelineResponse.getError();
        System.out.println("Error");
        System.out.format("Code: %s\n", status.getCode());
        System.out.format("Message: %s\n", status.getMessage());
    }
}
Also used : Status(com.google.rpc.Status) PredictSchemata(com.google.cloud.aiplatform.v1.PredictSchemata) TrainingPipeline(com.google.cloud.aiplatform.v1.TrainingPipeline) AutoMlImageClassificationInputs(com.google.cloud.aiplatform.v1.schema.trainingjob.definition.AutoMlImageClassificationInputs) TimestampSplit(com.google.cloud.aiplatform.v1.TimestampSplit) Port(com.google.cloud.aiplatform.v1.Port) ExportFormat(com.google.cloud.aiplatform.v1.Model.ExportFormat) InputDataConfig(com.google.cloud.aiplatform.v1.InputDataConfig) LocationName(com.google.cloud.aiplatform.v1.LocationName) PredefinedSplit(com.google.cloud.aiplatform.v1.PredefinedSplit) FilterSplit(com.google.cloud.aiplatform.v1.FilterSplit) FractionSplit(com.google.cloud.aiplatform.v1.FractionSplit) ModelContainerSpec(com.google.cloud.aiplatform.v1.ModelContainerSpec) DeployedModelRef(com.google.cloud.aiplatform.v1.DeployedModelRef) Model(com.google.cloud.aiplatform.v1.Model) PipelineServiceSettings(com.google.cloud.aiplatform.v1.PipelineServiceSettings) EnvVar(com.google.cloud.aiplatform.v1.EnvVar) PipelineServiceClient(com.google.cloud.aiplatform.v1.PipelineServiceClient)

Aggregations

AutoMlImageClassificationInputs (com.google.cloud.aiplatform.v1beta1.schema.trainingjob.definition.AutoMlImageClassificationInputs)3 JsonObject (com.google.gson.JsonObject)3 Value (com.google.protobuf.Value)3 Test (org.junit.Test)3 DeployedModelRef (com.google.cloud.aiplatform.v1.DeployedModelRef)1 EnvVar (com.google.cloud.aiplatform.v1.EnvVar)1 FilterSplit (com.google.cloud.aiplatform.v1.FilterSplit)1 FractionSplit (com.google.cloud.aiplatform.v1.FractionSplit)1 InputDataConfig (com.google.cloud.aiplatform.v1.InputDataConfig)1 LocationName (com.google.cloud.aiplatform.v1.LocationName)1 Model (com.google.cloud.aiplatform.v1.Model)1 ExportFormat (com.google.cloud.aiplatform.v1.Model.ExportFormat)1 ModelContainerSpec (com.google.cloud.aiplatform.v1.ModelContainerSpec)1 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)1 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)1 Port (com.google.cloud.aiplatform.v1.Port)1 PredefinedSplit (com.google.cloud.aiplatform.v1.PredefinedSplit)1 PredictSchemata (com.google.cloud.aiplatform.v1.PredictSchemata)1 TimestampSplit (com.google.cloud.aiplatform.v1.TimestampSplit)1 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)1