Skip to content

钙钛矿太阳能电池人工神经网络ppsci实现 #1055

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

ZcwDev
Copy link

@ZcwDev ZcwDev commented Dec 30, 2024

PR types

New features

PR changes

  1. Add perovskite solar cells neural network model (psc_nn.py)
  2. Add configuration file for the model (psc_nn.yaml)
  3. Implement hyperparameter optimization using Optuna
  4. Add evaluation and visualization functionality

Describe

This PR implements a neural network model for predicting the short-circuit current density (Jsc) of perovskite solar cells. Key features include:

  1. Model Architecture:

    • Multi-layer perceptron (MLP) with configurable layers and units
    • Hyperparameter optimization using Optuna
    • Support for multiple optimizers (Adam, RMSProp, SGD)
  2. Training Features:

    • Weighted MSE loss function
    • Learning rate scheduling with warmup
    • Evaluation during training
    • Model checkpointing
  3. Evaluation:

    • Multiple metrics (RMSE, R2, MAPE)
    • Results visualization
    • Model validation
  4. Configuration:

    • YAML-based configuration
    • Flexible hyperparameter settings
    • Separate train/eval modes

@CLAassistant
Copy link

CLAassistant commented Dec 30, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ZcwDev
❌ 张成威


张成威 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢提交PR,有几点PR相关的问题:

  1. 请使用pre-commit对代码进行格式化
    image
  2. 除了mkdocs之外,请同步更新README.md和index.md内的案例列表

Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ML_Pipeline文件夹名字建议改一下,如perovskite_solar_cells

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该文件已经上传,请将所有相关的路径替换为以下url:
https://paddle-org.bj.bcebos.com/paddlescience/models/PerovskiteSolarCells/solar_cell_pretrained.pdparams

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名建议改为相关明确的,nn_optuna_ppsci看不出来是什么案例的配置文件

)

