[Example] Add an example of predicting forward diastolic deformation of the left ventricular myocardium#1008
Closed
MGWanderer1 wants to merge 9 commits intoPaddlePaddle:developfrom
Closed
[Example] Add an example of predicting forward diastolic deformation of the left ventricular myocardium#1008MGWanderer1 wants to merge 9 commits intoPaddlePaddle:developfrom
MGWanderer1 wants to merge 9 commits intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
lijialin03
reviewed
Nov 6, 2024
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import equation as eq_func |
Contributor
There was a problem hiding this comment.
我看了一下现在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 |
| subdir: ./ | ||
|
|
||
| EVAL_CSV_PATH: label.csv | ||
| DATA_CSV_PATH: data_train.csv |
Contributor
There was a problem hiding this comment.
跟反问题统一,改为./data/forward.csv吧
| log_freq: 200 | ||
|
|
||
| # set geometry | ||
| GEOM_PATH: ./stl/ES_python_mesh.stl |
Contributor
There was a problem hiding this comment.
跟反问题统一,改为./sta/heart.stl
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}, |
| # {"traction_x": -cfg.P, "traction_y": -cfg.P, "traction_z": -cfg.P}, | ||
| {"traction": -cfg.P}, | ||
| geom["endo"], | ||
| # test, |
| @@ -0,0 +1,84 @@ | |||
| hydra: | |||
Contributor
There was a problem hiding this comment.
在最开始增加:
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, | ||
| ) |
Contributor
There was a problem hiding this comment.
改为:
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, | ||
| ) |
Contributor
There was a problem hiding this comment.
改为:
solver = ppsci.solver.Solver(
model=model,
validator=validator,
visualizer=visualizer,
cfg=cfg,
)
lijialin03
reviewed
Nov 6, 2024
Contributor
lijialin03
left a comment
There was a problem hiding this comment.
辛苦提交代码~
这个PR中带了不属于这次提交的jointContribution中的代码,可以新开一个本地分支拉一下PaddleScience中develop分支,再改动
不用新建forward_heart目录了,把内容放到现有的example/heart目录下的对应位置即可,在文件名中带forward和inverse来区分文件(文件名相关改动在上面的comments中有)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.