Skip to content

Commit df64a1b

Browse files
committed
整合agment.md文档
1 parent 8150de0 commit df64a1b

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

docs/zh/examples/amgnet.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@
5656
python amgnet_cylinder.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/amgnet/amgnet_cylinder_pretrained.pdparams
5757
```
5858

59+
=== "模型导出命令"
60+
61+
=== "amgnet_cylinder"
62+
63+
``` sh
64+
python amgnet_cylinder.py mode=export
65+
```
66+
67+
=== "Python推理命令"
68+
69+
=== "amgnet_cylinder"
70+
71+
``` sh
72+
python amgnet_cylinder.py mode=infer
73+
```
74+
5975
| 预训练模型 | 指标 |
6076
|:--| :--|
6177
| [amgnet_airfoil_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/amgnet/amgnet_airfoil_pretrained.pdparams) | loss(RMSE_validator): 0.0001 <br> RMSE.RMSE(RMSE_validator): 0.01315 |
@@ -291,6 +307,64 @@ unzip data.zip
291307
--8<--
292308
```
293309

310+
### 3.7 模型导出与推理
311+
312+
训练完成后,我们可以将模型导出为静态图格式,并使用Python推理引擎进行部署。
313+
314+
#### 3.7.1 导出模型
315+
316+
我们首先需要在 `amgnet_cylinder.py` 中实现 `export` 函数,它负责加载训练好的模型,并将其保存为推理所需的格式。
317+
318+
``` py linenums="235"
319+
--8<--
320+
examples/amgnet/amgnet_cylinder.py:235:256
321+
--8<--
322+
```
323+
324+
通过运行以下命令,即可执行导出:
325+
326+
```bash
327+
python amgnet_cylinder.py mode=export
328+
```
329+
330+
导出的模型将包含 `amgnet_cylinder.pdmodel` (模型结构) 和 `amgnet_cylinder.pdiparams` (模型权重) 文件,保存在配置文件 `INFER.export_path` 所指定的目录中。
331+
332+
#### 3.7.2 创建推理器
333+
334+
为了执行推理,我们创建了一个专用的 `AMGNPredictor` 类,存放于 `deploy/python_infer/amgn_predictor.py`。这个类继承自 `ppsci.deploy.base_predictor.Predictor`,并实现了加载模型和执行预测的核心逻辑。
335+
336+
``` py linenums="28"
337+
--8<--
338+
examples/amgnet/deploy/python_infer/amgn_predictor.py:28:87
339+
--8<--
340+
```
341+
342+
#### 3.7.3 执行推理
343+
344+
最后,我们实现 `inference` 函数。该函数会实例化 `AMGNPredictor`,加载数据,并循环执行预测,最后将结果可视化。
345+
346+
``` py linenums="259"
347+
--8<--
348+
examples/amgnet/amgnet_cylinder.py:259:298
349+
--8<--
350+
```
351+
352+
通过以下命令来运行推理:
353+
354+
```bash
355+
python amgnet_cylinder.py mode=infer
356+
```
357+
358+
#### 3.7.4 新增配置
359+
360+
为了支持以上功能,需要在 `conf/amgnet_cylinder.yaml` 中添加 `INFER` 配置项。
361+
362+
``` yaml linenums="65"
363+
--8<--
364+
examples/amgnet/conf/amgnet_cylinder.yaml:65:68
365+
--8<--
366+
```
367+
294368
## 4. 完整代码
295369

296370
=== "airfoil"

0 commit comments

Comments
 (0)