Skip to content

Commit f67cc71

Browse files
Merge branch 'PaddlePaddle:develop' into develop
2 parents b4e59a6 + 2a8a8c4 commit f67cc71

File tree

7 files changed

+267
-176
lines changed

7 files changed

+267
-176
lines changed

deploy/python_infer/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def _create_paddle_predictor(
163163

164164
# enable memory optim
165165
config.enable_memory_optim()
166-
config.disable_glog_info()
166+
# config.disable_glog_info()
167167
# enable zero copy
168168
config.switch_use_feed_fetch_ops(False)
169169
config.switch_ir_optim(self.ir_optim)

examples/yinglong/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,22 @@ wget https://paddle-org.bj.bcebos.com/paddlescience/datasets/yinglong/hrrr_examp
4646
tar -xvf hrrr_example_24vars.tar
4747
wget https://paddle-org.bj.bcebos.com/paddlescience/datasets/yinglong/hrrr_example_69vars.tar
4848
tar -xvf hrrr_example_69vars.tar
49-
wget https://paddle-org.bj.bcebos.com/paddlescience/models/yinglong/yinglong_models.tar
50-
tar -xvf yinglong_models.tar
49+
wget https://paddle-org.bj.bcebos.com/paddlescience/models/yinglong/inference.tar
50+
tar -xvf inference.tar
5151
```
5252

5353
### 2. Run the code
5454

5555
The following code runs the Yinglong model, and the model output will be saved in 'output/result.npy'.
5656

5757
``` shell
58+
cd PaddleScience
5859
export PYTHONPATH=$PWD
60+
cd ./examples/yinglong
5961
# YingLong-12 Layers
60-
python examples/yinglong/predict_12layers.py
62+
python predict_12layers.py mode=infer
6163
# YingLong-24 Layers
62-
# python examples/yinglong/predict_24layers.py
64+
python predict_24layers.py mode=infer
6365
```
6466

6567
We also visualized the predicted wind speed at 10 meters above ground level, with an initial field of 0:00 on January 1, 2022. Click [here](https://paddle-org.bj.bcebos.com/paddlescience/docs/Yinglong/result.gif) to view the prediction results.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
hydra:
2+
run:
3+
# dynamic output directory according to running time and override name
4+
# dir: outputs_yinglong/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
5+
dir: ./outputs_yinglong_12
6+
job:
7+
name: ${mode} # name of logfile
8+
chdir: false # keep current working direcotry unchaned
9+
config:
10+
override_dirname:
11+
exclude_keys:
12+
- TRAIN.checkpoint_path
13+
- TRAIN.pretrained_model_path
14+
- EVAL.pretrained_model_path
15+
- INFER.pretrained_model_path
16+
- mode
17+
- output_dir
18+
- log_freq
19+
callbacks:
20+
init_callback:
21+
_target_: ppsci.utils.callbacks.InitCallback
22+
sweep:
23+
# output directory for multirun
24+
dir: ${hydra.run.dir}
25+
subdir: ./
26+
27+
# general settings
28+
mode: infer # running mode: infer
29+
seed: 2023
30+
output_dir: ${hydra:run.dir}
31+
log_freq: 20
32+
33+
# inference settings
34+
INFER:
35+
pretrained_model_path: null
36+
export_path: ./inference/yinglong_12
37+
pdmodel_path: ${INFER.export_path}.pdmodel
38+
pdpiparams_path: ${INFER.export_path}.pdiparams
39+
onnx_path: ${INFER.export_path}.onnx
40+
device: gpu
41+
engine: native
42+
precision: fp32
43+
ir_optim: false
44+
min_subgraph_size: 30
45+
gpu_mem: 100
46+
gpu_id: 0
47+
max_batch_size: 1
48+
num_cpu_threads: 10
49+
batch_size: 1
50+
mean_path: ./hrrr_example_24vars/stat/mean_crop.npy
51+
std_path: ./hrrr_example_24vars/stat/std_crop.npy
52+
input_file: ./hrrr_example_24vars/valid/2022/01/01.h5
53+
init_time: 2022/01/01/00
54+
nwp_file: ./hrrr_example_24vars/nwp_convert/2022/01/01/00.h5
55+
num_timestamps: 22
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
hydra:
2+
run:
3+
# dynamic output directory according to running time and override name
4+
# dir: outputs_yinglong/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
5+
dir: ./outputs_yinglong_24
6+
job:
7+
name: ${mode} # name of logfile
8+
chdir: false # keep current working direcotry unchaned
9+
config:
10+
override_dirname:
11+
exclude_keys:
12+
- TRAIN.checkpoint_path
13+
- TRAIN.pretrained_model_path
14+
- EVAL.pretrained_model_path
15+
- INFER.pretrained_model_path
16+
- mode
17+
- output_dir
18+
- log_freq
19+
callbacks:
20+
init_callback:
21+
_target_: ppsci.utils.callbacks.InitCallback
22+
sweep:
23+
# output directory for multirun
24+
dir: ${hydra.run.dir}
25+
subdir: ./
26+
27+
# general settings
28+
mode: infer # running mode: infer
29+
seed: 2023
30+
output_dir: ${hydra:run.dir}
31+
log_freq: 20
32+
33+
# inference settings
34+
INFER:
35+
pretrained_model_path: null
36+
export_path: ./inference/yinglong_24
37+
pdmodel_path: ${INFER.export_path}.pdmodel
38+
pdpiparams_path: ${INFER.export_path}.pdiparams
39+
onnx_path: ${INFER.export_path}.onnx
40+
device: gpu
41+
engine: native
42+
precision: fp32
43+
ir_optim: false
44+
min_subgraph_size: 30
45+
gpu_mem: 100
46+
gpu_id: 0
47+
max_batch_size: 1
48+
num_cpu_threads: 10
49+
batch_size: 1
50+
mean_path: ./hrrr_example_69vars/stat/mean_crop.npy
51+
std_path: ./hrrr_example_69vars/stat/std_crop.npy
52+
input_file: ./hrrr_example_69vars/valid/2022/01/01.h5
53+
init_time: 2022/01/01/00
54+
nwp_file: ./hrrr_example_69vars/nwp_convert/2022/01/01/00.h5
55+
num_timestamps: 22

examples/yinglong/predict_12layers.py

Lines changed: 23 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,74 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import argparse
1615
from os import path as osp
1716

1817
import h5py
18+
import hydra
1919
import numpy as np
2020
import paddle
2121
import pandas as pd
22+
from omegaconf import DictConfig
2223
from packaging import version
2324

2425
from examples.yinglong.plot import save_plot_weather_from_dict
25-
from examples.yinglong.predictor import YingLong
26+
from examples.yinglong.predictor import YingLongPredictor
2627
from ppsci.utils import logger
2728

2829

29-
def parse_args():
30-
parser = argparse.ArgumentParser()
31-
parser.add_argument(
32-
"--model_file",
33-
type=str,
34-
default="./yinglong_models/yinglong_12.pdmodel",
35-
help="Model filename",
36-
)
37-
parser.add_argument(
38-
"--params_file",
39-
type=str,
40-
default="./yinglong_models/yinglong_12.pdiparams",
41-
help="Parameter filename",
42-
)
43-
parser.add_argument(
44-
"--mean_path",
45-
type=str,
46-
default="./hrrr_example_24vars/stat/mean_crop.npy",
47-
help="Mean filename",
48-
)
49-
parser.add_argument(
50-
"--std_path",
51-
type=str,
52-
default="./hrrr_example_24vars/stat/std_crop.npy",
53-
help="Standard deviation filename",
54-
)
55-
parser.add_argument(
56-
"--input_file",
57-
type=str,
58-
default="./hrrr_example_24vars/valid/2022/01/01.h5",
59-
help="Input filename",
60-
)
61-
parser.add_argument(
62-
"--init_time", type=str, default="2022/01/01/00", help="Init time"
63-
)
64-
parser.add_argument(
65-
"--nwp_file",
66-
type=str,
67-
default="./hrrr_example_24vars/nwp_convert/2022/01/01/00.h5",
68-
help="NWP filename",
69-
)
70-
parser.add_argument(
71-
"--num_timestamps", type=int, default=22, help="Number of timestamps"
72-
)
73-
parser.add_argument(
74-
"--output_path", type=str, default="output", help="Output file path"
75-
)
76-
77-
return parser.parse_args()
78-
79-
80-
def main():
81-
args = parse_args()
82-
logger.init_logger("ppsci", osp.join(args.output_path, "predict.log"), "info")
30+
def inference(cfg: DictConfig):
8331
# log paddlepaddle's version
8432
if version.Version(paddle.__version__) != version.Version("0.0.0"):
8533
paddle_version = paddle.__version__
@@ -93,19 +41,17 @@ def main():
9341

9442
logger.info(f"Using paddlepaddle {paddle_version}")
9543

96-
num_timestamps = args.num_timestamps
44+
num_timestamps = cfg.INFER.num_timestamps
9745
# create predictor
98-
predictor = YingLong(
99-
args.model_file, args.params_file, args.mean_path, args.std_path
100-
)
46+
predictor = YingLongPredictor(cfg)
10147

10248
# load data
10349
# HRRR Crop use 24 atmospheric variable,their index in the dataset is from 0 to 23.
10450
# The variable name is 'z50', 'z500', 'z850', 'z1000', 't50', 't500', 't850', 'z1000',
10551
# 's50', 's500', 's850', 's1000', 'u50', 'u500', 'u850', 'u1000', 'v50', 'v500',
10652
# 'v850', 'v1000', 'mslp', 'u10', 'v10', 't2m'.
107-
input_file = h5py.File(args.input_file, "r")["fields"]
108-
nwp_file = h5py.File(args.nwp_file, "r")["fields"]
53+
input_file = h5py.File(cfg.INFER.input_file, "r")["fields"]
54+
nwp_file = h5py.File(cfg.INFER.nwp_file, "r")["fields"]
10955

11056
# input_data.shape: (1, 24, 440, 408)
11157
input_data = input_file[0:1]
@@ -115,18 +61,18 @@ def main():
11561
ground_truth = input_file[1 : num_timestamps + 1]
11662

11763
# create time stamps
118-
cur_time = pd.to_datetime(args.init_time, format="%Y/%m/%d/%H")
64+
cur_time = pd.to_datetime(cfg.INFER.init_time, format="%Y/%m/%d/%H")
11965
time_stamps = [[cur_time]]
12066
for _ in range(num_timestamps):
12167
cur_time += pd.Timedelta(hours=1)
12268
time_stamps.append([cur_time])
12369

12470
# run predictor
125-
pred_data = predictor(input_data, time_stamps, nwp_data)
71+
pred_data = predictor.predict(input_data, time_stamps, nwp_data)
12672
pred_data = pred_data.squeeze(axis=1) # (num_timestamps, 24, 440, 408)
12773

12874
# save predict data
129-
save_path = osp.join(args.output_path, "result.npy")
75+
save_path = osp.join(cfg.output_dir, "result.npy")
13076
np.save(save_path, pred_data)
13177
logger.info(f"Save output to {save_path}")
13278

@@ -139,15 +85,15 @@ def main():
13985
data_dict = {}
14086
visu_keys = []
14187
for i in range(num_timestamps):
142-
visu_key = f"Init time: {args.init_time}h\n Ground truth: {i+1}h"
88+
visu_key = f"Init time: {cfg.INFER.init_time}h\n Ground truth: {i+1}h"
14389
visu_keys.append(visu_key)
14490
data_dict[visu_key] = ground_truth_wind[i]
145-
visu_key = f"Init time: {args.init_time}h\n YingLong-12 Layers: {i+1}h"
91+
visu_key = f"Init time: {cfg.INFER.init_time}h\n YingLong-12 Layers: {i+1}h"
14692
visu_keys.append(visu_key)
14793
data_dict[visu_key] = pred_wind[i]
14894

14995
save_plot_weather_from_dict(
150-
foldername=args.output_path,
96+
foldername=cfg.output_dir,
15197
data_dict=data_dict,
15298
visu_keys=visu_keys,
15399
xticks=np.linspace(0, 407, 7),
@@ -159,7 +105,15 @@ def main():
159105
colorbar_label="m/s",
160106
num_timestamps=12, # only plot 12 timestamps
161107
)
162-
logger.info(f"Save plot to {args.output_path}")
108+
logger.info(f"Save plot to {cfg.output_dir}")
109+
110+
111+
@hydra.main(version_base=None, config_path="./conf", config_name="yinglong_12.yaml")
112+
def main(cfg: DictConfig):
113+
if cfg.mode == "infer":
114+
inference(cfg)
115+
else:
116+
raise ValueError(f"cfg.mode should in ['infer'], but got '{cfg.mode}'")
163117

164118

165119
if __name__ == "__main__":

0 commit comments

Comments
 (0)