-
Notifications
You must be signed in to change notification settings - Fork 185
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
base: develop
Are you sure you want to change the base?
Conversation
Thanks for your contribution! |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import equation as eq_func |
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.
我看了一下现在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 |
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.
改为./data/label.csv
subdir: ./ | ||
|
||
EVAL_CSV_PATH: label.csv | ||
DATA_CSV_PATH: data_train.csv |
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.
跟反问题统一,改为./data/forward.csv吧
log_freq: 200 | ||
|
||
# set geometry | ||
GEOM_PATH: ./stl/ES_python_mesh.stl |
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.
跟反问题统一,改为./sta/heart.stl
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.
文件名改为forward.yaml
# {"traction_x": 0, "traction_y": 0, "traction_z": 0}, | ||
# {"traction_x": -cfg.P, "traction_y": -cfg.P, "traction_z": -cfg.P}, |
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.
删除注释代码
# {"traction_x": -cfg.P, "traction_y": -cfg.P, "traction_z": -cfg.P}, | ||
{"traction": -cfg.P}, | ||
geom["endo"], | ||
# test, |
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.
同上
@@ -0,0 +1,84 @@ | |||
hydra: |
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.
在最开始增加:
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_
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, | ||
) |
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.
改为:
solver = ppsci.solver.Solver(
model,
constraint,
optimizer=optimizer,
equation=equation,
validator=validator,
visualizer=visualizer,
cfg=cfg,
)
solver = ppsci.solver.Solver( | ||
model=model, | ||
output_dir=cfg.output_dir, | ||
validator=validator, | ||
visualizer=visualizer, | ||
pretrained_model_path=cfg.EVAL.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.
改为:
solver = ppsci.solver.Solver(
model=model,
validator=validator,
visualizer=visualizer,
cfg=cfg,
)
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中带了不属于这次提交的jointContribution中的代码,可以新开一个本地分支拉一下PaddleScience中develop分支,再改动
不用新建forward_heart目录了,把内容放到现有的example/heart目录下的对应位置即可,在文件名中带forward和inverse来区分文件(文件名相关改动在上面的comments中有)
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.