Skip to content
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

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

Conversation

ADream-ki
Copy link

@ADream-ki ADream-ki commented Sep 2, 2024

PR types

Others

PR changes

APIs

Describe

AI-aided geometric design of anti-infection catheters 论文复现

Copy link

paddle-bot bot commented Sep 2, 2024

Thanks for your contribution!

@ADream-ki ADream-ki changed the title 【Hackathon 7th】No.7 AI-aided geometric design of anti-infection catheters 论文复现 【Hackathon 7th No.7】No.7 AI-aided geometric design of anti-infection catheters 论文复现 Sep 2, 2024
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,有一些修改建议如下,另外提交的代码请使用pre-commit格式化(参考文档:https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/development/#1


=== "模型训练命令"

``sh python laplace2d.py ``
Copy link
Collaborator

Choose a reason for hiding this comment

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

请使用三个重音符号包裹代码块,下同


| 预训练模型 | 指标 |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------- |
| [GeoFno.pdparams](https://paddle-orghttps://aistudio.baidu.com/datasetdetail/291940.bj.bcebos.com/paddlescience/models/laplace2d/laplace2d_pretrained.pdparams) | Test loss(LPLoss): 0.07319313049316406 |
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. laplace案例模版的内容请删除干净
  2. 预训练模型可以放aistudio或者本PR里,我会帮忙上传

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 1 to 24
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: ./

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
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: ./

Comment on lines 23 to 26
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"
Copy link
Collaborator

Choose a reason for hiding this comment

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

请删除路径中的"examples/geofno/"前缀,一般默认当前路径在examples/geofno/下

Comment on lines 129 to 133
# 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,
)
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
# 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,
)

Comment on lines 149 to 140
# 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")

Copy link
Collaborator

Choose a reason for hiding this comment

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

删除


plt.legend()
plt.tight_layout()
plt.savefig("Validation."+str(sample_id)+".pdf")
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
plt.savefig("Validation."+str(sample_id)+".pdf")
plt.savefig(f"Validation.{sample_id}.pdf")

Comment on lines 192 to 231
raise ValueError(
f"cfg.mode should in ['train', 'eval', 'export', 'infer'], but got '{cfg.mode}'"
)
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 58 to 62
def count_params(model):
c = 0
for p in model.parameters():
c += np.prod(p.shape) # 使用paddle.prod计算参数的总数
return c
Copy link
Collaborator

Choose a reason for hiding this comment

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

不重要的调试函数可以删除


