提交 bd5b0b4c 编写于 作者: D Dong Daxiang 提交者: GitHub

Update README.md

上级 4d06837c
...@@ -27,40 +27,36 @@ pip install paddle-serving-server ...@@ -27,40 +27,36 @@ pip install paddle-serving-server
``` python ``` python
import sys import sys
import paddle import paddle
import paddle.fluid as fluid
train_reader = paddle.batch(paddle.reader.shuffle( train_reader = paddle.batch(paddle.reader.shuffle(
paddle.dataset.uci_housing.train(), buf_size=500), batch_size=16) paddle.dataset.uci_housing.train(), buf_size=500), batch_size=16)
test_reader = paddle.batch(paddle.reader.shuffle( x = paddle.fluid.data(name='x', shape=[None, 13], dtype='float32')
paddle.dataset.uci_housing.test(), buf_size=500), batch_size=16) y = paddle.fluid.data(name='y', shape=[None, 1], dtype='float32')
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) y_predict = paddle.fluid.layers.fc(input=x, size=1, act=None)
cost = fluid.layers.square_error_cost(input=y_predict, label=y) cost = paddle.fluid.layers.square_error_cost(input=y_predict, label=y)
avg_loss = fluid.layers.mean(cost) avg_loss = paddle.fluid.layers.mean(cost)
sgd_optimizer = fluid.optimizer.SGD(learning_rate=0.01) sgd_optimizer = paddle.fluid.optimizer.SGD(learning_rate=0.01)
sgd_optimizer.minimize(avg_loss) sgd_optimizer.minimize(avg_loss)
place = fluid.CPUPlace() place = paddle.fluid.CPUPlace()
feeder = fluid.DataFeeder(place=place, feed_list=[x, y]) feeder = paddle.fluid.DataFeeder(place=place, feed_list=[x, y])
exe = fluid.Executor(place) exe = paddle.fluid.Executor(place)
exe.run(fluid.default_startup_program()) exe.run(paddle.fluid.default_startup_program())
import paddle_serving_client.io as serving_io import paddle_serving_client.io as serving_io
for pass_id in range(30): for pass_id in range(30):
for data_train in train_reader(): for data_train in train_reader():
avg_loss_value, = exe.run( avg_loss_value, = exe.run(
fluid.default_main_program(), paddle.fluid.default_main_program(),
feed=feeder.feed(data_train), feed=feeder.feed(data_train),
fetch_list=[avg_loss]) fetch_list=[avg_loss])
serving_io.save_model( serving_io.save_model(
"serving_server_model", "serving_client_conf", "serving_server_model", "serving_client_conf",
{"x": x}, {"y": y_predict}, fluid.default_main_program()) {"x": x}, {"y": y_predict}, paddle.fluid.default_main_program())
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册