提交 324f4196 编写于 作者: H HexToString

update doc

上级 ef889659
...@@ -37,7 +37,7 @@ python3.6 -m paddle_serving_server.serve --model uci_housing_model --thread 10 - ...@@ -37,7 +37,7 @@ python3.6 -m paddle_serving_server.serve --model uci_housing_model --thread 10 -
### 客户端使用curl访问 ### 客户端使用curl访问
```shell ```shell
curl -XPOST http://127.0.0.1:9393/GeneralModelService/inference -d ' {"tensor":[{"float_data":[0.0137,-0.1136,0.2553,-0.0692,0.0582,-0.0727,-0.1583,-0.0584,0.6283,0.4919,0.1856,0.0795,-0.0332],"elem_type":1,"shape":[1,13]}],"fetch_var_names":["price"],"log_id":0}' curl -XPOST http://0.0.0.0:9393/GeneralModelService/inference -d ' {"tensor":[{"float_data":[0.0137,-0.1136,0.2553,-0.0692,0.0582,-0.0727,-0.1583,-0.0584,0.6283,0.4919,0.1856,0.0795,-0.0332],"elem_type":1,"name":"x","alias_name":"x","shape":[1,13]}],"fetch_var_names":["price"],"log_id":0}'
``` ```
其中`127.0.0.1:9393`为IP和Port,根据您服务端启动的IP和Port自行设定。 其中`127.0.0.1:9393`为IP和Port,根据您服务端启动的IP和Port自行设定。
......
...@@ -25,7 +25,8 @@ public class PaddleServingClientExample { ...@@ -25,7 +25,8 @@ public class PaddleServingClientExample {
List<String> fetch = Arrays.asList("price"); List<String> fetch = Arrays.asList("price");
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
client.setIP("172.17.0.2");
client.setPort("9393");
String result = client.predict(feed_data, fetch, true, 0); String result = client.predict(feed_data, fetch, true, 0);
System.out.println(result); System.out.println(result);
...@@ -73,6 +74,8 @@ public class PaddleServingClientExample { ...@@ -73,6 +74,8 @@ public class PaddleServingClientExample {
}}; }};
List<String> fetch = Arrays.asList("save_infer_model/scale_0.tmp_0"); List<String> fetch = Arrays.asList("save_infer_model/scale_0.tmp_0");
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
client.setIP("172.17.0.2");
client.setPort("9393");
String result = client.predict(feed_data, fetch, true, 0); String result = client.predict(feed_data, fetch, true, 0);
System.out.println(result); System.out.println(result);
return true; return true;
...@@ -91,8 +94,9 @@ public class PaddleServingClientExample { ...@@ -91,8 +94,9 @@ public class PaddleServingClientExample {
put("segment_ids", Nd4j.createFromArray(segment_ids)); put("segment_ids", Nd4j.createFromArray(segment_ids));
}}; }};
List<String> fetch = Arrays.asList("pooled_output"); List<String> fetch = Arrays.asList("pooled_output");
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
client.setIP("172.17.0.2");
client.setPort("9393");
String result = client.predict(feed_data, fetch, true, 0); String result = client.predict(feed_data, fetch, true, 0);
System.out.println(result); System.out.println(result);
return true; return true;
...@@ -160,6 +164,8 @@ public class PaddleServingClientExample { ...@@ -160,6 +164,8 @@ public class PaddleServingClientExample {
}}; }};
List<String> fetch = Arrays.asList("prob"); List<String> fetch = Arrays.asList("prob");
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
client.setIP("172.17.0.2");
client.setPort("9393");
String result = client.predict(feed_data, fetch, true, 0); String result = client.predict(feed_data, fetch, true, 0);
System.out.println(result); System.out.println(result);
return true; return true;
......
...@@ -109,7 +109,7 @@ public class HttpClient { ...@@ -109,7 +109,7 @@ public class HttpClient {
feedTensorLen_ = null; feedTensorLen_ = null;
feedNameToIndex_ = null; feedNameToIndex_ = null;
httpTimeoutS_ = 200000; httpTimeoutS_ = 200000;
ip = "127.0.0.1"; ip = "0.0.0.0";
port = "9393"; port = "9393";
serverPort = "9393"; serverPort = "9393";
serviceName = "/GeneralModelService/inference"; serviceName = "/GeneralModelService/inference";
...@@ -151,10 +151,13 @@ public class HttpClient { ...@@ -151,10 +151,13 @@ public class HttpClient {
public void loadClientConfig(String model_config_path) { public void loadClientConfig(String model_config_path) {
GeneralModelConfig.Builder model_conf_builder = GeneralModelConfig.newBuilder(); GeneralModelConfig.Builder model_conf_builder = GeneralModelConfig.newBuilder();
try { try {
String model_config_str = Files.readString(Paths.get(model_config_path)); byte[] data = Files.readAllBytes(Paths.get(model_config_path));
String model_config_str = new String(data, "utf-8");
com.google.protobuf.TextFormat.getParser().merge(model_config_str, model_conf_builder); com.google.protobuf.TextFormat.getParser().merge(model_config_str, model_conf_builder);
} catch (com.google.protobuf.TextFormat.ParseException e) { } catch (com.google.protobuf.TextFormat.ParseException e) {
System.out.format("Parse client config failed: %s\n", e.toString()); System.out.format("Parse client config failed: %s\n", e.toString());
} catch (Exception e) {
System.out.format("Open client config failed: %s\n", e.toString());
} }
GeneralModelConfig model_conf = model_conf_builder.build(); GeneralModelConfig model_conf = model_conf_builder.build();
...@@ -202,7 +205,8 @@ public class HttpClient { ...@@ -202,7 +205,8 @@ public class HttpClient {
String key_str = null; String key_str = null;
String encrypt_url = "http://" + this.ip + ":" +this.port; String encrypt_url = "http://" + this.ip + ":" +this.port;
try { try {
key_str = Files.readString(Paths.get(keyFilePath)); byte[] data = Files.readAllBytes(Paths.get(keyFilePath));
key_str = new String(data, "utf-8");
} catch (Exception e) { } catch (Exception e) {
System.out.format("Open key file failed: %s\n", e.toString()); System.out.format("Open key file failed: %s\n", e.toString());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册