diff --git a/.tools/build_docker.sh b/.tools/build_docker.sh index 60474b1c6c56d7f84c8e5ee19132d93dbf19df9c..242f8de16639f6c333d99f2ff4c7e24f86788c98 100755 --- a/.tools/build_docker.sh +++ b/.tools/build_docker.sh @@ -64,7 +64,7 @@ RUN pip install -U nltk \ RUN ${update_mirror_cmd} apt-get update && \ apt-get install -y locales patch && \ - apt-get -y install gcc curl git && \ + apt-get -y install gcc curl git vim && \ apt-get -y clean && \ localedef -f UTF-8 -i en_US en_US.UTF-8 && \ pip install --upgrade pip && \ diff --git a/01.fit_a_line/README.cn.md b/01.fit_a_line/README.cn.md index 30e78a42ddb5c36072485c5dbecd63433dc91065..5aa1b1d5bc524a6d570130471d17733c894f0a0e 100644 --- a/01.fit_a_line/README.cn.md +++ b/01.fit_a_line/README.cn.md @@ -126,8 +126,18 @@ y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear()) y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1)) -cost = paddle.layer.mse_cost(input=y_predict, label=y) +cost = paddle.layer.square_error_cost(input=y_predict, label=y) ``` + +### 保存网络拓扑 + +```python +# Save the inference topology to protobuf. +inference_topology = paddle.topology.Topology(layers=y_predict) +with open("inference_topology.pkl", 'wb') as f: + inference_topology.serialize_for_inference(f) +``` + ### 创建参数 ```python diff --git a/01.fit_a_line/README.md b/01.fit_a_line/README.md index 814cd1c110581318e59c6a43e7ce47227d640cd3..3229664370d3c1568726c4f7a5a38fb200417f4d 100644 --- a/01.fit_a_line/README.md +++ b/01.fit_a_line/README.md @@ -132,8 +132,19 @@ y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear()) y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1)) -cost = paddle.layer.mse_cost(input=y_predict, label=y) +cost = paddle.layer.square_error_cost(input=y_predict, label=y) ``` + +### Save Topology + +```python +# Save the inference topology to protobuf. +inference_topology = paddle.topology.Topology(layers=y_predict) +with open("inference_topology.pkl", 'wb') as f: + inference_topology.serialize_for_inference(f) +``` + + ### Create Parameters ```python diff --git a/01.fit_a_line/index.cn.html b/01.fit_a_line/index.cn.html index 933e5a4d8bfb53cb50a9675ea907d939203742da..c69a8dc1006cad4e2b051cc25fd2fed8a4e25706 100644 --- a/01.fit_a_line/index.cn.html +++ b/01.fit_a_line/index.cn.html @@ -168,8 +168,18 @@ y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear()) y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1)) -cost = paddle.layer.mse_cost(input=y_predict, label=y) +cost = paddle.layer.square_error_cost(input=y_predict, label=y) ``` + +### 保存网络拓扑 + +```python +# Save the inference topology to protobuf. +inference_topology = paddle.topology.Topology(layers=y_predict) +with open("inference_topology.pkl", 'wb') as f: + inference_topology.serialize_for_inference(f) +``` + ### 创建参数 ```python diff --git a/01.fit_a_line/index.html b/01.fit_a_line/index.html index f143f7fa65fe9ab4168739eaa9495292c64e3326..769cad945e6a32383711fcebc7dbd29e6e9140d3 100644 --- a/01.fit_a_line/index.html +++ b/01.fit_a_line/index.html @@ -174,8 +174,19 @@ y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear()) y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1)) -cost = paddle.layer.mse_cost(input=y_predict, label=y) +cost = paddle.layer.square_error_cost(input=y_predict, label=y) ``` + +### Save Topology + +```python +# Save the inference topology to protobuf. +inference_topology = paddle.topology.Topology(layers=y_predict) +with open("inference_topology.pkl", 'wb') as f: + inference_topology.serialize_for_inference(f) +``` + + ### Create Parameters ```python diff --git a/01.fit_a_line/train.py b/01.fit_a_line/train.py index 255180d3c4322e8dd201e96917e288e3ee209d61..15f94f94124c0da5c5cd1f57863721f7145b9dc2 100644 --- a/01.fit_a_line/train.py +++ b/01.fit_a_line/train.py @@ -12,6 +12,11 @@ def main(): y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1)) cost = paddle.layer.square_error_cost(input=y_predict, label=y) + # Save the inference topology to protobuf. + inference_topology = paddle.topology.Topology(layers=y_predict) + with open("inference_topology.pkl", 'wb') as f: + inference_topology.serialize_for_inference(f) + # create parameters parameters = paddle.parameters.create(cost) @@ -21,10 +26,6 @@ def main(): trainer = paddle.trainer.SGD( cost=cost, parameters=parameters, update_equation=optimizer) - # save model proto as file - with open("model.proto", "w") as f: - f.write(str(trainer.__topology_in_proto__)) - feeding = {'x': 0, 'y': 1} # event_handler to print training and testing info