-
Notifications
You must be signed in to change notification settings - Fork 172
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 7th PPSCI No.7】No.7 AI-aided geometric design of anti-infection catheters 论文复现 #986
base: develop
Are you sure you want to change the base?
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.
感谢提交PR,有一些修改建议如下,另外提交的代码请使用pre-commit格式化(参考文档:https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/development/#1)
docs/zh/examples/catheter.md
Outdated
|
||
=== "模型训练命令" | ||
|
||
``sh python laplace2d.py `` |
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.
请使用三个重音符号包裹代码块,下同
docs/zh/examples/catheter.md
Outdated
|
||
| 预训练模型 | 指标 | | ||
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------- | | ||
| [GeoFno.pdparams](https://paddle-orghttps://aistudio.baidu.com/datasetdetail/291940.bj.bcebos.com/paddlescience/models/laplace2d/laplace2d_pretrained.pdparams) | Test loss(LPLoss): 0.07319313049316406 | |
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.
- laplace案例模版的内容请删除干净
- 预训练模型可以放aistudio或者本PR里,我会帮忙上传
docs/zh/examples/laplace2d.md
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.
请不要修改无关文件
examples/geofno/conf/geofno.yaml
Outdated
hydra: | ||
run: | ||
# dynamic output directory according to running time and override name | ||
dir: outputs_geofno/${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: ${geofno.run.dir} | ||
subdir: ./ | ||
|
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.
hydra: | |
run: | |
# dynamic output directory according to running time and override name | |
dir: outputs_geofno/${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: ${geofno.run.dir} | |
subdir: ./ | |
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_geofno/${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: ${geofno.run.dir} | |
subdir: ./ | |
examples/geofno/conf/geofno.yaml
Outdated
x_path: "examples/geofno/data/training/x_1d_structured_mesh.npy" | ||
y_path: "examples/geofno/data/training/y_1d_structured_mesh.npy" | ||
para_path: "examples/geofno/data/training/data_info.npy" | ||
output_path: "examples/geofno/data/training/density_1d_data.npy" |
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/geofno/"前缀,一般默认当前路径在examples/geofno/下
examples/geofno/geofno.py
Outdated
# initialize solver OK | ||
solver = ppsci.solver.Solver( | ||
model, | ||
constraint, | ||
cfg.output_dir, | ||
optimizer, | ||
epochs=cfg.TRAIN.epochs, | ||
iters_per_epoch=ITERS_PER_EPOCH, | ||
eval_during_train=cfg.TRAIN.eval_during_train, | ||
validator=l2rel_validator, | ||
save_freq=cfg.TRAIN.save_freq, | ||
seed=cfg.seed, | ||
) |
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.
# initialize solver OK | |
solver = ppsci.solver.Solver( | |
model, | |
constraint, | |
cfg.output_dir, | |
optimizer, | |
epochs=cfg.TRAIN.epochs, | |
iters_per_epoch=ITERS_PER_EPOCH, | |
eval_during_train=cfg.TRAIN.eval_during_train, | |
validator=l2rel_validator, | |
save_freq=cfg.TRAIN.save_freq, | |
seed=cfg.seed, | |
) | |
# initialize solver OK | |
solver = ppsci.solver.Solver( | |
model, | |
constraint, | |
cfg.output_dir, | |
optimizer, | |
epochs=cfg.TRAIN.epochs, | |
iters_per_epoch=ITERS_PER_EPOCH, | |
eval_during_train=cfg.TRAIN.eval_during_train, | |
validator=l2rel_validator, | |
save_freq=cfg.TRAIN.save_freq, | |
) |
examples/geofno/geofno.py
Outdated
# set random seed for reproducibility | ||
ppsci.utils.misc.set_random_seed(cfg.seed) | ||
# initialize logger | ||
logger.init_logger("ppsci", osp.join(cfg.output_dir, f"{cfg.mode}.log"), "info") | ||
|
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/geofno/geofno.py
Outdated
|
||
plt.legend() | ||
plt.tight_layout() | ||
plt.savefig("Validation."+str(sample_id)+".pdf") |
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.
plt.savefig("Validation."+str(sample_id)+".pdf") | |
plt.savefig(f"Validation.{sample_id}.pdf") |
examples/geofno/geofno.py
Outdated
raise ValueError( | ||
f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'" | ||
) |
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/geofno/utilities3.py
Outdated
def count_params(model): | ||
c = 0 | ||
for p in model.parameters(): | ||
c += np.prod(p.shape) # 使用paddle.prod计算参数的总数 | ||
return c |
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.
不重要的调试函数可以删除
docs/zh/examples/catheter.md
Outdated
|
||
| 预训练模型 | 指标 | | ||
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------- | | ||
| [GeoFno.pdparams](https://paddle-orghttps://aistudio.baidu.com/datasetdetail/291940.bj.bcebos.com/paddlescience/models/laplace2d/laplace2d_pretrained.pdparams) | Test loss(LPLoss): 0.07319313049316406 | |
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.
刚刚弄完
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.
to fix
examples/geofno/utilities3.py
Outdated
|
||
|
||
# loss function with rel/abs Lp loss | ||
class LpLoss(nn.Layer): |
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.
删除utilities3.py
复用:ppsci.loss.L2Loss
如果不能复用,新建一个/workspace/wangguan/Hackathon_7/ppsci/loss/Lp.py
docs/zh/examples/laplace2d.md
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.
复原laplace2.md
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.
这两个好像还没做,注意下
3. catheter_design.ipynb
: Real-time design optimization by using Geo-FNO model and BFGS algorithm.
catheter_analysis.ipynb
: Compassion with linear regression model; Visualization of the landscape of the loss function around the optimal design.
docs/zh/examples/catheter.md
Outdated
|
||
## 1. 背景简介 | ||
|
||
[论文](https://www.science.org/doi/pdf/10.1126/sciadv.adj1741)提出了一种基于人工智能的导尿管几何设计方法,可以有效抑制细菌逆流,从而预防 CAUTI。该方法通过流体动力学和粒子动力学模拟研究细菌运动机制,并使用人工智能模型优化导尿管几何形状,使其能够最大程度地抑制细菌逆流。实验结果表明,该设计能够将细菌逆流的程度降低一到两个数量级,具有安全、有效、易于实施和成本低等优点,有望成为未来 CAUTI 预防的重要手段。 |
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.
人工智能辅助的抗感染导管几何创新设计
在狭窄管道内的流体环境中,细菌能借助流体动力学作用逆流迁移,对使用植入性导管的患者构成泌尿道感染的严重威胁。尽管已有提议采用涂层与结构化表面来抑制导管内的细菌滋生,但遗憾的是,至今尚无一种表面结构或涂层技术能从根本上解决污染难题。鉴于此,我们依据逆流游动的物理原理,创新性地提出了一种几何设计方案,并通过人工智能模型对细菌流入动力学进行预测与优化。相较于传统模拟方法,所采用的傅立叶神经算子人工智能技术实现了显著的速度提升。
在准二维微流体实验中,我们以大肠杆菌为对象,验证了该设计的抗感染机制,并在临床相关流速下,通过3D打印的导管原型对其有效性进行了评估。实验结果显示,我们的导管设计在抑制导管上游端细菌污染方面,实现了1-2个数量级的提升,有望大幅延长导管的安全留置时间,并整体降低导管相关性尿路感染的风险。
![1725428017615](image/catheter/1725428017615.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.
Training Test Loss 也放一下
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.
已经加了
加在aistudio那里了 |
docs/zh/examples/catheter.md
Outdated
@@ -0,0 +1,195 @@ | |||
# Catheter | |||
|
|||
<a href="https://aistudio.baidu.com/aistudio/projectdetail/6169897?sUid=455441&shared=1&ts=1684122038217" class="md-button md-button--primary" style>AI Studio 快速体验</a> |
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/geofno/catheter.py
Outdated
################################################################ | ||
# fourier layer | ||
################################################################ | ||
class SpectralConv1d(nn.Layer): |
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/geofno/geofno.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.
建议把这个案例文件,以及文件夹,命名为catheter
当前的catheter.py,因为其包含了geofno网络架构,建议命名为geofno
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.
你好,已经按照要求修改了
抱歉抱歉,忘了公开数据集了,现在已经可以了,请review @wangguan1995 |
已经修改了,但是有个问题,这个是怎么回事吗 |
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.
这里不用改,固定是hydra
Co-authored-by: HydrogenSulfate <[email protected]>
好的好的,我现在试试 |
已经好了,请您review一下 |
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,辛苦按照review修改一下。
https://paddle-org.bj.bcebos.com/paddlescience/docs/catheter/1725427977357.png
https://paddle-org.bj.bcebos.com/paddlescience/docs/catheter/1725428017615.png
https://paddle-org.bj.bcebos.com/paddlescience/docs/catheter/1725894134717.png
batch_size: 20 | ||
d: 2 | ||
p: 2 | ||
pretrained_model_path: "https://paddle-org.bj.bcebos.com/paddlescience/models/GeoFNO/GeoFNO_pretrained.pdparams" |
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.
为什么训练的时候要载入预训练模型呢?
docs/zh/examples/catheter.md
Outdated
其中 | ||
|
||
- `dt(q)` 代表细菌方向变化率 | ||
- `ω ⃗ ` 代表流体涡量 |
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.
确实,他有一个乱码了
docs/zh/examples/catheter.md
Outdated
|
||
=== "模型训练命令" | ||
|
||
``sh python catheter.py `` |
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.
``sh python catheter.py `` | |
``` sh | |
python catheter.py | |
``` |
|
||
# set model | ||
model = ppsci.arch.FNO1d(**cfg.MODEL) | ||
model.set_state_dict(paddle.load(cfg.TRAIN.pretrained_model_path)) |
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.
因为我发现模型初始化并不稳定
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.
因为我发现模型初始化并不稳定
-
模型的初始化跟随机种子相关,而模型运行之前,随机种子应该是在callback.py里固定了:
PaddleScience/ppsci/utils/callbacks.py
Lines 86 to 96 in 645e438
# fix random seed for reproducibility misc.set_random_seed(full_cfg.seed) # initialze logger while creating output directory logger.init_logger( "ppsci", osp.join(full_cfg.output_dir, f"{full_cfg.mode}.log") if full_cfg.output_dir and full_cfg.mode not in ["export", "infer"] else None, full_cfg.log_level, ) -
一般实验可复现性通过固定随机种子来保证,加载固定的参数这种做法不太常见
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/catheter/catheter.py
Outdated
def evaluate(cfg: DictConfig): | ||
# set model | ||
model = ppsci.arch.FNO1d(**cfg.MODEL) | ||
model.set_state_dict(paddle.load(cfg.TRAIN.model_path)) |
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.
model.set_state_dict(paddle.load(cfg.TRAIN.model_path)) | |
ppsci.utils.save_load.load_pretrain( | |
model, | |
cfg.EVAL.pretrained_model_path, | |
) |
examples/catheter/conf/catheter.yaml
Outdated
LOSS: | ||
batch_size: 20 | ||
d: 2 | ||
p: 2 |
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.
LOSS:
这个字段是不是可以删除?代码里好像没用到这个字段
examples/catheter/conf/catheter.yaml
Outdated
epochs: 2001 | ||
learning_rate: 0.001 | ||
milestones: [160, 400, 750, 1000, 1300, 1600, 1800] | ||
gamma: 0.25 | ||
epochs: 1001 |
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.
两处的epochs为什么会不一样呢
examples/catheter/conf/catheter.yaml
Outdated
|
||
# inference settings | ||
INFER: | ||
export_path: ./inference/catheter |
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.
文件结尾补充一行空行
ppsci/arch/__init__.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.
在arch.md里也添加一下FNO1d
|
||
""" | ||
1D Fourier layer. It does FFT, linear transform, and Inverse FFT. | ||
""" | ||
|
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.
__init__
的docstring需要移动到类定义,即class SpectralConv1d
下方
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.
inference我再改改,其他已经好了
PR types
Others
PR changes
APIs
Describe
AI-aided geometric design of anti-infection catheters 论文复现