-
Notifications
You must be signed in to change notification settings - Fork 233
[Example] Add preformer for precipitation nowcasting #976
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
b7e0216
9092f86
038b3fc
52adb6a
c110ae4
88eda6a
b99da76
4511659
945ba45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,239 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Preformer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 开始训练、评估前,请下载数据集文件 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 开始评估前,请下载或训练生成预训练模型 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+6
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以稍微介绍一下数据集的准备过程吗?比如如何下载和解压后的文件组织形式? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| === "模型训练命令" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ``` sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # 模型训练 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| python examples/preformer/train.py | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| python examples/preformer/train.py | |
| python train.py |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,删除该行注释
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| python examples/preformer/train.py mode=eval | |
| python train.py mode=eval |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该案例是关于降水的,这个数据集好像是交通的,数据集与代码不一致
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 模型导出章节可以不用出现在文章中,删除
- 请补充模型导出的函数
def export和def inference到examples\preformer\main.py中,参考:PaddleScience/examples/allen_cahn/allen_cahn_piratenet.py
Lines 235 to 269 in 83f6739
def export(cfg: DictConfig): # set model model = ppsci.arch.PirateNet(**cfg.MODEL) # initialize solver solver = ppsci.solver.Solver(model, cfg=cfg) # 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, with_onnx=False) def inference(cfg: DictConfig): from deploy.python_infer import pinn_predictor predictor = pinn_predictor.PINNPredictor(cfg) data = sio.loadmat(cfg.DATA_PATH) u_ref = data["usol"].astype(dtype) # (nt, nx) t_star = data["t"].flatten().astype(dtype) # [nt, ] x_star = data["x"].flatten().astype(dtype) # [nx, ] tx_star = misc.cartesian_product(t_star, x_star).astype(dtype) input_dict = {"t": tx_star[:, 0:1], "x": tx_star[:, 1:2]} 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()) } u_pred = output_dict["u"].reshape([len(t_star), len(x_star)]) plot(t_star, x_star, u_ref, u_pred, cfg.output_dir) - 模型导出和模型推理执行命令请添加到文档开头处的"=== "模型评估命令""后面
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个章节也可以删除
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处只放运行主程序main.py的代码即可
| 数据集接口: | |
| ``` py linenums="1" title="ppsci\data\dataset\era5sq_dataset.py" | |
| --8<-- | |
| ppsci\data\dataset\era5sq_dataset.py | |
| --8<-- | |
| ``` | |
| 模型结构: | |
| ``` py linenums="1" title="ppsci/arch/preformer.py" | |
| --8<-- | |
| ppsci/arch/preformer.py | |
| --8<-- | |
| ``` | |
| 模型训练: | |
| ``` py linenums="1" title="examples/preformer/train.py" | |
| --8<-- | |
| examples/preformer/train.py | |
| --8<-- | |
| ``` | |
| 配置文件: | |
| ``` py linenums="1" title="examples/preformer/conf/train.yaml" | |
| --8<-- | |
| examples/preformer/conf/train.yaml | |
| --8<-- | |
| ``` | |
| ``` py linenums="1" title="examples/preformer/main.py" | |
| --8<-- | |
| examples/preformer/main.py | |
| --8<-- |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hydra: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # dynamic output directory according to running time and override name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir: outputs_preformer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| job: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: ${mode} # name of logfile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chdir: false # keep current working directory unchanged | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| override_dirname: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exclude_keys: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - TRAIN.checkpoint_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - TRAIN.trained_model_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - EVAL.trained_model_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - output_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - log_freq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sweep: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # output directory for multirun | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir: ${hydra.run.dir} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subdir: ./ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # general settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: train # running mode: train/eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| seed: 1024 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output_dir: ${hydra:run.dir} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log_freq: 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # set training hyper-parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SQ_LEN: 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IMG_H: 192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IMG_W: 256 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| USE_SAMPLED_DATA: false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # set train data path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TRAIN_FILE_PATH: /patch/to/ERA5/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DATA_MEAN_PATH: examples/weather/datasets/era5/stat/mean.nc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DATA_STD_PATH: examples/weather/datasets/era5/stat/std.nc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # set evaluate data path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VALID_FILE_PATH: /patch/to/ERA5/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # model settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MODEL: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| afno: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input_keys: ["input"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output_keys: ["output"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shape_in: [6, 12, IMG_H, IMG_W] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shape_in: [6, 12, IMG_H, IMG_W] | |
| shape_in: | |
| - 6 | |
| - 12 | |
| - ${IMG_H} | |
| - ${IMG_W} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文件中的
examples/preformer/train.py路径应该全部替换为examples/preformer/main.py