-
Notifications
You must be signed in to change notification settings - Fork 187
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
Hackathon 5th No.58 A physics-informed deep neural network for surrogate modeling in classical elasto-plasticity #558
Conversation
Thanks for your contribution! |
|
已使用 transform修改模型,文档需要引用代码行,在代码修改完后再增加
数据集在 https://github.com/meghbali/ANNElastoplasticity/tree/main/Datasets/WG |
文档只需引用必要的代码,能够说清楚方案即可 |
先只看了一下ppsci下的代码,example下我看目前基本上还是paddle的代码,验收标准是合入paddlescience,所以需要进行替换。 |
已增加文档,引用代码行在代码修改完成后再更新 |
dataset格式是自定义字段,使用pickle.load读取,如果增加那是不是在ppsci.utils.reader.py增加 |
是的,需要在ppsci.utils.reader.py增加读入.dat的部分 |
参考 https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/l1_loss_cn.html#l1-loss |
已修改 |
使用最新版本paddle ,还是提示错误,错误位置是ppsci/loss/l1.py,如果label_key是List会有错误 |
|
是的,经过检查,paddle.nn.L1Loss是逐元素平均的,而ppsci.loss.L1Loss是按batch平均的,感谢你的反馈,麻烦参考ppsci.loss.MSELoss,增加一个MAELoss的API吧。 |
已增加 MAELoss |
examples/epnn/epnn.py
Outdated
) | ||
dstrainel = dstrain_real - dstrainpl_real | ||
dstrainelv = paddle.matmul(x=dstrainel, y=oneten1) | ||
dstrainelvten = paddle.multiply(x=dstrainelv, y=paddle.to_tensor(oneten2)) |
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/epnn/epnn.py
Outdated
) | ||
|
||
model_list = functions.get_model_list( | ||
IHLAYERS, INEURONS, data_train_state1, data_train_stress1 |
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.
同理:
- 这边的
data_train_state1
并没有往本文件传一下的必要 - 其实进到
get_model_list
中看的话,只是用到了数据的shape,既然如此传递shape即可,似乎没有必要连数据一起传递
examples/epnn/epnn.py
Outdated
learning_rate=scheduler_stress, | ||
weight_decay=0.0, | ||
)(model_list[2]) | ||
optimizer_ratio = paddle.optimizer.Adam( |
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/epnn/epnn.py
Outdated
Returns: | ||
paddle.Tensor: Loss value. | ||
""" | ||
criterion = val_loss_criterion |
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.
eval_loss_func需要统计信息,没有修改嵌套函数
examples/epnn/epnn.py
Outdated
min_stress = paddle.to_tensor(data=get_data["miny"]) | ||
range_stress = paddle.to_tensor(data=get_data["rangey"]) | ||
global common_param | ||
common_param = [ |
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.
如果要用set_params,最好封装个类,不然依然使用global,似乎没什么意义
这个值实际上并没有必要在functions和epnn中来回传递,只要把loss_function封装到functions中,然后参照hpinns,把common_param写在文件最开始即可,不过看functions.set_params(functions.Data.get_common_param(DATASET_STATE, DATASET_STRESS))
这一行,这行代码将一个从functions中计算得到的值传回了functions文件,完全没有必要
examples/epnn/functions.py
Outdated
for i in range(epochs): | ||
shuffled_indices = paddle.randperm(n=self.data_train_state1.x.shape[0]) | ||
input_dict_train["state_x"].append( | ||
self.data_train_state1.x[shuffled_indices[0 : self.itrain]] |
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.
好的,那就不用data sampler了吧
"dataset": { | ||
"name": "NamedArrayDataset", | ||
"input": input_dict_train, | ||
"label": label_dict_train, |
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/epnn/functions.py
Outdated
get_data = ppsci.utils.reader.load_dat_file(dataset_state) | ||
data_state = Data( | ||
x=paddle.to_tensor(data=get_data["X"]), | ||
y=paddle.to_tensor(data=get_data["y"]), |
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.
Data 中调 Data 很奇怪
examples/epnn/functions.py
Outdated
shuffled_indices[n_train + n_cross_valid : n_train + n_cross_valid + n_test] | ||
], | ||
) | ||
return data_train, data_cross_valid, data_test |
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/epnn/functions.py
Outdated
self.y = y | ||
self.n_samples = self.x.shape[0] | ||
|
||
def get_data(dataset_state, dataset_stress, ntrain_size, irepeat): |
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.
把它和set_common_param挪出Data吧
examples/epnn/functions.py
Outdated
).get(10) | ||
|
||
def set_common_param(dataset_state, dataset_stress): | ||
global common_param |
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.
同一个文件里可以直接赋值,不用写global
examples/epnn/functions.py
Outdated
|
||
def plot_loss(): | ||
global loss_log | ||
global OUTPUT_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.
不用写global,另外solver里有plot_loss_history这个函数,可以参考看看能不能用
examples/epnn/functions.py
Outdated
|
||
|
||
def loss_func(output_dict, criterion) -> paddle.Tensor: | ||
global gkratio, common_param |
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.
不用写global
examples/epnn/functions.py
Outdated
Returns: | ||
paddle.Tensor: Loss value. | ||
""" | ||
global loss_log |
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/epnn/functions.py
Outdated
train_size = train_size_float.astype(int) | ||
itrain = train_size[ntrain_size - 1] | ||
|
||
ppsci.utils.misc.set_random_seed(seed=10 + irepeat) |
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.
这句好像没有用到
PR内容较长,当前PR关闭再新建PR #606 |
PR types
Others
PR changes
Others
Describe
PaddlePaddle/Paddle#57262
已使用 transform修改模型,文档需要引用代码行,在代码修改完后再增加
训练精度
torch
paddle
数据集在 https://github.com/meghbali/ANNElastoplasticity/tree/main/Datasets/WG
dstate-16-plas.dat
dstress-16-plas.dat