Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
16e5fb5a
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
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看板
提交
16e5fb5a
编写于
2月 06, 2020
作者:
M
MRXLT
提交者:
GitHub
2月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #130 from guru4elephant/add_fit_a_line
Add fit a line
上级
0964c75b
7b019541
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
74 addition
and
0 deletion
+74
-0
python/examples/fit_a_line/local_train.py
python/examples/fit_a_line/local_train.py
+36
-0
python/examples/fit_a_line/test_client.py
python/examples/fit_a_line/test_client.py
+15
-0
python/examples/fit_a_line/test_server.py
python/examples/fit_a_line/test_server.py
+19
-0
python/paddle_serving_client/io/__init__.py
python/paddle_serving_client/io/__init__.py
+4
-0
未找到文件。
python/examples/fit_a_line/local_train.py
0 → 100644
浏览文件 @
16e5fb5a
import
sys
import
paddle
import
paddle.fluid
as
fluid
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
train
(),
buf_size
=
500
),
batch_size
=
16
)
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
16
)
x
=
fluid
.
data
(
name
=
'x'
,
shape
=
[
None
,
13
],
dtype
=
'float32'
)
y
=
fluid
.
data
(
name
=
'y'
,
shape
=
[
None
,
1
],
dtype
=
'float32'
)
y_predict
=
fluid
.
layers
.
fc
(
input
=
x
,
size
=
1
,
act
=
None
)
cost
=
fluid
.
layers
.
square_error_cost
(
input
=
y_predict
,
label
=
y
)
avg_loss
=
fluid
.
layers
.
mean
(
cost
)
sgd_optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
0.01
)
sgd_optimizer
.
minimize
(
avg_loss
)
place
=
fluid
.
CPUPlace
()
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
[
x
,
y
])
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
import
paddle_serving_client.io
as
serving_io
for
pass_id
in
range
(
30
):
for
data_train
in
train_reader
():
avg_loss_value
,
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
feeder
.
feed
(
data_train
),
fetch_list
=
[
avg_loss
])
serving_io
.
save_model
(
"serving_server_model"
,
"serving_client_conf"
,
{
"x"
:
x
},
{
"y"
:
y_predict
},
fluid
.
default_main_program
())
python/examples/fit_a_line/test_client.py
0 → 100644
浏览文件 @
16e5fb5a
from
paddle_serving_client
import
Client
import
paddle
import
sys
client
=
Client
()
client
.
load_client_config
(
sys
.
argv
[
1
])
client
.
connect
([
"127.0.0.1:9292"
])
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
uci_housing
.
test
(),
buf_size
=
500
),
batch_size
=
1
)
for
data
in
test_reader
():
fetch_map
=
client
.
predict
(
feed
=
{
"x"
:
data
[
0
][
0
]},
fetch
=
[
"y"
])
print
(
"{} {}"
.
format
(
fetch_map
[
"y"
][
0
],
data
[
0
][
1
][
0
]))
python/examples/fit_a_line/test_server.py
0 → 100644
浏览文件 @
16e5fb5a
import
os
import
sys
from
paddle_serving_server
import
OpMaker
from
paddle_serving_server
import
OpSeqMaker
from
paddle_serving_server
import
Server
op_maker
=
OpMaker
()
read_op
=
op_maker
.
create
(
'general_reader'
)
general_infer_op
=
op_maker
.
create
(
'general_infer'
)
op_seq_maker
=
OpSeqMaker
()
op_seq_maker
.
add_op
(
read_op
)
op_seq_maker
.
add_op
(
general_infer_op
)
server
=
Server
()
server
.
set_op_sequence
(
op_seq_maker
.
get_op_sequence
())
server
.
load_model_config
(
sys
.
argv
[
1
])
server
.
prepare_server
(
workdir
=
"work_dir1"
,
port
=
9292
,
device
=
"cpu"
)
server
.
run_server
()
python/paddle_serving_client/io/__init__.py
浏览文件 @
16e5fb5a
...
@@ -71,6 +71,10 @@ def save_model(server_model_folder,
...
@@ -71,6 +71,10 @@ def save_model(server_model_folder,
fout
.
write
(
str
(
config
))
fout
.
write
(
str
(
config
))
with
open
(
"{}/serving_server_conf.prototxt"
.
format
(
server_model_folder
),
"w"
)
as
fout
:
with
open
(
"{}/serving_server_conf.prototxt"
.
format
(
server_model_folder
),
"w"
)
as
fout
:
fout
.
write
(
str
(
config
))
fout
.
write
(
str
(
config
))
with
open
(
"{}/serving_client_conf.stream.prototxt"
.
format
(
client_config_folder
),
"wb"
)
as
fout
:
fout
.
write
(
config
.
serialize_to_string
())
with
open
(
"{}/serving_server_conf.stream.prototxt"
.
format
(
server_model_folder
),
"wb"
)
as
fout
:
fout
.
write
(
config
.
serialize_to_string
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录