-
Notifications
You must be signed in to change notification settings - Fork 165
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. 29】 add export and inference #793
Conversation
Thanks for your contribution! |
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.
感谢大佬提交代码。@lijialin03 周一辛苦看一下几个模型的推理结果是否符合预期
=== "模型导出命令" | ||
|
||
``` sh | ||
python topopt.py mode=export INFER.pretrained_model_name=Uniform |
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.
是否可以以注释的形式补充另外几个Poisson系列的模型呢?模型推理命令同
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/topopt/conf/topopt.yaml
Outdated
@@ -14,8 +14,13 @@ hydra: | |||
- EVAL.pretrained_model_path_dict | |||
- EVAL.batch_size | |||
- EVAL.num_val_step | |||
- EXPORT.pretrained_model_name |
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.
EXPORT->INFER
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/topopt/conf/topopt.yaml
Outdated
INFER: | ||
pretrained_model_name: null # a string, indicating which model you want to export. Support [Uniform, Poisson5, Poisson10, Poisson30]. | ||
pretrained_model_path_dict: {'Uniform': 'https://paddle-org.bj.bcebos.com/paddlescience/models/topopt/uniform_pretrained.pdparams', 'Poisson5': 'https://paddle-org.bj.bcebos.com/paddlescience/models/topopt/poisson5_pretrained.pdparams', 'Poisson10': 'https://paddle-org.bj.bcebos.com/paddlescience/models/topopt/poisson10_pretrained.pdparams', 'Poisson30': 'https://paddle-org.bj.bcebos.com/paddlescience/models/topopt/poisson30_pretrained.pdparams'} | ||
export_path: ./inference/topopt |
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.
如果在pretrained_model_path_dict里的模型是互相独立的,可以把export_path改为./inference/topopt_${INFER.pretrained_model_name}
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/topopt/conf/topopt.yaml
Outdated
sampler_num: 8 # a integer number, indicating the sampling rate of the sampling method, supported when `sampler_key` is Fixed or Poisson. | ||
img_num: 4 | ||
res_img_figsize: null | ||
save_res_path: ./inference/predicted |
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.
此处的save_res_path也可以改为./inference/predicted_${INFER.pretrained_model_name}
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/topopt/topopt.py
Outdated
model, | ||
eval_with_no_grad=True, | ||
pretrained_model_path=cfg.INFER.pretrained_model_path_dict[ | ||
cfg.EXPORT.pretrained_model_name |
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.
EXPORT->INFER
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/topopt/topopt.py
Outdated
solver.export(input_spec, cfg.INFER.export_path) | ||
|
||
|
||
# model inference |
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.
这行注释可以删除
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/topopt/topopt.py
Outdated
def save_topopt_img( | ||
input_dict, output_dict, ground_truth, res_path, figsize=None, npy=False | ||
): |
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.
- save_topopt_img函数可以加一下typehint
- 为了更容易理解和更符合语义,建议这两个参数名改一下:
npy
->save_npy
,res_path
->save_dir
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/topopt/topopt.py
Outdated
print(output[i]) | ||
plt.title("Prediction") | ||
plt.subplot(1, 4, 4) | ||
plt.axis("off") | ||
plt.imshow(np.round(ground_truth[i][0]), cmap="gray") | ||
print(ground_truth[i]) |
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.
两处print可以删除,否则会打印大量矩阵元素,如果是为了友好提示可以在for循环的最后一行使用logger.message信息打印保存成功的提示
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/topopt/topopt.py
Outdated
plt.savefig(osp.join(res_path, "Prediction_" + str(i) + ".png")) | ||
plt.close() | ||
if npy: | ||
with open(osp(res_path, "Prediction_" + str(i) + ".npy"), "wb") as f: |
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.
两处字符串拼接改为f-string:"Prediction_" + str(i) + ".png"
改为f"Prediction_{i}.png"
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.
已修改
): | ||
|
||
input = input_dict["input"] | ||
output = output_dict["output"] |
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.
保存前先创建文件夹,否则会报错
output = output_dict["output"] | |
output = output_dict["output"] | |
import os | |
os.makedirs(res_path, exist_ok=True) |
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/topopt/topopt.py
Outdated
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import paddle | ||
from omegaconf import DictConfig | ||
from paddle import nn | ||
from paddle.static import InputSpec | ||
from topoptmodel import TopOptNN | ||
|
||
import ppsci | ||
from deploy.python_infer import pinn_predictor |
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.
这几行import建议放在对应函数内部,否则会影响整体topopt的代码块行数定位
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.
已修改
已验证推理结果符合预期 |
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.
LGTM
* add export and inference * update
PR types
Others
PR changes
Others
Describe
#788