| 预训练模型 | 指标 |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------- |
| [GeoFno.pdparams](https://paddle-orghttps://aistudio.baidu.com/datasetdetail/291940.bj.bcebos.com/paddlescience/models/laplace2d/laplace2d_pretrained.pdparams) | Test loss(LPLoss): 0.07319313049316406 |
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
Author

Choose a reason for hiding this comment

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

刚刚弄完

Copy link
Author

Choose a reason for hiding this comment

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

链接也弄好了

Copy link
Contributor

@wangguan1995 wangguan1995 left a comment

Choose a reason for hiding this comment

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

to fix



# loss function with rel/abs Lp loss
class LpLoss(nn.Layer):
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

复原laplace2.md

Copy link
Contributor

@wangguan1995 wangguan1995 left a 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.

  1. catheter_analysis.ipynb: Compassion with linear regression model; Visualization of the landscape of the loss function around the optimal design.


## 1. 背景简介

[论文](https://www.science.org/doi/pdf/10.1126/sciadv.adj1741)提出了一种基于人工智能的导尿管几何设计方法,可以有效抑制细菌逆流,从而预防 CAUTI。该方法通过流体动力学和粒子动力学模拟研究细菌运动机制,并使用人工智能模型优化导尿管几何形状,使其能够最大程度地抑制细菌逆流。实验结果表明,该设计能够将细菌逆流的程度降低一到两个数量级,具有安全、有效、易于实施和成本低等优点,有望成为未来 CAUTI 预防的重要手段。
Copy link
Contributor

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)

可以看到模型预测结果与真实结果基本一致,模型泛化效果良好。

Copy link
Contributor

Choose a reason for hiding this comment

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

Training Test Loss 也放一下

Copy link
Author

Choose a reason for hiding this comment

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

已经加了

@ADream-ki
Copy link
Author

这两个好像还没做,注意下 3. catheter_design.ipynb: Real-time design optimization by using Geo-FNO model and BFGS algorithm.

  1. catheter_analysis.ipynb: Compassion with linear regression model; Visualization of the landscape of the loss function around the optimal design.

加在aistudio那里了

@luotao1 luotao1 changed the title 【Hackathon 7th No.7】No.7 AI-aided geometric design of anti-infection catheters 论文复现 【Hackathon 7th PPSCI No.7】No.7 AI-aided geometric design of anti-infection catheters 论文复现 Sep 18, 2024
@@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

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

image

这个链接不太对啊....

################################################################
# fourier layer
################################################################
class SpectralConv1d(nn.Layer):
Copy link
Contributor

Choose a reason for hiding this comment

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

神经网络的代码,应归类到:ppsci/arch
调用方式如图:
image

这样方便网络算法直接,快速的横向对比,对用户友好,别的数据集也可以用这种网络~

Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

抱歉,我马上改掉,最近在写论文

Copy link
Author

Choose a reason for hiding this comment

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

你好,已经按照要求修改了

@CLAassistant
Copy link

CLAassistant commented Sep 25, 2024

CLA assistant check
All committers have signed the CLA.

@wangguan1995
Copy link
Contributor

wangguan1995 commented Oct 8, 2024

image
image

数据集没有公开,另外需要【挂载】到aistudio项目上

@ADream-ki
Copy link
Author

ADream-ki commented Oct 9, 2024

抱歉抱歉,忘了公开数据集了,现在已经可以了,请review @wangguan1995

@wangguan1995
Copy link
Contributor

AIStudio需要修复以下内容,最终做到用户【一键跑通训练推理】:

  1. 补充数据解压脚本,到3个ipynb文件内
!unzip ./data/data291940/data.zip -d .
!mkdir MyData
!mv ./data/test/ MyData
!mv ./data/training/ MyData
  1. 修复 geofno_analysis.ipynb bug:
    image

  2. 修复 main.ipynb bug:
    image

@ADream-ki
Copy link
Author

已经修改了,但是有个问题,这个是怎么回事吗
image
@wangguan1995

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.

这里不用改,固定是hydra

examples/catheter/conf/catheter.yaml Outdated Show resolved Hide resolved
@ADream-ki
Copy link
Author

好的好的,我现在试试

@ADream-ki
Copy link
Author

已经好了,请您review一下

@ADream-ki
Copy link
Author

@HydrogenSulfate

HydrogenSulfate
HydrogenSulfate previously approved these changes Nov 5, 2024
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,辛苦按照review修改一下。

  1. 修改完毕之后,提交代码之前,请按照文档安装pre-commit:
    image
  2. 文档中的图片已经上传至云端,请将文档里的图片地址替换成如下地址:
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"
Copy link
Collaborator

Choose a reason for hiding this comment

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

为什么训练的时候要载入预训练模型呢?

其中

- `dt(q)` 代表细菌方向变化率
- `ω ⃗ ` 代表流体涡量
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
Author

Choose a reason for hiding this comment

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

确实,他有一个乱码了


=== "模型训练命令"

``sh python catheter.py ``
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
``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))
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
Author

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.

因为我发现模型初始化并不稳定

  1. 模型的初始化跟随机种子相关,而模型运行之前,随机种子应该是在callback.py里固定了:

    # 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,
    )
    ,你说的初始化不稳定是指随机初始化对训练最终精度影响较大吗?

  2. 一般实验可复现性通过固定随机种子来保证,加载固定的参数这种做法不太常见

Copy link
Author

Choose a reason for hiding this comment

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

不知道是不是我电脑问题,我设置了随机数种子,但他有时候就是随机数不一样,我改改再试试

def evaluate(cfg: DictConfig):
# set model
model = ppsci.arch.FNO1d(**cfg.MODEL)
model.set_state_dict(paddle.load(cfg.TRAIN.model_path))
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
model.set_state_dict(paddle.load(cfg.TRAIN.model_path))
ppsci.utils.save_load.load_pretrain(
model,
cfg.EVAL.pretrained_model_path,
)

Comment on lines 60 to 63
LOSS:
batch_size: 20
d: 2
p: 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

LOSS:这个字段是不是可以删除?代码里好像没用到这个字段

Comment on lines 66 to 70
epochs: 2001
learning_rate: 0.001
milestones: [160, 400, 750, 1000, 1300, 1600, 1800]
gamma: 0.25
epochs: 1001
Copy link
Collaborator

Choose a reason for hiding this comment

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

两处的epochs为什么会不一样呢


# inference settings
INFER:
export_path: ./inference/catheter
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.

在arch.md里也添加一下FNO1d

Comment on lines +28 to +32

"""
1D Fourier layer. It does FFT, linear transform, and Inverse FFT.
"""

Copy link
Collaborator

Choose a reason for hiding this comment

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

__init__的docstring需要移动到类定义,即class SpectralConv1d下方

Copy link
Author

Choose a reason for hiding this comment

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

我看看

Copy link
Author

Choose a reason for hiding this comment

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

inference我再改改,其他已经好了

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.

5 participants