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

【SCU】【PPSCI Export&Infer No.8】amgnet_cylinder #1027

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions docs/zh/examples/amgnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

本案例运行前需通过 `pip install -r requirements.txt` 命令,安装 [**P**addle **G**raph **L**earning](https://github.com/PaddlePaddle/PGL) 图学习工具和 [PyAMG](https://github.com/pyamg/pyamg) 代数多重网格工具。

=== "模型导出命令"

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

=== "模型推理命令"

``` sh
python amgnet_cylinder.py mode=infer
```

=== "模型训练命令"

=== "amgnet_airfoil"
Expand Down
33 changes: 33 additions & 0 deletions examples/amgnet/amgnet_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import ppsci
from ppsci.utils import logger
import paddle
import numpy as np

if TYPE_CHECKING:
import paddle
Expand Down Expand Up @@ -212,6 +214,37 @@ def evaluate(cfg: DictConfig):
)


def inference(model_path: str, input_data_path: str):

model = paddle.jit.load(model_path)
model.eval()

input_data = np.load(input_data_path, allow_pickle=True)
input_graph = input_data["input_graph"]

graph = ppsci.utils.GraphData(
nodes=input_graph["node_features"],
edges=input_graph["edges"],
edge_features=input_graph["edge_features"],
)

with paddle.no_grad():
predictions = model(graph)

return {
"velocity_x": predictions["velocity_x"].numpy(),
"velocity_y": predictions["velocity_y"].numpy(),
"pressure": predictions["pressure"].numpy(),
}


result = inference("pretrained_model.pdparams", "input_graph_data.npz")
print("Velocity X:", result["velocity_x"])
print("Velocity Y:", result["velocity_y"])
print("Pressure:", result["pressure"])
Comment on lines +217 to +244
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. 这段代码能运行吗?
  2. 没有实现export函数




@hydra.main(version_base=None, config_path="./conf", config_name="amgnet_cylinder.yaml")
def main(cfg: DictConfig):
if cfg.mode == "train":
Expand Down
17 changes: 17 additions & 0 deletions examples/amgnet/conf/amgnet_cylinder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@ EVAL:
batch_size: 1
pretrained_model_path: null
eval_with_no_grad: true

INFER:
pretrained_model_path: https://paddle-org.bj.bcebos.com/paddlescience/models/amgnet/amgnet_cylinder_pretrained.pdparams
export_path: ./inference/laplace2d
pdmodel_path: ${INFER.export_path}.pdmodel
pdpiparams_path: ${INFER.export_path}.pdiparams
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
num_cpu_threads: 4
batch_size: 64