def create_validator(input_dict, batch_size, name="validator"):
"""创建评估器"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释建议改为英文

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名建议改为案例相关的名字,比如perovskite_solar_cells之类的

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名使用小写,并且改成有意义的名字,如overview、pipeline

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样的文件名问题

Comment on lines 69 to 73
"sampler": {
"name": "BatchSampler",
"drop_last": False,
"shuffle": False,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

69-73这个sampler字段在drop_last和shuffle都是false情况下,可以删掉

Comment on lines 1 to 4
mode: "train"
seed: 42
output_dir: "./output"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件开头建议加上如下的配置:

defaults:
- ppsci_default
- TRAIN: train_default
- TRAIN/ema: ema_default
- TRAIN/swa: swa_default
- EVAL: eval_default
- INFER: infer_default
- hydra/job/config/override_dirname/exclude_keys: exclude_keys_default
- _self_
hydra:
run:
# dynamic output directory according to running time and override name
dir: outputs_allen_cahn_piratenet/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
job:
name: ${mode} # name of logfile
chdir: false # keep current working directory unchanged
callbacks:
init_callback:
_target_: ppsci.utils.callbacks.InitCallback
sweep:
# output directory for multirun
dir: ${hydra.run.dir}
subdir: ./

eval:
batch_size: 64
eval_with_no_grad: true
pretrained_model_path: null # 预训练模型路径,可以是本地路径或URL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释建议改为英文

Comment on lines 122 to 128
print("Starting training...")
ppsci.utils.misc.set_random_seed(cfg.seed)
logger.init_logger("ppsci", osp.join(cfg.output_dir, f"{cfg.mode}.log"), "info")

if not os.path.exists(cfg.output_dir):
os.makedirs(cfg.output_dir)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以删除,配置文件中添加了callback字段后,会自动创建output_dir

Comment on lines 170 to 174
eval_during_train=True,
eval_freq=5,
save_freq=10,
eval_with_no_grad=True,
log_freq=50,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些字段建议移动到yaml中,由yaml控制

Comment on lines 218 to 221
eval_freq=5,
save_freq=10,
eval_with_no_grad=cfg.eval.eval_with_no_grad,
log_freq=50,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Comment on lines 243 to 246
print("Starting evaluation...")
ppsci.utils.misc.set_random_seed(cfg.seed)
logger.init_logger("ppsci", osp.join(cfg.output_dir, f"{cfg.mode}.log"), "info")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,可删除

@HydrogenSulfate
Copy link
Collaborator

HydrogenSulfate commented Jan 2, 2025

@ZhangPassion pre-commit运行时需要指定--files为你的修改文件examples/perovskite_solar_cells,否则jointContribution文件夹下也会受到影响,可以通过git checkout develop jointContribution还原这个文件夹的改动。

image

@HydrogenSulfate
Copy link
Collaborator

@ZhangPassion 完善一下PR描述,
image


mode: "train"
seed: 42
output_dir: "./output"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
output_dir: "./output"
output_dir: ${hydra:run.dir}

Comment on lines 52 to 53
warmup_epoch: 2
warmup_start_lr: 1.0e-6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
warmup_epoch: 2
warmup_start_lr: 1.0e-6
warmup_epoch: 2
warmup_start_lr: 1.0e-6

Comment on lines 90 to 93
gamma=0.95,
decay_steps=5,
warmup_epoch=2,
warmup_start_lr=1.0e-6,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里请使用cfg的配置

Copy link

paddle-bot bot commented Jan 6, 2025

Thanks for your contribution!

@leeleolay
Copy link
Contributor

leeleolay commented Mar 12, 2025

提交的代码对与本项目无关的代码看起来有所改动,另外没有找到相关的requirement文件,辛苦整理一下代码,也提供一下可用于模型训练的数据集

@ZcwDev
Copy link
Author

ZcwDev commented Mar 23, 2025

提交的代码对与本项目无关的代码看起来有所改动,另外没有找到相关的requirement文件,辛苦整理一下代码,也提供一下可用于模型训练的数据集

数据集:
通过网盘分享的文件:data.zip
链接: https://pan.baidu.com/s/17Cob37nbYVUvDbVxxznhHg?pwd=g8ip 提取码: g8ip
--来自百度网盘超级会员v4的分享

@leeleolay
Copy link
Contributor

image 文档加载过程中有个warning,辛苦检查一下路径

@leeleolay
Copy link
Contributor

截屏2025-04-17 11 44 45 这里的案例名称建议修改为和文档一致的名称,比如psc_nn

@leeleolay
Copy link
Contributor

image 文档这里的代码显示有点问题

@leeleolay
Copy link
Contributor

同上
image

@leeleolay
Copy link
Contributor

文档里的requirements.txt是Conda 环境导出文件,建议修改为pip的,另外里面只需保留必要的安装依赖项即可,项目看起来用到了optuna,但是安装依赖的文档里没有囊括进来。代码运行训练时,config里只设置了10个epoch,但是程序运行时会迭代重复循环,辛苦检查一下代码逻辑。

@leeleolay
Copy link
Contributor

image 评估模型也出错了,辛苦检查一下错误

@ZcwDev
Copy link
Author

ZcwDev commented Apr 22, 2025

image 评估模型也出错了,辛苦检查一下错误
1745317665892
我的运行没问题呀

@leeleolay
Copy link
Contributor

leeleolay commented May 8, 2025

提交的代码有合入冲突,辛苦解决一下吧。
不能强制推送,需要手动解决每个冲突

@leeleolay
Copy link
Contributor

image 模型评估命令运行有问题。模型训练命令,模型会反复运行,停止不了,检查一下运行逻辑。

@leeleolay
Copy link
Contributor

image requirements这里面的paddle版本的制定,我测试是cpu也可以的,是否一定限制gpu的3.0.0的版本哈,可以考虑注释掉这行或者再修改

@leeleolay
Copy link
Contributor

https://paddle-org.bj.bcebos.com/paddlescience%2Fdatasets%2Fpsc%2Fdata.zip
可以在文档中添加数据集的下载链接,方便用户使用

@ZcwDev
Copy link
Author

ZcwDev commented Jun 2, 2025

image 模型评估命令运行有问题。模型训练命令,模型会反复运行,停止不了,检查一下运行逻辑。

image 我用GPU运行的很快,你cpu可能要多等一会,就出结果了,验证的参数我换了一个,现在应该可以了(之前忘记换了)

@ZcwDev
Copy link
Author

ZcwDev commented Jun 2, 2025

要是能运行的话,帮我之前参数的下载路径也换成最新的吧谢谢

@leeleolay
Copy link
Contributor

image 模型评估命令运行有问题。模型训练命令,模型会反复运行,停止不了,检查一下运行逻辑。

image 我用GPU运行的很快,你cpu可能要多等一会,就出结果了,验证的参数我换了一个,现在应该可以了(之前忘记换了)

是训练命令,不是评估命令。训练的时候,任务不会自动终止,反复迭代的。和CPU没有关系。CPU是指在requirements中可以修改一下,原先的指定了gpu

@leeleolay
Copy link
Contributor

要是能运行的话,帮我之前参数的下载路径也换成最新的吧谢谢

这个辛苦你这边修改一下吧,数据的链接可以在文档的前面标记一下链接。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请不要修改无关文件,合入develop最新代码可解决

Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你提交的代码文件请使用pre-commit格式化

@ZcwDev
Copy link
Author

ZcwDev commented Jun 6, 2025

image 模型评估命令运行有问题。模型训练命令,模型会反复运行,停止不了,检查一下运行逻辑。

image 我用GPU运行的很快,你cpu可能要多等一会,就出结果了,验证的参数我换了一个,现在应该可以了(之前忘记换了)

是训练命令,不是评估命令。训练的时候,任务不会自动终止,反复迭代的。和CPU没有关系。CPU是指在requirements中可以修改一下,原先的指定了gpu

图片上的就是我的训练完成结果,确实是停止了啊

张成威 added 2 commits June 20, 2025 15:18
- Update line number references in perovskite_solar_cells_nn.md
- Align documentation with formatted psc_nn.py code structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants