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);
}
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]));
}
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);
}
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;
}
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();
}
Aggregations