README.md 5.0 KB
Newer Older
W
wangjiawei04 已提交
1 2 3 4 5 6 7 8 9
## Tutorial of Java Client for Paddle Serving

(English|[简体中文](./README_CN.md))

### Development Environment

In order to facilitate users to use java for development, we provide the compiled Serving project to be placed in the java mirror. The way to get the mirror and enter the development environment is

```
H
heya02 已提交
10 11
docker pull registry.baidubce.com/paddlepaddle/serving:0.5.0-java
docker run --rm -dit --name java_serving registry.baidubce.com/paddlepaddle/serving:0.5.0-java
W
wangjiawei04 已提交
12 13 14 15 16 17 18 19 20
docker exec -it java_serving bash
cd Serving/java
```

The Serving folder is at the develop branch when the docker image is generated. You need to git pull to the latest version or git checkout to the desired branch.

### Install client dependencies

Due to the large number of dependent libraries, the image has been compiled once at the time of generation, and the user can perform the following operations
M
MRXLT 已提交
21 22 23 24 25 26 27 28 29

```
mvn compile
mvn install
cd examples
mvn compile
mvn install
```

30
### Start the server(not pipeline)
M
MRXLT 已提交
31

W
wangjiawei04 已提交
32
Take the fit_a_line model as an example, the server starts
M
MRXLT 已提交
33 34

```
W
wangjiawei04 已提交
35 36 37
cd ../../python/examples/fit_a_line
sh get_data.sh
python -m paddle_serving_server.serve --model uci_housing_model --thread 10 --port 9393 --use_multilang &
M
MRXLT 已提交
38 39
```

W
wangjiawei04 已提交
40 41
Client prediction

M
MRXLT 已提交
42
```
W
wangjiawei04 已提交
43
cd ../../../java/examples/target
M
MRXLT 已提交
44 45
java -cp paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PaddleServingClientExample fit_a_line
```
M
MRXLT 已提交
46

W
wangjiawei04 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
Take yolov4 as an example, the server starts

```
python -m paddle_serving_app.package --get_model yolov4
tar -xzvf yolov4.tar.gz
python -m paddle_serving_server_gpu.serve --model yolov4_model --port 9393 --gpu_ids 0 --use_multilang & #It needs to be executed in GPU Docker, otherwise the execution method of CPU must be used.
```

Client prediction

```
# in /Serving/java/examples/target
java -cp paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PaddleServingClientExample yolov4 ../../../python/examples/yolov4/000000570688.jpg
# The case of yolov4 needs to specify a picture as input
```
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
### Start the server(pipeline)

as for input data type = string,take IMDB model ensemble as an example,the server starts

```
cd ../../python/examples/pipeline/imdb_model_ensemble
sh get_data.sh
python -m paddle_serving_server.serve --model imdb_cnn_model --port 9292 &> cnn.log &
python -m paddle_serving_server.serve --model imdb_bow_model --port 9393 &> bow.log &
python test_pipeline_server.py &>pipeline.log &
```

Client prediction(Synchronous)

```
cd ../../../java/examples/target
java -cp paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PipelineClientExample string_imdb_predict
```

Client prediction(Asynchronous)

```
cd ../../../java/examples/target
java -cp paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PipelineClientExample asyn_predict
```


as for input data type = INDArray,take uci_housing_model as an example,the server starts

```
cd ../../python/examples/pipeline/simple_web_service
sh get_data.sh
94
python web_service_java.py &>log.txt &
95 96 97 98 99 100 101 102 103
```

Client prediction(Synchronous)

```
cd ../../../java/examples/target
java -cp paddle-serving-sdk-java-examples-0.0.1-jar-with-dependencies.jar PipelineClientExample indarray_predict
```

T
123  
Thomas Young 已提交
104 105 106 107 108 109 110
### Precautions for details

1.In the example, all models(not pipeline) need to use `--use_multilang` to start GRPC multi-programming language support, and the port number is 9393. If you need another port, you need to modify it in the java file

2.Currently Serving has launched the Pipeline mode (see [Pipeline Serving](../doc/PIPELINE_SERVING.md) for details). Pipeline Serving Client for Java is released.

3.The parameters`ip` and`port` in PipelineClientExample.java(path:java/examples/src/main/java/[PipelineClientExample.java](./examples/src/main/java/PipelineClientExample.java)),needs to be connected with the corresponding pipeline server parameters`ip` and`port` which is defined in the config.yaml(Taking IMDB model ensemble as an example,path:python/examples/pipeline/imdb_model_ensemble/[config.yaml](../python/examples/pipeline/imdb_model_ensemble/config.yml)
W
wangjiawei04 已提交
111 112 113

### Customization guidance

T
123  
Thomas Young 已提交
114 115
Because the docker image of Java does not contain the compilation and development environment required by serving, and the regular docker image of serving does not contain the compilation and development environment required by Java, the secondary compilation and development of GPU serving and Java client need to be completed under their respective docker images. So, we take GPU mode as an example to explain the two ways of development and deployment.

W
wangjiawei04 已提交
116

T
123  
Thomas Young 已提交
117
The first is that when GPU serving and Java client are running in the same GPU image, the user needs to copy the files compiled in the java image (path:/serving /Java) to the path /serving/Java of the GPU image.
W
wangjiawei04 已提交
118 119


T
111  
Thomas Young 已提交
120
The second is that GPU serving and Java client are deployed in their respective docker images (or different hosts with compilation and development environment). At this time, you only need to pay attention to the `ip` and`port` correspondence between the Java client and GPU serving. See item 3 of the above precautions for details.
W
wangjiawei04 已提交
121

122