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

[Example] Add an example of predicting forward diastolic deformation of the left ventricular myocardium #1008

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

Conversation

MGWanderer1
Copy link
Contributor

PR types

Others

PR changes

Others

Describe

The code provides a deformation prediction for the left ventricle during the diastolic phase under a linear elastic constitutive model, utilizing 20% of the actual data points for validation to achieve improved accuracy.

Copy link

paddle-bot bot commented Nov 4, 2024

Thanks for your contribution!

# See the License for the specific language governing permissions and
# limitations under the License.

import equation as eq_func
Copy link
Contributor

Choose a reason for hiding this comment

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

我看了一下现在equation里的公式部分和inverse里的equation一样,就用一份吧,把inverse下的那个equation文件的开头改为:

def __init__(
        self,
        E: Union[float, str, paddle.base.framework.EagerParamBase],
        nu: Union[float, str],
        P: Union[float, str],
        dim: int = 3,
        time: bool = False,
        detach_keys: Optional[Tuple[str, ...]] = None,
    ):
        super().__init__()
        self.detach_keys = detach_keys
        self.dim = dim
        self.time = time

        t, x, y, z = self.create_symbols("t x y z")
        normal_x, normal_y, normal_z = self.create_symbols("normal_x normal_y normal_z")
        invars = (x, y)
        if time:
            invars = (t,) + invars
        if self.dim == 3:
            invars += (z,)

        u = self.create_function("u", invars)
        v = self.create_function("v", invars)
        w = self.create_function("w", invars) if dim == 3 else sp.Number(0)

        if isinstance(nu, str):
            nu = self.create_function(nu, invars)
        if isinstance(P, str):
            P = self.create_function(P, invars)
        if isinstance(E, str):
            E = self.create_function(E, invars)
            self.E = E
        elif isinstance(E, paddle.base.framework.EagerParamBase):
            self.E = E
            self.learnable_parameters.append(self.E)
            E = self.create_symbols(self.E.name)

        self.nu = nu
        self.P = P

类名改为

class Hooke(base.PDE):

然后把inverse.py中调用的代码(第37行)改为:

equation = {"Hooke": eq_func.Hooke(E=E, nu=cfg.nu, P=cfg.P, dim=3)}

dir: ${hydra.run.dir}
subdir: ./

EVAL_CSV_PATH: label.csv
Copy link
Contributor

Choose a reason for hiding this comment

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

改为./data/label.csv

subdir: ./

EVAL_CSV_PATH: label.csv
DATA_CSV_PATH: data_train.csv
Copy link
Contributor

Choose a reason for hiding this comment

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

跟反问题统一,改为./data/forward.csv吧

log_freq: 200

# set geometry
GEOM_PATH: ./stl/ES_python_mesh.stl
Copy link
Contributor

Choose a reason for hiding this comment

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

跟反问题统一,改为./sta/heart.stl

Copy link
Contributor

Choose a reason for hiding this comment

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

文件名改为forward.yaml

Comment on lines +69 to +70
# {"traction_x": 0, "traction_y": 0, "traction_z": 0},
# {"traction_x": -cfg.P, "traction_y": -cfg.P, "traction_z": -cfg.P},
Copy link
Contributor

Choose a reason for hiding this comment

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

删除注释代码

# {"traction_x": -cfg.P, "traction_y": -cfg.P, "traction_z": -cfg.P},
{"traction": -cfg.P},
geom["endo"],
# test,
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

@@ -0,0 +1,84 @@
hydra:
Copy link
Contributor

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_

Comment on lines +191 to +212
solver = ppsci.solver.Solver(
model,
constraint,
cfg.output_dir,
optimizer,
lr_scheduler,
cfg.TRAIN.epochs,
cfg.TRAIN.iters_per_epoch,
save_freq=cfg.TRAIN.save_freq,
log_freq=cfg.log_freq,
eval_freq=cfg.TRAIN.eval_freq,
eval_during_train=cfg.TRAIN.eval_during_train,
eval_with_no_grad=cfg.EVAL.eval_with_no_grad,
seed=cfg.seed,
equation=equation,
geom=geom,
validator=validator,
visualizer=visualizer,
checkpoint_path=cfg.TRAIN.checkpoint_path,
pretrained_model_path=cfg.TRAIN.pretrained_model_path,
# loss_aggregator=loss_aggregator,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

改为:

solver = ppsci.solver.Solver(
        model,
        constraint,
        optimizer=optimizer,
        equation=equation,
        validator=validator,
        visualizer=visualizer,
        cfg=cfg,
    )

Comment on lines +289 to +295
solver = ppsci.solver.Solver(
model=model,
output_dir=cfg.output_dir,
validator=validator,
visualizer=visualizer,
pretrained_model_path=cfg.EVAL.pretrained_model_path,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

改为:

solver = ppsci.solver.Solver(
        model=model,
        validator=validator,
        visualizer=visualizer,
        cfg=cfg,
    )

Copy link
Contributor

@lijialin03 lijialin03 left a comment

Choose a reason for hiding this comment

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

辛苦提交代码~
这个PR中带了不属于这次提交的jointContribution中的代码,可以新开一个本地分支拉一下PaddleScience中develop分支,再改动
不用新建forward_heart目录了,把内容放到现有的example/heart目录下的对应位置即可,在文件名中带forward和inverse来区分文件(文件名相关改动在上面的comments中有)

@HydrogenSulfate HydrogenSulfate changed the title [Add]add an example of predicting forward diastolic deformation of the left ventricular myocardium [Example] Add an example of predicting forward diastolic deformation of the left ventricular myocardium Nov 7, 2024
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.

2 participants