use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.
the class RandomABTestUnitTest method simpleTest.
@Test
public void simpleTest() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
PredictorSpec.Builder predictorSpecBuilder = PredictorSpec.newBuilder();
predictorSpecBuilder.setName("p1");
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);
PredictiveUnit pu1 = predictiveUnitBuilder.build();
predictiveUnitBuilder = PredictiveUnit.newBuilder();
predictiveUnitBuilder.setName("2");
predictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.MODEL);
predictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.SIMPLE_MODEL);
PredictiveUnit pu2 = predictiveUnitBuilder.build();
predictiveUnitBuilder = PredictiveUnit.newBuilder();
predictiveUnitBuilder.setName("3");
predictiveUnitBuilder.setType(PredictiveUnit.PredictiveUnitType.ROUTER);
predictiveUnitBuilder.setImplementation(PredictiveUnit.PredictiveUnitImplementation.RANDOM_ABTEST);
predictiveUnitBuilder.addChildren(pu1);
predictiveUnitBuilder.addChildren(pu2);
Parameter.Builder pBuilder = Parameter.newBuilder().setName("ratioA").setValue("0.5").setType(ParameterType.FLOAT);
predictiveUnitBuilder.addParameters(pBuilder.build());
PredictiveUnit pu3 = predictiveUnitBuilder.build();
predictorSpecBuilder.setGraph(pu3);
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 SimpleModelUnitTest method simpleTestWithImageNoVersion.
@Test
public void simpleTestWithImageNoVersion() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
// PredictorSpecBuilder.setEnabled(true);
PredictorSpecBuilder.setName("p1");
// PredictorSpecBuilder.setRoot("1");
PredictorSpecBuilder.setReplicas(1);
final String imageName = "myimage";
PodTemplateSpec.Builder ptsBuilder = PodTemplateSpec.newBuilder().setSpec(PodSpec.newBuilder().addContainers(Container.newBuilder().setImage(imageName).setName("1")));
PredictorSpecBuilder.setComponentSpec(ptsBuilder);
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);
Assert.assertEquals(imageName, predictorState.getRootState().imageName);
Assert.assertEquals("", predictorState.getRootState().imageVersion);
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 SimpleModelUnitTest method simpleTestWithImageVersion.
@Test
public void simpleTestWithImageVersion() throws InterruptedException, ExecutionException, InvalidProtocolBufferException {
PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
// PredictorSpecBuilder.setEnabled(true);
PredictorSpecBuilder.setName("p1");
// PredictorSpecBuilder.setRoot("1");
PredictorSpecBuilder.setReplicas(1);
final String imageName = "myimage";
final String imageVersion = "0.1";
PodTemplateSpec.Builder ptsBuilder = PodTemplateSpec.newBuilder().setSpec(PodSpec.newBuilder().addContainers(Container.newBuilder().setImage(imageName + ":" + imageVersion).setName("1")));
PredictorSpecBuilder.setComponentSpec(ptsBuilder);
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);
Assert.assertEquals(imageName, predictorState.getRootState().imageName);
Assert.assertEquals(imageVersion, predictorState.getRootState().imageVersion);
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 RestClientController method predictions.
@RequestMapping(value = "/api/v0.1/predictions", method = RequestMethod.POST, consumes = "application/json; charset=utf-8", produces = "application/json; charset=utf-8")
public ResponseEntity<String> predictions(RequestEntity<String> requestEntity) {
SeldonMessage request;
try {
SeldonMessage.Builder builder = SeldonMessage.newBuilder();
ProtoBufUtils.updateMessageBuilderFromJson(builder, requestEntity.getBody());
request = builder.build();
} catch (InvalidProtocolBufferException e) {
logger.error("Bad request", e);
throw new APIException(ApiExceptionType.ENGINE_INVALID_JSON, requestEntity.getBody());
}
try {
SeldonMessage response = predictionService.predict(request);
String json = ProtoBufUtils.toJson(response);
return new ResponseEntity<String>(json, HttpStatus.OK);
} catch (InterruptedException e) {
throw new APIException(ApiExceptionType.ENGINE_INTERRUPTED, e.getMessage());
} catch (ExecutionException e) {
if (e.getCause().getClass() == APIException.class) {
throw (APIException) e.getCause();
} else {
throw new APIException(ApiExceptionType.ENGINE_EXECUTION_FAILURE, e.getMessage());
}
} catch (InvalidProtocolBufferException e) {
throw new APIException(ApiExceptionType.ENGINE_INVALID_JSON, "");
}
}
use of io.seldon.protos.PredictionProtos.SeldonMessage in project seldon-core by SeldonIO.
the class SeldonClientExample method predict.
public void predict() throws InvalidProtocolBufferException {
SeldonMessage request = SeldonMessage.newBuilder().setData(DefaultData.newBuilder().setTensor(Tensor.newBuilder().addValues(1.0).addShape(1))).build();
SeldonMessage response = blockingStub.predict(request);
logger.info(ProtoBufUtils.toJson(response));
}
Aggregations