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