Search in sources :

Example 11 with SeldonMessage

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));
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage)

Example 12 with SeldonMessage

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

the class TestPredictionProto method defaultRequest.

@Test
public void defaultRequest() throws InvalidProtocolBufferException {
    String[] features = { "a", "b" };
    Double[] values = { 1.0, 2.0, 1.5, 2.2 };
    DefaultData.Builder defB = DefaultData.newBuilder();
    defB.addAllNames(Arrays.asList(features));
    defB.setTensor(Tensor.newBuilder().addShape(1).addShape(values.length).addAllValues(Arrays.asList(values)).build());
    SeldonMessage.Builder b = SeldonMessage.newBuilder();
    Value v;
    Value v1 = Value.newBuilder().setNumberValue(1.0).build();
    b.setData(defB.build()).setMeta(Meta.newBuilder().putTags("key", v1).build());
    SeldonMessage request = b.build();
    String json = ProtoBufUtils.toJson(request);
    System.out.println(json);
    SeldonMessage.Builder b2 = SeldonMessage.newBuilder();
    ProtoBufUtils.updateMessageBuilderFromJson(b2, json);
    SeldonMessage request2 = b2.build();
    String json2 = ProtoBufUtils.toJson(request2);
    System.out.println(json2);
    Assert.assertEquals(json, json2);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) Value(com.google.protobuf.Value) ByteString(com.google.protobuf.ByteString) DefaultData(io.seldon.protos.PredictionProtos.DefaultData) Test(org.junit.Test)

Example 13 with SeldonMessage

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

the class TestPredictionProto method parse_json.

@Test
public void parse_json() throws InvalidProtocolBufferException {
    String json = "{\"request\":{\"values\":[[1.0],[2.0]]}}";
    SeldonMessage.Builder builder = SeldonMessage.newBuilder();
    ProtoBufUtils.updateMessageBuilderFromJson(builder, json);
    SeldonMessage request = builder.build();
    String json2 = ProtoBufUtils.toJson(request);
    System.out.println(json2);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 14 with SeldonMessage

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

the class TestPredictionProto method parse_tags_array.

@Test
public void parse_tags_array() throws InvalidProtocolBufferException {
    String json = "{\"meta\":{\"tags\":{\"user\":[\"a\",\"b\"],\"gender\":\"female\"}},\"request\":{\"ndarray\":[[1.0,2.0],[3.0,4.0]]}}";
    SeldonMessage.Builder builder = SeldonMessage.newBuilder();
    ProtoBufUtils.updateMessageBuilderFromJson(builder, json);
    SeldonMessage request = builder.build();
    Assert.assertEquals(2, request.getData().getNdarray().getValuesCount());
    String json2 = ProtoBufUtils.toJson(request);
    System.out.println(json2);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 15 with SeldonMessage

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

the class TestPredictionProto method parse_custom_json.

@Test
public void parse_custom_json() throws InvalidProtocolBufferException {
    String json = "{\"request\":{\"ndarray\":[[1.0,2.0],[3.0,4.0]]}}";
    SeldonMessage.Builder builder = SeldonMessage.newBuilder();
    ProtoBufUtils.updateMessageBuilderFromJson(builder, json);
    SeldonMessage request = builder.build();
    Assert.assertEquals(2, request.getData().getNdarray().getValuesCount());
    String json2 = ProtoBufUtils.toJson(request);
    System.out.println(json2);
}
Also used : SeldonMessage(io.seldon.protos.PredictionProtos.SeldonMessage) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

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