Git Product home page Git Product logo

1dbloodflowpinns-pelvic-pytorch's Introduction

1DBloodFlowPINNs-pelvic-pytorch

简介

本项目将PredictiveIntelligenceLab/1DBloodFlowPINNs中的Pelvic部分使用pytorch复现。

原项目是论文《Georgios Kissas, Yibo Yang, Eileen Hwuang, Walter R. Witschey, John A. Detre, Paris Perdikaris. "Machine learning in cardiovascular flows modeling: Predicting pulse wave propagation from non-invasive clinical measurements using physics-informed deep learning." (2019).》的代码。该论文使用PINN(physics informed neural network)神经网络结构求解Navier-Stokes方程,从而计算主动脉中的血压分布。

注意:代码中的血管序号与论文中的不一致。本代码中的序号和数据均与PredictiveIntelligenceLab/1DBloodFlowPINNs保持一致,血管序号和其中的lower bound, upper bound位置如下图所示:

下面介绍本项目中的代码。

代码

文件及运行方法

  • /data:用到的数据。
  • /pyfile1207:某次训练后的结果,仅供参考。包括result_lossresult_modelresult_Pressureresult_Velocity。这些文件夹说明见下方。
  • /result_loss:储存训练过程中的loss变化。使用draw_log_loss.py可以画图。
  • /result_model:储存训练得到的模型。使用net.py中的predict函数可以调用并测试。
  • /result_Pressure:在训练过程,使用当前的模型进行预测,并于有限元计算的结果进行对比。
  • /result_Velocity:与上一个类似,分别计算的是pressure和velocity的值。
  • dataset.py:将数据制作成pytorch需要的dataset的形式。
  • draw_log_loss.py:画出训练过程中loss变化图。
  • loss.py:PINN中的定义损失函数。
  • net.py:PINN网络结构。
  • test.py:使用训练好的模型预测。
  • train.py:训练脚本。
  • utility.py:功能函数。

运行方法:

  • 训练前清空result_Pressureresult_Velocityresult_lossresult_model。不清空也没关系,会自动覆盖。如果要保留训练结果,需要将这些文件储存到别的地方。
  • 运行train.py即可。
  • 训练过程中可查看result_Velocityresult_Pressure,观察模型训练情况。
  • 训练结束后,运行draw_log_loss.py,可在result_loss/log_loss_4.jpg查看损失函数变化情况。
  • 训练结束后,可使用test.py,使用训练好的模型进行预测。

requirements

  • pytorch 1.7,1+cuda101 ,安装:pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
  • numpy
  • matplotlib
  • os
  • json

PINN

网络结构为全连接层,代码为net.py

损失函数为NS方程残差的均方误差、测量值的均方误差、连接点约束的均方误差之和,详细设置参考论文,代码为loss.py

损失函数中需要的偏导数使用torch.autograd.grad()计算,代码为train.py中170行前后。

训练和测试

训练脚本为train.py。训练参数为,先使用lr=1e-3训练290000次,再使用lr=1e-4训练50000次。训练时间约为44小时,占用显存不到1GB。原tensorflow程序运行时间为7小时,时间较长的原因可能是因为本程序每次训练过程中七个网络依次计算,如果使用7个gpu改为并行计算可能可以大大提升训练速度。

测试脚本为test.py,可自定义x,t,i_vessel。

结果

pyflie1207保存了一次训练得到的结果,这次训练使用的超参数设置(学习率、参数初始化方法等)与原tensorflow程序相同。

训练后的模型在论文中设定的test points位置的预测结果如下图所示:

图中展示了7个血管中test points位置的血压随时间按变化的情况。其中红色曲线为有限元方法计算的参考结果,蓝色曲线为使用神经网络计算的结果。

这次训练过程中损失函数变化如下图所示:

数值结果和损失函数变化曲线都基本与原tensorflow程序相同。

但使用神经网络的缺点是模型结构、学习率等超参数不容易确定,如果设定不好容易陷入局部最优解,在求解偏微分方程的问题中影响很大。下图和调试过程中某次更改学习率变化策略后的结果,虽然损失函数变化看起来正常,但预测的血压函数在测试点的值与参考结果相差很大。

1dbloodflowpinns-pelvic-pytorch's People

Contributors

meteorlium avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.