Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
3aeda852
S
Serving
项目概览
PaddlePaddle
/
Serving
9 个月 前同步成功
通知
183
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3aeda852
编写于
2月 04, 2021
作者:
H
HexToString
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix JAVA_SDK
上级
56bf8827
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
133 deletion
+10
-133
doc/JAVA_SDK.md
doc/JAVA_SDK.md
+5
-66
doc/JAVA_SDK_CN.md
doc/JAVA_SDK_CN.md
+5
-67
未找到文件。
doc/JAVA_SDK.md
浏览文件 @
3aeda852
...
...
@@ -20,6 +20,7 @@ The following table shows compatibilities between Paddle Serving Server and Java
| :---------------------------: | :--------------: |
| 0.3.2 | 0.0.1 |
1、Directly use the provided Java SDK as the client for prediction
### Install Java SDK
You can download jar and install it to the local Maven repository:
...
...
@@ -29,14 +30,6 @@ wget https://paddle-serving.bj.bcebos.com/jar/paddle-serving-sdk-java-0.0.1.jar
mvn
install
:install-file
-Dfile
=
$PWD
/paddle-serving-sdk-java-0.0.1.jar
-DgroupId
=
io.paddle.serving.client
-DartifactId
=
paddle-serving-sdk-java
-Dversion
=
0.0.1
-Dpackaging
=
jar
```
Or compile from the source code and install it to the local Maven repository:
```
shell
cd
Serving/java
mvn compile
mvn
install
```
### Maven configure
```
text
...
...
@@ -47,63 +40,9 @@ mvn install
</dependency>
```
2、Use it after compiling from the source code. See the file:
https://github.com/PaddlePaddle/Serving/blob/develop/java/README_CN.md
3、examples for using the java client, see the file:
https://github.com/PaddlePaddle/Serving/blob/develop/java/README_CN.md
## Example
Here we will show how to use Java SDK for Boston house price prediction. Please refer to
[
examples
](
../java/examples
)
folder for more examples.
### Get model
```
shell
wget
--no-check-certificate
https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
tar
-xzf
uci_housing.tar.gz
```
### Start Python Server
```
shell
python
-m
paddle_serving_server.serve
--model
uci_housing_model
--port
9393
--use_multilang
```
#### Client side code example
```
java
import
io.paddle.serving.client.*
;
import
org.nd4j.linalg.api.ndarray.INDArray
;
import
org.nd4j.linalg.factory.Nd4j
;
import
java.util.*
;
public
class
PaddleServingClientExample
{
public
static
void
main
(
String
[]
args
)
{
float
[]
data
=
{
0.0137f
,
-
0.1136f
,
0.2553f
,
-
0.0692f
,
0.0582f
,
-
0.0727f
,
-
0.1583f
,
-
0.0584f
,
0.6283f
,
0.4919f
,
0.1856f
,
0.0795f
,
-
0.0332f
};
INDArray
npdata
=
Nd4j
.
createFromArray
(
data
);
HashMap
<
String
,
INDArray
>
feed_data
=
new
HashMap
<
String
,
INDArray
>()
{{
put
(
"x"
,
npdata
);
}};
List
<
String
>
fetch
=
Arrays
.
asList
(
"price"
);
Client
client
=
new
Client
();
String
target
=
"localhost:9393"
;
boolean
succ
=
client
.
connect
(
target
);
if
(
succ
!=
true
)
{
System
.
out
.
println
(
"connect failed."
);
return
;
}
Map
<
String
,
INDArray
>
fetch_map
=
client
.
predict
(
feed_data
,
fetch
);
if
(
fetch_map
==
null
)
{
System
.
out
.
println
(
"predict failed."
);
return
;
}
for
(
Map
.
Entry
<
String
,
INDArray
>
e
:
fetch_map
.
entrySet
())
{
System
.
out
.
println
(
"Key = "
+
e
.
getKey
()
+
", Value = "
+
e
.
getValue
());
}
return
;
}
}
```
doc/JAVA_SDK_CN.md
浏览文件 @
3aeda852
...
...
@@ -19,6 +19,7 @@ Paddle Serving 提供了 Java SDK,支持 Client 端用 Java 语言进行预测
| :---------------------------: | :--------------: |
| 0.3.2 | 0.0.1 |
1、直接使用提供的Java SDK作为Client进行预测
### 安装
您可以直接下载 jar,安装到本地 Maven 库:
...
...
@@ -28,14 +29,6 @@ wget https://paddle-serving.bj.bcebos.com/jar/paddle-serving-sdk-java-0.0.1.jar
mvn
install
:install-file
-Dfile
=
$PWD
/paddle-serving-sdk-java-0.0.1.jar
-DgroupId
=
io.paddle.serving.client
-DartifactId
=
paddle-serving-sdk-java
-Dversion
=
0.0.1
-Dpackaging
=
jar
```
或者从源码进行编译,安装到本地 Maven 库:
```
shell
cd
Serving/java
mvn compile
mvn
install
```
### Maven 配置
```
text
...
...
@@ -46,64 +39,9 @@ mvn install
</dependency>
```
2、从源码进行编译后使用,详细步骤见:
https://github.com/PaddlePaddle/Serving/blob/develop/java/README_CN.md
3、相关使用示例见:
https://github.com/PaddlePaddle/Serving/blob/develop/java/README_CN.md
## 使用样例
这里将展示如何使用 Java SDK 进行房价预测,更多例子详见
[
examples
](
../java/examples
)
文件夹。
### 获取房价预测模型
```
shell
wget
--no-check-certificate
https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
tar
-xzf
uci_housing.tar.gz
```
### 启动 Python 端 Server
```
shell
python
-m
paddle_serving_server.serve
--model
uci_housing_model
--port
9393
--use_multilang
```
### Client 端代码示例
```
java
import
io.paddle.serving.client.*
;
import
org.nd4j.linalg.api.ndarray.INDArray
;
import
org.nd4j.linalg.factory.Nd4j
;
import
java.util.*
;
public
class
PaddleServingClientExample
{
public
static
void
main
(
String
[]
args
)
{
float
[]
data
=
{
0.0137f
,
-
0.1136f
,
0.2553f
,
-
0.0692f
,
0.0582f
,
-
0.0727f
,
-
0.1583f
,
-
0.0584f
,
0.6283f
,
0.4919f
,
0.1856f
,
0.0795f
,
-
0.0332f
};
INDArray
npdata
=
Nd4j
.
createFromArray
(
data
);
HashMap
<
String
,
INDArray
>
feed_data
=
new
HashMap
<
String
,
INDArray
>()
{{
put
(
"x"
,
npdata
);
}};
List
<
String
>
fetch
=
Arrays
.
asList
(
"price"
);
Client
client
=
new
Client
();
String
target
=
"localhost:9393"
;
boolean
succ
=
client
.
connect
(
target
);
if
(
succ
!=
true
)
{
System
.
out
.
println
(
"connect failed."
);
return
;
}
Map
<
String
,
INDArray
>
fetch_map
=
client
.
predict
(
feed_data
,
fetch
);
if
(
fetch_map
==
null
)
{
System
.
out
.
println
(
"predict failed."
);
return
;
}
for
(
Map
.
Entry
<
String
,
INDArray
>
e
:
fetch_map
.
entrySet
())
{
System
.
out
.
println
(
"Key = "
+
e
.
getKey
()
+
", Value = "
+
e
.
getValue
());
}
return
;
}
}
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录