MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / main

Method main

serving/sdk/java/src/main/java/Demo.java:38–90  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

36 }
37
38 public static void main(String[] args) {
39 Demo demo = new Demo();
40 String modelEntry = "";
41 int[] state = {0};
42 Pointer model = Processor.INSTANCE.initialize(modelEntry, modelConfig, state);
43 if (state[0] == -1) {
44 System.err.println("initialize error");
45 }
46
47 // input type: float
48 Predict.ArrayDataType dtype = Predict.ArrayDataType.DT_FLOAT;
49 // input shape: [1, 1]
50 Predict.ArrayShape arrayShape =
51 Predict.ArrayShape.newBuilder()
52 .addDim(1)
53 .addDim(1)
54 .build();
55 // input array
56 Predict.ArrayProto input =
57 Predict.ArrayProto.newBuilder()
58 .addFloatVal((float) 1.0)
59 .setDtype(dtype)
60 .setArrayShape(arrayShape)
61 .build();
62 // PredictRequest
63 Predict.PredictRequest req =
64 Predict.PredictRequest.newBuilder()
65 .setSignatureName("serving_default")
66 .addOutputFilter("y:0")
67 .putInputs("x:0", input)
68 .build();
69 byte[] buffer = req.toByteArray();
70 int size = req.getSerializedSize();
71
72 // do process
73 PointerByReference output = new PointerByReference();
74 int[] outputSize = {0};
75 state[0] = Processor.INSTANCE.process(model, buffer, size, output, outputSize);
76
77 // parse response
78 byte[] outputString = output.getValue().getByteArray(0, outputSize[0]);
79 String s = new String(outputString);
80 try {
81 Predict.PredictResponse resp =
82 Predict.PredictResponse.newBuilder()
83 .mergeFrom(outputString)
84 .build();
85 System.out.println(resp.toString());
86 } catch (Exception e) {
87 System.err.println("parse response error");
88 }
89
90 }
91}

Callers

nothing calls this directly

Calls 4

initializeMethod · 0.65
buildMethod · 0.65
processMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected