Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PPSCI Export&Infer No.25】bracket #878

Merged
merged 27 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aad358e
ppsci.equation.PDE.parameters/state_dict/set_state_dict api fix
UnityLiker Mar 28, 2024
dbddb1b
ppsci.equation.PDE.parameters/state_dict/set_state_dict api fix
UnityLiker Mar 28, 2024
e327bcd
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleScien…
UnityLiker Mar 28, 2024
4c4f631
fix api docs in the timedomain
UnityLiker Apr 1, 2024
5e35cd9
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleScien…
UnityLiker Apr 1, 2024
1610d18
Merge branch 'develop' into dev_model
HydrogenSulfate Apr 2, 2024
c547533
fix api docs of timedomain
UnityLiker Apr 2, 2024
a302cd8
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleScien…
UnityLiker Apr 2, 2024
d22ba53
Merge branch 'develop' into dev_model
HydrogenSulfate Apr 3, 2024
4cf16b4
fix api docs of timedomain
UnityLiker Apr 3, 2024
62941da
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleScien…
UnityLiker Apr 3, 2024
0b4d04a
Merge branch 'dev_model' of https://github.com/1want2sleep/PaddleScie…
UnityLiker Apr 3, 2024
69cdd3a
ppsci api docs fixed
UnityLiker Apr 9, 2024
01f54d5
ppsci api docs fixed
UnityLiker Apr 9, 2024
ca34443
ppsci api docs fixed
UnityLiker Apr 10, 2024
bd621ab
ppsci api docs fixed
UnityLiker Apr 12, 2024
902b5c1
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleScien…
UnityLiker Apr 12, 2024
559a4a4
add export and infer for bracket
UnityLiker May 6, 2024
397431c
add export and infer for bracket
UnityLiker May 6, 2024
18d247f
updata bracket doc
UnityLiker May 6, 2024
d6e1f0c
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleScien…
UnityLiker May 7, 2024
c85c063
solve conflict according to the branch named develop
UnityLiker May 7, 2024
a6d6fcf
Update examples/bracket/conf/bracket.yaml
HydrogenSulfate May 7, 2024
ebf95fc
Update examples/bracket/conf/bracket.yaml
HydrogenSulfate May 7, 2024
0840aa3
Update examples/bracket/conf/bracket.yaml
HydrogenSulfate May 7, 2024
e91fdd9
add export&inference for bracket
UnityLiker May 7, 2024
dddd910
Merge branch 'dev_model' of https://github.com/1want2sleep/PaddleScie…
UnityLiker May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/zh/examples/bracket.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@
python bracket.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/bracket/bracket_pretrained.pdparams
```

=== "模型导出命令"

``` sh
python bracket.py mode=export
```

=== "模型推理命令"

``` sh
# linux
wget -nc https://paddle-org.bj.bcebos.com/paddlescience/datasets/bracket/bracket_dataset.tar
# windows
# curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/bracket/bracket_dataset.tar --output bracket_dataset.tar
# unzip it
tar -xvf bracket_dataset.tar
python bracket.py mode=infer
```

| 预训练模型 | 指标 |
|:--| :--|
| [bracket_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/bracket/bracket_pretrained.pdparams) | loss(commercial_ref_u_v_w_sigmas): 32.28704<br>MSE.u(commercial_ref_u_v_w_sigmas): 0.00005<br>MSE.v(commercial_ref_u_v_w_sigmas): 0.00000<br>MSE.w(commercial_ref_u_v_w_sigmas): 0.00734<br>MSE.sigma_xx(commercial_ref_u_v_w_sigmas): 27.64751<br>MSE.sigma_yy(commercial_ref_u_v_w_sigmas): 1.23101<br>MSE.sigma_zz(commercial_ref_u_v_w_sigmas): 0.89106<br>MSE.sigma_xy(commercial_ref_u_v_w_sigmas): 0.84370<br>MSE.sigma_xz(commercial_ref_u_v_w_sigmas): 1.42126<br>MSE.sigma_yz(commercial_ref_u_v_w_sigmas): 0.24510 |
Expand Down
63 changes: 63 additions & 0 deletions examples/bracket/bracket.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,65 @@
import ppsci


def export(cfg: DictConfig):
# set model
disp_net = ppsci.arch.MLP(**cfg.MODEL.disp_net)
stress_net = ppsci.arch.MLP(**cfg.MODEL.stress_net)
# wrap to a model_list
model = ppsci.arch.ModelList((disp_net, stress_net))

# 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)


def inference(cfg: DictConfig):
from deploy.python_infer import pinn_predictor

predictor = pinn_predictor.PINNPredictor(cfg)
ref_xyzu = ppsci.utils.reader.load_csv_file(
cfg.DEFORMATION_X_PATH,
("x", "y", "z", "u"),
{
"x": "X Location (m)",
"y": "Y Location (m)",
"z": "Z Location (m)",
"u": "Directional Deformation (m)",
},
"\t",
)
input_dict = {
"x": ref_xyzu["x"],
"y": ref_xyzu["y"],
"z": ref_xyzu["z"],
}
output_dict = predictor.predict(input_dict, cfg.INFER.batch_size)

# mapping data to cfg.INFER.output_keys
output_keys = cfg.MODEL.disp_net.output_keys + cfg.MODEL.stress_net.output_keys
output_dict = {
store_key: output_dict[infer_key]
for store_key, infer_key in zip(output_keys, output_dict.keys())
}

ppsci.visualize.save_vtu_from_dict(
"./bracket_pred",
{**input_dict, **output_dict},
input_dict.keys(),
output_keys,
)


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个函数辛苦移动到evaluate下方吧,按照一般流程的顺序排列

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.不辛苦(●ˇ∀ˇ●)

def train(cfg: DictConfig):
# set model
disp_net = ppsci.arch.MLP(**cfg.MODEL.disp_net)
Expand Down Expand Up @@ -520,6 +579,10 @@ def main(cfg: DictConfig):
train(cfg)
elif cfg.mode == "eval":
evaluate(cfg)
elif cfg.mode == "export":
export(cfg)
elif cfg.mode == "infer":
inference(cfg)
else:
raise ValueError(f"cfg.mode should in ['train', 'eval'], but got '{cfg.mode}'")

Expand Down
18 changes: 18 additions & 0 deletions examples/bracket/conf/bracket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,21 @@ EVAL:
eval_with_no_grad: true
batch_size:
sup_validator: 128

# inference settings
INFER:
pretrained_model_path: "https://paddle-org.bj.bcebos.com/paddlescience/models/bracket/bracket_pretrained.pdparams"
export_path: ./inference/bracket
pdmodel_path: ${INFER.export_path}.pdmodel
pdpiparams_path: ${INFER.export_path}.pdiparams
HydrogenSulfate marked this conversation as resolved.
Show resolved Hide resolved
device: gpu
engine: native
precision: fp32
onnx_path: ${INFER.export_path}.onnx
ir_optim: true
min_subgraph_size: 10
gpu_mem: 4000
gpu_id: 0
max_batch_size: 64
HydrogenSulfate marked this conversation as resolved.
Show resolved Hide resolved
num_cpu_threads: 4
batch_size: 16
HydrogenSulfate marked this conversation as resolved.
Show resolved Hide resolved