forked from PaddlePaddle/PaddleHelix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
43 lines (36 loc) · 1.39 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
def print_metrics(loss, f_max, auprc):
print(f"loss: {loss:.4f}, f_max: {f_max:.4f}, auprc: {auprc:.4f}")
def get_model_params_state(model, args, epoch, f_max, auprc):
return {
"model": model.state_dict(),
"epoch": epoch,
"num_convs": args.num_convs,
"dense_dims": args.dense_dims,
"feat_drop": args.feat_drop,
"hidden_dim": args.hidden_dim,
"n_channels": args.n_channels,
"cmap_thresh": args.cmap_thresh,
"task": args.task,
"n_labels": args.n_labels,
"num_heads": args.num_heads,
"num_angle": args.num_angle,
"merge_e2e": args.merge_e2e,
"merge_e2n": args.merge_e2n,
"val_f_max": f"{f_max:.4f}",
"val_auprc": f"{auprc:.4f}",
}
def add_saved_args_and_params(args, state_dict):
args.num_convs = state_dict["num_convs"]
args.dense_dims = state_dict["dense_dims"]
args.feat_drop = state_dict["feat_drop"]
args.hidden_dim = state_dict["hidden_dim"]
args.num_heads = state_dict["num_heads"]
args.num_angle = state_dict["num_angle"]
args.merge_e2e = state_dict["merge_e2e"]
args.merge_e2n = state_dict["merge_e2n"]
args.n_channels = state_dict["n_channels"]
args.cmap_thresh = state_dict["cmap_thresh"]
args.task = state_dict["task"]
args.n_labels = state_dict["n_labels"]
return None # In-place modification of args