Skip to content

Commit

Permalink
update final code
Browse files Browse the repository at this point in the history
  • Loading branch information
HydrogenSulfate committed Oct 18, 2023
1 parent a59bc28 commit 7eb4aab
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 137 deletions.
32 changes: 16 additions & 16 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@

![panorama](https://paddle-org.bj.bcebos.com/paddlescience/docs/overview/panorama.png)

!!! tip "快速安装"
--8<--
./README.md:update
--8<--

=== "方式1: 源码安装[推荐]"
## 快速安装

--8<--
./README.md:git_install
--8<--
=== "方式1: 源码安装[推荐]"

=== "方式2: pip安装"
--8<--
./README.md:git_install
--8<--

``` shell
pip install paddlesci
```
=== "方式2: pip安装"

=== "[完整安装流程](./zh/install_setup.md)"
``` shell
pip install paddlesci
```

``` shell
pip install paddlesci
```
=== "[完整安装流程](./zh/install_setup.md)"

--8<--
./README.md:update
--8<--
``` shell
pip install paddlesci
```

--8<--
./README.md:feature
Expand Down
147 changes: 101 additions & 46 deletions docs/zh/examples/amgnet.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,62 @@
# 2D-Darcy
# AMGNet

<!-- <a href="https://aistudio.baidu.com/aistudio/projectdetail/6184070?contributionType=1&sUid=438690&shared=1&ts=1684239806160" class="md-button md-button--primary" style>AI Studio快速体验</a> -->

=== "模型训练命令"

=== "amgnet_airfoil"

``` sh
# linux
wget https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip
# windows
# curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip --output data.zip
# unzip it
unzip data.zip
python amgnet_airfoil.py
```
=== "amgnet_cylinder"

``` sh
# linux
wget https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip
# windows
# curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip --output data.zip
# unzip it
unzip data.zip
python amgnet_cylinder.py
```

=== "模型评估命令"

=== "amgnet_airfoil"

``` sh
# linux
wget https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip
# windows
# curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip --output data.zip
# unzip it
unzip data.zip
python amgnet_airfoil.py mode=eval EVAL.pretained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/amgnet/amgnet_airfoil_pretrained.pdparams
```
=== "amgnet_cylinder"

``` sh
# linux
wget https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip
# windows
# curl https://paddle-org.bj.bcebos.com/paddlescience/datasets/AMGNet/data.zip --output data.zip
# unzip it
unzip data.zip
python amgnet_cylinder.py mode=eval EVAL.pretrained_model_path=https://paddle-org.bj.bcebos.com/paddlescience/models/amgnet/amgnet_cylinder_pretrained.pdparams
```

| 预训练模型 | 指标 |
|:--| :--|
| [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 |
| [amgnet_cylinder_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/amgnet/amgnet_cylinder_pretrained.pdparams) | loss(RMSE_validator): 0.00048 <br> RMSE.RMSE(RMSE_validator): 0.02197 |

## 1. 背景简介

近年来,深度学习在计算机视觉和自然语言处理方面的成功应用,促使人们探索人工智能在科学计算领域的应用,尤其是在计算流体力学(CFD)领域的应用。
Expand Down Expand Up @@ -29,7 +84,7 @@

!!! info "注意事项"

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

### 3.1 数据集下载

Expand All @@ -48,17 +103,17 @@ unzip data.zip

=== "airfoil"

``` py linenums="60"
``` py linenums="61"
--8<--
examples/amgnet/amgnet_airfoil.py:60:71
examples/amgnet/amgnet_airfoil.py:61:62
--8<--
```

=== "cylinder"

``` py linenums="60"
``` py linenums="61"
--8<--
examples/amgnet/amgnet_cylinder.py:60:71
examples/amgnet/amgnet_cylinder.py:61:62
--8<--
```

Expand All @@ -68,77 +123,77 @@ unzip data.zip

在本案例中,我们使用监督数据集对模型进行训练,因此需要构建监督约束。

在定义约束之前,我们需要指定数据集的路径、`batch_size` 等相关配置,将这些信息封装到字典中,如下所示。
在定义约束之前,我们需要指定数据集的路径等相关配置,将这些信息存放到对应的 YAML 文件中,如下所示。

=== "airfoil"

``` py linenums="73"
``` py linenums="21"
--8<--
examples/amgnet/amgnet_airfoil.py:73:90
examples/amgnet/conf/amgnet_airfoil.yaml:21:27
--8<--
```

=== "cylinder"

``` py linenums="73"
``` py linenums="21"
--8<--
examples/amgnet/amgnet_cylinder.py:73:90
examples/amgnet/conf/amgnet_cylinder.yaml:21:27
--8<--
```

接着定义训练损失函数的计算过程,如下所示。

=== "airfoil"

``` py linenums="33"
``` py linenums="35"
--8<--
examples/amgnet/amgnet_airfoil.py:33:36
examples/amgnet/amgnet_airfoil.py:35:40
--8<--
```

=== "cylinder"

``` py linenums="33"
``` py linenums="35"
--8<--
examples/amgnet/amgnet_cylinder.py:33:36
examples/amgnet/amgnet_cylinder.py:35:40
--8<--
```

最后构建监督约束,如下所示。

=== "airfoil"

``` py linenums="92"
``` py linenums="82"
--8<--
examples/amgnet/amgnet_airfoil.py:92:100
examples/amgnet/amgnet_airfoil.py:82:90
--8<--
```

=== "cylinder"

``` py linenums="92"
``` py linenums="82"
--8<--
examples/amgnet/amgnet_cylinder.py:92:100
examples/amgnet/amgnet_cylinder.py:82:90
--8<--
```

### 3.4 超参数设定

接下来我们需要指定训练轮数,此处使用 500 轮训练轮数
设置训练轮数等参数,如下所示

=== "airfoil"

``` py linenums="102"
``` py linenums="41"
--8<--
examples/amgnet/amgnet_airfoil.py:102:103
examples/amgnet/conf/amgnet_airfoil.yaml:41:51
--8<--
```

=== "cylinder"

``` py linenums="102"
``` py linenums="41"
--8<--
examples/amgnet/amgnet_cylinder.py:102:103
examples/amgnet/conf/amgnet_cylinder.yaml:41:51
--8<--
```

Expand All @@ -148,53 +203,53 @@ unzip data.zip

=== "airfoil"

``` py linenums="105"
``` py linenums="92"
--8<--
examples/amgnet/amgnet_airfoil.py:105:106
examples/amgnet/amgnet_airfoil.py:92:93
--8<--
```

=== "cylinder"

``` py linenums="105"
``` py linenums="92"
--8<--
examples/amgnet/amgnet_cylinder.py:105:106
examples/amgnet/amgnet_cylinder.py:92:93
--8<--
```

### 3.6 评估器构建

在训练过程中通常会按一定轮数间隔,用验证集(测试集)评估当前模型的训练情况,因此使用 `ppsci.validate.SupervisedValidator` 构建评估器,构建过程与 [约束构建](#34) 类似,只需把数据目录改为测试集的目录,并设置 `batch_size=1` 即可。
在训练过程中通常会按一定轮数间隔,用验证集(测试集)评估当前模型的训练情况,因此使用 `ppsci.validate.SupervisedValidator` 构建评估器,构建过程与 [约束构建](#34) 类似,只需把数据目录改为测试集的目录,并在配置文件中设置 `EVAL.batch_size=1` 即可。

=== "airfoil"

``` py linenums="108"
``` py linenums="95"
--8<--
examples/amgnet/amgnet_airfoil.py:108:131
examples/amgnet/amgnet_airfoil.py:95:118
--8<--
```
=== "cylinder"

``` py linenums="108"
``` py linenums="95"
--8<--
examples/amgnet/amgnet_cylinder.py:108:131
examples/amgnet/amgnet_cylinder.py:95:118
--8<--
```

评估指标为预测结果和真实结果的 RMSE 值,因此需自定义指标计算函数,如下所示。

=== "airfoil"

``` py linenums="39"
``` py linenums="43"
--8<--
examples/amgnet/amgnet_airfoil.py:39:48
examples/amgnet/amgnet_airfoil.py:43:52
--8<--
```
=== "cylinder"

``` py linenums="39"
``` py linenums="43"
--8<--
examples/amgnet/amgnet_cylinder.py:39:48
examples/amgnet/amgnet_cylinder.py:43:52
--8<--
```

Expand All @@ -204,16 +259,16 @@ unzip data.zip

=== "airfoil"

``` py linenums="133"
``` py linenums="120"
--8<--
examples/amgnet/amgnet_airfoil.py:133:149
examples/amgnet/amgnet_airfoil.py:120:136
--8<--
```
=== "cylinder"

``` py linenums="133"
``` py linenums="120"
--8<--
examples/amgnet/amgnet_cylinder.py:133:149
examples/amgnet/amgnet_cylinder.py:120:136
--8<--
```

Expand All @@ -223,16 +278,16 @@ unzip data.zip

=== "airfoil"

``` py linenums="151"
``` py linenums="138"
--8<--
examples/amgnet/amgnet_airfoil.py:151:
examples/amgnet/amgnet_airfoil.py:138:
--8<--
```
=== "cylinder"

``` py linenums="151"
``` py linenums="138"
--8<--
examples/amgnet/amgnet_cylinder.py:151:
examples/amgnet/amgnet_cylinder.py:138:
--8<--
```

Expand Down Expand Up @@ -276,7 +331,7 @@ unzip data.zip
![Cylinder_0_p](https://paddle-org.bj.bcebos.com/paddlescience/docs/AMGNet/cylinder_0field.png1_field.png){ loading=lazy }
<figcaption>左:预测压力 p,右:实际压力 p</figcaption>
![Cylinder_0_vec_y](https://paddle-org.bj.bcebos.com/paddlescience/docs/AMGNet/cylinder_0field.png2_field.png){ loading=lazy }
<figcaption>左:预测y方向流速 p,右:实际 y 方向流速</figcaption>
<figcaption>左:预测 y 方向流速 p,右:实际 y 方向流速</figcaption>
</figure>

可以看到模型预测结果与真实结果基本一致。
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/examples/bracket.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

| 预训练模型 | 指标 |
|:--| :--|
| [bracket_pretrained.pdparams](https://paddle-org.bj.bcebos.com/paddlescience/models/bracket/bracket_pretrained.pdparams) | loss(commercial_ref_u_v_w_sigmas): 32.28704, MSE.u(commercial_ref_u_v_w_sigmas): 0.00005, MSE.v(commercial_ref_u_v_w_sigmas): 0.00000, MSE.w(commercial_ref_u_v_w_sigmas): 0.00734, MSE.sigma_xx(commercial_ref_u_v_w_sigmas): 27.64751, MSE.sigma_yy(commercial_ref_u_v_w_sigmas): 1.23101, MSE.sigma_zz(commercial_ref_u_v_w_sigmas): 0.89106, MSE.sigma_xy(commercial_ref_u_v_w_sigmas): 0.84370, MSE.sigma_xz(commercial_ref_u_v_w_sigmas): 1.42126, MSE.sigma_yz(commercial_ref_u_v_w_sigmas): 0.24510 |
| [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 |

## 1. 背景简介

Expand Down
Loading

0 comments on commit 7eb4aab

Please sign in to comment.