-
Notifications
You must be signed in to change notification settings - Fork 223
Description
This project will be mentored by @HydrogenSulfate and @xusuyong
以下是待添加模型导出和python推理功能的案例列表:
1、8、10、19、28、34 题,共6题可以继续认领
序号 | 文档文件 | 案例文件 | 认领人/状态/PR号 |
---|---|---|---|
1 | deephpms.md | deephpms/burgers.pydeephpms/korteweg_de_vries.py deephpms/kuramoto_sivashinsky.py deephpms/navier_stokes.py deephpms/schrodinger.py |
@quite125 @Haroldlhl @jiangandhao |
2 | deeponet.md | operator_learning/deeponet.py | @liujun121533 @HydrogenSulfate @essos-bot |
3 | euler_beam.md | euler_beam/euler_beam.py | @GreatV |
4 | laplace2d.md | laplace/laplace2d.py | @GreatV |
5 | lorenz.md | lorenz/train_transformer.py | @GreatV |
6 | rossler.md | rossler/train_transformer.py | @GreatV |
7 | volterra_ide.md | ide/volterra_ide.py | @GreatV |
8 | amgnet.md | amgnet/amgnet_airfoil.pyamgnet/amgnet_cylinder.py | @yangrongxinuser @Hydralune @jiangandhao |
9 | bubble.md | bubble/bubble.py | @wufei2 |
10 | cfdgcn.md | cfdgcn/cfdgcn.py | @yangrongxinuser |
11 | cylinder2d_unsteady.md | cylinder/2d_unsteady/cylinder2d_unsteady_Re100.py | @wufei2 |
12 | cylinder2d_unsteady_transformer_physx.md | cylinder/2d_unsteady/transformer_physx/train_transformer.py | @wufei2 |
13 | darcy2d.md | darcy/darcy2d.py | @wufei2 |
14 | deepcfd.md | deepcfd/deepcfd.py | @GoldenStain |
15 | ldc2d_steady.md | ldc/ldc2d_steady_Re10.py | @wufei2 |
16 | ldc2d_unsteady.md | ldc/ldc2d_unsteady_Re10.py | @wufei2 |
17 | labelfree_DNN_surrogate.md | pipe/poiseuille_flow.py | @jincheng23 @yangrongxinuser @PolaKuma |
18 | aneurysm/aneurysm_flow.py | ||
19 | phycrnet.md | phycrnet/main.py | @Sylence8 @fangfangssj |
20 | shock_wave.md | shock_wave/shock_wave.py | @smallpoxscattered |
21 | tempoGAN.md | tempoGAN/tempoGAN.py | @smallpoxscattered |
22 | nsfnet4.md | nsfnet/VP_NSFNet4.py | @smallpoxscattered |
23 | viv.md | fsi/viv.py | @smallpoxscattered |
24 | biharmonic2d.md | biharmonic2d/biharmonic2d.py | @smallpoxscattered |
25 | bracket.md | bracket/bracket.py | @1want2sleep |
26 | control_arm.md | control_arm/forward_analysis.py | @smallpoxscattered |
27 | epnn.md | control_arm/inverse_parameter.py | @smallpoxscattered |
28 | phylstm.md | phylstm/phylstm2.pyphylstm/phylstm3.py | @jincheng23 @wwwuyan |
29 | topopt.md | topopt/topopt.py | @NKNaN |
30 | heat_exchanger.md | heat_exchanger/heat_exchanger.py | @wufei2 |
31 | heat_pinn.md | heat_pinn/heat_pinn.py | @1want2sleep |
32 | phygeonet.md | phygeonet/heat_equation.py phygeonet/heat_equation_with_bc.py |
@yangrongxinuser @ZHOU05030 @PolaKuma |
33 | hpinns/holography.py | ||
34 | fourcastnet.md | fourcastnet/train_pretrain.py fourcastnet/train_precip.py fourcastnet/train_finetune.py |
@mayiru1021 |
35 | nowcastnet.md | nowcastnet/nowcastnet.py | @smallpoxscattered @kineast |
认领方式
请大家以 comment 的形式认领任务,如:
【报名】:1、3、12-13
多个任务之间需要使用中文顿号分隔,报名多个连续任务可用横线表示,如 2-5
PR 提交格式:在 PR 的标题中以 【PPSCI Export&Infer No.】 开头,注明任务编号
看板信息
任务方向 | 任务数量 | 提交作品 / 任务认领 | 提交率 | 完成 | 完成率 |
---|---|---|---|---|---|
快乐开源 | 35 | 33 / 33 | 94.29% | 28 | 80.0% |
统计信息
排名不分先后 @HydrogenSulfate (1) @GreatV (5) @wufei2 (7) @GoldenStain (1) @PolaKuma (2) @smallpoxscattered (8) @1want2sleep (2) @NKNaN (1) @mayiru1021 (1)
1. 背景
PaddleScience 套件为现有的 30+ 模型支持了一键训练、一键测试功能,但通过模型导出和python推理功能才能使得每个案例可以快速部署在各种设备上。
2. 收益
学习模型导出和python推理的基本流程,为案例代码添加模型导出和python推理功能
3. 开发流程
3.1 安装 PaddleScience
- 安装 Paddle:https://paddlescience-docs.readthedocs.io/zh/latest/zh/install_setup/#13-paddlepaddle
- 安装 PaddleScience(git 源码安装):https://paddlescience-docs.readthedocs.io/zh/latest/zh/install_setup/#__tabbed_1_1
3.2 代码开发
以为 aneurysm 案例添加模型导出和 python 推理函数为例
def export(cfg: DictConfig):
# set model
model = ppsci.arch.MLP(**cfg.MODEL)
# initialize solver
solver = ppsci.solver.Solver(
model,
pretrained_model_path=cfg.INFER.pretrained_model_path,
)
# export model
from paddle.static import InputSpec
input_spec = [
{key: InputSpec([None, 1], "float32", name=key) for key in model.input_keys},
]
solver.export(input_spec, cfg.INFER.export_path)
-
参考
train/eval
函数,以同样的方式实例化一个网络模型model
,如果 -
实例化一个
solver
,传入model
、预训练模型路径变量cfg.INFER.pretrained_model_path
(该路径设置为案例文档开头“模型评估命令”的EVAL.pretrained_model_path
后的url值即可,如下所示)
-
根据
model
的forwrad
函数接受的输入格式,构造同样格式的input_spec
。aneurysm 的输入格式为{"x": Tensor, "y": Tensor, "z": Tensor}
,因此构造的input_spec
为:{"x": InputSpec([None, 1], "float32", name="x"), "y": InputSpec([None, 1], "float32", name="y"), "z": InputSpec([None, 1], "float32", name="z")}
-
调用
solver.export
导出模型至cfg.INFER.export_path
路径下,导出成功后会打印:Inference model has been exported to: ./inference/aneurysm, including *.pdmodel, *.pdiparams and *.pdiparams.info files.
至此模型导出函数export就完成了。接下来介绍如何撰写 python 推理代码inference
函数
def inference(cfg: DictConfig):
from deploy.python_infer import pinn_predictor
predictor = pinn_predictor.PINNPredictor(cfg)
eval_data_dict = reader.load_csv_file(
cfg.EVAL_CSV_PATH,
("x", "y", "z", "u", "v", "w", "p"),
{
"x": "Points:0",
"y": "Points:1",
"z": "Points:2",
"u": "U:0",
"v": "U:1",
"w": "U:2",
"p": "p",
},
)
input_dict = {
"x": (eval_data_dict["x"] - cfg.CENTER[0]) * cfg.SCALE,
"y": (eval_data_dict["y"] - cfg.CENTER[1]) * cfg.SCALE,
"z": (eval_data_dict["z"] - cfg.CENTER[2]) * cfg.SCALE,
}
output_dict = predictor.predict(input_dict, cfg.INFER.batch_size)
# mapping data to cfg.INFER.output_keys
output_dict = {
store_key: output_dict[infer_key]
for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys())
}
ppsci.visualize.save_vtu_from_dict(
"./aneurysm_pred.vtu",
{**input_dict, **output_dict},
input_dict.keys(),
cfg.MODEL.output_keys,
)
- 导入本模型对应的
predictor
,因为 aneurysm 的输入都是形状为[batch_size, channels]
的Tensor,因此使用导入pinn_predictor
即可;如果输入形状语义或者组织结构与之不同,则需要参照deploy/python_infer/pinn_predictor.py
的PINNPredictor
,写一个对应的XXXPredictor
,再导入使用 - 以
cfg
为参数,实例化predictor
- 参考
eval
函数,构造输入数据input_dict
- 调用
predictor.predict
接受输入数据并推理得到输出output_dict
- 由于 python 推理的输出名字与原
model
的输出名字不同,因此需要将输出output_dict
的键重新映射回正确的键上 - 参照
eval
函数,用保存/打印等方式记录推理输出output_dict
运行结果如下所示
如果在模型导出/推理时需要额外的超参数,则可以将这些超参数添加到案例对应 YAML 文件的 INFER
字段下,参考:https://github.com/PaddlePaddle/PaddleScience/pull/786/files#diff-1c33a8b95e9d0c72395763d5c906936652654533714e23211e2e2bb204d379f3R50-R55
3.3 文档添加 export&inference 运行命令
按照 3. 编写文档教程,安装文档渲染插件并渲染文档,用网页打开文档预览链接。
添加后文档渲染结果如下所示
3.4 整理代码并提交PR
参考 PaddleScience文档-贡献指南-整理代码并提交
4. 参考资料
Metadata
Metadata
Assignees
Labels
Type
Projects
Status