Search in sources :

Example 6 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class AverageCombinerTest method testSimpleNDArrayCase.

@Test
public void testSimpleNDArrayCase() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException {
    List<SeldonMessage> predictorReturns = new ArrayList<>();
    String[] names = { "c", "d" };
    Double[] values1 = { 1.0, 1.0 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setNdarray(ListValue.newBuilder().addValues(Value.newBuilder().setListValue(ListValue.newBuilder().addValues(Value.newBuilder().setNumberValue(values1[0])).addValues(Value.newBuilder().setNumberValue(values1[1])).build())).build()).build()).build());
    Double[] values2 = { 1.0, 0.5 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setNdarray(ListValue.newBuilder().addValues(Value.newBuilder().setListValue(ListValue.newBuilder().addValues(Value.newBuilder().setNumberValue(values2[0])).addValues(Value.newBuilder().setNumberValue(values2[1])).build())).build()).build()).build());
    Double[] values3 = { 2.2, 0.9 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setNdarray(ListValue.newBuilder().addValues(Value.newBuilder().setListValue(ListValue.newBuilder().addValues(Value.newBuilder().setNumberValue(values3[0])).addValues(Value.newBuilder().setNumberValue(values3[1])).build())).build()).build()).build());
    AverageCombinerUnit averageCombinerUnit = new AverageCombinerUnit();
    SeldonMessage average = averageCombinerUnit.aggregate(predictorReturns, null);
    Assert.assertThat(average.getData().getNamesList().get(0), is(names[0]));
    Double[][] expected_values = { { (1.0 + 1.0 + 2.2) / 3, (1.0 + 0.5 + 0.9) / 3 } };
    Assert.assertEquals(expected_values[0][0], average.getData().getNdarray().getValues(0).getListValue().getValues(0).getNumberValue(), 1e-7);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class AverageCombinerTest method testUniqueInput.

@Test
public void testUniqueInput() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException {
    List<SeldonMessage> predictorReturns = new ArrayList<>();
    String[] names = { "c" };
    Double[] values1 = { 1.0, 5.0, 0.3 };
    predictorReturns.add(SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(names)).setTensor(Tensor.newBuilder().addShape(1).addShape(3).addAllValues(Arrays.asList(values1)).build()).build()).build());
    AverageCombinerUnit averageCombinerUnit = new AverageCombinerUnit();
    SeldonMessage average = averageCombinerUnit.aggregate(predictorReturns, null);
    Assert.assertThat(average.getData().getNamesList().get(0), is(names[0]));
    Double[][] expected_values = { { 1.0, 5.0, 0.3 } };
    Assert.assertThat(average.getData().getTensor().getValuesList().get(0), is(expected_values[0][0]));
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class SimpleModelUnitTest method simpleTest.

@Test
public void simpleTest() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
    PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
    // PredictorSpecBuilder.setEnabled(true);
    PredictorSpecBuilder.setName("p1");
    // PredictorSpecBuilder.setRoot("1");
    PredictorSpecBuilder.setReplicas(1);
    PredictorSpecBuilder.setComponentSpec(PodTemplateSpec.newBuilder());
    PredictiveUnit.Builder PredictiveUnitBuilder = PredictiveUnit.newBuilder();
    PredictiveUnitBuilder.setName("1");
    PredictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.MODEL);
    PredictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.SIMPLE_MODEL);
    PredictorSpecBuilder.setGraph(PredictiveUnitBuilder.build());
    PredictorSpec predictor = PredictorSpecBuilder.build();
    PredictorState predictorState = predictorBean.predictorStateFromPredictorSpec(predictor);
    SeldonMessage p = SeldonMessage.newBuilder().build();
    SeldonMessage predictorReturn = predictorBean.predict(p, predictorState);
    Assert.assertEquals((double) SimpleModelUnit.values[0], predictorReturn.getData().getTensor().getValues(0), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[1], predictorReturn.getData().getTensor().getValues(1), 0);
    Assert.assertEquals((double) SimpleModelUnit.values[2], predictorReturn.getData().getTensor().getValues(2), 0);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) PredictiveUnit(io.seldon.protos.DeploymentProtos.PredictiveUnit) PredictorSpec(io.seldon.protos.DeploymentProtos.PredictorSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class SimpleModelUnit method transformInput.

@Override
public SeldonMessage transformInput(SeldonMessage input, PredictiveUnitState state) {
    SeldonMessage output = SeldonMessage.newBuilder().setStatus(Status.newBuilder().setStatus(Status.StatusFlag.SUCCESS).build()).setMeta(// .addModel(state.id))
    Meta.newBuilder()).setData(DefaultData.newBuilder().addAllNames(Arrays.asList(classes)).setTensor(Tensor.newBuilder().addShape(1).addShape(values.length).addAllValues(Arrays.asList(values)))).build();
    System.out.println("Model " + state.name + " finishing computations");
    return output;
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage)

Example 10 with SeldonMessage

use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.

the class PredictionService method predict.

public SeldonMessage predict(SeldonMessage request) throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
    if (!request.hasMeta()) {
        request = request.toBuilder().setMeta(Meta.newBuilder().setPuid(puidGenerator.nextPuidId()).build()).build();
    } else if (StringUtils.isEmpty(request.getMeta().getPuid())) {
        request = request.toBuilder().setMeta(request.getMeta().toBuilder().setPuid(puidGenerator.nextPuidId()).build()).build();
    }
    String puid = request.getMeta().getPuid();
    PredictorState predictorState = predictorBean.predictorStateFromPredictorSpec(enginePredictor.getPredictorSpec());
    SeldonMessage predictorReturn = predictorBean.predict(request, predictorState);
    SeldonMessage.Builder builder = SeldonMessage.newBuilder(predictorReturn).setMeta(Meta.newBuilder(predictorReturn.getMeta()).setPuid(puid));
    return builder.build();
}
Also used : PredictorState(io.seldon.engine.predictors.PredictorState) SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage)

Aggregations

SeldonMessage (io.seldon.protos.PredictionProtos.SeldonMessage)28 Test (org.junit.Test)18 ByteString (com.google.protobuf.ByteString)7 ArrayList (java.util.ArrayList)5 PredictiveUnit (io.seldon.protos.DeploymentProtos.PredictiveUnit)4 PredictorSpec (io.seldon.protos.DeploymentProtos.PredictorSpec)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 APIException (io.seldon.engine.exception.APIException)3 HashMap (java.util.HashMap)3 PodTemplateSpec (io.kubernetes.client.proto.V1.PodTemplateSpec)2 DefaultData (io.seldon.protos.PredictionProtos.DefaultData)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Value (com.google.protobuf.Value)1 SeldonAPIException (io.seldon.apife.exception.SeldonAPIException)1 PredictorState (io.seldon.engine.predictors.PredictorState)1 Parameter (io.seldon.protos.DeploymentProtos.Parameter)1 IOException (java.io.IOException)1