Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +9 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/1000.state +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/1000_Network.pth +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/1000_Network_ema.pth +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/2000.state +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/2000_Network.pth +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/2000_Network_ema.pth +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/3000.state +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/3000_Network.pth +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/3000_Network_ema.pth +3 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/conv2former_2xb4_e3000_dpms_s20.json +162 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/double_encoder_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet128_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet16_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet32_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_1131_encoder_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_newca_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_nosca_silu_noinp_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_ours_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_res_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_reverseca_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_splitca_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_1xb8_e3000_dpms_s20_noinp.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_middle_fusion.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_cosine.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_datan1.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_datan2.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen1.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen2.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaUnet.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_sum_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion.json +148 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/ours_4bs1_multi_x0.json +145 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/ours_down4_ca_4bs2_multi_x0.json +145 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/ours_multi_x0.json +182 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/palette_1xb8_e5000_dpms_s20_no_noise.json +159 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/palette_1xb8_e5000_dpms_s20_y_t-1.json +159 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/palette_4bs2_multi_old_x0.json +145 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/base_dataset.py +48 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/base_model.py +171 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/base_network.py +48 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/dpm_solver_pytorch.py +1306 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/dpm_solver_pytorch_no_noise.py +1306 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/logger.py +171 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/praser.py +155 -0
- experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/util.py +159 -0
.gitattributes
CHANGED
@@ -33,3 +33,12 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/1000.state filter=lfs diff=lfs merge=lfs -text
|
37 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/2000.state filter=lfs diff=lfs merge=lfs -text
|
38 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/3000.state filter=lfs diff=lfs merge=lfs -text
|
39 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_old_5000_230624_144530/checkpoint/1000.state filter=lfs diff=lfs merge=lfs -text
|
40 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_old_5000_230624_144530/checkpoint/1500.state filter=lfs diff=lfs merge=lfs -text
|
41 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_old_5000_230624_144530/checkpoint/2000.state filter=lfs diff=lfs merge=lfs -text
|
42 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_old_5000_230624_144530/checkpoint/2500.state filter=lfs diff=lfs merge=lfs -text
|
43 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_old_5000_230624_144530/checkpoint/3000.state filter=lfs diff=lfs merge=lfs -text
|
44 |
+
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_old_5000_230624_144530/checkpoint/500.state filter=lfs diff=lfs merge=lfs -text
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/1000.state
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8e24c53149ec4fbad1633893313bda64c06ad519ce850726eb63f089f5d030a9
|
3 |
+
size 166896761
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/1000_Network.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d0a68d797fe43ead00b2188b640104466e4d6e1e0c9f942ac6ea9b370110a5d2
|
3 |
+
size 91912909
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/1000_Network_ema.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:70bd51950fdd7a55d5cb733d31e6a93e1ad1040288a34b31d0089bf40ff3d8c9
|
3 |
+
size 91863129
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/2000.state
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:43d174cacd920918423c18a862bfcf6de4bf92163d3779e8806a9a61972f2993
|
3 |
+
size 166896761
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/2000_Network.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:66ceed2b0b7a2dcfc8b0b06f8345fc7651bfcc1b0baeb58c8003659611d5f457
|
3 |
+
size 91912909
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/2000_Network_ema.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f15b6eab418e98ee78525fa620d06bd24d3f03364152dd9a9f700b2e95a9fa2c
|
3 |
+
size 91863129
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/3000.state
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:48ef547c9cf998f1a2b6bdfdc6ea2e8ac11b75e0285f3c7163cfee3b919d3462
|
3 |
+
size 166896761
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/3000_Network.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c2e2e7acb42ec24bc3412364e7a8b757701387bee1488544584bb5c74d274c3f
|
3 |
+
size 91912909
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/checkpoint/3000_Network_ema.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3315e3d3a3b881993f2b5e0dae18cf46c3d4b28a7d7794f6e337f5f170a6feb4
|
3 |
+
size 91863129
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/conv2former_2xb4_e3000_dpms_s20.json
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "conv2former_2xb4_e3000_dpms_s20",
|
3 |
+
"gpu_ids": [
|
4 |
+
// 2,3 for train
|
5 |
+
3 // for test
|
6 |
+
],
|
7 |
+
"seed": -1,
|
8 |
+
"finetune_norm": false,
|
9 |
+
"path": {
|
10 |
+
"base_dir": "experiments",
|
11 |
+
"code": "code",
|
12 |
+
"tb_logger": "tb_logger",
|
13 |
+
"results": "results",
|
14 |
+
"checkpoint": "checkpoint",
|
15 |
+
"resume_state": "experiments/train_conv2former_2xb4_e3000_dpms_s20_230514_091009/checkpoint/3000"
|
16 |
+
},
|
17 |
+
"datasets": {
|
18 |
+
"train": {
|
19 |
+
"which_dataset": {
|
20 |
+
"name": [
|
21 |
+
"data.dataset",
|
22 |
+
"Sen2_MTC_New_Multi"
|
23 |
+
],
|
24 |
+
"args": {
|
25 |
+
"data_root": "../pmaa/data",
|
26 |
+
"mode": "train"
|
27 |
+
}
|
28 |
+
},
|
29 |
+
"dataloader": {
|
30 |
+
"validation_split": 2,
|
31 |
+
"args": {
|
32 |
+
"batch_size": 4,
|
33 |
+
"num_workers": 4,
|
34 |
+
"shuffle": true,
|
35 |
+
"pin_memory": true,
|
36 |
+
"drop_last": true
|
37 |
+
},
|
38 |
+
"val_args": {
|
39 |
+
"batch_size": 1,
|
40 |
+
"num_workers": 4,
|
41 |
+
"shuffle": false,
|
42 |
+
"pin_memory": true,
|
43 |
+
"drop_last": false
|
44 |
+
}
|
45 |
+
}
|
46 |
+
},
|
47 |
+
"val": {
|
48 |
+
"which_dataset": {
|
49 |
+
"name": "Sen2_MTC_New_Multi",
|
50 |
+
"args": {
|
51 |
+
"data_root": "../pmaa/data",
|
52 |
+
"mode": "val"
|
53 |
+
}
|
54 |
+
}
|
55 |
+
},
|
56 |
+
"test": {
|
57 |
+
"which_dataset": {
|
58 |
+
"name": "Sen2_MTC_New_Multi",
|
59 |
+
"args": {
|
60 |
+
"data_root": "../pmaa/data",
|
61 |
+
"mode": "test"
|
62 |
+
}
|
63 |
+
},
|
64 |
+
"dataloader": {
|
65 |
+
"args": {
|
66 |
+
"batch_size": 1,
|
67 |
+
"num_workers": 1,
|
68 |
+
"pin_memory": true
|
69 |
+
}
|
70 |
+
}
|
71 |
+
}
|
72 |
+
},
|
73 |
+
"model": {
|
74 |
+
"which_model": {
|
75 |
+
"name": [
|
76 |
+
"models.model",
|
77 |
+
"Palette"
|
78 |
+
],
|
79 |
+
"args": {
|
80 |
+
"sample_num": 8,
|
81 |
+
"task": "decloud",
|
82 |
+
"ema_scheduler": {
|
83 |
+
"ema_start": 1,
|
84 |
+
"ema_iter": 1,
|
85 |
+
"ema_decay": 0.9999
|
86 |
+
},
|
87 |
+
"optimizers": [
|
88 |
+
{
|
89 |
+
"lr": 5e-05,
|
90 |
+
"weight_decay": 0
|
91 |
+
}
|
92 |
+
]
|
93 |
+
}
|
94 |
+
},
|
95 |
+
"which_networks": [
|
96 |
+
{
|
97 |
+
"name": [
|
98 |
+
"models.network_x0_dpm_solver",
|
99 |
+
"Network"
|
100 |
+
],
|
101 |
+
"args": {
|
102 |
+
"init_type": "kaiming",
|
103 |
+
"module_name": "conv2former",
|
104 |
+
"unet": {
|
105 |
+
"in_channel": 12, //3*3+3(noise)
|
106 |
+
"out_channel": 3,
|
107 |
+
"inner_channel": 64,
|
108 |
+
"channel_mults": [
|
109 |
+
1,
|
110 |
+
2,
|
111 |
+
4,
|
112 |
+
8
|
113 |
+
],
|
114 |
+
"attn_res": [
|
115 |
+
// 32,
|
116 |
+
16
|
117 |
+
// 8
|
118 |
+
],
|
119 |
+
"num_head_channels": 32,
|
120 |
+
"res_blocks": 2,
|
121 |
+
"dropout": 0.2,
|
122 |
+
"image_size": 256 // default 224
|
123 |
+
},
|
124 |
+
"beta_schedule": {
|
125 |
+
"train": {
|
126 |
+
"schedule": "linear",
|
127 |
+
"n_timestep": 2000,
|
128 |
+
"linear_start": 1e-06,
|
129 |
+
"linear_end": 0.01
|
130 |
+
},
|
131 |
+
"test": {
|
132 |
+
"schedule": "linear",
|
133 |
+
"n_timestep": 1000,
|
134 |
+
"linear_start": 0.0001,
|
135 |
+
"linear_end": 0.09
|
136 |
+
}
|
137 |
+
}
|
138 |
+
}
|
139 |
+
}
|
140 |
+
],
|
141 |
+
"which_losses": [
|
142 |
+
"mse_loss"
|
143 |
+
],
|
144 |
+
"which_metrics": [
|
145 |
+
"mae"
|
146 |
+
]
|
147 |
+
},
|
148 |
+
"train": {
|
149 |
+
"n_epoch": 3000,
|
150 |
+
"n_iter": 100000000,
|
151 |
+
"val_epoch": 10,
|
152 |
+
"save_checkpoint_epoch": 100,
|
153 |
+
"log_iter": 10000,
|
154 |
+
"tensorboard": true
|
155 |
+
},
|
156 |
+
"debug": {
|
157 |
+
"val_epoch": 1,
|
158 |
+
"save_checkpoint_epoch": 1,
|
159 |
+
"log_iter": 10,
|
160 |
+
"debug_split": 50
|
161 |
+
}
|
162 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/double_encoder_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "double_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
1
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_double_1xb8_e3000_dpms_s20_noinp_230515_045603/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 4,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "double_encoder",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 10,
|
138 |
+
"save_checkpoint_epoch": 100,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet128_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet128_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
3
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet128_1xb8_e3000_dpms_s20_noinp_230518_175307/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 4,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 128,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 10,
|
138 |
+
"save_checkpoint_epoch": 100,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet16_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet16_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
2
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet16_1xb8_e3000_dpms_s20_noinp_230518_175110/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 4,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 16,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 10,
|
138 |
+
"save_checkpoint_epoch": 100,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet32_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet32_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet32_1xb8_e3000_dpms_s20_noinp_230518_174833/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 4,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 32,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 10,
|
138 |
+
"save_checkpoint_epoch": 100,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_1131_encoder_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet64_1131_encoder_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
1
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet64_1131_encoder_1xb8_e3000_dpms_s20_noinp_230520_171633/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 4,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 3, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 10,
|
138 |
+
"save_checkpoint_epoch": 100,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_newca_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet64_newca_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet64_newca_noinp_230528_021014/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_newca_noinp",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 500,
|
138 |
+
"save_checkpoint_epoch": 500,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_nosca_silu_noinp_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet64_nosca_silu_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
3
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet64_nosca_silu_noinp_230528_021215/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_nosca_silu_noinp",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 500,
|
138 |
+
"save_checkpoint_epoch": 500,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_ours_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet64_ours_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet64_ours_1xb8_e3000_dpms_s20_noinp_230520_094059/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_ours",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 100,
|
138 |
+
"save_checkpoint_epoch": 500,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_res_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet64_res_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
2
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet64_res_1xb8_e3000_dpms_s20_noinp_230520_101605/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_res",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 100,
|
138 |
+
"save_checkpoint_epoch": 500,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_reverseca_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet64_reverseca",
|
3 |
+
"gpu_ids": [
|
4 |
+
1
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet64_reverseca_230528_021307/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_reverseca_noinp",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 500,
|
138 |
+
"save_checkpoint_epoch": 500,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet64_splitca_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet64_splitca",
|
3 |
+
"gpu_ids": [
|
4 |
+
2
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet64_splitca_230525_063547/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_splitca_noinp",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 500,
|
138 |
+
"save_checkpoint_epoch": 500,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_1xb8_e3000_dpms_s20_noinp.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_1xb8_e3000_dpms_s20_noinp",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet_1xb8_e3000_dpms_s20_noinp_230514_083943/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 4,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 12,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 10,
|
138 |
+
"save_checkpoint_epoch": 100,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_middle_fusion.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_middle_fusion",
|
3 |
+
"gpu_ids": [
|
4 |
+
2
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_middle_fusion_230604_042247/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_middle_fusion",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion_230531_024841/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_concat_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond",
|
3 |
+
"gpu_ids": [
|
4 |
+
1
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet_double_encoder_splitcaCond_230604_154843/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_230604_151849/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_cosine.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet_cosine",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "cosine",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "cosine",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid",
|
3 |
+
"gpu_ids": [
|
4 |
+
1
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "sigmoid",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "sigmoid",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_datan1.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_datan1",
|
3 |
+
"gpu_ids": [
|
4 |
+
2
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New1"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New1",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New1",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "sigmoid",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "sigmoid",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_datan2.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_datan2",
|
3 |
+
"gpu_ids": [
|
4 |
+
3
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New2"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New2",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New2",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "sigmoid",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "sigmoid",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen1.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen1",
|
3 |
+
"gpu_ids": [
|
4 |
+
1
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New1"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New1",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New1",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_noise_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "sigmoid",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "sigmoid",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen2.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen2",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New2"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New2",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New2",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_noise_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "sigmoid",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "sigmoid",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3",
|
3 |
+
"gpu_ids": [
|
4 |
+
2
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_noise_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaCond_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "sigmoid",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "sigmoid",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_double_encoder_splitcaUnet.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_double_encoder_splitcaUnet",
|
3 |
+
"gpu_ids": [
|
4 |
+
3
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet_double_encoder_splitcaUnet_230604_154955/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_double_encoder_splitcaUnet",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/nafnet_sum_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "nafnet_sum_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion",
|
3 |
+
"gpu_ids": [
|
4 |
+
1
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": "experiments/train_nafnet_sum_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion_230531_025339/checkpoint/3000"
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "../pmaa/data",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 1,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "../pmaa/data",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "../pmaa/data",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 1,
|
66 |
+
"num_workers": 1,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "nafnet_sum_no_condskip_nodrop_noparams_splitca_double_encoder_decoder_noCondFFN_middle_fusion",
|
103 |
+
"unet": {
|
104 |
+
"img_channel": 3,
|
105 |
+
"width": 64,
|
106 |
+
"middle_blk_num": 1,
|
107 |
+
"enc_blk_nums": [1, 1, 1, 1],
|
108 |
+
"dec_blk_nums": [1, 1, 1, 1]
|
109 |
+
},
|
110 |
+
"beta_schedule": {
|
111 |
+
"train": {
|
112 |
+
"schedule": "linear",
|
113 |
+
"n_timestep": 2000,
|
114 |
+
"linear_start": 1e-06,
|
115 |
+
"linear_end": 0.01
|
116 |
+
},
|
117 |
+
"test": {
|
118 |
+
"schedule": "linear",
|
119 |
+
"n_timestep": 1000,
|
120 |
+
"linear_start": 0.0001,
|
121 |
+
"linear_end": 0.09
|
122 |
+
}
|
123 |
+
}
|
124 |
+
}
|
125 |
+
}
|
126 |
+
],
|
127 |
+
"which_losses": [
|
128 |
+
"mse_loss"
|
129 |
+
],
|
130 |
+
"which_metrics": [
|
131 |
+
"mae"
|
132 |
+
]
|
133 |
+
},
|
134 |
+
"train": {
|
135 |
+
"n_epoch": 3000,
|
136 |
+
"n_iter": 100000000,
|
137 |
+
"val_epoch": 1000,
|
138 |
+
"save_checkpoint_epoch": 1000,
|
139 |
+
"log_iter": 10000,
|
140 |
+
"tensorboard": true
|
141 |
+
},
|
142 |
+
"debug": {
|
143 |
+
"val_epoch": 1,
|
144 |
+
"save_checkpoint_epoch": 1,
|
145 |
+
"log_iter": 10,
|
146 |
+
"debug_split": 50
|
147 |
+
}
|
148 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/ours_4bs1_multi_x0.json
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "ours_multi_4bs1_x0", // experiments name
|
3 |
+
"gpu_ids": [0, 1, 2, 3], // gpu ids list, default is single 0
|
4 |
+
"seed" : -1, // random seed, seed <0 represents randomization not used
|
5 |
+
"finetune_norm": false, // find the parameters to optimize
|
6 |
+
|
7 |
+
"path": { //set every part file path
|
8 |
+
"base_dir": "experiments", // base path for all log except resume_state
|
9 |
+
"code": "code", // code backup
|
10 |
+
"tb_logger": "tb_logger", // path of tensorboard logger
|
11 |
+
"results": "results",
|
12 |
+
"checkpoint": "checkpoint",
|
13 |
+
// "resume_state": "experiments/inpainting_places2_220413_143231/checkpoint/25"
|
14 |
+
"resume_state": null // ex: 100, loading .state and .pth from given epoch and iteration
|
15 |
+
},
|
16 |
+
|
17 |
+
"datasets": { // train or test
|
18 |
+
"train": {
|
19 |
+
"which_dataset": { // import designated dataset using arguments
|
20 |
+
"name": ["data.dataset", "Sen2_MTC_New_Multi"], // import Dataset() class / function(not recommend) from data.dataset.py (default is [data.dataset.py])
|
21 |
+
"args":{ // arguments to initialize dataset
|
22 |
+
"data_root": "../pmaa/data",
|
23 |
+
"mode": "train"
|
24 |
+
}
|
25 |
+
},
|
26 |
+
"dataloader":{
|
27 |
+
"validation_split": 2, // percent or number ## 這裡沒有生效(因為我們自己的數據集有專門劃分的驗證集)
|
28 |
+
"args":{ // arguments to initialize train_dataloader
|
29 |
+
"batch_size": 1, // batch size in each gpu
|
30 |
+
"num_workers": 1,
|
31 |
+
"shuffle": true,
|
32 |
+
"pin_memory": true,
|
33 |
+
"drop_last": true
|
34 |
+
},
|
35 |
+
"val_args":{ // arguments to initialize valid_dataloader, will overwrite the parameters in train_dataloader
|
36 |
+
"batch_size": 1, // batch size in each gpu
|
37 |
+
"num_workers": 4,
|
38 |
+
"shuffle": false,
|
39 |
+
"pin_memory": true,
|
40 |
+
"drop_last": false
|
41 |
+
}
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"val": {
|
45 |
+
"which_dataset": {
|
46 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
47 |
+
"args":{
|
48 |
+
"data_root": "../pmaa/data",
|
49 |
+
"mode": "val"
|
50 |
+
}
|
51 |
+
}
|
52 |
+
},
|
53 |
+
"test": {
|
54 |
+
"which_dataset": {
|
55 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
56 |
+
"args":{
|
57 |
+
"data_root": "../pmaa/data",
|
58 |
+
"mode": "test"
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"dataloader":{
|
62 |
+
"args":{
|
63 |
+
"batch_size": 8,
|
64 |
+
"num_workers": 8,
|
65 |
+
"pin_memory": true
|
66 |
+
}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
},
|
70 |
+
|
71 |
+
"model": { // networks/metrics/losses/optimizers/lr_schedulers is a list and model is a dict
|
72 |
+
"which_model": { // import designated model(trainer) using arguments
|
73 |
+
"name": ["models.model", "Palette"], // import Model() class / function(not recommend) from models.model.py (default is [models.model.py])
|
74 |
+
"args": {
|
75 |
+
"sample_num": 8, // process of each image
|
76 |
+
"task": "decloud",
|
77 |
+
"ema_scheduler": {
|
78 |
+
"ema_start": 1,
|
79 |
+
"ema_iter": 1,
|
80 |
+
"ema_decay": 0.9999
|
81 |
+
},
|
82 |
+
"optimizers": [
|
83 |
+
{ "lr": 5e-5, "weight_decay": 0}
|
84 |
+
]
|
85 |
+
}
|
86 |
+
},
|
87 |
+
"which_networks": [ // import designated list of networks using arguments
|
88 |
+
{
|
89 |
+
"name": ["models.network_x0", "Network"], // import Network() class / function(not recommend) from default file (default is [models/network.py])
|
90 |
+
"args": { // arguments to initialize network
|
91 |
+
"init_type": "kaiming", // method can be [normal | xavier| xavier_uniform | kaiming | orthogonal], default is kaiming
|
92 |
+
"module_name": "ours", // sr3 | guided_diffusion | ours
|
93 |
+
"unet": {
|
94 |
+
"inp_channels": 12,
|
95 |
+
"out_channels": 3,
|
96 |
+
"encoder_dims": [64, 128, 256, 512],
|
97 |
+
"decoder_dims": [512, 256, 128, 64],
|
98 |
+
"encoder_blocks": [1, 1, 1, 1],
|
99 |
+
"decoder_blocks": [1, 1, 1, 1],
|
100 |
+
"drop_path_rate": 0.1,
|
101 |
+
"norm_type": "ln",
|
102 |
+
"act_type": "silu"
|
103 |
+
},
|
104 |
+
"beta_schedule": {
|
105 |
+
"train": {
|
106 |
+
"schedule": "linear",
|
107 |
+
"n_timestep": 2000,
|
108 |
+
// "n_timestep": 5, // debug
|
109 |
+
"linear_start": 1e-6,
|
110 |
+
"linear_end": 0.01
|
111 |
+
},
|
112 |
+
"test": {
|
113 |
+
"schedule": "linear",
|
114 |
+
"n_timestep": 1000,
|
115 |
+
"linear_start": 1e-4,
|
116 |
+
"linear_end": 0.09
|
117 |
+
}
|
118 |
+
}
|
119 |
+
}
|
120 |
+
}
|
121 |
+
],
|
122 |
+
"which_losses": [ // import designated list of losses without arguments
|
123 |
+
"mse_loss" // import mse_loss() function/class from default file (default is [models/losses.py]), equivalent to { "name": "mse_loss", "args":{}}
|
124 |
+
],
|
125 |
+
"which_metrics": [ // import designated list of metrics without arguments
|
126 |
+
"mae" // import mae() function/class from default file (default is [models/metrics.py]), equivalent to { "name": "mae", "args":{}}
|
127 |
+
]
|
128 |
+
},
|
129 |
+
|
130 |
+
"train": { // arguments for basic training
|
131 |
+
"n_epoch": 1e8, // max epochs, not limited now
|
132 |
+
"n_iter": 1e8, // max interations
|
133 |
+
"val_epoch": 5, // valdation every specified number of epochs
|
134 |
+
"save_checkpoint_epoch": 100,
|
135 |
+
"log_iter": 1e4, // log every specified number of iterations
|
136 |
+
"tensorboard" : true // tensorboardX enable
|
137 |
+
},
|
138 |
+
|
139 |
+
"debug": { // arguments in debug mode, which will replace arguments in train
|
140 |
+
"val_epoch": 1,
|
141 |
+
"save_checkpoint_epoch": 1,
|
142 |
+
"log_iter": 10,
|
143 |
+
"debug_split": 50 // percent or number, change the size of dataloder to debug_split.
|
144 |
+
}
|
145 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/ours_down4_ca_4bs2_multi_x0.json
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "ours_down4_ca_4bs2_multi_x0", // experiments name
|
3 |
+
"gpu_ids": [0, 1, 2, 3], // gpu ids list, default is single 0
|
4 |
+
"seed" : -1, // random seed, seed <0 represents randomization not used
|
5 |
+
"finetune_norm": false, // find the parameters to optimize
|
6 |
+
|
7 |
+
"path": { //set every part file path
|
8 |
+
"base_dir": "experiments", // base path for all log except resume_state
|
9 |
+
"code": "code", // code backup
|
10 |
+
"tb_logger": "tb_logger", // path of tensorboard logger
|
11 |
+
"results": "results",
|
12 |
+
"checkpoint": "checkpoint",
|
13 |
+
// "resume_state": "experiments/inpainting_places2_220413_143231/checkpoint/25"
|
14 |
+
"resume_state": null // ex: 100, loading .state and .pth from given epoch and iteration
|
15 |
+
},
|
16 |
+
|
17 |
+
"datasets": { // train or test
|
18 |
+
"train": {
|
19 |
+
"which_dataset": { // import designated dataset using arguments
|
20 |
+
"name": ["data.dataset", "Sen2_MTC_New_Multi"], // import Dataset() class / function(not recommend) from data.dataset.py (default is [data.dataset.py])
|
21 |
+
"args":{ // arguments to initialize dataset
|
22 |
+
"data_root": "../pmaa/data",
|
23 |
+
"mode": "train"
|
24 |
+
}
|
25 |
+
},
|
26 |
+
"dataloader":{
|
27 |
+
"validation_split": 2, // percent or number ## 這裡沒有生效(因為我們自己的數據集有專門劃分的驗證集)
|
28 |
+
"args":{ // arguments to initialize train_dataloader
|
29 |
+
"batch_size": 2, // batch size in each gpu
|
30 |
+
"num_workers": 4,
|
31 |
+
"shuffle": true,
|
32 |
+
"pin_memory": true,
|
33 |
+
"drop_last": true
|
34 |
+
},
|
35 |
+
"val_args":{ // arguments to initialize valid_dataloader, will overwrite the parameters in train_dataloader
|
36 |
+
"batch_size": 1, // batch size in each gpu
|
37 |
+
"num_workers": 4,
|
38 |
+
"shuffle": false,
|
39 |
+
"pin_memory": true,
|
40 |
+
"drop_last": false
|
41 |
+
}
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"val": {
|
45 |
+
"which_dataset": {
|
46 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
47 |
+
"args":{
|
48 |
+
"data_root": "../pmaa/data",
|
49 |
+
"mode": "val"
|
50 |
+
}
|
51 |
+
}
|
52 |
+
},
|
53 |
+
"test": {
|
54 |
+
"which_dataset": {
|
55 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
56 |
+
"args":{
|
57 |
+
"data_root": "../pmaa/data",
|
58 |
+
"mode": "test"
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"dataloader":{
|
62 |
+
"args":{
|
63 |
+
"batch_size": 8,
|
64 |
+
"num_workers": 8,
|
65 |
+
"pin_memory": true
|
66 |
+
}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
},
|
70 |
+
|
71 |
+
"model": { // networks/metrics/losses/optimizers/lr_schedulers is a list and model is a dict
|
72 |
+
"which_model": { // import designated model(trainer) using arguments
|
73 |
+
"name": ["models.model", "Palette"], // import Model() class / function(not recommend) from models.model.py (default is [models.model.py])
|
74 |
+
"args": {
|
75 |
+
"sample_num": 8, // process of each image
|
76 |
+
"task": "decloud",
|
77 |
+
"ema_scheduler": {
|
78 |
+
"ema_start": 1,
|
79 |
+
"ema_iter": 1,
|
80 |
+
"ema_decay": 0.9999
|
81 |
+
},
|
82 |
+
"optimizers": [
|
83 |
+
{ "lr": 5e-5, "weight_decay": 0}
|
84 |
+
]
|
85 |
+
}
|
86 |
+
},
|
87 |
+
"which_networks": [ // import designated list of networks using arguments
|
88 |
+
{
|
89 |
+
"name": ["models.network_x0_dpm_solver", "Network"], // import Network() class / function(not recommend) from default file (default is [models/network.py])
|
90 |
+
"args": { // arguments to initialize network
|
91 |
+
"init_type": "kaiming", // method can be [normal | xavier| xavier_uniform | kaiming | orthogonal], default is kaiming
|
92 |
+
"module_name": "ours_down4_ca", // sr3 | guided_diffusion | ours | ours_down4_ca
|
93 |
+
"unet": {
|
94 |
+
"inp_channels": 12,
|
95 |
+
"out_channels": 3,
|
96 |
+
"encoder_dims": [64, 128, 256, 512, 1024],
|
97 |
+
"decoder_dims": [1024, 512, 256, 128, 64],
|
98 |
+
"encoder_blocks": [1, 1, 1, 1, 1],
|
99 |
+
"decoder_blocks": [1, 1, 1, 1, 1],
|
100 |
+
"drop_path_rate": 0.1,
|
101 |
+
"norm_type": "ln",
|
102 |
+
"act_type": "silu"
|
103 |
+
},
|
104 |
+
"beta_schedule": {
|
105 |
+
"train": {
|
106 |
+
"schedule": "linear",
|
107 |
+
"n_timestep": 2000,
|
108 |
+
// "n_timestep": 5, // debug
|
109 |
+
"linear_start": 1e-6,
|
110 |
+
"linear_end": 0.01
|
111 |
+
},
|
112 |
+
"test": {
|
113 |
+
"schedule": "linear",
|
114 |
+
"n_timestep": 1000,
|
115 |
+
"linear_start": 1e-4,
|
116 |
+
"linear_end": 0.09
|
117 |
+
}
|
118 |
+
}
|
119 |
+
}
|
120 |
+
}
|
121 |
+
],
|
122 |
+
"which_losses": [ // import designated list of losses without arguments
|
123 |
+
"mse_loss" // import mse_loss() function/class from default file (default is [models/losses.py]), equivalent to { "name": "mse_loss", "args":{}}
|
124 |
+
],
|
125 |
+
"which_metrics": [ // import designated list of metrics without arguments
|
126 |
+
"mae" // import mae() function/class from default file (default is [models/metrics.py]), equivalent to { "name": "mae", "args":{}}
|
127 |
+
]
|
128 |
+
},
|
129 |
+
|
130 |
+
"train": { // arguments for basic training
|
131 |
+
"n_epoch": 5000, // max epochs, not limited now
|
132 |
+
"n_iter": 1e8, // max interations
|
133 |
+
"val_epoch": 100, // valdation every specified number of epochs
|
134 |
+
"save_checkpoint_epoch": 500,
|
135 |
+
"log_iter": 1e4, // log every specified number of iterations
|
136 |
+
"tensorboard" : false // tensorboardX enable
|
137 |
+
},
|
138 |
+
|
139 |
+
"debug": { // arguments in debug mode, which will replace arguments in train
|
140 |
+
"val_epoch": 50,
|
141 |
+
"save_checkpoint_epoch": 500,
|
142 |
+
"log_iter": 10,
|
143 |
+
"debug_split": 50 // percent or number, change the size of dataloder to debug_split.
|
144 |
+
}
|
145 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/ours_multi_x0.json
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "palette_multi_bs_4_tanh_x0", // experiments name
|
3 |
+
<<<<<<< HEAD
|
4 |
+
"gpu_ids": [0, 1, 2, 3], // gpu ids list, default is single 0
|
5 |
+
=======
|
6 |
+
"gpu_ids": [2], // gpu ids list, default is single 0
|
7 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
8 |
+
"seed" : -1, // random seed, seed <0 represents randomization not used
|
9 |
+
"finetune_norm": false, // find the parameters to optimize
|
10 |
+
|
11 |
+
"path": { //set every part file path
|
12 |
+
"base_dir": "experiments", // base path for all log except resume_state
|
13 |
+
"code": "code", // code backup
|
14 |
+
"tb_logger": "tb_logger", // path of tensorboard logger
|
15 |
+
"results": "results",
|
16 |
+
"checkpoint": "checkpoint",
|
17 |
+
// "resume_state": "experiments/inpainting_places2_220413_143231/checkpoint/25"
|
18 |
+
<<<<<<< HEAD
|
19 |
+
"resume_state": "experiments/train_palette_multi_bs_4_tanh_x0_230402_080308/checkpoint/1520" // ex: 100, loading .state and .pth from given epoch and iteration
|
20 |
+
=======
|
21 |
+
"resume_state": null // ex: 100, loading .state and .pth from given epoch and iteration
|
22 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
23 |
+
},
|
24 |
+
|
25 |
+
"datasets": { // train or test
|
26 |
+
"train": {
|
27 |
+
"which_dataset": { // import designated dataset using arguments
|
28 |
+
"name": ["data.dataset", "Sen2_MTC_New_Multi"], // import Dataset() class / function(not recommend) from data.dataset.py (default is [data.dataset.py])
|
29 |
+
"args":{ // arguments to initialize dataset
|
30 |
+
<<<<<<< HEAD
|
31 |
+
"data_root": "../pmaa/data",
|
32 |
+
=======
|
33 |
+
"data_root": "datasets",
|
34 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
35 |
+
"mode": "train"
|
36 |
+
}
|
37 |
+
},
|
38 |
+
"dataloader":{
|
39 |
+
"validation_split": 2, // percent or number ## 這裡沒有生效(因為我們自己的數據集有專門劃分的驗證集)
|
40 |
+
"args":{ // arguments to initialize train_dataloader
|
41 |
+
<<<<<<< HEAD
|
42 |
+
"batch_size": 8, // batch size in each gpu
|
43 |
+
"num_workers": 8,
|
44 |
+
=======
|
45 |
+
"batch_size": 4, // batch size in each gpu
|
46 |
+
"num_workers": 4,
|
47 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
48 |
+
"shuffle": true,
|
49 |
+
"pin_memory": true,
|
50 |
+
"drop_last": true
|
51 |
+
},
|
52 |
+
"val_args":{ // arguments to initialize valid_dataloader, will overwrite the parameters in train_dataloader
|
53 |
+
"batch_size": 1, // batch size in each gpu
|
54 |
+
"num_workers": 4,
|
55 |
+
"shuffle": false,
|
56 |
+
"pin_memory": true,
|
57 |
+
"drop_last": false
|
58 |
+
}
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"val": {
|
62 |
+
"which_dataset": {
|
63 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
64 |
+
"args":{
|
65 |
+
<<<<<<< HEAD
|
66 |
+
"data_root": "../pmaa/data",
|
67 |
+
=======
|
68 |
+
"data_root": "datasets",
|
69 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
70 |
+
"mode": "val"
|
71 |
+
}
|
72 |
+
}
|
73 |
+
},
|
74 |
+
"test": {
|
75 |
+
"which_dataset": {
|
76 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
77 |
+
"args":{
|
78 |
+
<<<<<<< HEAD
|
79 |
+
"data_root": "../pmaa/data",
|
80 |
+
=======
|
81 |
+
"data_root": "datasets",
|
82 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
83 |
+
"mode": "test"
|
84 |
+
}
|
85 |
+
},
|
86 |
+
"dataloader":{
|
87 |
+
"args":{
|
88 |
+
"batch_size": 8,
|
89 |
+
<<<<<<< HEAD
|
90 |
+
"num_workers": 8,
|
91 |
+
=======
|
92 |
+
"num_workers": 4,
|
93 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
94 |
+
"pin_memory": true
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
},
|
99 |
+
|
100 |
+
"model": { // networks/metrics/losses/optimizers/lr_schedulers is a list and model is a dict
|
101 |
+
"which_model": { // import designated model(trainer) using arguments
|
102 |
+
"name": ["models.model", "Palette"], // import Model() class / function(not recommend) from models.model.py (default is [models.model.py])
|
103 |
+
"args": {
|
104 |
+
"sample_num": 8, // process of each image
|
105 |
+
"task": "decloud",
|
106 |
+
"ema_scheduler": {
|
107 |
+
"ema_start": 1,
|
108 |
+
"ema_iter": 1,
|
109 |
+
"ema_decay": 0.9999
|
110 |
+
},
|
111 |
+
"optimizers": [
|
112 |
+
<<<<<<< HEAD
|
113 |
+
{ "lr": 0.0002, "weight_decay": 0}
|
114 |
+
=======
|
115 |
+
{ "lr": 5e-5, "weight_decay": 0}
|
116 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
117 |
+
]
|
118 |
+
}
|
119 |
+
},
|
120 |
+
"which_networks": [ // import designated list of networks using arguments
|
121 |
+
{
|
122 |
+
"name": ["models.network_x0", "Network"], // import Network() class / function(not recommend) from default file (default is [models/network.py])
|
123 |
+
"args": { // arguments to initialize network
|
124 |
+
"init_type": "kaiming", // method can be [normal | xavier| xavier_uniform | kaiming | orthogonal], default is kaiming
|
125 |
+
"module_name": "ours", // sr3 | guided_diffusion | ours
|
126 |
+
"unet": {
|
127 |
+
"inp_channels": 12,
|
128 |
+
"out_channels": 3,
|
129 |
+
"encoder_dims": [64, 128, 256, 512],
|
130 |
+
"decoder_dims": [512, 256, 128, 64],
|
131 |
+
"encoder_blocks": [1, 1, 1, 1],
|
132 |
+
"decoder_blocks": [1, 1, 1, 1],
|
133 |
+
"drop_path_rate": 0.1,
|
134 |
+
"norm_type": "ln",
|
135 |
+
"act_type": "silu"
|
136 |
+
},
|
137 |
+
"beta_schedule": {
|
138 |
+
"train": {
|
139 |
+
"schedule": "linear",
|
140 |
+
"n_timestep": 2000,
|
141 |
+
// "n_timestep": 5, // debug
|
142 |
+
"linear_start": 1e-6,
|
143 |
+
"linear_end": 0.01
|
144 |
+
},
|
145 |
+
"test": {
|
146 |
+
"schedule": "linear",
|
147 |
+
"n_timestep": 1000,
|
148 |
+
"linear_start": 1e-4,
|
149 |
+
"linear_end": 0.09
|
150 |
+
}
|
151 |
+
}
|
152 |
+
}
|
153 |
+
}
|
154 |
+
],
|
155 |
+
"which_losses": [ // import designated list of losses without arguments
|
156 |
+
"mse_loss" // import mse_loss() function/class from default file (default is [models/losses.py]), equivalent to { "name": "mse_loss", "args":{}}
|
157 |
+
],
|
158 |
+
"which_metrics": [ // import designated list of metrics without arguments
|
159 |
+
"mae" // import mae() function/class from default file (default is [models/metrics.py]), equivalent to { "name": "mae", "args":{}}
|
160 |
+
]
|
161 |
+
},
|
162 |
+
|
163 |
+
"train": { // arguments for basic training
|
164 |
+
"n_epoch": 1e8, // max epochs, not limited now
|
165 |
+
"n_iter": 1e8, // max interations
|
166 |
+
"val_epoch": 5, // valdation every specified number of epochs
|
167 |
+
<<<<<<< HEAD
|
168 |
+
"save_checkpoint_epoch": 100,
|
169 |
+
=======
|
170 |
+
"save_checkpoint_epoch": 10,
|
171 |
+
>>>>>>> a13ebef0541ec6fe26f52d5598a109d848a51b9c
|
172 |
+
"log_iter": 1e4, // log every specified number of iterations
|
173 |
+
"tensorboard" : true // tensorboardX enable
|
174 |
+
},
|
175 |
+
|
176 |
+
"debug": { // arguments in debug mode, which will replace arguments in train
|
177 |
+
"val_epoch": 1,
|
178 |
+
"save_checkpoint_epoch": 1,
|
179 |
+
"log_iter": 10,
|
180 |
+
"debug_split": 50 // percent or number, change the size of dataloder to debug_split.
|
181 |
+
}
|
182 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/palette_1xb8_e5000_dpms_s20_no_noise.json
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "palette_1xb8_e5000_dpms_s20_no_noise",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "datasets",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 8,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "datasets",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "datasets",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 8,
|
66 |
+
"num_workers": 8,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver_no_noise",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "tanh",
|
103 |
+
"unet": {
|
104 |
+
"in_channel": 9,
|
105 |
+
"out_channel": 3,
|
106 |
+
"inner_channel": 64,
|
107 |
+
"channel_mults": [
|
108 |
+
1,
|
109 |
+
2,
|
110 |
+
4,
|
111 |
+
8
|
112 |
+
],
|
113 |
+
"attn_res": [
|
114 |
+
16
|
115 |
+
],
|
116 |
+
"num_head_channels": 32,
|
117 |
+
"res_blocks": 2,
|
118 |
+
"dropout": 0.2,
|
119 |
+
"image_size": 256
|
120 |
+
},
|
121 |
+
"beta_schedule": {
|
122 |
+
"train": {
|
123 |
+
"schedule": "linear",
|
124 |
+
"n_timestep": 2000,
|
125 |
+
"linear_start": 1e-06,
|
126 |
+
"linear_end": 0.01
|
127 |
+
},
|
128 |
+
"test": {
|
129 |
+
"schedule": "linear",
|
130 |
+
"n_timestep": 1000,
|
131 |
+
"linear_start": 0.0001,
|
132 |
+
"linear_end": 0.09
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
}
|
137 |
+
],
|
138 |
+
"which_losses": [
|
139 |
+
"mse_loss"
|
140 |
+
],
|
141 |
+
"which_metrics": [
|
142 |
+
"mae"
|
143 |
+
]
|
144 |
+
},
|
145 |
+
"train": {
|
146 |
+
"n_epoch": 5000,
|
147 |
+
"n_iter": 100000000,
|
148 |
+
"val_epoch": 10,
|
149 |
+
"save_checkpoint_epoch": 10,
|
150 |
+
"log_iter": 10000,
|
151 |
+
"tensorboard": false
|
152 |
+
},
|
153 |
+
"debug": {
|
154 |
+
"val_epoch": 1,
|
155 |
+
"save_checkpoint_epoch": 1,
|
156 |
+
"log_iter": 10,
|
157 |
+
"debug_split": 50
|
158 |
+
}
|
159 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/palette_1xb8_e5000_dpms_s20_y_t-1.json
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "palette_1xb8_e5000_dpms_s20_y_t-1",
|
3 |
+
"gpu_ids": [
|
4 |
+
0
|
5 |
+
],
|
6 |
+
"seed": -1,
|
7 |
+
"finetune_norm": false,
|
8 |
+
"path": {
|
9 |
+
"base_dir": "experiments",
|
10 |
+
"code": "code",
|
11 |
+
"tb_logger": "tb_logger",
|
12 |
+
"results": "results",
|
13 |
+
"checkpoint": "checkpoint",
|
14 |
+
"resume_state": null
|
15 |
+
},
|
16 |
+
"datasets": {
|
17 |
+
"train": {
|
18 |
+
"which_dataset": {
|
19 |
+
"name": [
|
20 |
+
"data.dataset",
|
21 |
+
"Sen2_MTC_New_Multi"
|
22 |
+
],
|
23 |
+
"args": {
|
24 |
+
"data_root": "datasets",
|
25 |
+
"mode": "train"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
"dataloader": {
|
29 |
+
"validation_split": 2,
|
30 |
+
"args": {
|
31 |
+
"batch_size": 8,
|
32 |
+
"num_workers": 8,
|
33 |
+
"shuffle": true,
|
34 |
+
"pin_memory": true,
|
35 |
+
"drop_last": true
|
36 |
+
},
|
37 |
+
"val_args": {
|
38 |
+
"batch_size": 1,
|
39 |
+
"num_workers": 8,
|
40 |
+
"shuffle": false,
|
41 |
+
"pin_memory": true,
|
42 |
+
"drop_last": false
|
43 |
+
}
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"val": {
|
47 |
+
"which_dataset": {
|
48 |
+
"name": "Sen2_MTC_New_Multi",
|
49 |
+
"args": {
|
50 |
+
"data_root": "datasets",
|
51 |
+
"mode": "val"
|
52 |
+
}
|
53 |
+
}
|
54 |
+
},
|
55 |
+
"test": {
|
56 |
+
"which_dataset": {
|
57 |
+
"name": "Sen2_MTC_New_Multi",
|
58 |
+
"args": {
|
59 |
+
"data_root": "datasets",
|
60 |
+
"mode": "test"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"dataloader": {
|
64 |
+
"args": {
|
65 |
+
"batch_size": 8,
|
66 |
+
"num_workers": 8,
|
67 |
+
"pin_memory": true
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
},
|
72 |
+
"model": {
|
73 |
+
"which_model": {
|
74 |
+
"name": [
|
75 |
+
"models.model",
|
76 |
+
"Palette"
|
77 |
+
],
|
78 |
+
"args": {
|
79 |
+
"sample_num": 8,
|
80 |
+
"task": "decloud",
|
81 |
+
"ema_scheduler": {
|
82 |
+
"ema_start": 1,
|
83 |
+
"ema_iter": 1,
|
84 |
+
"ema_decay": 0.9999
|
85 |
+
},
|
86 |
+
"optimizers": [
|
87 |
+
{
|
88 |
+
"lr": 5e-05,
|
89 |
+
"weight_decay": 0
|
90 |
+
}
|
91 |
+
]
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"which_networks": [
|
95 |
+
{
|
96 |
+
"name": [
|
97 |
+
"models.network_x0_dpm_solver_y_t-1",
|
98 |
+
"Network"
|
99 |
+
],
|
100 |
+
"args": {
|
101 |
+
"init_type": "kaiming",
|
102 |
+
"module_name": "tanh",
|
103 |
+
"unet": {
|
104 |
+
"in_channel": 12,
|
105 |
+
"out_channel": 3,
|
106 |
+
"inner_channel": 64,
|
107 |
+
"channel_mults": [
|
108 |
+
1,
|
109 |
+
2,
|
110 |
+
4,
|
111 |
+
8
|
112 |
+
],
|
113 |
+
"attn_res": [
|
114 |
+
16
|
115 |
+
],
|
116 |
+
"num_head_channels": 32,
|
117 |
+
"res_blocks": 2,
|
118 |
+
"dropout": 0.2,
|
119 |
+
"image_size": 256
|
120 |
+
},
|
121 |
+
"beta_schedule": {
|
122 |
+
"train": {
|
123 |
+
"schedule": "linear",
|
124 |
+
"n_timestep": 2000,
|
125 |
+
"linear_start": 1e-06,
|
126 |
+
"linear_end": 0.01
|
127 |
+
},
|
128 |
+
"test": {
|
129 |
+
"schedule": "linear",
|
130 |
+
"n_timestep": 1000,
|
131 |
+
"linear_start": 0.0001,
|
132 |
+
"linear_end": 0.09
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
}
|
137 |
+
],
|
138 |
+
"which_losses": [
|
139 |
+
"mse_loss"
|
140 |
+
],
|
141 |
+
"which_metrics": [
|
142 |
+
"mae"
|
143 |
+
]
|
144 |
+
},
|
145 |
+
"train": {
|
146 |
+
"n_epoch": 5000,
|
147 |
+
"n_iter": 100000000,
|
148 |
+
"val_epoch": 10,
|
149 |
+
"save_checkpoint_epoch": 10,
|
150 |
+
"log_iter": 10000,
|
151 |
+
"tensorboard": true
|
152 |
+
},
|
153 |
+
"debug": {
|
154 |
+
"val_epoch": 1,
|
155 |
+
"save_checkpoint_epoch": 1,
|
156 |
+
"log_iter": 10,
|
157 |
+
"debug_split": 50
|
158 |
+
}
|
159 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/config/palette_4bs2_multi_old_x0.json
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "palette_4bs2_multi_old_x0", // experiments name
|
3 |
+
"gpu_ids": [0, 1, 2, 3], // gpu ids list, default is single 0
|
4 |
+
"seed" : -1, // random seed, seed <0 represents randomization not used
|
5 |
+
"finetune_norm": false, // find the parameters to optimize
|
6 |
+
|
7 |
+
"path": { //set every part file path
|
8 |
+
"base_dir": "experiments", // base path for all log except resume_state
|
9 |
+
"code": "code", // code backup
|
10 |
+
"tb_logger": "tb_logger", // path of tensorboard logger
|
11 |
+
"results": "results",
|
12 |
+
"checkpoint": "checkpoint",
|
13 |
+
// "resume_state": "experiments/inpainting_places2_220413_143231/checkpoint/25"
|
14 |
+
"resume_state": null // ex: 100, loading .state and .pth from given epoch and iteration
|
15 |
+
},
|
16 |
+
|
17 |
+
"datasets": { // train or test
|
18 |
+
"train": {
|
19 |
+
"which_dataset": { // import designated dataset using arguments
|
20 |
+
"name": ["data.dataset", "Sen2_MTC_Old_Multi"], // import Dataset() class / function(not recommend) from data.dataset.py (default is [data.dataset.py])
|
21 |
+
"args":{ // arguments to initialize dataset
|
22 |
+
"data_root": "../pmaa/data",
|
23 |
+
"mode": "train"
|
24 |
+
}
|
25 |
+
},
|
26 |
+
"dataloader":{
|
27 |
+
"validation_split": 2, // percent or number ## 這裡沒有生效(因為我們自己的數據集有專門劃分的驗證集)
|
28 |
+
"args":{ // arguments to initialize train_dataloader
|
29 |
+
"batch_size": 2, // batch size in each gpu
|
30 |
+
"num_workers": 4,
|
31 |
+
"shuffle": true,
|
32 |
+
"pin_memory": true,
|
33 |
+
"drop_last": true
|
34 |
+
},
|
35 |
+
"val_args":{ // arguments to initialize valid_dataloader, will overwrite the parameters in train_dataloader
|
36 |
+
"batch_size": 1, // batch size in each gpu
|
37 |
+
"num_workers": 4,
|
38 |
+
"shuffle": false,
|
39 |
+
"pin_memory": true,
|
40 |
+
"drop_last": false
|
41 |
+
}
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"val": {
|
45 |
+
"which_dataset": {
|
46 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
47 |
+
"args":{
|
48 |
+
"data_root": "../pmaa/data",
|
49 |
+
"mode": "val"
|
50 |
+
}
|
51 |
+
}
|
52 |
+
},
|
53 |
+
"test": {
|
54 |
+
"which_dataset": {
|
55 |
+
"name": "Sen2_MTC_New_Multi", // import Dataset() class / function(not recommend) from default file
|
56 |
+
"args":{
|
57 |
+
"data_root": "../pmaa/data",
|
58 |
+
"mode": "test"
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"dataloader":{
|
62 |
+
"args":{
|
63 |
+
"batch_size": 8,
|
64 |
+
"num_workers": 8,
|
65 |
+
"pin_memory": true
|
66 |
+
}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
},
|
70 |
+
|
71 |
+
"model": { // networks/metrics/losses/optimizers/lr_schedulers is a list and model is a dict
|
72 |
+
"which_model": { // import designated model(trainer) using arguments
|
73 |
+
"name": ["models.model", "Palette"], // import Model() class / function(not recommend) from models.model.py (default is [models.model.py])
|
74 |
+
"args": {
|
75 |
+
"sample_num": 8, // process of each image
|
76 |
+
"task": "decloud",
|
77 |
+
"ema_scheduler": {
|
78 |
+
"ema_start": 1,
|
79 |
+
"ema_iter": 1,
|
80 |
+
"ema_decay": 0.9999
|
81 |
+
},
|
82 |
+
"optimizers": [
|
83 |
+
{ "lr": 5e-5, "weight_decay": 0}
|
84 |
+
]
|
85 |
+
}
|
86 |
+
},
|
87 |
+
"which_networks": [ // import designated list of networks using arguments
|
88 |
+
{
|
89 |
+
"name": ["models.network_x0_dpm_solver", "Network"], // import Network() class / function(not recommend) from default file (default is [models/network.py])
|
90 |
+
"args": { // arguments to initialize network
|
91 |
+
"init_type": "kaiming", // method can be [normal | xavier| xavier_uniform | kaiming | orthogonal], default is kaiming
|
92 |
+
"module_name": "ours_down4_ca", // sr3 | guided_diffusion | ours | ours_down4_ca
|
93 |
+
"unet": {
|
94 |
+
"inp_channels": 12,
|
95 |
+
"out_channels": 3,
|
96 |
+
"encoder_dims": [64, 128, 256, 512, 1024],
|
97 |
+
"decoder_dims": [1024, 512, 256, 128, 64],
|
98 |
+
"encoder_blocks": [1, 1, 1, 1, 1],
|
99 |
+
"decoder_blocks": [1, 1, 1, 1, 1],
|
100 |
+
"drop_path_rate": 0.1,
|
101 |
+
"norm_type": "ln",
|
102 |
+
"act_type": "silu"
|
103 |
+
},
|
104 |
+
"beta_schedule": {
|
105 |
+
"train": {
|
106 |
+
"schedule": "linear",
|
107 |
+
"n_timestep": 2000,
|
108 |
+
// "n_timestep": 5, // debug
|
109 |
+
"linear_start": 1e-6,
|
110 |
+
"linear_end": 0.01
|
111 |
+
},
|
112 |
+
"test": {
|
113 |
+
"schedule": "linear",
|
114 |
+
"n_timestep": 1000,
|
115 |
+
"linear_start": 1e-4,
|
116 |
+
"linear_end": 0.09
|
117 |
+
}
|
118 |
+
}
|
119 |
+
}
|
120 |
+
}
|
121 |
+
],
|
122 |
+
"which_losses": [ // import designated list of losses without arguments
|
123 |
+
"mse_loss" // import mse_loss() function/class from default file (default is [models/losses.py]), equivalent to { "name": "mse_loss", "args":{}}
|
124 |
+
],
|
125 |
+
"which_metrics": [ // import designated list of metrics without arguments
|
126 |
+
"mae" // import mae() function/class from default file (default is [models/metrics.py]), equivalent to { "name": "mae", "args":{}}
|
127 |
+
]
|
128 |
+
},
|
129 |
+
|
130 |
+
"train": { // arguments for basic training
|
131 |
+
"n_epoch": 5000, // max epochs, not limited now
|
132 |
+
"n_iter": 1e8, // max interations
|
133 |
+
"val_epoch": 100, // valdation every specified number of epochs
|
134 |
+
"save_checkpoint_epoch": 500,
|
135 |
+
"log_iter": 1e4, // log every specified number of iterations
|
136 |
+
"tensorboard" : false // tensorboardX enable
|
137 |
+
},
|
138 |
+
|
139 |
+
"debug": { // arguments in debug mode, which will replace arguments in train
|
140 |
+
"val_epoch": 50,
|
141 |
+
"save_checkpoint_epoch": 500,
|
142 |
+
"log_iter": 10,
|
143 |
+
"debug_split": 50 // percent or number, change the size of dataloder to debug_split.
|
144 |
+
}
|
145 |
+
}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/base_dataset.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch.utils.data as data
|
2 |
+
from torchvision import transforms
|
3 |
+
from PIL import Image
|
4 |
+
import os
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
IMG_EXTENSIONS = [
|
8 |
+
'.jpg', '.JPG', '.jpeg', '.JPEG',
|
9 |
+
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
|
10 |
+
]
|
11 |
+
|
12 |
+
def is_image_file(filename):
|
13 |
+
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
|
14 |
+
|
15 |
+
def make_dataset(dir):
|
16 |
+
if os.path.isfile(dir):
|
17 |
+
images = [i for i in np.genfromtxt(dir, dtype=np.str, encoding='utf-8')]
|
18 |
+
else:
|
19 |
+
images = []
|
20 |
+
assert os.path.isdir(dir), '%s is not a valid directory' % dir
|
21 |
+
for root, _, fnames in sorted(os.walk(dir)):
|
22 |
+
for fname in sorted(fnames):
|
23 |
+
if is_image_file(fname):
|
24 |
+
path = os.path.join(root, fname)
|
25 |
+
images.append(path)
|
26 |
+
|
27 |
+
return images
|
28 |
+
|
29 |
+
def pil_loader(path):
|
30 |
+
return Image.open(path).convert('RGB')
|
31 |
+
|
32 |
+
class BaseDataset(data.Dataset):
|
33 |
+
def __init__(self, data_root, image_size=[256, 256], loader=pil_loader):
|
34 |
+
self.imgs = make_dataset(data_root)
|
35 |
+
self.tfs = transforms.Compose([
|
36 |
+
transforms.Resize((image_size[0], image_size[1])),
|
37 |
+
transforms.ToTensor(),
|
38 |
+
transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010))
|
39 |
+
])
|
40 |
+
self.loader = loader
|
41 |
+
|
42 |
+
def __getitem__(self, index):
|
43 |
+
path = self.imgs[index]
|
44 |
+
img = self.tfs(self.loader(path))
|
45 |
+
return img
|
46 |
+
|
47 |
+
def __len__(self):
|
48 |
+
return len(self.imgs)
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/base_model.py
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from abc import abstractmethod
|
3 |
+
from functools import partial
|
4 |
+
import collections
|
5 |
+
|
6 |
+
import torch
|
7 |
+
import torch.nn as nn
|
8 |
+
|
9 |
+
|
10 |
+
import core.util as Util
|
11 |
+
CustomResult = collections.namedtuple('CustomResult', 'name result')
|
12 |
+
|
13 |
+
class BaseModel():
|
14 |
+
def __init__(self, opt, phase_loader, val_loader, metrics, logger, writer):
|
15 |
+
""" init model with basic input, which are from __init__(**kwargs) function in inherited class """
|
16 |
+
self.opt = opt
|
17 |
+
self.phase = opt['phase']
|
18 |
+
self.set_device = partial(Util.set_device, rank=opt['global_rank'])
|
19 |
+
|
20 |
+
''' optimizers and schedulers '''
|
21 |
+
self.schedulers = []
|
22 |
+
self.optimizers = []
|
23 |
+
|
24 |
+
''' process record '''
|
25 |
+
self.batch_size = self.opt['datasets'][self.phase]['dataloader']['args']['batch_size']
|
26 |
+
self.epoch = 0
|
27 |
+
self.iter = 0
|
28 |
+
|
29 |
+
self.phase_loader = phase_loader
|
30 |
+
self.val_loader = val_loader
|
31 |
+
self.metrics = metrics
|
32 |
+
|
33 |
+
''' logger to log file, which only work on GPU 0. writer to tensorboard and result file '''
|
34 |
+
self.logger = logger
|
35 |
+
self.writer = writer
|
36 |
+
self.results_dict = CustomResult([],[]) # {"name":[], "result":[]}
|
37 |
+
|
38 |
+
def train(self):
|
39 |
+
while self.epoch <= self.opt['train']['n_epoch'] and self.iter <= self.opt['train']['n_iter']:
|
40 |
+
self.epoch += 1
|
41 |
+
if self.opt['distributed']:
|
42 |
+
''' sets the epoch for this sampler. When :attr:`shuffle=True`, this ensures all replicas use a different random ordering for each epoch '''
|
43 |
+
self.phase_loader.sampler.set_epoch(self.epoch)
|
44 |
+
|
45 |
+
train_log = self.train_step()
|
46 |
+
|
47 |
+
''' save logged informations into log dict '''
|
48 |
+
train_log.update({'epoch': self.epoch, 'iters': self.iter})
|
49 |
+
|
50 |
+
''' print logged informations to the screen and tensorboard '''
|
51 |
+
for key, value in train_log.items():
|
52 |
+
self.logger.info('{:5s}: {}\t'.format(str(key), value))
|
53 |
+
|
54 |
+
if self.epoch % self.opt['train']['save_checkpoint_epoch'] == 0:
|
55 |
+
self.logger.info('Saving the self at the end of epoch {:.0f}'.format(self.epoch))
|
56 |
+
self.save_everything()
|
57 |
+
|
58 |
+
if self.epoch % self.opt['train']['val_epoch'] == 0:
|
59 |
+
self.logger.info("\n\n\n------------------------------Validation Start------------------------------")
|
60 |
+
if self.val_loader is None:
|
61 |
+
self.logger.warning('Validation stop where dataloader is None, Skip it.')
|
62 |
+
else:
|
63 |
+
val_log = self.val_step()
|
64 |
+
for key, value in val_log.items():
|
65 |
+
self.logger.info('{:5s}: {}\t'.format(str(key), value))
|
66 |
+
self.logger.info("\n------------------------------Validation End------------------------------\n\n")
|
67 |
+
self.logger.info('Number of Epochs has reached the limit, End.')
|
68 |
+
|
69 |
+
def test(self):
|
70 |
+
pass
|
71 |
+
|
72 |
+
@abstractmethod
|
73 |
+
def train_step(self):
|
74 |
+
raise NotImplementedError('You must specify how to train your networks.')
|
75 |
+
|
76 |
+
@abstractmethod
|
77 |
+
def val_step(self):
|
78 |
+
raise NotImplementedError('You must specify how to do validation on your networks.')
|
79 |
+
|
80 |
+
def test_step(self):
|
81 |
+
pass
|
82 |
+
|
83 |
+
def print_network(self, network):
|
84 |
+
""" print network structure, only work on GPU 0 """
|
85 |
+
if self.opt['global_rank'] !=0:
|
86 |
+
return
|
87 |
+
if isinstance(network, nn.DataParallel) or isinstance(network, nn.parallel.DistributedDataParallel):
|
88 |
+
network = network.module
|
89 |
+
|
90 |
+
s, n = str(network), sum(map(lambda x: x.numel(), network.parameters()))
|
91 |
+
net_struc_str = '{}'.format(network.__class__.__name__)
|
92 |
+
self.logger.info('Network structure: {}, with parameters: {:,d}'.format(net_struc_str, n))
|
93 |
+
self.logger.info(s)
|
94 |
+
|
95 |
+
def save_network(self, network, network_label):
|
96 |
+
""" save network structure, only work on GPU 0 """
|
97 |
+
if self.opt['global_rank'] !=0:
|
98 |
+
return
|
99 |
+
save_filename = '{}_{}.pth'.format(self.epoch, network_label)
|
100 |
+
save_path = os.path.join(self.opt['path']['checkpoint'], save_filename)
|
101 |
+
if isinstance(network, nn.DataParallel) or isinstance(network, nn.parallel.DistributedDataParallel):
|
102 |
+
network = network.module
|
103 |
+
state_dict = network.state_dict()
|
104 |
+
for key, param in state_dict.items():
|
105 |
+
state_dict[key] = param.cpu()
|
106 |
+
torch.save(state_dict, save_path)
|
107 |
+
|
108 |
+
def load_network(self, network, network_label, strict=True):
|
109 |
+
if self.opt['path']['resume_state'] is None:
|
110 |
+
return
|
111 |
+
self.logger.info('Beign loading pretrained model [{:s}] ...'.format(network_label))
|
112 |
+
|
113 |
+
model_path = "{}_{}.pth".format(self.opt['path']['resume_state'], network_label)
|
114 |
+
|
115 |
+
if not os.path.exists(model_path):
|
116 |
+
self.logger.warning('Pretrained model in [{:s}] is not existed, Skip it'.format(model_path))
|
117 |
+
return
|
118 |
+
|
119 |
+
self.logger.info('Loading pretrained model from [{:s}] ...'.format(model_path))
|
120 |
+
if isinstance(network, nn.DataParallel) or isinstance(network, nn.parallel.DistributedDataParallel):
|
121 |
+
network = network.module
|
122 |
+
network.load_state_dict(torch.load(model_path, map_location = lambda storage, loc: Util.set_device(storage)), strict=strict)
|
123 |
+
|
124 |
+
def save_training_state(self):
|
125 |
+
""" saves training state during training, only work on GPU 0 """
|
126 |
+
if self.opt['global_rank'] !=0:
|
127 |
+
return
|
128 |
+
assert isinstance(self.optimizers, list) and isinstance(self.schedulers, list), 'optimizers and schedulers must be a list.'
|
129 |
+
state = {'epoch': self.epoch, 'iter': self.iter, 'schedulers': [], 'optimizers': []}
|
130 |
+
for s in self.schedulers:
|
131 |
+
state['schedulers'].append(s.state_dict())
|
132 |
+
for o in self.optimizers:
|
133 |
+
state['optimizers'].append(o.state_dict())
|
134 |
+
save_filename = '{}.state'.format(self.epoch)
|
135 |
+
save_path = os.path.join(self.opt['path']['checkpoint'], save_filename)
|
136 |
+
torch.save(state, save_path)
|
137 |
+
|
138 |
+
def resume_training(self):
|
139 |
+
""" resume the optimizers and schedulers for training, only work when phase is test or resume training enable """
|
140 |
+
if self.phase!='train' or self. opt['path']['resume_state'] is None:
|
141 |
+
return
|
142 |
+
self.logger.info('Beign loading training states'.format())
|
143 |
+
assert isinstance(self.optimizers, list) and isinstance(self.schedulers, list), 'optimizers and schedulers must be a list.'
|
144 |
+
|
145 |
+
state_path = "{}.state".format(self. opt['path']['resume_state'])
|
146 |
+
|
147 |
+
if not os.path.exists(state_path):
|
148 |
+
self.logger.warning('Training state in [{:s}] is not existed, Skip it'.format(state_path))
|
149 |
+
return
|
150 |
+
|
151 |
+
self.logger.info('Loading training state for [{:s}] ...'.format(state_path))
|
152 |
+
resume_state = torch.load(state_path, map_location = lambda storage, loc: self.set_device(storage))
|
153 |
+
|
154 |
+
resume_optimizers = resume_state['optimizers']
|
155 |
+
resume_schedulers = resume_state['schedulers']
|
156 |
+
assert len(resume_optimizers) == len(self.optimizers), 'Wrong lengths of optimizers {} != {}'.format(len(resume_optimizers), len(self.optimizers))
|
157 |
+
assert len(resume_schedulers) == len(self.schedulers), 'Wrong lengths of schedulers {} != {}'.format(len(resume_schedulers), len(self.schedulers))
|
158 |
+
for i, o in enumerate(resume_optimizers):
|
159 |
+
self.optimizers[i].load_state_dict(o)
|
160 |
+
for i, s in enumerate(resume_schedulers):
|
161 |
+
self.schedulers[i].load_state_dict(s)
|
162 |
+
|
163 |
+
self.epoch = resume_state['epoch']
|
164 |
+
self.iter = resume_state['iter']
|
165 |
+
|
166 |
+
def load_everything(self):
|
167 |
+
pass
|
168 |
+
|
169 |
+
@abstractmethod
|
170 |
+
def save_everything(self):
|
171 |
+
raise NotImplementedError('You must specify how to save your networks, optimizers and schedulers.')
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/base_network.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch.nn as nn
|
2 |
+
class BaseNetwork(nn.Module):
|
3 |
+
def __init__(self, init_type='kaiming', gain=0.02):
|
4 |
+
super(BaseNetwork, self).__init__()
|
5 |
+
self.init_type = init_type
|
6 |
+
self.gain = gain
|
7 |
+
|
8 |
+
def init_weights(self):
|
9 |
+
"""
|
10 |
+
initialize network's weights
|
11 |
+
init_type: normal | xavier | kaiming | orthogonal
|
12 |
+
https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/9451e70673400885567d08a9e97ade2524c700d0/models/networks.py#L39
|
13 |
+
"""
|
14 |
+
|
15 |
+
def init_func(m):
|
16 |
+
classname = m.__class__.__name__
|
17 |
+
if classname.find('InstanceNorm2d') != -1:
|
18 |
+
if hasattr(m, 'weight') and m.weight is not None:
|
19 |
+
nn.init.constant_(m.weight.data, 1.0)
|
20 |
+
if hasattr(m, 'bias') and m.bias is not None:
|
21 |
+
nn.init.constant_(m.bias.data, 0.0)
|
22 |
+
elif hasattr(m, 'weight') and (classname.find('Conv') != -1 or classname.find('Linear') != -1):
|
23 |
+
if self.init_type == 'normal':
|
24 |
+
nn.init.normal_(m.weight.data, 0.0, self.gain)
|
25 |
+
elif self.init_type == 'xavier':
|
26 |
+
nn.init.xavier_normal_(m.weight.data, gain=self.gain)
|
27 |
+
elif self.init_type == 'xavier_uniform':
|
28 |
+
nn.init.xavier_uniform_(m.weight.data, gain=1.0)
|
29 |
+
elif self.init_type == 'kaiming':
|
30 |
+
nn.init.kaiming_normal_(m.weight.data, a=0, mode='fan_in')
|
31 |
+
elif self.init_type == 'orthogonal':
|
32 |
+
nn.init.orthogonal_(m.weight.data, gain=self.gain)
|
33 |
+
elif self.init_type == 'none': # uses pytorch's default init method
|
34 |
+
m.reset_parameters()
|
35 |
+
else:
|
36 |
+
raise NotImplementedError('initialization method [%s] is not implemented' % self.init_type)
|
37 |
+
if hasattr(m, 'bias') and m.bias is not None:
|
38 |
+
nn.init.constant_(m.bias.data, 0.0)
|
39 |
+
|
40 |
+
self.apply(init_func)
|
41 |
+
# propagate to children
|
42 |
+
for m in self.children():
|
43 |
+
if hasattr(m, 'init_weights'):
|
44 |
+
m.init_weights(self.init_type, self.gain)
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/dpm_solver_pytorch.py
ADDED
@@ -0,0 +1,1306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn.functional as F
|
3 |
+
import math
|
4 |
+
|
5 |
+
|
6 |
+
class NoiseScheduleVP:
|
7 |
+
def __init__(
|
8 |
+
self,
|
9 |
+
schedule='discrete',
|
10 |
+
betas=None,
|
11 |
+
alphas_cumprod=None,
|
12 |
+
continuous_beta_0=0.1,
|
13 |
+
continuous_beta_1=20.,
|
14 |
+
dtype=torch.float32,
|
15 |
+
):
|
16 |
+
"""Create a wrapper class for the forward SDE (VP type).
|
17 |
+
|
18 |
+
***
|
19 |
+
Update: We support discrete-time diffusion models by implementing a picewise linear interpolation for log_alpha_t.
|
20 |
+
We recommend to use schedule='discrete' for the discrete-time diffusion models, especially for high-resolution images.
|
21 |
+
***
|
22 |
+
|
23 |
+
The forward SDE ensures that the condition distribution q_{t|0}(x_t | x_0) = N ( alpha_t * x_0, sigma_t^2 * I ).
|
24 |
+
We further define lambda_t = log(alpha_t) - log(sigma_t), which is the half-logSNR (described in the DPM-Solver paper).
|
25 |
+
Therefore, we implement the functions for computing alpha_t, sigma_t and lambda_t. For t in [0, T], we have:
|
26 |
+
|
27 |
+
log_alpha_t = self.marginal_log_mean_coeff(t)
|
28 |
+
sigma_t = self.marginal_std(t)
|
29 |
+
lambda_t = self.marginal_lambda(t)
|
30 |
+
|
31 |
+
Moreover, as lambda(t) is an invertible function, we also support its inverse function:
|
32 |
+
|
33 |
+
t = self.inverse_lambda(lambda_t)
|
34 |
+
|
35 |
+
===============================================================
|
36 |
+
|
37 |
+
We support both discrete-time DPMs (trained on n = 0, 1, ..., N-1) and continuous-time DPMs (trained on t in [t_0, T]).
|
38 |
+
|
39 |
+
1. For discrete-time DPMs:
|
40 |
+
|
41 |
+
For discrete-time DPMs trained on n = 0, 1, ..., N-1, we convert the discrete steps to continuous time steps by:
|
42 |
+
t_i = (i + 1) / N
|
43 |
+
e.g. for N = 1000, we have t_0 = 1e-3 and T = t_{N-1} = 1.
|
44 |
+
We solve the corresponding diffusion ODE from time T = 1 to time t_0 = 1e-3.
|
45 |
+
|
46 |
+
Args:
|
47 |
+
betas: A `torch.Tensor`. The beta array for the discrete-time DPM. (See the original DDPM paper for details)
|
48 |
+
alphas_cumprod: A `torch.Tensor`. The cumprod alphas for the discrete-time DPM. (See the original DDPM paper for details)
|
49 |
+
|
50 |
+
Note that we always have alphas_cumprod = cumprod(1 - betas). Therefore, we only need to set one of `betas` and `alphas_cumprod`.
|
51 |
+
|
52 |
+
**Important**: Please pay special attention for the args for `alphas_cumprod`:
|
53 |
+
The `alphas_cumprod` is the \hat{alpha_n} arrays in the notations of DDPM. Specifically, DDPMs assume that
|
54 |
+
q_{t_n | 0}(x_{t_n} | x_0) = N ( \sqrt{\hat{alpha_n}} * x_0, (1 - \hat{alpha_n}) * I ).
|
55 |
+
Therefore, the notation \hat{alpha_n} is different from the notation alpha_t in DPM-Solver. In fact, we have
|
56 |
+
alpha_{t_n} = \sqrt{\hat{alpha_n}},
|
57 |
+
and
|
58 |
+
log(alpha_{t_n}) = 0.5 * log(\hat{alpha_n}).
|
59 |
+
|
60 |
+
|
61 |
+
2. For continuous-time DPMs:
|
62 |
+
|
63 |
+
We support the linear VPSDE for the continuous time setting. The hyperparameters for the noise
|
64 |
+
schedule are the default settings in Yang Song's ScoreSDE:
|
65 |
+
|
66 |
+
Args:
|
67 |
+
beta_min: A `float` number. The smallest beta for the linear schedule.
|
68 |
+
beta_max: A `float` number. The largest beta for the linear schedule.
|
69 |
+
T: A `float` number. The ending time of the forward process.
|
70 |
+
|
71 |
+
===============================================================
|
72 |
+
|
73 |
+
Args:
|
74 |
+
schedule: A `str`. The noise schedule of the forward SDE. 'discrete' for discrete-time DPMs,
|
75 |
+
'linear' for continuous-time DPMs.
|
76 |
+
Returns:
|
77 |
+
A wrapper object of the forward SDE (VP type).
|
78 |
+
|
79 |
+
===============================================================
|
80 |
+
|
81 |
+
Example:
|
82 |
+
|
83 |
+
# For discrete-time DPMs, given betas (the beta array for n = 0, 1, ..., N - 1):
|
84 |
+
>>> ns = NoiseScheduleVP('discrete', betas=betas)
|
85 |
+
|
86 |
+
# For discrete-time DPMs, given alphas_cumprod (the \hat{alpha_n} array for n = 0, 1, ..., N - 1):
|
87 |
+
>>> ns = NoiseScheduleVP('discrete', alphas_cumprod=alphas_cumprod)
|
88 |
+
|
89 |
+
# For continuous-time DPMs (VPSDE), linear schedule:
|
90 |
+
>>> ns = NoiseScheduleVP('linear', continuous_beta_0=0.1, continuous_beta_1=20.)
|
91 |
+
|
92 |
+
"""
|
93 |
+
|
94 |
+
if schedule not in ['discrete', 'linear']:
|
95 |
+
raise ValueError("Unsupported noise schedule {}. The schedule needs to be 'discrete' or 'linear'".format(schedule))
|
96 |
+
|
97 |
+
self.schedule = schedule
|
98 |
+
if schedule == 'discrete':
|
99 |
+
if betas is not None:
|
100 |
+
log_alphas = 0.5 * torch.log(1 - betas).cumsum(dim=0)
|
101 |
+
else:
|
102 |
+
assert alphas_cumprod is not None
|
103 |
+
log_alphas = 0.5 * torch.log(alphas_cumprod)
|
104 |
+
self.T = 1.
|
105 |
+
self.log_alpha_array = self.numerical_clip_alpha(log_alphas).reshape((1, -1,)).to(dtype=dtype)
|
106 |
+
self.total_N = self.log_alpha_array.shape[1]
|
107 |
+
self.t_array = torch.linspace(0., 1., self.total_N + 1)[1:].reshape((1, -1)).to(dtype=dtype)
|
108 |
+
else:
|
109 |
+
self.T = 1.
|
110 |
+
self.total_N = 1000
|
111 |
+
self.beta_0 = continuous_beta_0
|
112 |
+
self.beta_1 = continuous_beta_1
|
113 |
+
|
114 |
+
def numerical_clip_alpha(self, log_alphas, clipped_lambda=-5.1):
|
115 |
+
"""
|
116 |
+
For some beta schedules such as cosine schedule, the log-SNR has numerical isssues.
|
117 |
+
We clip the log-SNR near t=T within -5.1 to ensure the stability.
|
118 |
+
Such a trick is very useful for diffusion models with the cosine schedule, such as i-DDPM, guided-diffusion and GLIDE.
|
119 |
+
"""
|
120 |
+
log_sigmas = 0.5 * torch.log(1. - torch.exp(2. * log_alphas))
|
121 |
+
lambs = log_alphas - log_sigmas
|
122 |
+
idx = torch.searchsorted(torch.flip(lambs, [0]), clipped_lambda)
|
123 |
+
if idx > 0:
|
124 |
+
log_alphas = log_alphas[:-idx]
|
125 |
+
return log_alphas
|
126 |
+
|
127 |
+
def marginal_log_mean_coeff(self, t):
|
128 |
+
"""
|
129 |
+
Compute log(alpha_t) of a given continuous-time label t in [0, T].
|
130 |
+
"""
|
131 |
+
if self.schedule == 'discrete':
|
132 |
+
return interpolate_fn(t.reshape((-1, 1)), self.t_array.to(t.device), self.log_alpha_array.to(t.device)).reshape((-1))
|
133 |
+
elif self.schedule == 'linear':
|
134 |
+
return -0.25 * t ** 2 * (self.beta_1 - self.beta_0) - 0.5 * t * self.beta_0
|
135 |
+
|
136 |
+
def marginal_alpha(self, t):
|
137 |
+
"""
|
138 |
+
Compute alpha_t of a given continuous-time label t in [0, T].
|
139 |
+
"""
|
140 |
+
return torch.exp(self.marginal_log_mean_coeff(t))
|
141 |
+
|
142 |
+
def marginal_std(self, t):
|
143 |
+
"""
|
144 |
+
Compute sigma_t of a given continuous-time label t in [0, T].
|
145 |
+
"""
|
146 |
+
return torch.sqrt(1. - torch.exp(2. * self.marginal_log_mean_coeff(t)))
|
147 |
+
|
148 |
+
def marginal_lambda(self, t):
|
149 |
+
"""
|
150 |
+
Compute lambda_t = log(alpha_t) - log(sigma_t) of a given continuous-time label t in [0, T].
|
151 |
+
"""
|
152 |
+
log_mean_coeff = self.marginal_log_mean_coeff(t)
|
153 |
+
log_std = 0.5 * torch.log(1. - torch.exp(2. * log_mean_coeff))
|
154 |
+
return log_mean_coeff - log_std
|
155 |
+
|
156 |
+
def inverse_lambda(self, lamb):
|
157 |
+
"""
|
158 |
+
Compute the continuous-time label t in [0, T] of a given half-logSNR lambda_t.
|
159 |
+
"""
|
160 |
+
if self.schedule == 'linear':
|
161 |
+
tmp = 2. * (self.beta_1 - self.beta_0) * torch.logaddexp(-2. * lamb, torch.zeros((1,)).to(lamb))
|
162 |
+
Delta = self.beta_0**2 + tmp
|
163 |
+
return tmp / (torch.sqrt(Delta) + self.beta_0) / (self.beta_1 - self.beta_0)
|
164 |
+
elif self.schedule == 'discrete':
|
165 |
+
log_alpha = -0.5 * torch.logaddexp(torch.zeros((1,)).to(lamb.device), -2. * lamb)
|
166 |
+
t = interpolate_fn(log_alpha.reshape((-1, 1)), torch.flip(self.log_alpha_array.to(lamb.device), [1]), torch.flip(self.t_array.to(lamb.device), [1]))
|
167 |
+
return t.reshape((-1,))
|
168 |
+
|
169 |
+
|
170 |
+
def model_wrapper(
|
171 |
+
model,
|
172 |
+
noise_schedule,
|
173 |
+
model_type="noise",
|
174 |
+
model_kwargs={},
|
175 |
+
guidance_type="uncond",
|
176 |
+
condition=None,
|
177 |
+
unconditional_condition=None,
|
178 |
+
guidance_scale=1.,
|
179 |
+
classifier_fn=None,
|
180 |
+
classifier_kwargs={},
|
181 |
+
):
|
182 |
+
"""Create a wrapper function for the noise prediction model.
|
183 |
+
|
184 |
+
DPM-Solver needs to solve the continuous-time diffusion ODEs. For DPMs trained on discrete-time labels, we need to
|
185 |
+
firstly wrap the model function to a noise prediction model that accepts the continuous time as the input.
|
186 |
+
|
187 |
+
We support four types of the diffusion model by setting `model_type`:
|
188 |
+
|
189 |
+
1. "noise": noise prediction model. (Trained by predicting noise).
|
190 |
+
|
191 |
+
2. "x_start": data prediction model. (Trained by predicting the data x_0 at time 0).
|
192 |
+
|
193 |
+
3. "v": velocity prediction model. (Trained by predicting the velocity).
|
194 |
+
The "v" prediction is derivation detailed in Appendix D of [1], and is used in Imagen-Video [2].
|
195 |
+
|
196 |
+
[1] Salimans, Tim, and Jonathan Ho. "Progressive distillation for fast sampling of diffusion models."
|
197 |
+
arXiv preprint arXiv:2202.00512 (2022).
|
198 |
+
[2] Ho, Jonathan, et al. "Imagen Video: High Definition Video Generation with Diffusion Models."
|
199 |
+
arXiv preprint arXiv:2210.02303 (2022).
|
200 |
+
|
201 |
+
4. "score": marginal score function. (Trained by denoising score matching).
|
202 |
+
Note that the score function and the noise prediction model follows a simple relationship:
|
203 |
+
```
|
204 |
+
noise(x_t, t) = -sigma_t * score(x_t, t)
|
205 |
+
```
|
206 |
+
|
207 |
+
We support three types of guided sampling by DPMs by setting `guidance_type`:
|
208 |
+
1. "uncond": unconditional sampling by DPMs.
|
209 |
+
The input `model` has the following format:
|
210 |
+
``
|
211 |
+
model(x, t_input, **model_kwargs) -> noise | x_start | v | score
|
212 |
+
``
|
213 |
+
|
214 |
+
2. "classifier": classifier guidance sampling [3] by DPMs and another classifier.
|
215 |
+
The input `model` has the following format:
|
216 |
+
``
|
217 |
+
model(x, t_input, **model_kwargs) -> noise | x_start | v | score
|
218 |
+
``
|
219 |
+
|
220 |
+
The input `classifier_fn` has the following format:
|
221 |
+
``
|
222 |
+
classifier_fn(x, t_input, cond, **classifier_kwargs) -> logits(x, t_input, cond)
|
223 |
+
``
|
224 |
+
|
225 |
+
[3] P. Dhariwal and A. Q. Nichol, "Diffusion models beat GANs on image synthesis,"
|
226 |
+
in Advances in Neural Information Processing Systems, vol. 34, 2021, pp. 8780-8794.
|
227 |
+
|
228 |
+
3. "classifier-free": classifier-free guidance sampling by conditional DPMs.
|
229 |
+
The input `model` has the following format:
|
230 |
+
``
|
231 |
+
model(x, t_input, cond, **model_kwargs) -> noise | x_start | v | score
|
232 |
+
``
|
233 |
+
And if cond == `unconditional_condition`, the model output is the unconditional DPM output.
|
234 |
+
|
235 |
+
[4] Ho, Jonathan, and Tim Salimans. "Classifier-free diffusion guidance."
|
236 |
+
arXiv preprint arXiv:2207.12598 (2022).
|
237 |
+
|
238 |
+
|
239 |
+
The `t_input` is the time label of the model, which may be discrete-time labels (i.e. 0 to 999)
|
240 |
+
or continuous-time labels (i.e. epsilon to T).
|
241 |
+
|
242 |
+
We wrap the model function to accept only `x` and `t_continuous` as inputs, and outputs the predicted noise:
|
243 |
+
``
|
244 |
+
def model_fn(x, t_continuous) -> noise:
|
245 |
+
t_input = get_model_input_time(t_continuous)
|
246 |
+
return noise_pred(model, x, t_input, **model_kwargs)
|
247 |
+
``
|
248 |
+
where `t_continuous` is the continuous time labels (i.e. epsilon to T). And we use `model_fn` for DPM-Solver.
|
249 |
+
|
250 |
+
===============================================================
|
251 |
+
|
252 |
+
Args:
|
253 |
+
model: A diffusion model with the corresponding format described above.
|
254 |
+
noise_schedule: A noise schedule object, such as NoiseScheduleVP.
|
255 |
+
model_type: A `str`. The parameterization type of the diffusion model.
|
256 |
+
"noise" or "x_start" or "v" or "score".
|
257 |
+
model_kwargs: A `dict`. A dict for the other inputs of the model function.
|
258 |
+
guidance_type: A `str`. The type of the guidance for sampling.
|
259 |
+
"uncond" or "classifier" or "classifier-free".
|
260 |
+
condition: A pytorch tensor. The condition for the guided sampling.
|
261 |
+
Only used for "classifier" or "classifier-free" guidance type.
|
262 |
+
unconditional_condition: A pytorch tensor. The condition for the unconditional sampling.
|
263 |
+
Only used for "classifier-free" guidance type.
|
264 |
+
guidance_scale: A `float`. The scale for the guided sampling.
|
265 |
+
classifier_fn: A classifier function. Only used for the classifier guidance.
|
266 |
+
classifier_kwargs: A `dict`. A dict for the other inputs of the classifier function.
|
267 |
+
Returns:
|
268 |
+
A noise prediction model that accepts the noised data and the continuous time as the inputs.
|
269 |
+
"""
|
270 |
+
|
271 |
+
def get_model_input_time(t_continuous):
|
272 |
+
"""
|
273 |
+
Convert the continuous-time `t_continuous` (in [epsilon, T]) to the model input time.
|
274 |
+
For discrete-time DPMs, we convert `t_continuous` in [1 / N, 1] to `t_input` in [0, 1000 * (N - 1) / N].
|
275 |
+
For continuous-time DPMs, we just use `t_continuous`.
|
276 |
+
"""
|
277 |
+
if noise_schedule.schedule == 'discrete':
|
278 |
+
return (t_continuous - 1. / noise_schedule.total_N) * 1000.
|
279 |
+
else:
|
280 |
+
return t_continuous
|
281 |
+
|
282 |
+
def noise_pred_fn(x, t_continuous, cond=None):
|
283 |
+
t_input = get_model_input_time(t_continuous)
|
284 |
+
if cond is None:
|
285 |
+
output = model(x, t_input, **model_kwargs)
|
286 |
+
else:
|
287 |
+
# output = model(x, t_input, cond, **model_kwargs) zxc
|
288 |
+
output = model(torch.cat((cond, x), dim=1), t_input, **model_kwargs)
|
289 |
+
if model_type == "noise":
|
290 |
+
return output
|
291 |
+
elif model_type == "x_start":
|
292 |
+
alpha_t, sigma_t = noise_schedule.marginal_alpha(t_continuous), noise_schedule.marginal_std(t_continuous)
|
293 |
+
return (x - alpha_t * output) / sigma_t
|
294 |
+
elif model_type == "v":
|
295 |
+
alpha_t, sigma_t = noise_schedule.marginal_alpha(t_continuous), noise_schedule.marginal_std(t_continuous)
|
296 |
+
return alpha_t * output + sigma_t * x
|
297 |
+
elif model_type == "score":
|
298 |
+
sigma_t = noise_schedule.marginal_std(t_continuous)
|
299 |
+
return -sigma_t * output
|
300 |
+
|
301 |
+
def cond_grad_fn(x, t_input):
|
302 |
+
"""
|
303 |
+
Compute the gradient of the classifier, i.e. nabla_{x} log p_t(cond | x_t).
|
304 |
+
"""
|
305 |
+
with torch.enable_grad():
|
306 |
+
x_in = x.detach().requires_grad_(True)
|
307 |
+
log_prob = classifier_fn(x_in, t_input, condition, **classifier_kwargs)
|
308 |
+
return torch.autograd.grad(log_prob.sum(), x_in)[0]
|
309 |
+
|
310 |
+
def model_fn(x, t_continuous):
|
311 |
+
"""
|
312 |
+
The noise predicition model function that is used for DPM-Solver.
|
313 |
+
"""
|
314 |
+
if guidance_type == "uncond":
|
315 |
+
return noise_pred_fn(x, t_continuous)
|
316 |
+
elif guidance_type == "classifier":
|
317 |
+
assert classifier_fn is not None
|
318 |
+
t_input = get_model_input_time(t_continuous)
|
319 |
+
cond_grad = cond_grad_fn(x, t_input)
|
320 |
+
sigma_t = noise_schedule.marginal_std(t_continuous)
|
321 |
+
noise = noise_pred_fn(x, t_continuous)
|
322 |
+
return noise - guidance_scale * expand_dims(sigma_t, x.dim()) * cond_grad
|
323 |
+
elif guidance_type == "classifier-free":
|
324 |
+
if guidance_scale == 1. or unconditional_condition is None:
|
325 |
+
return noise_pred_fn(x, t_continuous, cond=condition)
|
326 |
+
else:
|
327 |
+
x_in = torch.cat([x] * 2)
|
328 |
+
t_in = torch.cat([t_continuous] * 2)
|
329 |
+
c_in = torch.cat([unconditional_condition, condition])
|
330 |
+
noise_uncond, noise = noise_pred_fn(x_in, t_in, cond=c_in).chunk(2)
|
331 |
+
return noise_uncond + guidance_scale * (noise - noise_uncond)
|
332 |
+
|
333 |
+
assert model_type in ["noise", "x_start", "v", "score"]
|
334 |
+
assert guidance_type in ["uncond", "classifier", "classifier-free"]
|
335 |
+
return model_fn
|
336 |
+
|
337 |
+
|
338 |
+
class DPM_Solver:
|
339 |
+
def __init__(
|
340 |
+
self,
|
341 |
+
model_fn,
|
342 |
+
noise_schedule,
|
343 |
+
algorithm_type="dpmsolver++",
|
344 |
+
correcting_x0_fn=None,
|
345 |
+
correcting_xt_fn=None,
|
346 |
+
thresholding_max_val=1.,
|
347 |
+
dynamic_thresholding_ratio=0.995,
|
348 |
+
):
|
349 |
+
"""Construct a DPM-Solver.
|
350 |
+
|
351 |
+
We support both DPM-Solver (`algorithm_type="dpmsolver"`) and DPM-Solver++ (`algorithm_type="dpmsolver++"`).
|
352 |
+
|
353 |
+
We also support the "dynamic thresholding" method in Imagen[1]. For pixel-space diffusion models, you
|
354 |
+
can set both `algorithm_type="dpmsolver++"` and `correcting_x0_fn="dynamic_thresholding"` to use the
|
355 |
+
dynamic thresholding. The "dynamic thresholding" can greatly improve the sample quality for pixel-space
|
356 |
+
DPMs with large guidance scales. Note that the thresholding method is **unsuitable** for latent-space
|
357 |
+
DPMs (such as stable-diffusion).
|
358 |
+
|
359 |
+
To support advanced algorithms in image-to-image applications, we also support corrector functions for
|
360 |
+
both x0 and xt.
|
361 |
+
|
362 |
+
Args:
|
363 |
+
model_fn: A noise prediction model function which accepts the continuous-time input (t in [epsilon, T]):
|
364 |
+
``
|
365 |
+
def model_fn(x, t_continuous):
|
366 |
+
return noise
|
367 |
+
``
|
368 |
+
The shape of `x` is `(batch_size, **shape)`, and the shape of `t_continuous` is `(batch_size,)`.
|
369 |
+
noise_schedule: A noise schedule object, such as NoiseScheduleVP.
|
370 |
+
algorithm_type: A `str`. Either "dpmsolver" or "dpmsolver++".
|
371 |
+
correcting_x0_fn: A `str` or a function with the following format:
|
372 |
+
```
|
373 |
+
def correcting_x0_fn(x0, t):
|
374 |
+
x0_new = ...
|
375 |
+
return x0_new
|
376 |
+
```
|
377 |
+
This function is to correct the outputs of the data prediction model at each sampling step. e.g.,
|
378 |
+
```
|
379 |
+
x0_pred = data_pred_model(xt, t)
|
380 |
+
if correcting_x0_fn is not None:
|
381 |
+
x0_pred = correcting_x0_fn(x0_pred, t)
|
382 |
+
xt_1 = update(x0_pred, xt, t)
|
383 |
+
```
|
384 |
+
If `correcting_x0_fn="dynamic_thresholding"`, we use the dynamic thresholding proposed in Imagen[1].
|
385 |
+
correcting_xt_fn: A function with the following format:
|
386 |
+
```
|
387 |
+
def correcting_xt_fn(xt, t, step):
|
388 |
+
x_new = ...
|
389 |
+
return x_new
|
390 |
+
```
|
391 |
+
This function is to correct the intermediate samples xt at each sampling step. e.g.,
|
392 |
+
```
|
393 |
+
xt = ...
|
394 |
+
xt = correcting_xt_fn(xt, t, step)
|
395 |
+
```
|
396 |
+
thresholding_max_val: A `float`. The max value for thresholding.
|
397 |
+
Valid only when use `dpmsolver++` and `correcting_x0_fn="dynamic_thresholding"`.
|
398 |
+
dynamic_thresholding_ratio: A `float`. The ratio for dynamic thresholding (see Imagen[1] for details).
|
399 |
+
Valid only when use `dpmsolver++` and `correcting_x0_fn="dynamic_thresholding"`.
|
400 |
+
|
401 |
+
[1] Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily Denton, Seyed Kamyar Seyed Ghasemipour,
|
402 |
+
Burcu Karagol Ayan, S Sara Mahdavi, Rapha Gontijo Lopes, et al. Photorealistic text-to-image diffusion models
|
403 |
+
with deep language understanding. arXiv preprint arXiv:2205.11487, 2022b.
|
404 |
+
"""
|
405 |
+
self.model = lambda x, t: model_fn(x, t.expand((x.shape[0])))
|
406 |
+
self.noise_schedule = noise_schedule
|
407 |
+
assert algorithm_type in ["dpmsolver", "dpmsolver++"]
|
408 |
+
self.algorithm_type = algorithm_type
|
409 |
+
if correcting_x0_fn == "dynamic_thresholding":
|
410 |
+
self.correcting_x0_fn = self.dynamic_thresholding_fn
|
411 |
+
else:
|
412 |
+
self.correcting_x0_fn = correcting_x0_fn
|
413 |
+
self.correcting_xt_fn = correcting_xt_fn
|
414 |
+
self.dynamic_thresholding_ratio = dynamic_thresholding_ratio
|
415 |
+
self.thresholding_max_val = thresholding_max_val
|
416 |
+
|
417 |
+
def dynamic_thresholding_fn(self, x0, t):
|
418 |
+
"""
|
419 |
+
The dynamic thresholding method.
|
420 |
+
"""
|
421 |
+
dims = x0.dim()
|
422 |
+
p = self.dynamic_thresholding_ratio
|
423 |
+
s = torch.quantile(torch.abs(x0).reshape((x0.shape[0], -1)), p, dim=1)
|
424 |
+
s = expand_dims(torch.maximum(s, self.thresholding_max_val * torch.ones_like(s).to(s.device)), dims)
|
425 |
+
x0 = torch.clamp(x0, -s, s) / s
|
426 |
+
return x0
|
427 |
+
|
428 |
+
def noise_prediction_fn(self, x, t):
|
429 |
+
"""
|
430 |
+
Return the noise prediction model.
|
431 |
+
"""
|
432 |
+
return self.model(x, t)
|
433 |
+
|
434 |
+
def data_prediction_fn(self, x, t):
|
435 |
+
"""
|
436 |
+
Return the data prediction model (with corrector).
|
437 |
+
"""
|
438 |
+
noise = self.noise_prediction_fn(x, t)
|
439 |
+
alpha_t, sigma_t = self.noise_schedule.marginal_alpha(t), self.noise_schedule.marginal_std(t)
|
440 |
+
x0 = (x - sigma_t * noise) / alpha_t
|
441 |
+
if self.correcting_x0_fn is not None:
|
442 |
+
x0 = self.correcting_x0_fn(x0, t)
|
443 |
+
return x0
|
444 |
+
|
445 |
+
def model_fn(self, x, t):
|
446 |
+
"""
|
447 |
+
Convert the model to the noise prediction model or the data prediction model.
|
448 |
+
"""
|
449 |
+
if self.algorithm_type == "dpmsolver++":
|
450 |
+
return self.data_prediction_fn(x, t)
|
451 |
+
else:
|
452 |
+
return self.noise_prediction_fn(x, t)
|
453 |
+
|
454 |
+
def get_time_steps(self, skip_type, t_T, t_0, N, device):
|
455 |
+
"""Compute the intermediate time steps for sampling.
|
456 |
+
|
457 |
+
Args:
|
458 |
+
skip_type: A `str`. The type for the spacing of the time steps. We support three types:
|
459 |
+
- 'logSNR': uniform logSNR for the time steps.
|
460 |
+
- 'time_uniform': uniform time for the time steps. (**Recommended for high-resolutional data**.)
|
461 |
+
- 'time_quadratic': quadratic time for the time steps. (Used in DDIM for low-resolutional data.)
|
462 |
+
t_T: A `float`. The starting time of the sampling (default is T).
|
463 |
+
t_0: A `float`. The ending time of the sampling (default is epsilon).
|
464 |
+
N: A `int`. The total number of the spacing of the time steps.
|
465 |
+
device: A torch device.
|
466 |
+
Returns:
|
467 |
+
A pytorch tensor of the time steps, with the shape (N + 1,).
|
468 |
+
"""
|
469 |
+
if skip_type == 'logSNR':
|
470 |
+
lambda_T = self.noise_schedule.marginal_lambda(torch.tensor(t_T).to(device))
|
471 |
+
lambda_0 = self.noise_schedule.marginal_lambda(torch.tensor(t_0).to(device))
|
472 |
+
logSNR_steps = torch.linspace(lambda_T.cpu().item(), lambda_0.cpu().item(), N + 1).to(device)
|
473 |
+
return self.noise_schedule.inverse_lambda(logSNR_steps)
|
474 |
+
elif skip_type == 'time_uniform':
|
475 |
+
return torch.linspace(t_T, t_0, N + 1).to(device)
|
476 |
+
elif skip_type == 'time_quadratic':
|
477 |
+
t_order = 2
|
478 |
+
t = torch.linspace(t_T**(1. / t_order), t_0**(1. / t_order), N + 1).pow(t_order).to(device)
|
479 |
+
return t
|
480 |
+
else:
|
481 |
+
raise ValueError("Unsupported skip_type {}, need to be 'logSNR' or 'time_uniform' or 'time_quadratic'".format(skip_type))
|
482 |
+
|
483 |
+
def get_orders_and_timesteps_for_singlestep_solver(self, steps, order, skip_type, t_T, t_0, device):
|
484 |
+
"""
|
485 |
+
Get the order of each step for sampling by the singlestep DPM-Solver.
|
486 |
+
|
487 |
+
We combine both DPM-Solver-1,2,3 to use all the function evaluations, which is named as "DPM-Solver-fast".
|
488 |
+
Given a fixed number of function evaluations by `steps`, the sampling procedure by DPM-Solver-fast is:
|
489 |
+
- If order == 1:
|
490 |
+
We take `steps` of DPM-Solver-1 (i.e. DDIM).
|
491 |
+
- If order == 2:
|
492 |
+
- Denote K = (steps // 2). We take K or (K + 1) intermediate time steps for sampling.
|
493 |
+
- If steps % 2 == 0, we use K steps of DPM-Solver-2.
|
494 |
+
- If steps % 2 == 1, we use K steps of DPM-Solver-2 and 1 step of DPM-Solver-1.
|
495 |
+
- If order == 3:
|
496 |
+
- Denote K = (steps // 3 + 1). We take K intermediate time steps for sampling.
|
497 |
+
- If steps % 3 == 0, we use (K - 2) steps of DPM-Solver-3, and 1 step of DPM-Solver-2 and 1 step of DPM-Solver-1.
|
498 |
+
- If steps % 3 == 1, we use (K - 1) steps of DPM-Solver-3 and 1 step of DPM-Solver-1.
|
499 |
+
- If steps % 3 == 2, we use (K - 1) steps of DPM-Solver-3 and 1 step of DPM-Solver-2.
|
500 |
+
|
501 |
+
============================================
|
502 |
+
Args:
|
503 |
+
order: A `int`. The max order for the solver (2 or 3).
|
504 |
+
steps: A `int`. The total number of function evaluations (NFE).
|
505 |
+
skip_type: A `str`. The type for the spacing of the time steps. We support three types:
|
506 |
+
- 'logSNR': uniform logSNR for the time steps.
|
507 |
+
- 'time_uniform': uniform time for the time steps. (**Recommended for high-resolutional data**.)
|
508 |
+
- 'time_quadratic': quadratic time for the time steps. (Used in DDIM for low-resolutional data.)
|
509 |
+
t_T: A `float`. The starting time of the sampling (default is T).
|
510 |
+
t_0: A `float`. The ending time of the sampling (default is epsilon).
|
511 |
+
device: A torch device.
|
512 |
+
Returns:
|
513 |
+
orders: A list of the solver order of each step.
|
514 |
+
"""
|
515 |
+
if order == 3:
|
516 |
+
K = steps // 3 + 1
|
517 |
+
if steps % 3 == 0:
|
518 |
+
orders = [3,] * (K - 2) + [2, 1]
|
519 |
+
elif steps % 3 == 1:
|
520 |
+
orders = [3,] * (K - 1) + [1]
|
521 |
+
else:
|
522 |
+
orders = [3,] * (K - 1) + [2]
|
523 |
+
elif order == 2:
|
524 |
+
if steps % 2 == 0:
|
525 |
+
K = steps // 2
|
526 |
+
orders = [2,] * K
|
527 |
+
else:
|
528 |
+
K = steps // 2 + 1
|
529 |
+
orders = [2,] * (K - 1) + [1]
|
530 |
+
elif order == 1:
|
531 |
+
K = 1
|
532 |
+
orders = [1,] * steps
|
533 |
+
else:
|
534 |
+
raise ValueError("'order' must be '1' or '2' or '3'.")
|
535 |
+
if skip_type == 'logSNR':
|
536 |
+
# To reproduce the results in DPM-Solver paper
|
537 |
+
timesteps_outer = self.get_time_steps(skip_type, t_T, t_0, K, device)
|
538 |
+
else:
|
539 |
+
timesteps_outer = self.get_time_steps(skip_type, t_T, t_0, steps, device)[torch.cumsum(torch.tensor([0,] + orders), 0).to(device)]
|
540 |
+
return timesteps_outer, orders
|
541 |
+
|
542 |
+
def denoise_to_zero_fn(self, x, s):
|
543 |
+
"""
|
544 |
+
Denoise at the final step, which is equivalent to solve the ODE from lambda_s to infty by first-order discretization.
|
545 |
+
"""
|
546 |
+
return self.data_prediction_fn(x, s)
|
547 |
+
|
548 |
+
def dpm_solver_first_update(self, x, s, t, model_s=None, return_intermediate=False):
|
549 |
+
"""
|
550 |
+
DPM-Solver-1 (equivalent to DDIM) from time `s` to time `t`.
|
551 |
+
|
552 |
+
Args:
|
553 |
+
x: A pytorch tensor. The initial value at time `s`.
|
554 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
555 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
556 |
+
model_s: A pytorch tensor. The model function evaluated at time `s`.
|
557 |
+
If `model_s` is None, we evaluate the model by `x` and `s`; otherwise we directly use it.
|
558 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s`.
|
559 |
+
Returns:
|
560 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
561 |
+
"""
|
562 |
+
ns = self.noise_schedule
|
563 |
+
dims = x.dim()
|
564 |
+
lambda_s, lambda_t = ns.marginal_lambda(s), ns.marginal_lambda(t)
|
565 |
+
h = lambda_t - lambda_s
|
566 |
+
log_alpha_s, log_alpha_t = ns.marginal_log_mean_coeff(s), ns.marginal_log_mean_coeff(t)
|
567 |
+
sigma_s, sigma_t = ns.marginal_std(s), ns.marginal_std(t)
|
568 |
+
alpha_t = torch.exp(log_alpha_t)
|
569 |
+
|
570 |
+
if self.algorithm_type == "dpmsolver++":
|
571 |
+
phi_1 = torch.expm1(-h)
|
572 |
+
if model_s is None:
|
573 |
+
model_s = self.model_fn(x, s)
|
574 |
+
x_t = (
|
575 |
+
sigma_t / sigma_s * x
|
576 |
+
- alpha_t * phi_1 * model_s
|
577 |
+
)
|
578 |
+
if return_intermediate:
|
579 |
+
return x_t, {'model_s': model_s}
|
580 |
+
else:
|
581 |
+
return x_t
|
582 |
+
else:
|
583 |
+
phi_1 = torch.expm1(h)
|
584 |
+
if model_s is None:
|
585 |
+
model_s = self.model_fn(x, s)
|
586 |
+
x_t = (
|
587 |
+
torch.exp(log_alpha_t - log_alpha_s) * x
|
588 |
+
- (sigma_t * phi_1) * model_s
|
589 |
+
)
|
590 |
+
if return_intermediate:
|
591 |
+
return x_t, {'model_s': model_s}
|
592 |
+
else:
|
593 |
+
return x_t
|
594 |
+
|
595 |
+
def singlestep_dpm_solver_second_update(self, x, s, t, r1=0.5, model_s=None, return_intermediate=False, solver_type='dpmsolver'):
|
596 |
+
"""
|
597 |
+
Singlestep solver DPM-Solver-2 from time `s` to time `t`.
|
598 |
+
|
599 |
+
Args:
|
600 |
+
x: A pytorch tensor. The initial value at time `s`.
|
601 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
602 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
603 |
+
r1: A `float`. The hyperparameter of the second-order solver.
|
604 |
+
model_s: A pytorch tensor. The model function evaluated at time `s`.
|
605 |
+
If `model_s` is None, we evaluate the model by `x` and `s`; otherwise we directly use it.
|
606 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s` and `s1` (the intermediate time).
|
607 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
608 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
609 |
+
Returns:
|
610 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
611 |
+
"""
|
612 |
+
if solver_type not in ['dpmsolver', 'taylor']:
|
613 |
+
raise ValueError("'solver_type' must be either 'dpmsolver' or 'taylor', got {}".format(solver_type))
|
614 |
+
if r1 is None:
|
615 |
+
r1 = 0.5
|
616 |
+
ns = self.noise_schedule
|
617 |
+
lambda_s, lambda_t = ns.marginal_lambda(s), ns.marginal_lambda(t)
|
618 |
+
h = lambda_t - lambda_s
|
619 |
+
lambda_s1 = lambda_s + r1 * h
|
620 |
+
s1 = ns.inverse_lambda(lambda_s1)
|
621 |
+
log_alpha_s, log_alpha_s1, log_alpha_t = ns.marginal_log_mean_coeff(s), ns.marginal_log_mean_coeff(s1), ns.marginal_log_mean_coeff(t)
|
622 |
+
sigma_s, sigma_s1, sigma_t = ns.marginal_std(s), ns.marginal_std(s1), ns.marginal_std(t)
|
623 |
+
alpha_s1, alpha_t = torch.exp(log_alpha_s1), torch.exp(log_alpha_t)
|
624 |
+
|
625 |
+
if self.algorithm_type == "dpmsolver++":
|
626 |
+
phi_11 = torch.expm1(-r1 * h)
|
627 |
+
phi_1 = torch.expm1(-h)
|
628 |
+
|
629 |
+
if model_s is None:
|
630 |
+
model_s = self.model_fn(x, s)
|
631 |
+
x_s1 = (
|
632 |
+
(sigma_s1 / sigma_s) * x
|
633 |
+
- (alpha_s1 * phi_11) * model_s
|
634 |
+
)
|
635 |
+
model_s1 = self.model_fn(x_s1, s1)
|
636 |
+
if solver_type == 'dpmsolver':
|
637 |
+
x_t = (
|
638 |
+
(sigma_t / sigma_s) * x
|
639 |
+
- (alpha_t * phi_1) * model_s
|
640 |
+
- (0.5 / r1) * (alpha_t * phi_1) * (model_s1 - model_s)
|
641 |
+
)
|
642 |
+
elif solver_type == 'taylor':
|
643 |
+
x_t = (
|
644 |
+
(sigma_t / sigma_s) * x
|
645 |
+
- (alpha_t * phi_1) * model_s
|
646 |
+
+ (1. / r1) * (alpha_t * (phi_1 / h + 1.)) * (model_s1 - model_s)
|
647 |
+
)
|
648 |
+
else:
|
649 |
+
phi_11 = torch.expm1(r1 * h)
|
650 |
+
phi_1 = torch.expm1(h)
|
651 |
+
|
652 |
+
if model_s is None:
|
653 |
+
model_s = self.model_fn(x, s)
|
654 |
+
x_s1 = (
|
655 |
+
torch.exp(log_alpha_s1 - log_alpha_s) * x
|
656 |
+
- (sigma_s1 * phi_11) * model_s
|
657 |
+
)
|
658 |
+
model_s1 = self.model_fn(x_s1, s1)
|
659 |
+
if solver_type == 'dpmsolver':
|
660 |
+
x_t = (
|
661 |
+
torch.exp(log_alpha_t - log_alpha_s) * x
|
662 |
+
- (sigma_t * phi_1) * model_s
|
663 |
+
- (0.5 / r1) * (sigma_t * phi_1) * (model_s1 - model_s)
|
664 |
+
)
|
665 |
+
elif solver_type == 'taylor':
|
666 |
+
x_t = (
|
667 |
+
torch.exp(log_alpha_t - log_alpha_s) * x
|
668 |
+
- (sigma_t * phi_1) * model_s
|
669 |
+
- (1. / r1) * (sigma_t * (phi_1 / h - 1.)) * (model_s1 - model_s)
|
670 |
+
)
|
671 |
+
if return_intermediate:
|
672 |
+
return x_t, {'model_s': model_s, 'model_s1': model_s1}
|
673 |
+
else:
|
674 |
+
return x_t
|
675 |
+
|
676 |
+
def singlestep_dpm_solver_third_update(self, x, s, t, r1=1./3., r2=2./3., model_s=None, model_s1=None, return_intermediate=False, solver_type='dpmsolver'):
|
677 |
+
"""
|
678 |
+
Singlestep solver DPM-Solver-3 from time `s` to time `t`.
|
679 |
+
|
680 |
+
Args:
|
681 |
+
x: A pytorch tensor. The initial value at time `s`.
|
682 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
683 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
684 |
+
r1: A `float`. The hyperparameter of the third-order solver.
|
685 |
+
r2: A `float`. The hyperparameter of the third-order solver.
|
686 |
+
model_s: A pytorch tensor. The model function evaluated at time `s`.
|
687 |
+
If `model_s` is None, we evaluate the model by `x` and `s`; otherwise we directly use it.
|
688 |
+
model_s1: A pytorch tensor. The model function evaluated at time `s1` (the intermediate time given by `r1`).
|
689 |
+
If `model_s1` is None, we evaluate the model at `s1`; otherwise we directly use it.
|
690 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s`, `s1` and `s2` (the intermediate times).
|
691 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
692 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
693 |
+
Returns:
|
694 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
695 |
+
"""
|
696 |
+
if solver_type not in ['dpmsolver', 'taylor']:
|
697 |
+
raise ValueError("'solver_type' must be either 'dpmsolver' or 'taylor', got {}".format(solver_type))
|
698 |
+
if r1 is None:
|
699 |
+
r1 = 1. / 3.
|
700 |
+
if r2 is None:
|
701 |
+
r2 = 2. / 3.
|
702 |
+
ns = self.noise_schedule
|
703 |
+
lambda_s, lambda_t = ns.marginal_lambda(s), ns.marginal_lambda(t)
|
704 |
+
h = lambda_t - lambda_s
|
705 |
+
lambda_s1 = lambda_s + r1 * h
|
706 |
+
lambda_s2 = lambda_s + r2 * h
|
707 |
+
s1 = ns.inverse_lambda(lambda_s1)
|
708 |
+
s2 = ns.inverse_lambda(lambda_s2)
|
709 |
+
log_alpha_s, log_alpha_s1, log_alpha_s2, log_alpha_t = ns.marginal_log_mean_coeff(s), ns.marginal_log_mean_coeff(s1), ns.marginal_log_mean_coeff(s2), ns.marginal_log_mean_coeff(t)
|
710 |
+
sigma_s, sigma_s1, sigma_s2, sigma_t = ns.marginal_std(s), ns.marginal_std(s1), ns.marginal_std(s2), ns.marginal_std(t)
|
711 |
+
alpha_s1, alpha_s2, alpha_t = torch.exp(log_alpha_s1), torch.exp(log_alpha_s2), torch.exp(log_alpha_t)
|
712 |
+
|
713 |
+
if self.algorithm_type == "dpmsolver++":
|
714 |
+
phi_11 = torch.expm1(-r1 * h)
|
715 |
+
phi_12 = torch.expm1(-r2 * h)
|
716 |
+
phi_1 = torch.expm1(-h)
|
717 |
+
phi_22 = torch.expm1(-r2 * h) / (r2 * h) + 1.
|
718 |
+
phi_2 = phi_1 / h + 1.
|
719 |
+
phi_3 = phi_2 / h - 0.5
|
720 |
+
|
721 |
+
if model_s is None:
|
722 |
+
model_s = self.model_fn(x, s)
|
723 |
+
if model_s1 is None:
|
724 |
+
x_s1 = (
|
725 |
+
(sigma_s1 / sigma_s) * x
|
726 |
+
- (alpha_s1 * phi_11) * model_s
|
727 |
+
)
|
728 |
+
model_s1 = self.model_fn(x_s1, s1)
|
729 |
+
x_s2 = (
|
730 |
+
(sigma_s2 / sigma_s) * x
|
731 |
+
- (alpha_s2 * phi_12) * model_s
|
732 |
+
+ r2 / r1 * (alpha_s2 * phi_22) * (model_s1 - model_s)
|
733 |
+
)
|
734 |
+
model_s2 = self.model_fn(x_s2, s2)
|
735 |
+
if solver_type == 'dpmsolver':
|
736 |
+
x_t = (
|
737 |
+
(sigma_t / sigma_s) * x
|
738 |
+
- (alpha_t * phi_1) * model_s
|
739 |
+
+ (1. / r2) * (alpha_t * phi_2) * (model_s2 - model_s)
|
740 |
+
)
|
741 |
+
elif solver_type == 'taylor':
|
742 |
+
D1_0 = (1. / r1) * (model_s1 - model_s)
|
743 |
+
D1_1 = (1. / r2) * (model_s2 - model_s)
|
744 |
+
D1 = (r2 * D1_0 - r1 * D1_1) / (r2 - r1)
|
745 |
+
D2 = 2. * (D1_1 - D1_0) / (r2 - r1)
|
746 |
+
x_t = (
|
747 |
+
(sigma_t / sigma_s) * x
|
748 |
+
- (alpha_t * phi_1) * model_s
|
749 |
+
+ (alpha_t * phi_2) * D1
|
750 |
+
- (alpha_t * phi_3) * D2
|
751 |
+
)
|
752 |
+
else:
|
753 |
+
phi_11 = torch.expm1(r1 * h)
|
754 |
+
phi_12 = torch.expm1(r2 * h)
|
755 |
+
phi_1 = torch.expm1(h)
|
756 |
+
phi_22 = torch.expm1(r2 * h) / (r2 * h) - 1.
|
757 |
+
phi_2 = phi_1 / h - 1.
|
758 |
+
phi_3 = phi_2 / h - 0.5
|
759 |
+
|
760 |
+
if model_s is None:
|
761 |
+
model_s = self.model_fn(x, s)
|
762 |
+
if model_s1 is None:
|
763 |
+
x_s1 = (
|
764 |
+
(torch.exp(log_alpha_s1 - log_alpha_s)) * x
|
765 |
+
- (sigma_s1 * phi_11) * model_s
|
766 |
+
)
|
767 |
+
model_s1 = self.model_fn(x_s1, s1)
|
768 |
+
x_s2 = (
|
769 |
+
(torch.exp(log_alpha_s2 - log_alpha_s)) * x
|
770 |
+
- (sigma_s2 * phi_12) * model_s
|
771 |
+
- r2 / r1 * (sigma_s2 * phi_22) * (model_s1 - model_s)
|
772 |
+
)
|
773 |
+
model_s2 = self.model_fn(x_s2, s2)
|
774 |
+
if solver_type == 'dpmsolver':
|
775 |
+
x_t = (
|
776 |
+
(torch.exp(log_alpha_t - log_alpha_s)) * x
|
777 |
+
- (sigma_t * phi_1) * model_s
|
778 |
+
- (1. / r2) * (sigma_t * phi_2) * (model_s2 - model_s)
|
779 |
+
)
|
780 |
+
elif solver_type == 'taylor':
|
781 |
+
D1_0 = (1. / r1) * (model_s1 - model_s)
|
782 |
+
D1_1 = (1. / r2) * (model_s2 - model_s)
|
783 |
+
D1 = (r2 * D1_0 - r1 * D1_1) / (r2 - r1)
|
784 |
+
D2 = 2. * (D1_1 - D1_0) / (r2 - r1)
|
785 |
+
x_t = (
|
786 |
+
(torch.exp(log_alpha_t - log_alpha_s)) * x
|
787 |
+
- (sigma_t * phi_1) * model_s
|
788 |
+
- (sigma_t * phi_2) * D1
|
789 |
+
- (sigma_t * phi_3) * D2
|
790 |
+
)
|
791 |
+
|
792 |
+
if return_intermediate:
|
793 |
+
return x_t, {'model_s': model_s, 'model_s1': model_s1, 'model_s2': model_s2}
|
794 |
+
else:
|
795 |
+
return x_t
|
796 |
+
|
797 |
+
def multistep_dpm_solver_second_update(self, x, model_prev_list, t_prev_list, t, solver_type="dpmsolver"):
|
798 |
+
"""
|
799 |
+
Multistep solver DPM-Solver-2 from time `t_prev_list[-1]` to time `t`.
|
800 |
+
|
801 |
+
Args:
|
802 |
+
x: A pytorch tensor. The initial value at time `s`.
|
803 |
+
model_prev_list: A list of pytorch tensor. The previous computed model values.
|
804 |
+
t_prev_list: A list of pytorch tensor. The previous times, each time has the shape (1,)
|
805 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
806 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
807 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
808 |
+
Returns:
|
809 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
810 |
+
"""
|
811 |
+
if solver_type not in ['dpmsolver', 'taylor']:
|
812 |
+
raise ValueError("'solver_type' must be either 'dpmsolver' or 'taylor', got {}".format(solver_type))
|
813 |
+
ns = self.noise_schedule
|
814 |
+
model_prev_1, model_prev_0 = model_prev_list[-2], model_prev_list[-1]
|
815 |
+
t_prev_1, t_prev_0 = t_prev_list[-2], t_prev_list[-1]
|
816 |
+
lambda_prev_1, lambda_prev_0, lambda_t = ns.marginal_lambda(t_prev_1), ns.marginal_lambda(t_prev_0), ns.marginal_lambda(t)
|
817 |
+
log_alpha_prev_0, log_alpha_t = ns.marginal_log_mean_coeff(t_prev_0), ns.marginal_log_mean_coeff(t)
|
818 |
+
sigma_prev_0, sigma_t = ns.marginal_std(t_prev_0), ns.marginal_std(t)
|
819 |
+
alpha_t = torch.exp(log_alpha_t)
|
820 |
+
|
821 |
+
h_0 = lambda_prev_0 - lambda_prev_1
|
822 |
+
h = lambda_t - lambda_prev_0
|
823 |
+
r0 = h_0 / h
|
824 |
+
D1_0 = (1. / r0) * (model_prev_0 - model_prev_1)
|
825 |
+
if self.algorithm_type == "dpmsolver++":
|
826 |
+
phi_1 = torch.expm1(-h)
|
827 |
+
if solver_type == 'dpmsolver':
|
828 |
+
x_t = (
|
829 |
+
(sigma_t / sigma_prev_0) * x
|
830 |
+
- (alpha_t * phi_1) * model_prev_0
|
831 |
+
- 0.5 * (alpha_t * phi_1) * D1_0
|
832 |
+
)
|
833 |
+
elif solver_type == 'taylor':
|
834 |
+
x_t = (
|
835 |
+
(sigma_t / sigma_prev_0) * x
|
836 |
+
- (alpha_t * phi_1) * model_prev_0
|
837 |
+
+ (alpha_t * (phi_1 / h + 1.)) * D1_0
|
838 |
+
)
|
839 |
+
else:
|
840 |
+
phi_1 = torch.expm1(h)
|
841 |
+
if solver_type == 'dpmsolver':
|
842 |
+
x_t = (
|
843 |
+
(torch.exp(log_alpha_t - log_alpha_prev_0)) * x
|
844 |
+
- (sigma_t * phi_1) * model_prev_0
|
845 |
+
- 0.5 * (sigma_t * phi_1) * D1_0
|
846 |
+
)
|
847 |
+
elif solver_type == 'taylor':
|
848 |
+
x_t = (
|
849 |
+
(torch.exp(log_alpha_t - log_alpha_prev_0)) * x
|
850 |
+
- (sigma_t * phi_1) * model_prev_0
|
851 |
+
- (sigma_t * (phi_1 / h - 1.)) * D1_0
|
852 |
+
)
|
853 |
+
return x_t
|
854 |
+
|
855 |
+
def multistep_dpm_solver_third_update(self, x, model_prev_list, t_prev_list, t, solver_type='dpmsolver'):
|
856 |
+
"""
|
857 |
+
Multistep solver DPM-Solver-3 from time `t_prev_list[-1]` to time `t`.
|
858 |
+
|
859 |
+
Args:
|
860 |
+
x: A pytorch tensor. The initial value at time `s`.
|
861 |
+
model_prev_list: A list of pytorch tensor. The previous computed model values.
|
862 |
+
t_prev_list: A list of pytorch tensor. The previous times, each time has the shape (1,)
|
863 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
864 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
865 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
866 |
+
Returns:
|
867 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
868 |
+
"""
|
869 |
+
ns = self.noise_schedule
|
870 |
+
model_prev_2, model_prev_1, model_prev_0 = model_prev_list
|
871 |
+
t_prev_2, t_prev_1, t_prev_0 = t_prev_list
|
872 |
+
lambda_prev_2, lambda_prev_1, lambda_prev_0, lambda_t = ns.marginal_lambda(t_prev_2), ns.marginal_lambda(t_prev_1), ns.marginal_lambda(t_prev_0), ns.marginal_lambda(t)
|
873 |
+
log_alpha_prev_0, log_alpha_t = ns.marginal_log_mean_coeff(t_prev_0), ns.marginal_log_mean_coeff(t)
|
874 |
+
sigma_prev_0, sigma_t = ns.marginal_std(t_prev_0), ns.marginal_std(t)
|
875 |
+
alpha_t = torch.exp(log_alpha_t)
|
876 |
+
|
877 |
+
h_1 = lambda_prev_1 - lambda_prev_2
|
878 |
+
h_0 = lambda_prev_0 - lambda_prev_1
|
879 |
+
h = lambda_t - lambda_prev_0
|
880 |
+
r0, r1 = h_0 / h, h_1 / h
|
881 |
+
D1_0 = (1. / r0) * (model_prev_0 - model_prev_1)
|
882 |
+
D1_1 = (1. / r1) * (model_prev_1 - model_prev_2)
|
883 |
+
D1 = D1_0 + (r0 / (r0 + r1)) * (D1_0 - D1_1)
|
884 |
+
D2 = (1. / (r0 + r1)) * (D1_0 - D1_1)
|
885 |
+
if self.algorithm_type == "dpmsolver++":
|
886 |
+
phi_1 = torch.expm1(-h)
|
887 |
+
phi_2 = phi_1 / h + 1.
|
888 |
+
phi_3 = phi_2 / h - 0.5
|
889 |
+
x_t = (
|
890 |
+
(sigma_t / sigma_prev_0) * x
|
891 |
+
- (alpha_t * phi_1) * model_prev_0
|
892 |
+
+ (alpha_t * phi_2) * D1
|
893 |
+
- (alpha_t * phi_3) * D2
|
894 |
+
)
|
895 |
+
else:
|
896 |
+
phi_1 = torch.expm1(h)
|
897 |
+
phi_2 = phi_1 / h - 1.
|
898 |
+
phi_3 = phi_2 / h - 0.5
|
899 |
+
x_t = (
|
900 |
+
(torch.exp(log_alpha_t - log_alpha_prev_0)) * x
|
901 |
+
- (sigma_t * phi_1) * model_prev_0
|
902 |
+
- (sigma_t * phi_2) * D1
|
903 |
+
- (sigma_t * phi_3) * D2
|
904 |
+
)
|
905 |
+
return x_t
|
906 |
+
|
907 |
+
def singlestep_dpm_solver_update(self, x, s, t, order, return_intermediate=False, solver_type='dpmsolver', r1=None, r2=None):
|
908 |
+
"""
|
909 |
+
Singlestep DPM-Solver with the order `order` from time `s` to time `t`.
|
910 |
+
|
911 |
+
Args:
|
912 |
+
x: A pytorch tensor. The initial value at time `s`.
|
913 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
914 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
915 |
+
order: A `int`. The order of DPM-Solver. We only support order == 1 or 2 or 3.
|
916 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s`, `s1` and `s2` (the intermediate times).
|
917 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
918 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
919 |
+
r1: A `float`. The hyperparameter of the second-order or third-order solver.
|
920 |
+
r2: A `float`. The hyperparameter of the third-order solver.
|
921 |
+
Returns:
|
922 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
923 |
+
"""
|
924 |
+
if order == 1:
|
925 |
+
return self.dpm_solver_first_update(x, s, t, return_intermediate=return_intermediate)
|
926 |
+
elif order == 2:
|
927 |
+
return self.singlestep_dpm_solver_second_update(x, s, t, return_intermediate=return_intermediate, solver_type=solver_type, r1=r1)
|
928 |
+
elif order == 3:
|
929 |
+
return self.singlestep_dpm_solver_third_update(x, s, t, return_intermediate=return_intermediate, solver_type=solver_type, r1=r1, r2=r2)
|
930 |
+
else:
|
931 |
+
raise ValueError("Solver order must be 1 or 2 or 3, got {}".format(order))
|
932 |
+
|
933 |
+
def multistep_dpm_solver_update(self, x, model_prev_list, t_prev_list, t, order, solver_type='dpmsolver'):
|
934 |
+
"""
|
935 |
+
Multistep DPM-Solver with the order `order` from time `t_prev_list[-1]` to time `t`.
|
936 |
+
|
937 |
+
Args:
|
938 |
+
x: A pytorch tensor. The initial value at time `s`.
|
939 |
+
model_prev_list: A list of pytorch tensor. The previous computed model values.
|
940 |
+
t_prev_list: A list of pytorch tensor. The previous times, each time has the shape (1,)
|
941 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
942 |
+
order: A `int`. The order of DPM-Solver. We only support order == 1 or 2 or 3.
|
943 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
944 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
945 |
+
Returns:
|
946 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
947 |
+
"""
|
948 |
+
if order == 1:
|
949 |
+
return self.dpm_solver_first_update(x, t_prev_list[-1], t, model_s=model_prev_list[-1])
|
950 |
+
elif order == 2:
|
951 |
+
return self.multistep_dpm_solver_second_update(x, model_prev_list, t_prev_list, t, solver_type=solver_type)
|
952 |
+
elif order == 3:
|
953 |
+
return self.multistep_dpm_solver_third_update(x, model_prev_list, t_prev_list, t, solver_type=solver_type)
|
954 |
+
else:
|
955 |
+
raise ValueError("Solver order must be 1 or 2 or 3, got {}".format(order))
|
956 |
+
|
957 |
+
def dpm_solver_adaptive(self, x, order, t_T, t_0, h_init=0.05, atol=0.0078, rtol=0.05, theta=0.9, t_err=1e-5, solver_type='dpmsolver'):
|
958 |
+
"""
|
959 |
+
The adaptive step size solver based on singlestep DPM-Solver.
|
960 |
+
|
961 |
+
Args:
|
962 |
+
x: A pytorch tensor. The initial value at time `t_T`.
|
963 |
+
order: A `int`. The (higher) order of the solver. We only support order == 2 or 3.
|
964 |
+
t_T: A `float`. The starting time of the sampling (default is T).
|
965 |
+
t_0: A `float`. The ending time of the sampling (default is epsilon).
|
966 |
+
h_init: A `float`. The initial step size (for logSNR).
|
967 |
+
atol: A `float`. The absolute tolerance of the solver. For image data, the default setting is 0.0078, followed [1].
|
968 |
+
rtol: A `float`. The relative tolerance of the solver. The default setting is 0.05.
|
969 |
+
theta: A `float`. The safety hyperparameter for adapting the step size. The default setting is 0.9, followed [1].
|
970 |
+
t_err: A `float`. The tolerance for the time. We solve the diffusion ODE until the absolute error between the
|
971 |
+
current time and `t_0` is less than `t_err`. The default setting is 1e-5.
|
972 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
973 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
974 |
+
Returns:
|
975 |
+
x_0: A pytorch tensor. The approximated solution at time `t_0`.
|
976 |
+
|
977 |
+
[1] A. Jolicoeur-Martineau, K. Li, R. Piché-Taillefer, T. Kachman, and I. Mitliagkas, "Gotta go fast when generating data with score-based models," arXiv preprint arXiv:2105.14080, 2021.
|
978 |
+
"""
|
979 |
+
ns = self.noise_schedule
|
980 |
+
s = t_T * torch.ones((1,)).to(x)
|
981 |
+
lambda_s = ns.marginal_lambda(s)
|
982 |
+
lambda_0 = ns.marginal_lambda(t_0 * torch.ones_like(s).to(x))
|
983 |
+
h = h_init * torch.ones_like(s).to(x)
|
984 |
+
x_prev = x
|
985 |
+
nfe = 0
|
986 |
+
if order == 2:
|
987 |
+
r1 = 0.5
|
988 |
+
lower_update = lambda x, s, t: self.dpm_solver_first_update(x, s, t, return_intermediate=True)
|
989 |
+
higher_update = lambda x, s, t, **kwargs: self.singlestep_dpm_solver_second_update(x, s, t, r1=r1, solver_type=solver_type, **kwargs)
|
990 |
+
elif order == 3:
|
991 |
+
r1, r2 = 1. / 3., 2. / 3.
|
992 |
+
lower_update = lambda x, s, t: self.singlestep_dpm_solver_second_update(x, s, t, r1=r1, return_intermediate=True, solver_type=solver_type)
|
993 |
+
higher_update = lambda x, s, t, **kwargs: self.singlestep_dpm_solver_third_update(x, s, t, r1=r1, r2=r2, solver_type=solver_type, **kwargs)
|
994 |
+
else:
|
995 |
+
raise ValueError("For adaptive step size solver, order must be 2 or 3, got {}".format(order))
|
996 |
+
while torch.abs((s - t_0)).mean() > t_err:
|
997 |
+
t = ns.inverse_lambda(lambda_s + h)
|
998 |
+
x_lower, lower_noise_kwargs = lower_update(x, s, t)
|
999 |
+
x_higher = higher_update(x, s, t, **lower_noise_kwargs)
|
1000 |
+
delta = torch.max(torch.ones_like(x).to(x) * atol, rtol * torch.max(torch.abs(x_lower), torch.abs(x_prev)))
|
1001 |
+
norm_fn = lambda v: torch.sqrt(torch.square(v.reshape((v.shape[0], -1))).mean(dim=-1, keepdim=True))
|
1002 |
+
E = norm_fn((x_higher - x_lower) / delta).max()
|
1003 |
+
if torch.all(E <= 1.):
|
1004 |
+
x = x_higher
|
1005 |
+
s = t
|
1006 |
+
x_prev = x_lower
|
1007 |
+
lambda_s = ns.marginal_lambda(s)
|
1008 |
+
h = torch.min(theta * h * torch.float_power(E, -1. / order).float(), lambda_0 - lambda_s)
|
1009 |
+
nfe += order
|
1010 |
+
print('adaptive solver nfe', nfe)
|
1011 |
+
return x
|
1012 |
+
|
1013 |
+
def add_noise(self, x, t, noise=None):
|
1014 |
+
"""
|
1015 |
+
Compute the noised input xt = alpha_t * x + sigma_t * noise.
|
1016 |
+
|
1017 |
+
Args:
|
1018 |
+
x: A `torch.Tensor` with shape `(batch_size, *shape)`.
|
1019 |
+
t: A `torch.Tensor` with shape `(t_size,)`.
|
1020 |
+
Returns:
|
1021 |
+
xt with shape `(t_size, batch_size, *shape)`.
|
1022 |
+
"""
|
1023 |
+
alpha_t, sigma_t = self.noise_schedule.marginal_alpha(t), self.noise_schedule.marginal_std(t)
|
1024 |
+
if noise is None:
|
1025 |
+
noise = torch.randn((t.shape[0], *x.shape), device=x.device)
|
1026 |
+
x = x.reshape((-1, *x.shape))
|
1027 |
+
xt = expand_dims(alpha_t, x.dim()) * x + expand_dims(sigma_t, x.dim()) * noise
|
1028 |
+
if t.shape[0] == 1:
|
1029 |
+
return xt.squeeze(0)
|
1030 |
+
else:
|
1031 |
+
return xt
|
1032 |
+
|
1033 |
+
def inverse(self, x, steps=20, t_start=None, t_end=None, order=2, skip_type='time_uniform',
|
1034 |
+
method='multistep', lower_order_final=True, denoise_to_zero=False, solver_type='dpmsolver',
|
1035 |
+
atol=0.0078, rtol=0.05, return_intermediate=False,
|
1036 |
+
):
|
1037 |
+
"""
|
1038 |
+
Inverse the sample `x` from time `t_start` to `t_end` by DPM-Solver.
|
1039 |
+
For discrete-time DPMs, we use `t_start=1/N`, where `N` is the total time steps during training.
|
1040 |
+
"""
|
1041 |
+
t_0 = 1. / self.noise_schedule.total_N if t_start is None else t_start
|
1042 |
+
t_T = self.noise_schedule.T if t_end is None else t_end
|
1043 |
+
assert t_0 > 0 and t_T > 0, "Time range needs to be greater than 0. For discrete-time DPMs, it needs to be in [1 / N, 1], where N is the length of betas array"
|
1044 |
+
return self.sample(x, steps=steps, t_start=t_0, t_end=t_T, order=order, skip_type=skip_type,
|
1045 |
+
method=method, lower_order_final=lower_order_final, denoise_to_zero=denoise_to_zero, solver_type=solver_type,
|
1046 |
+
atol=atol, rtol=rtol, return_intermediate=return_intermediate)
|
1047 |
+
|
1048 |
+
def sample(self, x, steps=20, t_start=None, t_end=None, order=2, skip_type='time_uniform',
|
1049 |
+
method='multistep', lower_order_final=True, denoise_to_zero=False, solver_type='dpmsolver',
|
1050 |
+
atol=0.0078, rtol=0.05, return_intermediate=False,
|
1051 |
+
):
|
1052 |
+
"""
|
1053 |
+
Compute the sample at time `t_end` by DPM-Solver, given the initial `x` at time `t_start`.
|
1054 |
+
|
1055 |
+
=====================================================
|
1056 |
+
|
1057 |
+
We support the following algorithms for both noise prediction model and data prediction model:
|
1058 |
+
- 'singlestep':
|
1059 |
+
Singlestep DPM-Solver (i.e. "DPM-Solver-fast" in the paper), which combines different orders of singlestep DPM-Solver.
|
1060 |
+
We combine all the singlestep solvers with order <= `order` to use up all the function evaluations (steps).
|
1061 |
+
The total number of function evaluations (NFE) == `steps`.
|
1062 |
+
Given a fixed NFE == `steps`, the sampling procedure is:
|
1063 |
+
- If `order` == 1:
|
1064 |
+
- Denote K = steps. We use K steps of DPM-Solver-1 (i.e. DDIM).
|
1065 |
+
- If `order` == 2:
|
1066 |
+
- Denote K = (steps // 2) + (steps % 2). We take K intermediate time steps for sampling.
|
1067 |
+
- If steps % 2 == 0, we use K steps of singlestep DPM-Solver-2.
|
1068 |
+
- If steps % 2 == 1, we use (K - 1) steps of singlestep DPM-Solver-2 and 1 step of DPM-Solver-1.
|
1069 |
+
- If `order` == 3:
|
1070 |
+
- Denote K = (steps // 3 + 1). We take K intermediate time steps for sampling.
|
1071 |
+
- If steps % 3 == 0, we use (K - 2) steps of singlestep DPM-Solver-3, and 1 step of singlestep DPM-Solver-2 and 1 step of DPM-Solver-1.
|
1072 |
+
- If steps % 3 == 1, we use (K - 1) steps of singlestep DPM-Solver-3 and 1 step of DPM-Solver-1.
|
1073 |
+
- If steps % 3 == 2, we use (K - 1) steps of singlestep DPM-Solver-3 and 1 step of singlestep DPM-Solver-2.
|
1074 |
+
- 'multistep':
|
1075 |
+
Multistep DPM-Solver with the order of `order`. The total number of function evaluations (NFE) == `steps`.
|
1076 |
+
We initialize the first `order` values by lower order multistep solvers.
|
1077 |
+
Given a fixed NFE == `steps`, the sampling procedure is:
|
1078 |
+
Denote K = steps.
|
1079 |
+
- If `order` == 1:
|
1080 |
+
- We use K steps of DPM-Solver-1 (i.e. DDIM).
|
1081 |
+
- If `order` == 2:
|
1082 |
+
- We firstly use 1 step of DPM-Solver-1, then use (K - 1) step of multistep DPM-Solver-2.
|
1083 |
+
- If `order` == 3:
|
1084 |
+
- We firstly use 1 step of DPM-Solver-1, then 1 step of multistep DPM-Solver-2, then (K - 2) step of multistep DPM-Solver-3.
|
1085 |
+
- 'singlestep_fixed':
|
1086 |
+
Fixed order singlestep DPM-Solver (i.e. DPM-Solver-1 or singlestep DPM-Solver-2 or singlestep DPM-Solver-3).
|
1087 |
+
We use singlestep DPM-Solver-`order` for `order`=1 or 2 or 3, with total [`steps` // `order`] * `order` NFE.
|
1088 |
+
- 'adaptive':
|
1089 |
+
Adaptive step size DPM-Solver (i.e. "DPM-Solver-12" and "DPM-Solver-23" in the paper).
|
1090 |
+
We ignore `steps` and use adaptive step size DPM-Solver with a higher order of `order`.
|
1091 |
+
You can adjust the absolute tolerance `atol` and the relative tolerance `rtol` to balance the computatation costs
|
1092 |
+
(NFE) and the sample quality.
|
1093 |
+
- If `order` == 2, we use DPM-Solver-12 which combines DPM-Solver-1 and singlestep DPM-Solver-2.
|
1094 |
+
- If `order` == 3, we use DPM-Solver-23 which combines singlestep DPM-Solver-2 and singlestep DPM-Solver-3.
|
1095 |
+
|
1096 |
+
=====================================================
|
1097 |
+
|
1098 |
+
Some advices for choosing the algorithm:
|
1099 |
+
- For **unconditional sampling** or **guided sampling with small guidance scale** by DPMs:
|
1100 |
+
Use singlestep DPM-Solver or DPM-Solver++ ("DPM-Solver-fast" in the paper) with `order = 3`.
|
1101 |
+
e.g., DPM-Solver:
|
1102 |
+
>>> dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver")
|
1103 |
+
>>> x_sample = dpm_solver.sample(x, steps=steps, t_start=t_start, t_end=t_end, order=3,
|
1104 |
+
skip_type='time_uniform', method='singlestep')
|
1105 |
+
e.g., DPM-Solver++:
|
1106 |
+
>>> dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver++")
|
1107 |
+
>>> x_sample = dpm_solver.sample(x, steps=steps, t_start=t_start, t_end=t_end, order=3,
|
1108 |
+
skip_type='time_uniform', method='singlestep')
|
1109 |
+
- For **guided sampling with large guidance scale** by DPMs:
|
1110 |
+
Use multistep DPM-Solver with `algorithm_type="dpmsolver++"` and `order = 2`.
|
1111 |
+
e.g.
|
1112 |
+
>>> dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver++")
|
1113 |
+
>>> x_sample = dpm_solver.sample(x, steps=steps, t_start=t_start, t_end=t_end, order=2,
|
1114 |
+
skip_type='time_uniform', method='multistep')
|
1115 |
+
|
1116 |
+
We support three types of `skip_type`:
|
1117 |
+
- 'logSNR': uniform logSNR for the time steps. **Recommended for low-resolutional images**
|
1118 |
+
- 'time_uniform': uniform time for the time steps. **Recommended for high-resolutional images**.
|
1119 |
+
- 'time_quadratic': quadratic time for the time steps.
|
1120 |
+
|
1121 |
+
=====================================================
|
1122 |
+
Args:
|
1123 |
+
x: A pytorch tensor. The initial value at time `t_start`
|
1124 |
+
e.g. if `t_start` == T, then `x` is a sample from the standard normal distribution.
|
1125 |
+
steps: A `int`. The total number of function evaluations (NFE).
|
1126 |
+
t_start: A `float`. The starting time of the sampling.
|
1127 |
+
If `T` is None, we use self.noise_schedule.T (default is 1.0).
|
1128 |
+
t_end: A `float`. The ending time of the sampling.
|
1129 |
+
If `t_end` is None, we use 1. / self.noise_schedule.total_N.
|
1130 |
+
e.g. if total_N == 1000, we have `t_end` == 1e-3.
|
1131 |
+
For discrete-time DPMs:
|
1132 |
+
- We recommend `t_end` == 1. / self.noise_schedule.total_N.
|
1133 |
+
For continuous-time DPMs:
|
1134 |
+
- We recommend `t_end` == 1e-3 when `steps` <= 15; and `t_end` == 1e-4 when `steps` > 15.
|
1135 |
+
order: A `int`. The order of DPM-Solver.
|
1136 |
+
skip_type: A `str`. The type for the spacing of the time steps. 'time_uniform' or 'logSNR' or 'time_quadratic'.
|
1137 |
+
method: A `str`. The method for sampling. 'singlestep' or 'multistep' or 'singlestep_fixed' or 'adaptive'.
|
1138 |
+
denoise_to_zero: A `bool`. Whether to denoise to time 0 at the final step.
|
1139 |
+
Default is `False`. If `denoise_to_zero` is `True`, the total NFE is (`steps` + 1).
|
1140 |
+
|
1141 |
+
This trick is firstly proposed by DDPM (https://arxiv.org/abs/2006.11239) and
|
1142 |
+
score_sde (https://arxiv.org/abs/2011.13456). Such trick can improve the FID
|
1143 |
+
for diffusion models sampling by diffusion SDEs for low-resolutional images
|
1144 |
+
(such as CIFAR-10). However, we observed that such trick does not matter for
|
1145 |
+
high-resolutional images. As it needs an additional NFE, we do not recommend
|
1146 |
+
it for high-resolutional images.
|
1147 |
+
lower_order_final: A `bool`. Whether to use lower order solvers at the final steps.
|
1148 |
+
Only valid for `method=multistep` and `steps < 15`. We empirically find that
|
1149 |
+
this trick is a key to stabilizing the sampling by DPM-Solver with very few steps
|
1150 |
+
(especially for steps <= 10). So we recommend to set it to be `True`.
|
1151 |
+
solver_type: A `str`. The taylor expansion type for the solver. `dpmsolver` or `taylor`. We recommend `dpmsolver`.
|
1152 |
+
atol: A `float`. The absolute tolerance of the adaptive step size solver. Valid when `method` == 'adaptive'.
|
1153 |
+
rtol: A `float`. The relative tolerance of the adaptive step size solver. Valid when `method` == 'adaptive'.
|
1154 |
+
return_intermediate: A `bool`. Whether to save the xt at each step.
|
1155 |
+
When set to `True`, method returns a tuple (x0, intermediates); when set to False, method returns only x0.
|
1156 |
+
Returns:
|
1157 |
+
x_end: A pytorch tensor. The approximated solution at time `t_end`.
|
1158 |
+
|
1159 |
+
"""
|
1160 |
+
t_0 = 1. / self.noise_schedule.total_N if t_end is None else t_end
|
1161 |
+
t_T = self.noise_schedule.T if t_start is None else t_start
|
1162 |
+
assert t_0 > 0 and t_T > 0, "Time range needs to be greater than 0. For discrete-time DPMs, it needs to be in [1 / N, 1], where N is the length of betas array"
|
1163 |
+
if return_intermediate:
|
1164 |
+
assert method in ['multistep', 'singlestep', 'singlestep_fixed'], "Cannot use adaptive solver when saving intermediate values"
|
1165 |
+
if self.correcting_xt_fn is not None:
|
1166 |
+
assert method in ['multistep', 'singlestep', 'singlestep_fixed'], "Cannot use adaptive solver when correcting_xt_fn is not None"
|
1167 |
+
device = x.device
|
1168 |
+
intermediates = []
|
1169 |
+
with torch.no_grad():
|
1170 |
+
if method == 'adaptive':
|
1171 |
+
x = self.dpm_solver_adaptive(x, order=order, t_T=t_T, t_0=t_0, atol=atol, rtol=rtol, solver_type=solver_type)
|
1172 |
+
elif method == 'multistep':
|
1173 |
+
assert steps >= order
|
1174 |
+
timesteps = self.get_time_steps(skip_type=skip_type, t_T=t_T, t_0=t_0, N=steps, device=device)
|
1175 |
+
assert timesteps.shape[0] - 1 == steps
|
1176 |
+
# Init the initial values.
|
1177 |
+
step = 0
|
1178 |
+
t = timesteps[step]
|
1179 |
+
t_prev_list = [t]
|
1180 |
+
model_prev_list = [self.model_fn(x, t)]
|
1181 |
+
if self.correcting_xt_fn is not None:
|
1182 |
+
x = self.correcting_xt_fn(x, t, step)
|
1183 |
+
if return_intermediate:
|
1184 |
+
intermediates.append(x)
|
1185 |
+
# Init the first `order` values by lower order multistep DPM-Solver.
|
1186 |
+
for step in range(1, order):
|
1187 |
+
t = timesteps[step]
|
1188 |
+
x = self.multistep_dpm_solver_update(x, model_prev_list, t_prev_list, t, step, solver_type=solver_type)
|
1189 |
+
if self.correcting_xt_fn is not None:
|
1190 |
+
x = self.correcting_xt_fn(x, t, step)
|
1191 |
+
if return_intermediate:
|
1192 |
+
intermediates.append(x)
|
1193 |
+
t_prev_list.append(t)
|
1194 |
+
model_prev_list.append(self.model_fn(x, t))
|
1195 |
+
# Compute the remaining values by `order`-th order multistep DPM-Solver.
|
1196 |
+
for step in range(order, steps + 1):
|
1197 |
+
t = timesteps[step]
|
1198 |
+
# We only use lower order for steps < 10
|
1199 |
+
if lower_order_final and steps < 10:
|
1200 |
+
step_order = min(order, steps + 1 - step)
|
1201 |
+
else:
|
1202 |
+
step_order = order
|
1203 |
+
x = self.multistep_dpm_solver_update(x, model_prev_list, t_prev_list, t, step_order, solver_type=solver_type)
|
1204 |
+
if self.correcting_xt_fn is not None:
|
1205 |
+
x = self.correcting_xt_fn(x, t, step)
|
1206 |
+
if return_intermediate:
|
1207 |
+
intermediates.append(x)
|
1208 |
+
for i in range(order - 1):
|
1209 |
+
t_prev_list[i] = t_prev_list[i + 1]
|
1210 |
+
model_prev_list[i] = model_prev_list[i + 1]
|
1211 |
+
t_prev_list[-1] = t
|
1212 |
+
# We do not need to evaluate the final model value.
|
1213 |
+
if step < steps:
|
1214 |
+
model_prev_list[-1] = self.model_fn(x, t)
|
1215 |
+
elif method in ['singlestep', 'singlestep_fixed']:
|
1216 |
+
if method == 'singlestep':
|
1217 |
+
timesteps_outer, orders = self.get_orders_and_timesteps_for_singlestep_solver(steps=steps, order=order, skip_type=skip_type, t_T=t_T, t_0=t_0, device=device)
|
1218 |
+
elif method == 'singlestep_fixed':
|
1219 |
+
K = steps // order
|
1220 |
+
orders = [order,] * K
|
1221 |
+
timesteps_outer = self.get_time_steps(skip_type=skip_type, t_T=t_T, t_0=t_0, N=K, device=device)
|
1222 |
+
for step, order in enumerate(orders):
|
1223 |
+
s, t = timesteps_outer[step], timesteps_outer[step + 1]
|
1224 |
+
timesteps_inner = self.get_time_steps(skip_type=skip_type, t_T=s.item(), t_0=t.item(), N=order, device=device)
|
1225 |
+
lambda_inner = self.noise_schedule.marginal_lambda(timesteps_inner)
|
1226 |
+
h = lambda_inner[-1] - lambda_inner[0]
|
1227 |
+
r1 = None if order <= 1 else (lambda_inner[1] - lambda_inner[0]) / h
|
1228 |
+
r2 = None if order <= 2 else (lambda_inner[2] - lambda_inner[0]) / h
|
1229 |
+
x = self.singlestep_dpm_solver_update(x, s, t, order, solver_type=solver_type, r1=r1, r2=r2)
|
1230 |
+
if self.correcting_xt_fn is not None:
|
1231 |
+
x = self.correcting_xt_fn(x, t, step)
|
1232 |
+
if return_intermediate:
|
1233 |
+
intermediates.append(x)
|
1234 |
+
else:
|
1235 |
+
raise ValueError("Got wrong method {}".format(method))
|
1236 |
+
if denoise_to_zero:
|
1237 |
+
t = torch.ones((1,)).to(device) * t_0
|
1238 |
+
x = self.denoise_to_zero_fn(x, t)
|
1239 |
+
if self.correcting_xt_fn is not None:
|
1240 |
+
x = self.correcting_xt_fn(x, t, step + 1)
|
1241 |
+
if return_intermediate:
|
1242 |
+
intermediates.append(x)
|
1243 |
+
if return_intermediate:
|
1244 |
+
return x, intermediates
|
1245 |
+
else:
|
1246 |
+
return x
|
1247 |
+
|
1248 |
+
|
1249 |
+
|
1250 |
+
#############################################################
|
1251 |
+
# other utility functions
|
1252 |
+
#############################################################
|
1253 |
+
|
1254 |
+
def interpolate_fn(x, xp, yp):
|
1255 |
+
"""
|
1256 |
+
A piecewise linear function y = f(x), using xp and yp as keypoints.
|
1257 |
+
We implement f(x) in a differentiable way (i.e. applicable for autograd).
|
1258 |
+
The function f(x) is well-defined for all x-axis. (For x beyond the bounds of xp, we use the outmost points of xp to define the linear function.)
|
1259 |
+
|
1260 |
+
Args:
|
1261 |
+
x: PyTorch tensor with shape [N, C], where N is the batch size, C is the number of channels (we use C = 1 for DPM-Solver).
|
1262 |
+
xp: PyTorch tensor with shape [C, K], where K is the number of keypoints.
|
1263 |
+
yp: PyTorch tensor with shape [C, K].
|
1264 |
+
Returns:
|
1265 |
+
The function values f(x), with shape [N, C].
|
1266 |
+
"""
|
1267 |
+
N, K = x.shape[0], xp.shape[1]
|
1268 |
+
all_x = torch.cat([x.unsqueeze(2), xp.unsqueeze(0).repeat((N, 1, 1))], dim=2)
|
1269 |
+
sorted_all_x, x_indices = torch.sort(all_x, dim=2)
|
1270 |
+
x_idx = torch.argmin(x_indices, dim=2)
|
1271 |
+
cand_start_idx = x_idx - 1
|
1272 |
+
start_idx = torch.where(
|
1273 |
+
torch.eq(x_idx, 0),
|
1274 |
+
torch.tensor(1, device=x.device),
|
1275 |
+
torch.where(
|
1276 |
+
torch.eq(x_idx, K), torch.tensor(K - 2, device=x.device), cand_start_idx,
|
1277 |
+
),
|
1278 |
+
)
|
1279 |
+
end_idx = torch.where(torch.eq(start_idx, cand_start_idx), start_idx + 2, start_idx + 1)
|
1280 |
+
start_x = torch.gather(sorted_all_x, dim=2, index=start_idx.unsqueeze(2)).squeeze(2)
|
1281 |
+
end_x = torch.gather(sorted_all_x, dim=2, index=end_idx.unsqueeze(2)).squeeze(2)
|
1282 |
+
start_idx2 = torch.where(
|
1283 |
+
torch.eq(x_idx, 0),
|
1284 |
+
torch.tensor(0, device=x.device),
|
1285 |
+
torch.where(
|
1286 |
+
torch.eq(x_idx, K), torch.tensor(K - 2, device=x.device), cand_start_idx,
|
1287 |
+
),
|
1288 |
+
)
|
1289 |
+
y_positions_expanded = yp.unsqueeze(0).expand(N, -1, -1)
|
1290 |
+
start_y = torch.gather(y_positions_expanded, dim=2, index=start_idx2.unsqueeze(2)).squeeze(2)
|
1291 |
+
end_y = torch.gather(y_positions_expanded, dim=2, index=(start_idx2 + 1).unsqueeze(2)).squeeze(2)
|
1292 |
+
cand = start_y + (x - start_x) * (end_y - start_y) / (end_x - start_x)
|
1293 |
+
return cand
|
1294 |
+
|
1295 |
+
|
1296 |
+
def expand_dims(v, dims):
|
1297 |
+
"""
|
1298 |
+
Expand the tensor `v` to the dim `dims`.
|
1299 |
+
|
1300 |
+
Args:
|
1301 |
+
`v`: a PyTorch tensor with shape [N].
|
1302 |
+
`dim`: a `int`.
|
1303 |
+
Returns:
|
1304 |
+
a PyTorch tensor with shape [N, 1, 1, ..., 1] and the total dimension is `dims`.
|
1305 |
+
"""
|
1306 |
+
return v[(...,) + (None,)*(dims - 1)]
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/dpm_solver_pytorch_no_noise.py
ADDED
@@ -0,0 +1,1306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn.functional as F
|
3 |
+
import math
|
4 |
+
|
5 |
+
|
6 |
+
class NoiseScheduleVP:
|
7 |
+
def __init__(
|
8 |
+
self,
|
9 |
+
schedule='discrete',
|
10 |
+
betas=None,
|
11 |
+
alphas_cumprod=None,
|
12 |
+
continuous_beta_0=0.1,
|
13 |
+
continuous_beta_1=20.,
|
14 |
+
dtype=torch.float32,
|
15 |
+
):
|
16 |
+
"""Create a wrapper class for the forward SDE (VP type).
|
17 |
+
|
18 |
+
***
|
19 |
+
Update: We support discrete-time diffusion models by implementing a picewise linear interpolation for log_alpha_t.
|
20 |
+
We recommend to use schedule='discrete' for the discrete-time diffusion models, especially for high-resolution images.
|
21 |
+
***
|
22 |
+
|
23 |
+
The forward SDE ensures that the condition distribution q_{t|0}(x_t | x_0) = N ( alpha_t * x_0, sigma_t^2 * I ).
|
24 |
+
We further define lambda_t = log(alpha_t) - log(sigma_t), which is the half-logSNR (described in the DPM-Solver paper).
|
25 |
+
Therefore, we implement the functions for computing alpha_t, sigma_t and lambda_t. For t in [0, T], we have:
|
26 |
+
|
27 |
+
log_alpha_t = self.marginal_log_mean_coeff(t)
|
28 |
+
sigma_t = self.marginal_std(t)
|
29 |
+
lambda_t = self.marginal_lambda(t)
|
30 |
+
|
31 |
+
Moreover, as lambda(t) is an invertible function, we also support its inverse function:
|
32 |
+
|
33 |
+
t = self.inverse_lambda(lambda_t)
|
34 |
+
|
35 |
+
===============================================================
|
36 |
+
|
37 |
+
We support both discrete-time DPMs (trained on n = 0, 1, ..., N-1) and continuous-time DPMs (trained on t in [t_0, T]).
|
38 |
+
|
39 |
+
1. For discrete-time DPMs:
|
40 |
+
|
41 |
+
For discrete-time DPMs trained on n = 0, 1, ..., N-1, we convert the discrete steps to continuous time steps by:
|
42 |
+
t_i = (i + 1) / N
|
43 |
+
e.g. for N = 1000, we have t_0 = 1e-3 and T = t_{N-1} = 1.
|
44 |
+
We solve the corresponding diffusion ODE from time T = 1 to time t_0 = 1e-3.
|
45 |
+
|
46 |
+
Args:
|
47 |
+
betas: A `torch.Tensor`. The beta array for the discrete-time DPM. (See the original DDPM paper for details)
|
48 |
+
alphas_cumprod: A `torch.Tensor`. The cumprod alphas for the discrete-time DPM. (See the original DDPM paper for details)
|
49 |
+
|
50 |
+
Note that we always have alphas_cumprod = cumprod(1 - betas). Therefore, we only need to set one of `betas` and `alphas_cumprod`.
|
51 |
+
|
52 |
+
**Important**: Please pay special attention for the args for `alphas_cumprod`:
|
53 |
+
The `alphas_cumprod` is the \hat{alpha_n} arrays in the notations of DDPM. Specifically, DDPMs assume that
|
54 |
+
q_{t_n | 0}(x_{t_n} | x_0) = N ( \sqrt{\hat{alpha_n}} * x_0, (1 - \hat{alpha_n}) * I ).
|
55 |
+
Therefore, the notation \hat{alpha_n} is different from the notation alpha_t in DPM-Solver. In fact, we have
|
56 |
+
alpha_{t_n} = \sqrt{\hat{alpha_n}},
|
57 |
+
and
|
58 |
+
log(alpha_{t_n}) = 0.5 * log(\hat{alpha_n}).
|
59 |
+
|
60 |
+
|
61 |
+
2. For continuous-time DPMs:
|
62 |
+
|
63 |
+
We support the linear VPSDE for the continuous time setting. The hyperparameters for the noise
|
64 |
+
schedule are the default settings in Yang Song's ScoreSDE:
|
65 |
+
|
66 |
+
Args:
|
67 |
+
beta_min: A `float` number. The smallest beta for the linear schedule.
|
68 |
+
beta_max: A `float` number. The largest beta for the linear schedule.
|
69 |
+
T: A `float` number. The ending time of the forward process.
|
70 |
+
|
71 |
+
===============================================================
|
72 |
+
|
73 |
+
Args:
|
74 |
+
schedule: A `str`. The noise schedule of the forward SDE. 'discrete' for discrete-time DPMs,
|
75 |
+
'linear' for continuous-time DPMs.
|
76 |
+
Returns:
|
77 |
+
A wrapper object of the forward SDE (VP type).
|
78 |
+
|
79 |
+
===============================================================
|
80 |
+
|
81 |
+
Example:
|
82 |
+
|
83 |
+
# For discrete-time DPMs, given betas (the beta array for n = 0, 1, ..., N - 1):
|
84 |
+
>>> ns = NoiseScheduleVP('discrete', betas=betas)
|
85 |
+
|
86 |
+
# For discrete-time DPMs, given alphas_cumprod (the \hat{alpha_n} array for n = 0, 1, ..., N - 1):
|
87 |
+
>>> ns = NoiseScheduleVP('discrete', alphas_cumprod=alphas_cumprod)
|
88 |
+
|
89 |
+
# For continuous-time DPMs (VPSDE), linear schedule:
|
90 |
+
>>> ns = NoiseScheduleVP('linear', continuous_beta_0=0.1, continuous_beta_1=20.)
|
91 |
+
|
92 |
+
"""
|
93 |
+
|
94 |
+
if schedule not in ['discrete', 'linear']:
|
95 |
+
raise ValueError("Unsupported noise schedule {}. The schedule needs to be 'discrete' or 'linear'".format(schedule))
|
96 |
+
|
97 |
+
self.schedule = schedule
|
98 |
+
if schedule == 'discrete':
|
99 |
+
if betas is not None:
|
100 |
+
log_alphas = 0.5 * torch.log(1 - betas).cumsum(dim=0)
|
101 |
+
else:
|
102 |
+
assert alphas_cumprod is not None
|
103 |
+
log_alphas = 0.5 * torch.log(alphas_cumprod)
|
104 |
+
self.T = 1.
|
105 |
+
self.log_alpha_array = self.numerical_clip_alpha(log_alphas).reshape((1, -1,)).to(dtype=dtype)
|
106 |
+
self.total_N = self.log_alpha_array.shape[1]
|
107 |
+
self.t_array = torch.linspace(0., 1., self.total_N + 1)[1:].reshape((1, -1)).to(dtype=dtype)
|
108 |
+
else:
|
109 |
+
self.T = 1.
|
110 |
+
self.total_N = 1000
|
111 |
+
self.beta_0 = continuous_beta_0
|
112 |
+
self.beta_1 = continuous_beta_1
|
113 |
+
|
114 |
+
def numerical_clip_alpha(self, log_alphas, clipped_lambda=-5.1):
|
115 |
+
"""
|
116 |
+
For some beta schedules such as cosine schedule, the log-SNR has numerical isssues.
|
117 |
+
We clip the log-SNR near t=T within -5.1 to ensure the stability.
|
118 |
+
Such a trick is very useful for diffusion models with the cosine schedule, such as i-DDPM, guided-diffusion and GLIDE.
|
119 |
+
"""
|
120 |
+
log_sigmas = 0.5 * torch.log(1. - torch.exp(2. * log_alphas))
|
121 |
+
lambs = log_alphas - log_sigmas
|
122 |
+
idx = torch.searchsorted(torch.flip(lambs, [0]), clipped_lambda)
|
123 |
+
if idx > 0:
|
124 |
+
log_alphas = log_alphas[:-idx]
|
125 |
+
return log_alphas
|
126 |
+
|
127 |
+
def marginal_log_mean_coeff(self, t):
|
128 |
+
"""
|
129 |
+
Compute log(alpha_t) of a given continuous-time label t in [0, T].
|
130 |
+
"""
|
131 |
+
if self.schedule == 'discrete':
|
132 |
+
return interpolate_fn(t.reshape((-1, 1)), self.t_array.to(t.device), self.log_alpha_array.to(t.device)).reshape((-1))
|
133 |
+
elif self.schedule == 'linear':
|
134 |
+
return -0.25 * t ** 2 * (self.beta_1 - self.beta_0) - 0.5 * t * self.beta_0
|
135 |
+
|
136 |
+
def marginal_alpha(self, t):
|
137 |
+
"""
|
138 |
+
Compute alpha_t of a given continuous-time label t in [0, T].
|
139 |
+
"""
|
140 |
+
return torch.exp(self.marginal_log_mean_coeff(t))
|
141 |
+
|
142 |
+
def marginal_std(self, t):
|
143 |
+
"""
|
144 |
+
Compute sigma_t of a given continuous-time label t in [0, T].
|
145 |
+
"""
|
146 |
+
return torch.sqrt(1. - torch.exp(2. * self.marginal_log_mean_coeff(t)))
|
147 |
+
|
148 |
+
def marginal_lambda(self, t):
|
149 |
+
"""
|
150 |
+
Compute lambda_t = log(alpha_t) - log(sigma_t) of a given continuous-time label t in [0, T].
|
151 |
+
"""
|
152 |
+
log_mean_coeff = self.marginal_log_mean_coeff(t)
|
153 |
+
log_std = 0.5 * torch.log(1. - torch.exp(2. * log_mean_coeff))
|
154 |
+
return log_mean_coeff - log_std
|
155 |
+
|
156 |
+
def inverse_lambda(self, lamb):
|
157 |
+
"""
|
158 |
+
Compute the continuous-time label t in [0, T] of a given half-logSNR lambda_t.
|
159 |
+
"""
|
160 |
+
if self.schedule == 'linear':
|
161 |
+
tmp = 2. * (self.beta_1 - self.beta_0) * torch.logaddexp(-2. * lamb, torch.zeros((1,)).to(lamb))
|
162 |
+
Delta = self.beta_0**2 + tmp
|
163 |
+
return tmp / (torch.sqrt(Delta) + self.beta_0) / (self.beta_1 - self.beta_0)
|
164 |
+
elif self.schedule == 'discrete':
|
165 |
+
log_alpha = -0.5 * torch.logaddexp(torch.zeros((1,)).to(lamb.device), -2. * lamb)
|
166 |
+
t = interpolate_fn(log_alpha.reshape((-1, 1)), torch.flip(self.log_alpha_array.to(lamb.device), [1]), torch.flip(self.t_array.to(lamb.device), [1]))
|
167 |
+
return t.reshape((-1,))
|
168 |
+
|
169 |
+
|
170 |
+
def model_wrapper(
|
171 |
+
model,
|
172 |
+
noise_schedule,
|
173 |
+
model_type="noise",
|
174 |
+
model_kwargs={},
|
175 |
+
guidance_type="uncond",
|
176 |
+
condition=None,
|
177 |
+
unconditional_condition=None,
|
178 |
+
guidance_scale=1.,
|
179 |
+
classifier_fn=None,
|
180 |
+
classifier_kwargs={},
|
181 |
+
):
|
182 |
+
"""Create a wrapper function for the noise prediction model.
|
183 |
+
|
184 |
+
DPM-Solver needs to solve the continuous-time diffusion ODEs. For DPMs trained on discrete-time labels, we need to
|
185 |
+
firstly wrap the model function to a noise prediction model that accepts the continuous time as the input.
|
186 |
+
|
187 |
+
We support four types of the diffusion model by setting `model_type`:
|
188 |
+
|
189 |
+
1. "noise": noise prediction model. (Trained by predicting noise).
|
190 |
+
|
191 |
+
2. "x_start": data prediction model. (Trained by predicting the data x_0 at time 0).
|
192 |
+
|
193 |
+
3. "v": velocity prediction model. (Trained by predicting the velocity).
|
194 |
+
The "v" prediction is derivation detailed in Appendix D of [1], and is used in Imagen-Video [2].
|
195 |
+
|
196 |
+
[1] Salimans, Tim, and Jonathan Ho. "Progressive distillation for fast sampling of diffusion models."
|
197 |
+
arXiv preprint arXiv:2202.00512 (2022).
|
198 |
+
[2] Ho, Jonathan, et al. "Imagen Video: High Definition Video Generation with Diffusion Models."
|
199 |
+
arXiv preprint arXiv:2210.02303 (2022).
|
200 |
+
|
201 |
+
4. "score": marginal score function. (Trained by denoising score matching).
|
202 |
+
Note that the score function and the noise prediction model follows a simple relationship:
|
203 |
+
```
|
204 |
+
noise(x_t, t) = -sigma_t * score(x_t, t)
|
205 |
+
```
|
206 |
+
|
207 |
+
We support three types of guided sampling by DPMs by setting `guidance_type`:
|
208 |
+
1. "uncond": unconditional sampling by DPMs.
|
209 |
+
The input `model` has the following format:
|
210 |
+
``
|
211 |
+
model(x, t_input, **model_kwargs) -> noise | x_start | v | score
|
212 |
+
``
|
213 |
+
|
214 |
+
2. "classifier": classifier guidance sampling [3] by DPMs and another classifier.
|
215 |
+
The input `model` has the following format:
|
216 |
+
``
|
217 |
+
model(x, t_input, **model_kwargs) -> noise | x_start | v | score
|
218 |
+
``
|
219 |
+
|
220 |
+
The input `classifier_fn` has the following format:
|
221 |
+
``
|
222 |
+
classifier_fn(x, t_input, cond, **classifier_kwargs) -> logits(x, t_input, cond)
|
223 |
+
``
|
224 |
+
|
225 |
+
[3] P. Dhariwal and A. Q. Nichol, "Diffusion models beat GANs on image synthesis,"
|
226 |
+
in Advances in Neural Information Processing Systems, vol. 34, 2021, pp. 8780-8794.
|
227 |
+
|
228 |
+
3. "classifier-free": classifier-free guidance sampling by conditional DPMs.
|
229 |
+
The input `model` has the following format:
|
230 |
+
``
|
231 |
+
model(x, t_input, cond, **model_kwargs) -> noise | x_start | v | score
|
232 |
+
``
|
233 |
+
And if cond == `unconditional_condition`, the model output is the unconditional DPM output.
|
234 |
+
|
235 |
+
[4] Ho, Jonathan, and Tim Salimans. "Classifier-free diffusion guidance."
|
236 |
+
arXiv preprint arXiv:2207.12598 (2022).
|
237 |
+
|
238 |
+
|
239 |
+
The `t_input` is the time label of the model, which may be discrete-time labels (i.e. 0 to 999)
|
240 |
+
or continuous-time labels (i.e. epsilon to T).
|
241 |
+
|
242 |
+
We wrap the model function to accept only `x` and `t_continuous` as inputs, and outputs the predicted noise:
|
243 |
+
``
|
244 |
+
def model_fn(x, t_continuous) -> noise:
|
245 |
+
t_input = get_model_input_time(t_continuous)
|
246 |
+
return noise_pred(model, x, t_input, **model_kwargs)
|
247 |
+
``
|
248 |
+
where `t_continuous` is the continuous time labels (i.e. epsilon to T). And we use `model_fn` for DPM-Solver.
|
249 |
+
|
250 |
+
===============================================================
|
251 |
+
|
252 |
+
Args:
|
253 |
+
model: A diffusion model with the corresponding format described above.
|
254 |
+
noise_schedule: A noise schedule object, such as NoiseScheduleVP.
|
255 |
+
model_type: A `str`. The parameterization type of the diffusion model.
|
256 |
+
"noise" or "x_start" or "v" or "score".
|
257 |
+
model_kwargs: A `dict`. A dict for the other inputs of the model function.
|
258 |
+
guidance_type: A `str`. The type of the guidance for sampling.
|
259 |
+
"uncond" or "classifier" or "classifier-free".
|
260 |
+
condition: A pytorch tensor. The condition for the guided sampling.
|
261 |
+
Only used for "classifier" or "classifier-free" guidance type.
|
262 |
+
unconditional_condition: A pytorch tensor. The condition for the unconditional sampling.
|
263 |
+
Only used for "classifier-free" guidance type.
|
264 |
+
guidance_scale: A `float`. The scale for the guided sampling.
|
265 |
+
classifier_fn: A classifier function. Only used for the classifier guidance.
|
266 |
+
classifier_kwargs: A `dict`. A dict for the other inputs of the classifier function.
|
267 |
+
Returns:
|
268 |
+
A noise prediction model that accepts the noised data and the continuous time as the inputs.
|
269 |
+
"""
|
270 |
+
|
271 |
+
def get_model_input_time(t_continuous):
|
272 |
+
"""
|
273 |
+
Convert the continuous-time `t_continuous` (in [epsilon, T]) to the model input time.
|
274 |
+
For discrete-time DPMs, we convert `t_continuous` in [1 / N, 1] to `t_input` in [0, 1000 * (N - 1) / N].
|
275 |
+
For continuous-time DPMs, we just use `t_continuous`.
|
276 |
+
"""
|
277 |
+
if noise_schedule.schedule == 'discrete':
|
278 |
+
return (t_continuous - 1. / noise_schedule.total_N) * 1000.
|
279 |
+
else:
|
280 |
+
return t_continuous
|
281 |
+
|
282 |
+
def noise_pred_fn(x, t_continuous, cond=None):
|
283 |
+
t_input = get_model_input_time(t_continuous)
|
284 |
+
if cond is None:
|
285 |
+
output = model(x, t_input, **model_kwargs)
|
286 |
+
else:
|
287 |
+
# output = model(x, t_input, cond, **model_kwargs) zxc
|
288 |
+
output = model(cond, t_input, **model_kwargs)
|
289 |
+
if model_type == "noise":
|
290 |
+
return output
|
291 |
+
elif model_type == "x_start":
|
292 |
+
alpha_t, sigma_t = noise_schedule.marginal_alpha(t_continuous), noise_schedule.marginal_std(t_continuous)
|
293 |
+
return (x - alpha_t * output) / sigma_t
|
294 |
+
elif model_type == "v":
|
295 |
+
alpha_t, sigma_t = noise_schedule.marginal_alpha(t_continuous), noise_schedule.marginal_std(t_continuous)
|
296 |
+
return alpha_t * output + sigma_t * x
|
297 |
+
elif model_type == "score":
|
298 |
+
sigma_t = noise_schedule.marginal_std(t_continuous)
|
299 |
+
return -sigma_t * output
|
300 |
+
|
301 |
+
def cond_grad_fn(x, t_input):
|
302 |
+
"""
|
303 |
+
Compute the gradient of the classifier, i.e. nabla_{x} log p_t(cond | x_t).
|
304 |
+
"""
|
305 |
+
with torch.enable_grad():
|
306 |
+
x_in = x.detach().requires_grad_(True)
|
307 |
+
log_prob = classifier_fn(x_in, t_input, condition, **classifier_kwargs)
|
308 |
+
return torch.autograd.grad(log_prob.sum(), x_in)[0]
|
309 |
+
|
310 |
+
def model_fn(x, t_continuous):
|
311 |
+
"""
|
312 |
+
The noise predicition model function that is used for DPM-Solver.
|
313 |
+
"""
|
314 |
+
if guidance_type == "uncond":
|
315 |
+
return noise_pred_fn(x, t_continuous)
|
316 |
+
elif guidance_type == "classifier":
|
317 |
+
assert classifier_fn is not None
|
318 |
+
t_input = get_model_input_time(t_continuous)
|
319 |
+
cond_grad = cond_grad_fn(x, t_input)
|
320 |
+
sigma_t = noise_schedule.marginal_std(t_continuous)
|
321 |
+
noise = noise_pred_fn(x, t_continuous)
|
322 |
+
return noise - guidance_scale * expand_dims(sigma_t, x.dim()) * cond_grad
|
323 |
+
elif guidance_type == "classifier-free":
|
324 |
+
if guidance_scale == 1. or unconditional_condition is None:
|
325 |
+
return noise_pred_fn(x, t_continuous, cond=condition)
|
326 |
+
else:
|
327 |
+
x_in = torch.cat([x] * 2)
|
328 |
+
t_in = torch.cat([t_continuous] * 2)
|
329 |
+
c_in = torch.cat([unconditional_condition, condition])
|
330 |
+
noise_uncond, noise = noise_pred_fn(x_in, t_in, cond=c_in).chunk(2)
|
331 |
+
return noise_uncond + guidance_scale * (noise - noise_uncond)
|
332 |
+
|
333 |
+
assert model_type in ["noise", "x_start", "v", "score"]
|
334 |
+
assert guidance_type in ["uncond", "classifier", "classifier-free"]
|
335 |
+
return model_fn
|
336 |
+
|
337 |
+
|
338 |
+
class DPM_Solver:
|
339 |
+
def __init__(
|
340 |
+
self,
|
341 |
+
model_fn,
|
342 |
+
noise_schedule,
|
343 |
+
algorithm_type="dpmsolver++",
|
344 |
+
correcting_x0_fn=None,
|
345 |
+
correcting_xt_fn=None,
|
346 |
+
thresholding_max_val=1.,
|
347 |
+
dynamic_thresholding_ratio=0.995,
|
348 |
+
):
|
349 |
+
"""Construct a DPM-Solver.
|
350 |
+
|
351 |
+
We support both DPM-Solver (`algorithm_type="dpmsolver"`) and DPM-Solver++ (`algorithm_type="dpmsolver++"`).
|
352 |
+
|
353 |
+
We also support the "dynamic thresholding" method in Imagen[1]. For pixel-space diffusion models, you
|
354 |
+
can set both `algorithm_type="dpmsolver++"` and `correcting_x0_fn="dynamic_thresholding"` to use the
|
355 |
+
dynamic thresholding. The "dynamic thresholding" can greatly improve the sample quality for pixel-space
|
356 |
+
DPMs with large guidance scales. Note that the thresholding method is **unsuitable** for latent-space
|
357 |
+
DPMs (such as stable-diffusion).
|
358 |
+
|
359 |
+
To support advanced algorithms in image-to-image applications, we also support corrector functions for
|
360 |
+
both x0 and xt.
|
361 |
+
|
362 |
+
Args:
|
363 |
+
model_fn: A noise prediction model function which accepts the continuous-time input (t in [epsilon, T]):
|
364 |
+
``
|
365 |
+
def model_fn(x, t_continuous):
|
366 |
+
return noise
|
367 |
+
``
|
368 |
+
The shape of `x` is `(batch_size, **shape)`, and the shape of `t_continuous` is `(batch_size,)`.
|
369 |
+
noise_schedule: A noise schedule object, such as NoiseScheduleVP.
|
370 |
+
algorithm_type: A `str`. Either "dpmsolver" or "dpmsolver++".
|
371 |
+
correcting_x0_fn: A `str` or a function with the following format:
|
372 |
+
```
|
373 |
+
def correcting_x0_fn(x0, t):
|
374 |
+
x0_new = ...
|
375 |
+
return x0_new
|
376 |
+
```
|
377 |
+
This function is to correct the outputs of the data prediction model at each sampling step. e.g.,
|
378 |
+
```
|
379 |
+
x0_pred = data_pred_model(xt, t)
|
380 |
+
if correcting_x0_fn is not None:
|
381 |
+
x0_pred = correcting_x0_fn(x0_pred, t)
|
382 |
+
xt_1 = update(x0_pred, xt, t)
|
383 |
+
```
|
384 |
+
If `correcting_x0_fn="dynamic_thresholding"`, we use the dynamic thresholding proposed in Imagen[1].
|
385 |
+
correcting_xt_fn: A function with the following format:
|
386 |
+
```
|
387 |
+
def correcting_xt_fn(xt, t, step):
|
388 |
+
x_new = ...
|
389 |
+
return x_new
|
390 |
+
```
|
391 |
+
This function is to correct the intermediate samples xt at each sampling step. e.g.,
|
392 |
+
```
|
393 |
+
xt = ...
|
394 |
+
xt = correcting_xt_fn(xt, t, step)
|
395 |
+
```
|
396 |
+
thresholding_max_val: A `float`. The max value for thresholding.
|
397 |
+
Valid only when use `dpmsolver++` and `correcting_x0_fn="dynamic_thresholding"`.
|
398 |
+
dynamic_thresholding_ratio: A `float`. The ratio for dynamic thresholding (see Imagen[1] for details).
|
399 |
+
Valid only when use `dpmsolver++` and `correcting_x0_fn="dynamic_thresholding"`.
|
400 |
+
|
401 |
+
[1] Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily Denton, Seyed Kamyar Seyed Ghasemipour,
|
402 |
+
Burcu Karagol Ayan, S Sara Mahdavi, Rapha Gontijo Lopes, et al. Photorealistic text-to-image diffusion models
|
403 |
+
with deep language understanding. arXiv preprint arXiv:2205.11487, 2022b.
|
404 |
+
"""
|
405 |
+
self.model = lambda x, t: model_fn(x, t.expand((x.shape[0])))
|
406 |
+
self.noise_schedule = noise_schedule
|
407 |
+
assert algorithm_type in ["dpmsolver", "dpmsolver++"]
|
408 |
+
self.algorithm_type = algorithm_type
|
409 |
+
if correcting_x0_fn == "dynamic_thresholding":
|
410 |
+
self.correcting_x0_fn = self.dynamic_thresholding_fn
|
411 |
+
else:
|
412 |
+
self.correcting_x0_fn = correcting_x0_fn
|
413 |
+
self.correcting_xt_fn = correcting_xt_fn
|
414 |
+
self.dynamic_thresholding_ratio = dynamic_thresholding_ratio
|
415 |
+
self.thresholding_max_val = thresholding_max_val
|
416 |
+
|
417 |
+
def dynamic_thresholding_fn(self, x0, t):
|
418 |
+
"""
|
419 |
+
The dynamic thresholding method.
|
420 |
+
"""
|
421 |
+
dims = x0.dim()
|
422 |
+
p = self.dynamic_thresholding_ratio
|
423 |
+
s = torch.quantile(torch.abs(x0).reshape((x0.shape[0], -1)), p, dim=1)
|
424 |
+
s = expand_dims(torch.maximum(s, self.thresholding_max_val * torch.ones_like(s).to(s.device)), dims)
|
425 |
+
x0 = torch.clamp(x0, -s, s) / s
|
426 |
+
return x0
|
427 |
+
|
428 |
+
def noise_prediction_fn(self, x, t):
|
429 |
+
"""
|
430 |
+
Return the noise prediction model.
|
431 |
+
"""
|
432 |
+
return self.model(x, t)
|
433 |
+
|
434 |
+
def data_prediction_fn(self, x, t):
|
435 |
+
"""
|
436 |
+
Return the data prediction model (with corrector).
|
437 |
+
"""
|
438 |
+
noise = self.noise_prediction_fn(x, t)
|
439 |
+
alpha_t, sigma_t = self.noise_schedule.marginal_alpha(t), self.noise_schedule.marginal_std(t)
|
440 |
+
x0 = (x - sigma_t * noise) / alpha_t
|
441 |
+
if self.correcting_x0_fn is not None:
|
442 |
+
x0 = self.correcting_x0_fn(x0, t)
|
443 |
+
return x0
|
444 |
+
|
445 |
+
def model_fn(self, x, t):
|
446 |
+
"""
|
447 |
+
Convert the model to the noise prediction model or the data prediction model.
|
448 |
+
"""
|
449 |
+
if self.algorithm_type == "dpmsolver++":
|
450 |
+
return self.data_prediction_fn(x, t)
|
451 |
+
else:
|
452 |
+
return self.noise_prediction_fn(x, t)
|
453 |
+
|
454 |
+
def get_time_steps(self, skip_type, t_T, t_0, N, device):
|
455 |
+
"""Compute the intermediate time steps for sampling.
|
456 |
+
|
457 |
+
Args:
|
458 |
+
skip_type: A `str`. The type for the spacing of the time steps. We support three types:
|
459 |
+
- 'logSNR': uniform logSNR for the time steps.
|
460 |
+
- 'time_uniform': uniform time for the time steps. (**Recommended for high-resolutional data**.)
|
461 |
+
- 'time_quadratic': quadratic time for the time steps. (Used in DDIM for low-resolutional data.)
|
462 |
+
t_T: A `float`. The starting time of the sampling (default is T).
|
463 |
+
t_0: A `float`. The ending time of the sampling (default is epsilon).
|
464 |
+
N: A `int`. The total number of the spacing of the time steps.
|
465 |
+
device: A torch device.
|
466 |
+
Returns:
|
467 |
+
A pytorch tensor of the time steps, with the shape (N + 1,).
|
468 |
+
"""
|
469 |
+
if skip_type == 'logSNR':
|
470 |
+
lambda_T = self.noise_schedule.marginal_lambda(torch.tensor(t_T).to(device))
|
471 |
+
lambda_0 = self.noise_schedule.marginal_lambda(torch.tensor(t_0).to(device))
|
472 |
+
logSNR_steps = torch.linspace(lambda_T.cpu().item(), lambda_0.cpu().item(), N + 1).to(device)
|
473 |
+
return self.noise_schedule.inverse_lambda(logSNR_steps)
|
474 |
+
elif skip_type == 'time_uniform':
|
475 |
+
return torch.linspace(t_T, t_0, N + 1).to(device)
|
476 |
+
elif skip_type == 'time_quadratic':
|
477 |
+
t_order = 2
|
478 |
+
t = torch.linspace(t_T**(1. / t_order), t_0**(1. / t_order), N + 1).pow(t_order).to(device)
|
479 |
+
return t
|
480 |
+
else:
|
481 |
+
raise ValueError("Unsupported skip_type {}, need to be 'logSNR' or 'time_uniform' or 'time_quadratic'".format(skip_type))
|
482 |
+
|
483 |
+
def get_orders_and_timesteps_for_singlestep_solver(self, steps, order, skip_type, t_T, t_0, device):
|
484 |
+
"""
|
485 |
+
Get the order of each step for sampling by the singlestep DPM-Solver.
|
486 |
+
|
487 |
+
We combine both DPM-Solver-1,2,3 to use all the function evaluations, which is named as "DPM-Solver-fast".
|
488 |
+
Given a fixed number of function evaluations by `steps`, the sampling procedure by DPM-Solver-fast is:
|
489 |
+
- If order == 1:
|
490 |
+
We take `steps` of DPM-Solver-1 (i.e. DDIM).
|
491 |
+
- If order == 2:
|
492 |
+
- Denote K = (steps // 2). We take K or (K + 1) intermediate time steps for sampling.
|
493 |
+
- If steps % 2 == 0, we use K steps of DPM-Solver-2.
|
494 |
+
- If steps % 2 == 1, we use K steps of DPM-Solver-2 and 1 step of DPM-Solver-1.
|
495 |
+
- If order == 3:
|
496 |
+
- Denote K = (steps // 3 + 1). We take K intermediate time steps for sampling.
|
497 |
+
- If steps % 3 == 0, we use (K - 2) steps of DPM-Solver-3, and 1 step of DPM-Solver-2 and 1 step of DPM-Solver-1.
|
498 |
+
- If steps % 3 == 1, we use (K - 1) steps of DPM-Solver-3 and 1 step of DPM-Solver-1.
|
499 |
+
- If steps % 3 == 2, we use (K - 1) steps of DPM-Solver-3 and 1 step of DPM-Solver-2.
|
500 |
+
|
501 |
+
============================================
|
502 |
+
Args:
|
503 |
+
order: A `int`. The max order for the solver (2 or 3).
|
504 |
+
steps: A `int`. The total number of function evaluations (NFE).
|
505 |
+
skip_type: A `str`. The type for the spacing of the time steps. We support three types:
|
506 |
+
- 'logSNR': uniform logSNR for the time steps.
|
507 |
+
- 'time_uniform': uniform time for the time steps. (**Recommended for high-resolutional data**.)
|
508 |
+
- 'time_quadratic': quadratic time for the time steps. (Used in DDIM for low-resolutional data.)
|
509 |
+
t_T: A `float`. The starting time of the sampling (default is T).
|
510 |
+
t_0: A `float`. The ending time of the sampling (default is epsilon).
|
511 |
+
device: A torch device.
|
512 |
+
Returns:
|
513 |
+
orders: A list of the solver order of each step.
|
514 |
+
"""
|
515 |
+
if order == 3:
|
516 |
+
K = steps // 3 + 1
|
517 |
+
if steps % 3 == 0:
|
518 |
+
orders = [3,] * (K - 2) + [2, 1]
|
519 |
+
elif steps % 3 == 1:
|
520 |
+
orders = [3,] * (K - 1) + [1]
|
521 |
+
else:
|
522 |
+
orders = [3,] * (K - 1) + [2]
|
523 |
+
elif order == 2:
|
524 |
+
if steps % 2 == 0:
|
525 |
+
K = steps // 2
|
526 |
+
orders = [2,] * K
|
527 |
+
else:
|
528 |
+
K = steps // 2 + 1
|
529 |
+
orders = [2,] * (K - 1) + [1]
|
530 |
+
elif order == 1:
|
531 |
+
K = 1
|
532 |
+
orders = [1,] * steps
|
533 |
+
else:
|
534 |
+
raise ValueError("'order' must be '1' or '2' or '3'.")
|
535 |
+
if skip_type == 'logSNR':
|
536 |
+
# To reproduce the results in DPM-Solver paper
|
537 |
+
timesteps_outer = self.get_time_steps(skip_type, t_T, t_0, K, device)
|
538 |
+
else:
|
539 |
+
timesteps_outer = self.get_time_steps(skip_type, t_T, t_0, steps, device)[torch.cumsum(torch.tensor([0,] + orders), 0).to(device)]
|
540 |
+
return timesteps_outer, orders
|
541 |
+
|
542 |
+
def denoise_to_zero_fn(self, x, s):
|
543 |
+
"""
|
544 |
+
Denoise at the final step, which is equivalent to solve the ODE from lambda_s to infty by first-order discretization.
|
545 |
+
"""
|
546 |
+
return self.data_prediction_fn(x, s)
|
547 |
+
|
548 |
+
def dpm_solver_first_update(self, x, s, t, model_s=None, return_intermediate=False):
|
549 |
+
"""
|
550 |
+
DPM-Solver-1 (equivalent to DDIM) from time `s` to time `t`.
|
551 |
+
|
552 |
+
Args:
|
553 |
+
x: A pytorch tensor. The initial value at time `s`.
|
554 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
555 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
556 |
+
model_s: A pytorch tensor. The model function evaluated at time `s`.
|
557 |
+
If `model_s` is None, we evaluate the model by `x` and `s`; otherwise we directly use it.
|
558 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s`.
|
559 |
+
Returns:
|
560 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
561 |
+
"""
|
562 |
+
ns = self.noise_schedule
|
563 |
+
dims = x.dim()
|
564 |
+
lambda_s, lambda_t = ns.marginal_lambda(s), ns.marginal_lambda(t)
|
565 |
+
h = lambda_t - lambda_s
|
566 |
+
log_alpha_s, log_alpha_t = ns.marginal_log_mean_coeff(s), ns.marginal_log_mean_coeff(t)
|
567 |
+
sigma_s, sigma_t = ns.marginal_std(s), ns.marginal_std(t)
|
568 |
+
alpha_t = torch.exp(log_alpha_t)
|
569 |
+
|
570 |
+
if self.algorithm_type == "dpmsolver++":
|
571 |
+
phi_1 = torch.expm1(-h)
|
572 |
+
if model_s is None:
|
573 |
+
model_s = self.model_fn(x, s)
|
574 |
+
x_t = (
|
575 |
+
sigma_t / sigma_s * x
|
576 |
+
- alpha_t * phi_1 * model_s
|
577 |
+
)
|
578 |
+
if return_intermediate:
|
579 |
+
return x_t, {'model_s': model_s}
|
580 |
+
else:
|
581 |
+
return x_t
|
582 |
+
else:
|
583 |
+
phi_1 = torch.expm1(h)
|
584 |
+
if model_s is None:
|
585 |
+
model_s = self.model_fn(x, s)
|
586 |
+
x_t = (
|
587 |
+
torch.exp(log_alpha_t - log_alpha_s) * x
|
588 |
+
- (sigma_t * phi_1) * model_s
|
589 |
+
)
|
590 |
+
if return_intermediate:
|
591 |
+
return x_t, {'model_s': model_s}
|
592 |
+
else:
|
593 |
+
return x_t
|
594 |
+
|
595 |
+
def singlestep_dpm_solver_second_update(self, x, s, t, r1=0.5, model_s=None, return_intermediate=False, solver_type='dpmsolver'):
|
596 |
+
"""
|
597 |
+
Singlestep solver DPM-Solver-2 from time `s` to time `t`.
|
598 |
+
|
599 |
+
Args:
|
600 |
+
x: A pytorch tensor. The initial value at time `s`.
|
601 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
602 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
603 |
+
r1: A `float`. The hyperparameter of the second-order solver.
|
604 |
+
model_s: A pytorch tensor. The model function evaluated at time `s`.
|
605 |
+
If `model_s` is None, we evaluate the model by `x` and `s`; otherwise we directly use it.
|
606 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s` and `s1` (the intermediate time).
|
607 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
608 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
609 |
+
Returns:
|
610 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
611 |
+
"""
|
612 |
+
if solver_type not in ['dpmsolver', 'taylor']:
|
613 |
+
raise ValueError("'solver_type' must be either 'dpmsolver' or 'taylor', got {}".format(solver_type))
|
614 |
+
if r1 is None:
|
615 |
+
r1 = 0.5
|
616 |
+
ns = self.noise_schedule
|
617 |
+
lambda_s, lambda_t = ns.marginal_lambda(s), ns.marginal_lambda(t)
|
618 |
+
h = lambda_t - lambda_s
|
619 |
+
lambda_s1 = lambda_s + r1 * h
|
620 |
+
s1 = ns.inverse_lambda(lambda_s1)
|
621 |
+
log_alpha_s, log_alpha_s1, log_alpha_t = ns.marginal_log_mean_coeff(s), ns.marginal_log_mean_coeff(s1), ns.marginal_log_mean_coeff(t)
|
622 |
+
sigma_s, sigma_s1, sigma_t = ns.marginal_std(s), ns.marginal_std(s1), ns.marginal_std(t)
|
623 |
+
alpha_s1, alpha_t = torch.exp(log_alpha_s1), torch.exp(log_alpha_t)
|
624 |
+
|
625 |
+
if self.algorithm_type == "dpmsolver++":
|
626 |
+
phi_11 = torch.expm1(-r1 * h)
|
627 |
+
phi_1 = torch.expm1(-h)
|
628 |
+
|
629 |
+
if model_s is None:
|
630 |
+
model_s = self.model_fn(x, s)
|
631 |
+
x_s1 = (
|
632 |
+
(sigma_s1 / sigma_s) * x
|
633 |
+
- (alpha_s1 * phi_11) * model_s
|
634 |
+
)
|
635 |
+
model_s1 = self.model_fn(x_s1, s1)
|
636 |
+
if solver_type == 'dpmsolver':
|
637 |
+
x_t = (
|
638 |
+
(sigma_t / sigma_s) * x
|
639 |
+
- (alpha_t * phi_1) * model_s
|
640 |
+
- (0.5 / r1) * (alpha_t * phi_1) * (model_s1 - model_s)
|
641 |
+
)
|
642 |
+
elif solver_type == 'taylor':
|
643 |
+
x_t = (
|
644 |
+
(sigma_t / sigma_s) * x
|
645 |
+
- (alpha_t * phi_1) * model_s
|
646 |
+
+ (1. / r1) * (alpha_t * (phi_1 / h + 1.)) * (model_s1 - model_s)
|
647 |
+
)
|
648 |
+
else:
|
649 |
+
phi_11 = torch.expm1(r1 * h)
|
650 |
+
phi_1 = torch.expm1(h)
|
651 |
+
|
652 |
+
if model_s is None:
|
653 |
+
model_s = self.model_fn(x, s)
|
654 |
+
x_s1 = (
|
655 |
+
torch.exp(log_alpha_s1 - log_alpha_s) * x
|
656 |
+
- (sigma_s1 * phi_11) * model_s
|
657 |
+
)
|
658 |
+
model_s1 = self.model_fn(x_s1, s1)
|
659 |
+
if solver_type == 'dpmsolver':
|
660 |
+
x_t = (
|
661 |
+
torch.exp(log_alpha_t - log_alpha_s) * x
|
662 |
+
- (sigma_t * phi_1) * model_s
|
663 |
+
- (0.5 / r1) * (sigma_t * phi_1) * (model_s1 - model_s)
|
664 |
+
)
|
665 |
+
elif solver_type == 'taylor':
|
666 |
+
x_t = (
|
667 |
+
torch.exp(log_alpha_t - log_alpha_s) * x
|
668 |
+
- (sigma_t * phi_1) * model_s
|
669 |
+
- (1. / r1) * (sigma_t * (phi_1 / h - 1.)) * (model_s1 - model_s)
|
670 |
+
)
|
671 |
+
if return_intermediate:
|
672 |
+
return x_t, {'model_s': model_s, 'model_s1': model_s1}
|
673 |
+
else:
|
674 |
+
return x_t
|
675 |
+
|
676 |
+
def singlestep_dpm_solver_third_update(self, x, s, t, r1=1./3., r2=2./3., model_s=None, model_s1=None, return_intermediate=False, solver_type='dpmsolver'):
|
677 |
+
"""
|
678 |
+
Singlestep solver DPM-Solver-3 from time `s` to time `t`.
|
679 |
+
|
680 |
+
Args:
|
681 |
+
x: A pytorch tensor. The initial value at time `s`.
|
682 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
683 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
684 |
+
r1: A `float`. The hyperparameter of the third-order solver.
|
685 |
+
r2: A `float`. The hyperparameter of the third-order solver.
|
686 |
+
model_s: A pytorch tensor. The model function evaluated at time `s`.
|
687 |
+
If `model_s` is None, we evaluate the model by `x` and `s`; otherwise we directly use it.
|
688 |
+
model_s1: A pytorch tensor. The model function evaluated at time `s1` (the intermediate time given by `r1`).
|
689 |
+
If `model_s1` is None, we evaluate the model at `s1`; otherwise we directly use it.
|
690 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s`, `s1` and `s2` (the intermediate times).
|
691 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
692 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
693 |
+
Returns:
|
694 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
695 |
+
"""
|
696 |
+
if solver_type not in ['dpmsolver', 'taylor']:
|
697 |
+
raise ValueError("'solver_type' must be either 'dpmsolver' or 'taylor', got {}".format(solver_type))
|
698 |
+
if r1 is None:
|
699 |
+
r1 = 1. / 3.
|
700 |
+
if r2 is None:
|
701 |
+
r2 = 2. / 3.
|
702 |
+
ns = self.noise_schedule
|
703 |
+
lambda_s, lambda_t = ns.marginal_lambda(s), ns.marginal_lambda(t)
|
704 |
+
h = lambda_t - lambda_s
|
705 |
+
lambda_s1 = lambda_s + r1 * h
|
706 |
+
lambda_s2 = lambda_s + r2 * h
|
707 |
+
s1 = ns.inverse_lambda(lambda_s1)
|
708 |
+
s2 = ns.inverse_lambda(lambda_s2)
|
709 |
+
log_alpha_s, log_alpha_s1, log_alpha_s2, log_alpha_t = ns.marginal_log_mean_coeff(s), ns.marginal_log_mean_coeff(s1), ns.marginal_log_mean_coeff(s2), ns.marginal_log_mean_coeff(t)
|
710 |
+
sigma_s, sigma_s1, sigma_s2, sigma_t = ns.marginal_std(s), ns.marginal_std(s1), ns.marginal_std(s2), ns.marginal_std(t)
|
711 |
+
alpha_s1, alpha_s2, alpha_t = torch.exp(log_alpha_s1), torch.exp(log_alpha_s2), torch.exp(log_alpha_t)
|
712 |
+
|
713 |
+
if self.algorithm_type == "dpmsolver++":
|
714 |
+
phi_11 = torch.expm1(-r1 * h)
|
715 |
+
phi_12 = torch.expm1(-r2 * h)
|
716 |
+
phi_1 = torch.expm1(-h)
|
717 |
+
phi_22 = torch.expm1(-r2 * h) / (r2 * h) + 1.
|
718 |
+
phi_2 = phi_1 / h + 1.
|
719 |
+
phi_3 = phi_2 / h - 0.5
|
720 |
+
|
721 |
+
if model_s is None:
|
722 |
+
model_s = self.model_fn(x, s)
|
723 |
+
if model_s1 is None:
|
724 |
+
x_s1 = (
|
725 |
+
(sigma_s1 / sigma_s) * x
|
726 |
+
- (alpha_s1 * phi_11) * model_s
|
727 |
+
)
|
728 |
+
model_s1 = self.model_fn(x_s1, s1)
|
729 |
+
x_s2 = (
|
730 |
+
(sigma_s2 / sigma_s) * x
|
731 |
+
- (alpha_s2 * phi_12) * model_s
|
732 |
+
+ r2 / r1 * (alpha_s2 * phi_22) * (model_s1 - model_s)
|
733 |
+
)
|
734 |
+
model_s2 = self.model_fn(x_s2, s2)
|
735 |
+
if solver_type == 'dpmsolver':
|
736 |
+
x_t = (
|
737 |
+
(sigma_t / sigma_s) * x
|
738 |
+
- (alpha_t * phi_1) * model_s
|
739 |
+
+ (1. / r2) * (alpha_t * phi_2) * (model_s2 - model_s)
|
740 |
+
)
|
741 |
+
elif solver_type == 'taylor':
|
742 |
+
D1_0 = (1. / r1) * (model_s1 - model_s)
|
743 |
+
D1_1 = (1. / r2) * (model_s2 - model_s)
|
744 |
+
D1 = (r2 * D1_0 - r1 * D1_1) / (r2 - r1)
|
745 |
+
D2 = 2. * (D1_1 - D1_0) / (r2 - r1)
|
746 |
+
x_t = (
|
747 |
+
(sigma_t / sigma_s) * x
|
748 |
+
- (alpha_t * phi_1) * model_s
|
749 |
+
+ (alpha_t * phi_2) * D1
|
750 |
+
- (alpha_t * phi_3) * D2
|
751 |
+
)
|
752 |
+
else:
|
753 |
+
phi_11 = torch.expm1(r1 * h)
|
754 |
+
phi_12 = torch.expm1(r2 * h)
|
755 |
+
phi_1 = torch.expm1(h)
|
756 |
+
phi_22 = torch.expm1(r2 * h) / (r2 * h) - 1.
|
757 |
+
phi_2 = phi_1 / h - 1.
|
758 |
+
phi_3 = phi_2 / h - 0.5
|
759 |
+
|
760 |
+
if model_s is None:
|
761 |
+
model_s = self.model_fn(x, s)
|
762 |
+
if model_s1 is None:
|
763 |
+
x_s1 = (
|
764 |
+
(torch.exp(log_alpha_s1 - log_alpha_s)) * x
|
765 |
+
- (sigma_s1 * phi_11) * model_s
|
766 |
+
)
|
767 |
+
model_s1 = self.model_fn(x_s1, s1)
|
768 |
+
x_s2 = (
|
769 |
+
(torch.exp(log_alpha_s2 - log_alpha_s)) * x
|
770 |
+
- (sigma_s2 * phi_12) * model_s
|
771 |
+
- r2 / r1 * (sigma_s2 * phi_22) * (model_s1 - model_s)
|
772 |
+
)
|
773 |
+
model_s2 = self.model_fn(x_s2, s2)
|
774 |
+
if solver_type == 'dpmsolver':
|
775 |
+
x_t = (
|
776 |
+
(torch.exp(log_alpha_t - log_alpha_s)) * x
|
777 |
+
- (sigma_t * phi_1) * model_s
|
778 |
+
- (1. / r2) * (sigma_t * phi_2) * (model_s2 - model_s)
|
779 |
+
)
|
780 |
+
elif solver_type == 'taylor':
|
781 |
+
D1_0 = (1. / r1) * (model_s1 - model_s)
|
782 |
+
D1_1 = (1. / r2) * (model_s2 - model_s)
|
783 |
+
D1 = (r2 * D1_0 - r1 * D1_1) / (r2 - r1)
|
784 |
+
D2 = 2. * (D1_1 - D1_0) / (r2 - r1)
|
785 |
+
x_t = (
|
786 |
+
(torch.exp(log_alpha_t - log_alpha_s)) * x
|
787 |
+
- (sigma_t * phi_1) * model_s
|
788 |
+
- (sigma_t * phi_2) * D1
|
789 |
+
- (sigma_t * phi_3) * D2
|
790 |
+
)
|
791 |
+
|
792 |
+
if return_intermediate:
|
793 |
+
return x_t, {'model_s': model_s, 'model_s1': model_s1, 'model_s2': model_s2}
|
794 |
+
else:
|
795 |
+
return x_t
|
796 |
+
|
797 |
+
def multistep_dpm_solver_second_update(self, x, model_prev_list, t_prev_list, t, solver_type="dpmsolver"):
|
798 |
+
"""
|
799 |
+
Multistep solver DPM-Solver-2 from time `t_prev_list[-1]` to time `t`.
|
800 |
+
|
801 |
+
Args:
|
802 |
+
x: A pytorch tensor. The initial value at time `s`.
|
803 |
+
model_prev_list: A list of pytorch tensor. The previous computed model values.
|
804 |
+
t_prev_list: A list of pytorch tensor. The previous times, each time has the shape (1,)
|
805 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
806 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
807 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
808 |
+
Returns:
|
809 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
810 |
+
"""
|
811 |
+
if solver_type not in ['dpmsolver', 'taylor']:
|
812 |
+
raise ValueError("'solver_type' must be either 'dpmsolver' or 'taylor', got {}".format(solver_type))
|
813 |
+
ns = self.noise_schedule
|
814 |
+
model_prev_1, model_prev_0 = model_prev_list[-2], model_prev_list[-1]
|
815 |
+
t_prev_1, t_prev_0 = t_prev_list[-2], t_prev_list[-1]
|
816 |
+
lambda_prev_1, lambda_prev_0, lambda_t = ns.marginal_lambda(t_prev_1), ns.marginal_lambda(t_prev_0), ns.marginal_lambda(t)
|
817 |
+
log_alpha_prev_0, log_alpha_t = ns.marginal_log_mean_coeff(t_prev_0), ns.marginal_log_mean_coeff(t)
|
818 |
+
sigma_prev_0, sigma_t = ns.marginal_std(t_prev_0), ns.marginal_std(t)
|
819 |
+
alpha_t = torch.exp(log_alpha_t)
|
820 |
+
|
821 |
+
h_0 = lambda_prev_0 - lambda_prev_1
|
822 |
+
h = lambda_t - lambda_prev_0
|
823 |
+
r0 = h_0 / h
|
824 |
+
D1_0 = (1. / r0) * (model_prev_0 - model_prev_1)
|
825 |
+
if self.algorithm_type == "dpmsolver++":
|
826 |
+
phi_1 = torch.expm1(-h)
|
827 |
+
if solver_type == 'dpmsolver':
|
828 |
+
x_t = (
|
829 |
+
(sigma_t / sigma_prev_0) * x
|
830 |
+
- (alpha_t * phi_1) * model_prev_0
|
831 |
+
- 0.5 * (alpha_t * phi_1) * D1_0
|
832 |
+
)
|
833 |
+
elif solver_type == 'taylor':
|
834 |
+
x_t = (
|
835 |
+
(sigma_t / sigma_prev_0) * x
|
836 |
+
- (alpha_t * phi_1) * model_prev_0
|
837 |
+
+ (alpha_t * (phi_1 / h + 1.)) * D1_0
|
838 |
+
)
|
839 |
+
else:
|
840 |
+
phi_1 = torch.expm1(h)
|
841 |
+
if solver_type == 'dpmsolver':
|
842 |
+
x_t = (
|
843 |
+
(torch.exp(log_alpha_t - log_alpha_prev_0)) * x
|
844 |
+
- (sigma_t * phi_1) * model_prev_0
|
845 |
+
- 0.5 * (sigma_t * phi_1) * D1_0
|
846 |
+
)
|
847 |
+
elif solver_type == 'taylor':
|
848 |
+
x_t = (
|
849 |
+
(torch.exp(log_alpha_t - log_alpha_prev_0)) * x
|
850 |
+
- (sigma_t * phi_1) * model_prev_0
|
851 |
+
- (sigma_t * (phi_1 / h - 1.)) * D1_0
|
852 |
+
)
|
853 |
+
return x_t
|
854 |
+
|
855 |
+
def multistep_dpm_solver_third_update(self, x, model_prev_list, t_prev_list, t, solver_type='dpmsolver'):
|
856 |
+
"""
|
857 |
+
Multistep solver DPM-Solver-3 from time `t_prev_list[-1]` to time `t`.
|
858 |
+
|
859 |
+
Args:
|
860 |
+
x: A pytorch tensor. The initial value at time `s`.
|
861 |
+
model_prev_list: A list of pytorch tensor. The previous computed model values.
|
862 |
+
t_prev_list: A list of pytorch tensor. The previous times, each time has the shape (1,)
|
863 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
864 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
865 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
866 |
+
Returns:
|
867 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
868 |
+
"""
|
869 |
+
ns = self.noise_schedule
|
870 |
+
model_prev_2, model_prev_1, model_prev_0 = model_prev_list
|
871 |
+
t_prev_2, t_prev_1, t_prev_0 = t_prev_list
|
872 |
+
lambda_prev_2, lambda_prev_1, lambda_prev_0, lambda_t = ns.marginal_lambda(t_prev_2), ns.marginal_lambda(t_prev_1), ns.marginal_lambda(t_prev_0), ns.marginal_lambda(t)
|
873 |
+
log_alpha_prev_0, log_alpha_t = ns.marginal_log_mean_coeff(t_prev_0), ns.marginal_log_mean_coeff(t)
|
874 |
+
sigma_prev_0, sigma_t = ns.marginal_std(t_prev_0), ns.marginal_std(t)
|
875 |
+
alpha_t = torch.exp(log_alpha_t)
|
876 |
+
|
877 |
+
h_1 = lambda_prev_1 - lambda_prev_2
|
878 |
+
h_0 = lambda_prev_0 - lambda_prev_1
|
879 |
+
h = lambda_t - lambda_prev_0
|
880 |
+
r0, r1 = h_0 / h, h_1 / h
|
881 |
+
D1_0 = (1. / r0) * (model_prev_0 - model_prev_1)
|
882 |
+
D1_1 = (1. / r1) * (model_prev_1 - model_prev_2)
|
883 |
+
D1 = D1_0 + (r0 / (r0 + r1)) * (D1_0 - D1_1)
|
884 |
+
D2 = (1. / (r0 + r1)) * (D1_0 - D1_1)
|
885 |
+
if self.algorithm_type == "dpmsolver++":
|
886 |
+
phi_1 = torch.expm1(-h)
|
887 |
+
phi_2 = phi_1 / h + 1.
|
888 |
+
phi_3 = phi_2 / h - 0.5
|
889 |
+
x_t = (
|
890 |
+
(sigma_t / sigma_prev_0) * x
|
891 |
+
- (alpha_t * phi_1) * model_prev_0
|
892 |
+
+ (alpha_t * phi_2) * D1
|
893 |
+
- (alpha_t * phi_3) * D2
|
894 |
+
)
|
895 |
+
else:
|
896 |
+
phi_1 = torch.expm1(h)
|
897 |
+
phi_2 = phi_1 / h - 1.
|
898 |
+
phi_3 = phi_2 / h - 0.5
|
899 |
+
x_t = (
|
900 |
+
(torch.exp(log_alpha_t - log_alpha_prev_0)) * x
|
901 |
+
- (sigma_t * phi_1) * model_prev_0
|
902 |
+
- (sigma_t * phi_2) * D1
|
903 |
+
- (sigma_t * phi_3) * D2
|
904 |
+
)
|
905 |
+
return x_t
|
906 |
+
|
907 |
+
def singlestep_dpm_solver_update(self, x, s, t, order, return_intermediate=False, solver_type='dpmsolver', r1=None, r2=None):
|
908 |
+
"""
|
909 |
+
Singlestep DPM-Solver with the order `order` from time `s` to time `t`.
|
910 |
+
|
911 |
+
Args:
|
912 |
+
x: A pytorch tensor. The initial value at time `s`.
|
913 |
+
s: A pytorch tensor. The starting time, with the shape (1,).
|
914 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
915 |
+
order: A `int`. The order of DPM-Solver. We only support order == 1 or 2 or 3.
|
916 |
+
return_intermediate: A `bool`. If true, also return the model value at time `s`, `s1` and `s2` (the intermediate times).
|
917 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
918 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
919 |
+
r1: A `float`. The hyperparameter of the second-order or third-order solver.
|
920 |
+
r2: A `float`. The hyperparameter of the third-order solver.
|
921 |
+
Returns:
|
922 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
923 |
+
"""
|
924 |
+
if order == 1:
|
925 |
+
return self.dpm_solver_first_update(x, s, t, return_intermediate=return_intermediate)
|
926 |
+
elif order == 2:
|
927 |
+
return self.singlestep_dpm_solver_second_update(x, s, t, return_intermediate=return_intermediate, solver_type=solver_type, r1=r1)
|
928 |
+
elif order == 3:
|
929 |
+
return self.singlestep_dpm_solver_third_update(x, s, t, return_intermediate=return_intermediate, solver_type=solver_type, r1=r1, r2=r2)
|
930 |
+
else:
|
931 |
+
raise ValueError("Solver order must be 1 or 2 or 3, got {}".format(order))
|
932 |
+
|
933 |
+
def multistep_dpm_solver_update(self, x, model_prev_list, t_prev_list, t, order, solver_type='dpmsolver'):
|
934 |
+
"""
|
935 |
+
Multistep DPM-Solver with the order `order` from time `t_prev_list[-1]` to time `t`.
|
936 |
+
|
937 |
+
Args:
|
938 |
+
x: A pytorch tensor. The initial value at time `s`.
|
939 |
+
model_prev_list: A list of pytorch tensor. The previous computed model values.
|
940 |
+
t_prev_list: A list of pytorch tensor. The previous times, each time has the shape (1,)
|
941 |
+
t: A pytorch tensor. The ending time, with the shape (1,).
|
942 |
+
order: A `int`. The order of DPM-Solver. We only support order == 1 or 2 or 3.
|
943 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
944 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
945 |
+
Returns:
|
946 |
+
x_t: A pytorch tensor. The approximated solution at time `t`.
|
947 |
+
"""
|
948 |
+
if order == 1:
|
949 |
+
return self.dpm_solver_first_update(x, t_prev_list[-1], t, model_s=model_prev_list[-1])
|
950 |
+
elif order == 2:
|
951 |
+
return self.multistep_dpm_solver_second_update(x, model_prev_list, t_prev_list, t, solver_type=solver_type)
|
952 |
+
elif order == 3:
|
953 |
+
return self.multistep_dpm_solver_third_update(x, model_prev_list, t_prev_list, t, solver_type=solver_type)
|
954 |
+
else:
|
955 |
+
raise ValueError("Solver order must be 1 or 2 or 3, got {}".format(order))
|
956 |
+
|
957 |
+
def dpm_solver_adaptive(self, x, order, t_T, t_0, h_init=0.05, atol=0.0078, rtol=0.05, theta=0.9, t_err=1e-5, solver_type='dpmsolver'):
|
958 |
+
"""
|
959 |
+
The adaptive step size solver based on singlestep DPM-Solver.
|
960 |
+
|
961 |
+
Args:
|
962 |
+
x: A pytorch tensor. The initial value at time `t_T`.
|
963 |
+
order: A `int`. The (higher) order of the solver. We only support order == 2 or 3.
|
964 |
+
t_T: A `float`. The starting time of the sampling (default is T).
|
965 |
+
t_0: A `float`. The ending time of the sampling (default is epsilon).
|
966 |
+
h_init: A `float`. The initial step size (for logSNR).
|
967 |
+
atol: A `float`. The absolute tolerance of the solver. For image data, the default setting is 0.0078, followed [1].
|
968 |
+
rtol: A `float`. The relative tolerance of the solver. The default setting is 0.05.
|
969 |
+
theta: A `float`. The safety hyperparameter for adapting the step size. The default setting is 0.9, followed [1].
|
970 |
+
t_err: A `float`. The tolerance for the time. We solve the diffusion ODE until the absolute error between the
|
971 |
+
current time and `t_0` is less than `t_err`. The default setting is 1e-5.
|
972 |
+
solver_type: either 'dpmsolver' or 'taylor'. The type for the high-order solvers.
|
973 |
+
The type slightly impacts the performance. We recommend to use 'dpmsolver' type.
|
974 |
+
Returns:
|
975 |
+
x_0: A pytorch tensor. The approximated solution at time `t_0`.
|
976 |
+
|
977 |
+
[1] A. Jolicoeur-Martineau, K. Li, R. Piché-Taillefer, T. Kachman, and I. Mitliagkas, "Gotta go fast when generating data with score-based models," arXiv preprint arXiv:2105.14080, 2021.
|
978 |
+
"""
|
979 |
+
ns = self.noise_schedule
|
980 |
+
s = t_T * torch.ones((1,)).to(x)
|
981 |
+
lambda_s = ns.marginal_lambda(s)
|
982 |
+
lambda_0 = ns.marginal_lambda(t_0 * torch.ones_like(s).to(x))
|
983 |
+
h = h_init * torch.ones_like(s).to(x)
|
984 |
+
x_prev = x
|
985 |
+
nfe = 0
|
986 |
+
if order == 2:
|
987 |
+
r1 = 0.5
|
988 |
+
lower_update = lambda x, s, t: self.dpm_solver_first_update(x, s, t, return_intermediate=True)
|
989 |
+
higher_update = lambda x, s, t, **kwargs: self.singlestep_dpm_solver_second_update(x, s, t, r1=r1, solver_type=solver_type, **kwargs)
|
990 |
+
elif order == 3:
|
991 |
+
r1, r2 = 1. / 3., 2. / 3.
|
992 |
+
lower_update = lambda x, s, t: self.singlestep_dpm_solver_second_update(x, s, t, r1=r1, return_intermediate=True, solver_type=solver_type)
|
993 |
+
higher_update = lambda x, s, t, **kwargs: self.singlestep_dpm_solver_third_update(x, s, t, r1=r1, r2=r2, solver_type=solver_type, **kwargs)
|
994 |
+
else:
|
995 |
+
raise ValueError("For adaptive step size solver, order must be 2 or 3, got {}".format(order))
|
996 |
+
while torch.abs((s - t_0)).mean() > t_err:
|
997 |
+
t = ns.inverse_lambda(lambda_s + h)
|
998 |
+
x_lower, lower_noise_kwargs = lower_update(x, s, t)
|
999 |
+
x_higher = higher_update(x, s, t, **lower_noise_kwargs)
|
1000 |
+
delta = torch.max(torch.ones_like(x).to(x) * atol, rtol * torch.max(torch.abs(x_lower), torch.abs(x_prev)))
|
1001 |
+
norm_fn = lambda v: torch.sqrt(torch.square(v.reshape((v.shape[0], -1))).mean(dim=-1, keepdim=True))
|
1002 |
+
E = norm_fn((x_higher - x_lower) / delta).max()
|
1003 |
+
if torch.all(E <= 1.):
|
1004 |
+
x = x_higher
|
1005 |
+
s = t
|
1006 |
+
x_prev = x_lower
|
1007 |
+
lambda_s = ns.marginal_lambda(s)
|
1008 |
+
h = torch.min(theta * h * torch.float_power(E, -1. / order).float(), lambda_0 - lambda_s)
|
1009 |
+
nfe += order
|
1010 |
+
print('adaptive solver nfe', nfe)
|
1011 |
+
return x
|
1012 |
+
|
1013 |
+
def add_noise(self, x, t, noise=None):
|
1014 |
+
"""
|
1015 |
+
Compute the noised input xt = alpha_t * x + sigma_t * noise.
|
1016 |
+
|
1017 |
+
Args:
|
1018 |
+
x: A `torch.Tensor` with shape `(batch_size, *shape)`.
|
1019 |
+
t: A `torch.Tensor` with shape `(t_size,)`.
|
1020 |
+
Returns:
|
1021 |
+
xt with shape `(t_size, batch_size, *shape)`.
|
1022 |
+
"""
|
1023 |
+
alpha_t, sigma_t = self.noise_schedule.marginal_alpha(t), self.noise_schedule.marginal_std(t)
|
1024 |
+
if noise is None:
|
1025 |
+
noise = torch.randn((t.shape[0], *x.shape), device=x.device)
|
1026 |
+
x = x.reshape((-1, *x.shape))
|
1027 |
+
xt = expand_dims(alpha_t, x.dim()) * x + expand_dims(sigma_t, x.dim()) * noise
|
1028 |
+
if t.shape[0] == 1:
|
1029 |
+
return xt.squeeze(0)
|
1030 |
+
else:
|
1031 |
+
return xt
|
1032 |
+
|
1033 |
+
def inverse(self, x, steps=20, t_start=None, t_end=None, order=2, skip_type='time_uniform',
|
1034 |
+
method='multistep', lower_order_final=True, denoise_to_zero=False, solver_type='dpmsolver',
|
1035 |
+
atol=0.0078, rtol=0.05, return_intermediate=False,
|
1036 |
+
):
|
1037 |
+
"""
|
1038 |
+
Inverse the sample `x` from time `t_start` to `t_end` by DPM-Solver.
|
1039 |
+
For discrete-time DPMs, we use `t_start=1/N`, where `N` is the total time steps during training.
|
1040 |
+
"""
|
1041 |
+
t_0 = 1. / self.noise_schedule.total_N if t_start is None else t_start
|
1042 |
+
t_T = self.noise_schedule.T if t_end is None else t_end
|
1043 |
+
assert t_0 > 0 and t_T > 0, "Time range needs to be greater than 0. For discrete-time DPMs, it needs to be in [1 / N, 1], where N is the length of betas array"
|
1044 |
+
return self.sample(x, steps=steps, t_start=t_0, t_end=t_T, order=order, skip_type=skip_type,
|
1045 |
+
method=method, lower_order_final=lower_order_final, denoise_to_zero=denoise_to_zero, solver_type=solver_type,
|
1046 |
+
atol=atol, rtol=rtol, return_intermediate=return_intermediate)
|
1047 |
+
|
1048 |
+
def sample(self, x, steps=20, t_start=None, t_end=None, order=2, skip_type='time_uniform',
|
1049 |
+
method='multistep', lower_order_final=True, denoise_to_zero=False, solver_type='dpmsolver',
|
1050 |
+
atol=0.0078, rtol=0.05, return_intermediate=False,
|
1051 |
+
):
|
1052 |
+
"""
|
1053 |
+
Compute the sample at time `t_end` by DPM-Solver, given the initial `x` at time `t_start`.
|
1054 |
+
|
1055 |
+
=====================================================
|
1056 |
+
|
1057 |
+
We support the following algorithms for both noise prediction model and data prediction model:
|
1058 |
+
- 'singlestep':
|
1059 |
+
Singlestep DPM-Solver (i.e. "DPM-Solver-fast" in the paper), which combines different orders of singlestep DPM-Solver.
|
1060 |
+
We combine all the singlestep solvers with order <= `order` to use up all the function evaluations (steps).
|
1061 |
+
The total number of function evaluations (NFE) == `steps`.
|
1062 |
+
Given a fixed NFE == `steps`, the sampling procedure is:
|
1063 |
+
- If `order` == 1:
|
1064 |
+
- Denote K = steps. We use K steps of DPM-Solver-1 (i.e. DDIM).
|
1065 |
+
- If `order` == 2:
|
1066 |
+
- Denote K = (steps // 2) + (steps % 2). We take K intermediate time steps for sampling.
|
1067 |
+
- If steps % 2 == 0, we use K steps of singlestep DPM-Solver-2.
|
1068 |
+
- If steps % 2 == 1, we use (K - 1) steps of singlestep DPM-Solver-2 and 1 step of DPM-Solver-1.
|
1069 |
+
- If `order` == 3:
|
1070 |
+
- Denote K = (steps // 3 + 1). We take K intermediate time steps for sampling.
|
1071 |
+
- If steps % 3 == 0, we use (K - 2) steps of singlestep DPM-Solver-3, and 1 step of singlestep DPM-Solver-2 and 1 step of DPM-Solver-1.
|
1072 |
+
- If steps % 3 == 1, we use (K - 1) steps of singlestep DPM-Solver-3 and 1 step of DPM-Solver-1.
|
1073 |
+
- If steps % 3 == 2, we use (K - 1) steps of singlestep DPM-Solver-3 and 1 step of singlestep DPM-Solver-2.
|
1074 |
+
- 'multistep':
|
1075 |
+
Multistep DPM-Solver with the order of `order`. The total number of function evaluations (NFE) == `steps`.
|
1076 |
+
We initialize the first `order` values by lower order multistep solvers.
|
1077 |
+
Given a fixed NFE == `steps`, the sampling procedure is:
|
1078 |
+
Denote K = steps.
|
1079 |
+
- If `order` == 1:
|
1080 |
+
- We use K steps of DPM-Solver-1 (i.e. DDIM).
|
1081 |
+
- If `order` == 2:
|
1082 |
+
- We firstly use 1 step of DPM-Solver-1, then use (K - 1) step of multistep DPM-Solver-2.
|
1083 |
+
- If `order` == 3:
|
1084 |
+
- We firstly use 1 step of DPM-Solver-1, then 1 step of multistep DPM-Solver-2, then (K - 2) step of multistep DPM-Solver-3.
|
1085 |
+
- 'singlestep_fixed':
|
1086 |
+
Fixed order singlestep DPM-Solver (i.e. DPM-Solver-1 or singlestep DPM-Solver-2 or singlestep DPM-Solver-3).
|
1087 |
+
We use singlestep DPM-Solver-`order` for `order`=1 or 2 or 3, with total [`steps` // `order`] * `order` NFE.
|
1088 |
+
- 'adaptive':
|
1089 |
+
Adaptive step size DPM-Solver (i.e. "DPM-Solver-12" and "DPM-Solver-23" in the paper).
|
1090 |
+
We ignore `steps` and use adaptive step size DPM-Solver with a higher order of `order`.
|
1091 |
+
You can adjust the absolute tolerance `atol` and the relative tolerance `rtol` to balance the computatation costs
|
1092 |
+
(NFE) and the sample quality.
|
1093 |
+
- If `order` == 2, we use DPM-Solver-12 which combines DPM-Solver-1 and singlestep DPM-Solver-2.
|
1094 |
+
- If `order` == 3, we use DPM-Solver-23 which combines singlestep DPM-Solver-2 and singlestep DPM-Solver-3.
|
1095 |
+
|
1096 |
+
=====================================================
|
1097 |
+
|
1098 |
+
Some advices for choosing the algorithm:
|
1099 |
+
- For **unconditional sampling** or **guided sampling with small guidance scale** by DPMs:
|
1100 |
+
Use singlestep DPM-Solver or DPM-Solver++ ("DPM-Solver-fast" in the paper) with `order = 3`.
|
1101 |
+
e.g., DPM-Solver:
|
1102 |
+
>>> dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver")
|
1103 |
+
>>> x_sample = dpm_solver.sample(x, steps=steps, t_start=t_start, t_end=t_end, order=3,
|
1104 |
+
skip_type='time_uniform', method='singlestep')
|
1105 |
+
e.g., DPM-Solver++:
|
1106 |
+
>>> dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver++")
|
1107 |
+
>>> x_sample = dpm_solver.sample(x, steps=steps, t_start=t_start, t_end=t_end, order=3,
|
1108 |
+
skip_type='time_uniform', method='singlestep')
|
1109 |
+
- For **guided sampling with large guidance scale** by DPMs:
|
1110 |
+
Use multistep DPM-Solver with `algorithm_type="dpmsolver++"` and `order = 2`.
|
1111 |
+
e.g.
|
1112 |
+
>>> dpm_solver = DPM_Solver(model_fn, noise_schedule, algorithm_type="dpmsolver++")
|
1113 |
+
>>> x_sample = dpm_solver.sample(x, steps=steps, t_start=t_start, t_end=t_end, order=2,
|
1114 |
+
skip_type='time_uniform', method='multistep')
|
1115 |
+
|
1116 |
+
We support three types of `skip_type`:
|
1117 |
+
- 'logSNR': uniform logSNR for the time steps. **Recommended for low-resolutional images**
|
1118 |
+
- 'time_uniform': uniform time for the time steps. **Recommended for high-resolutional images**.
|
1119 |
+
- 'time_quadratic': quadratic time for the time steps.
|
1120 |
+
|
1121 |
+
=====================================================
|
1122 |
+
Args:
|
1123 |
+
x: A pytorch tensor. The initial value at time `t_start`
|
1124 |
+
e.g. if `t_start` == T, then `x` is a sample from the standard normal distribution.
|
1125 |
+
steps: A `int`. The total number of function evaluations (NFE).
|
1126 |
+
t_start: A `float`. The starting time of the sampling.
|
1127 |
+
If `T` is None, we use self.noise_schedule.T (default is 1.0).
|
1128 |
+
t_end: A `float`. The ending time of the sampling.
|
1129 |
+
If `t_end` is None, we use 1. / self.noise_schedule.total_N.
|
1130 |
+
e.g. if total_N == 1000, we have `t_end` == 1e-3.
|
1131 |
+
For discrete-time DPMs:
|
1132 |
+
- We recommend `t_end` == 1. / self.noise_schedule.total_N.
|
1133 |
+
For continuous-time DPMs:
|
1134 |
+
- We recommend `t_end` == 1e-3 when `steps` <= 15; and `t_end` == 1e-4 when `steps` > 15.
|
1135 |
+
order: A `int`. The order of DPM-Solver.
|
1136 |
+
skip_type: A `str`. The type for the spacing of the time steps. 'time_uniform' or 'logSNR' or 'time_quadratic'.
|
1137 |
+
method: A `str`. The method for sampling. 'singlestep' or 'multistep' or 'singlestep_fixed' or 'adaptive'.
|
1138 |
+
denoise_to_zero: A `bool`. Whether to denoise to time 0 at the final step.
|
1139 |
+
Default is `False`. If `denoise_to_zero` is `True`, the total NFE is (`steps` + 1).
|
1140 |
+
|
1141 |
+
This trick is firstly proposed by DDPM (https://arxiv.org/abs/2006.11239) and
|
1142 |
+
score_sde (https://arxiv.org/abs/2011.13456). Such trick can improve the FID
|
1143 |
+
for diffusion models sampling by diffusion SDEs for low-resolutional images
|
1144 |
+
(such as CIFAR-10). However, we observed that such trick does not matter for
|
1145 |
+
high-resolutional images. As it needs an additional NFE, we do not recommend
|
1146 |
+
it for high-resolutional images.
|
1147 |
+
lower_order_final: A `bool`. Whether to use lower order solvers at the final steps.
|
1148 |
+
Only valid for `method=multistep` and `steps < 15`. We empirically find that
|
1149 |
+
this trick is a key to stabilizing the sampling by DPM-Solver with very few steps
|
1150 |
+
(especially for steps <= 10). So we recommend to set it to be `True`.
|
1151 |
+
solver_type: A `str`. The taylor expansion type for the solver. `dpmsolver` or `taylor`. We recommend `dpmsolver`.
|
1152 |
+
atol: A `float`. The absolute tolerance of the adaptive step size solver. Valid when `method` == 'adaptive'.
|
1153 |
+
rtol: A `float`. The relative tolerance of the adaptive step size solver. Valid when `method` == 'adaptive'.
|
1154 |
+
return_intermediate: A `bool`. Whether to save the xt at each step.
|
1155 |
+
When set to `True`, method returns a tuple (x0, intermediates); when set to False, method returns only x0.
|
1156 |
+
Returns:
|
1157 |
+
x_end: A pytorch tensor. The approximated solution at time `t_end`.
|
1158 |
+
|
1159 |
+
"""
|
1160 |
+
t_0 = 1. / self.noise_schedule.total_N if t_end is None else t_end
|
1161 |
+
t_T = self.noise_schedule.T if t_start is None else t_start
|
1162 |
+
assert t_0 > 0 and t_T > 0, "Time range needs to be greater than 0. For discrete-time DPMs, it needs to be in [1 / N, 1], where N is the length of betas array"
|
1163 |
+
if return_intermediate:
|
1164 |
+
assert method in ['multistep', 'singlestep', 'singlestep_fixed'], "Cannot use adaptive solver when saving intermediate values"
|
1165 |
+
if self.correcting_xt_fn is not None:
|
1166 |
+
assert method in ['multistep', 'singlestep', 'singlestep_fixed'], "Cannot use adaptive solver when correcting_xt_fn is not None"
|
1167 |
+
device = x.device
|
1168 |
+
intermediates = []
|
1169 |
+
with torch.no_grad():
|
1170 |
+
if method == 'adaptive':
|
1171 |
+
x = self.dpm_solver_adaptive(x, order=order, t_T=t_T, t_0=t_0, atol=atol, rtol=rtol, solver_type=solver_type)
|
1172 |
+
elif method == 'multistep':
|
1173 |
+
assert steps >= order
|
1174 |
+
timesteps = self.get_time_steps(skip_type=skip_type, t_T=t_T, t_0=t_0, N=steps, device=device)
|
1175 |
+
assert timesteps.shape[0] - 1 == steps
|
1176 |
+
# Init the initial values.
|
1177 |
+
step = 0
|
1178 |
+
t = timesteps[step]
|
1179 |
+
t_prev_list = [t]
|
1180 |
+
model_prev_list = [self.model_fn(x, t)]
|
1181 |
+
if self.correcting_xt_fn is not None:
|
1182 |
+
x = self.correcting_xt_fn(x, t, step)
|
1183 |
+
if return_intermediate:
|
1184 |
+
intermediates.append(x)
|
1185 |
+
# Init the first `order` values by lower order multistep DPM-Solver.
|
1186 |
+
for step in range(1, order):
|
1187 |
+
t = timesteps[step]
|
1188 |
+
x = self.multistep_dpm_solver_update(x, model_prev_list, t_prev_list, t, step, solver_type=solver_type)
|
1189 |
+
if self.correcting_xt_fn is not None:
|
1190 |
+
x = self.correcting_xt_fn(x, t, step)
|
1191 |
+
if return_intermediate:
|
1192 |
+
intermediates.append(x)
|
1193 |
+
t_prev_list.append(t)
|
1194 |
+
model_prev_list.append(self.model_fn(x, t))
|
1195 |
+
# Compute the remaining values by `order`-th order multistep DPM-Solver.
|
1196 |
+
for step in range(order, steps + 1):
|
1197 |
+
t = timesteps[step]
|
1198 |
+
# We only use lower order for steps < 10
|
1199 |
+
if lower_order_final and steps < 10:
|
1200 |
+
step_order = min(order, steps + 1 - step)
|
1201 |
+
else:
|
1202 |
+
step_order = order
|
1203 |
+
x = self.multistep_dpm_solver_update(x, model_prev_list, t_prev_list, t, step_order, solver_type=solver_type)
|
1204 |
+
if self.correcting_xt_fn is not None:
|
1205 |
+
x = self.correcting_xt_fn(x, t, step)
|
1206 |
+
if return_intermediate:
|
1207 |
+
intermediates.append(x)
|
1208 |
+
for i in range(order - 1):
|
1209 |
+
t_prev_list[i] = t_prev_list[i + 1]
|
1210 |
+
model_prev_list[i] = model_prev_list[i + 1]
|
1211 |
+
t_prev_list[-1] = t
|
1212 |
+
# We do not need to evaluate the final model value.
|
1213 |
+
if step < steps:
|
1214 |
+
model_prev_list[-1] = self.model_fn(x, t)
|
1215 |
+
elif method in ['singlestep', 'singlestep_fixed']:
|
1216 |
+
if method == 'singlestep':
|
1217 |
+
timesteps_outer, orders = self.get_orders_and_timesteps_for_singlestep_solver(steps=steps, order=order, skip_type=skip_type, t_T=t_T, t_0=t_0, device=device)
|
1218 |
+
elif method == 'singlestep_fixed':
|
1219 |
+
K = steps // order
|
1220 |
+
orders = [order,] * K
|
1221 |
+
timesteps_outer = self.get_time_steps(skip_type=skip_type, t_T=t_T, t_0=t_0, N=K, device=device)
|
1222 |
+
for step, order in enumerate(orders):
|
1223 |
+
s, t = timesteps_outer[step], timesteps_outer[step + 1]
|
1224 |
+
timesteps_inner = self.get_time_steps(skip_type=skip_type, t_T=s.item(), t_0=t.item(), N=order, device=device)
|
1225 |
+
lambda_inner = self.noise_schedule.marginal_lambda(timesteps_inner)
|
1226 |
+
h = lambda_inner[-1] - lambda_inner[0]
|
1227 |
+
r1 = None if order <= 1 else (lambda_inner[1] - lambda_inner[0]) / h
|
1228 |
+
r2 = None if order <= 2 else (lambda_inner[2] - lambda_inner[0]) / h
|
1229 |
+
x = self.singlestep_dpm_solver_update(x, s, t, order, solver_type=solver_type, r1=r1, r2=r2)
|
1230 |
+
if self.correcting_xt_fn is not None:
|
1231 |
+
x = self.correcting_xt_fn(x, t, step)
|
1232 |
+
if return_intermediate:
|
1233 |
+
intermediates.append(x)
|
1234 |
+
else:
|
1235 |
+
raise ValueError("Got wrong method {}".format(method))
|
1236 |
+
if denoise_to_zero:
|
1237 |
+
t = torch.ones((1,)).to(device) * t_0
|
1238 |
+
x = self.denoise_to_zero_fn(x, t)
|
1239 |
+
if self.correcting_xt_fn is not None:
|
1240 |
+
x = self.correcting_xt_fn(x, t, step + 1)
|
1241 |
+
if return_intermediate:
|
1242 |
+
intermediates.append(x)
|
1243 |
+
if return_intermediate:
|
1244 |
+
return x, intermediates
|
1245 |
+
else:
|
1246 |
+
return x
|
1247 |
+
|
1248 |
+
|
1249 |
+
|
1250 |
+
#############################################################
|
1251 |
+
# other utility functions
|
1252 |
+
#############################################################
|
1253 |
+
|
1254 |
+
def interpolate_fn(x, xp, yp):
|
1255 |
+
"""
|
1256 |
+
A piecewise linear function y = f(x), using xp and yp as keypoints.
|
1257 |
+
We implement f(x) in a differentiable way (i.e. applicable for autograd).
|
1258 |
+
The function f(x) is well-defined for all x-axis. (For x beyond the bounds of xp, we use the outmost points of xp to define the linear function.)
|
1259 |
+
|
1260 |
+
Args:
|
1261 |
+
x: PyTorch tensor with shape [N, C], where N is the batch size, C is the number of channels (we use C = 1 for DPM-Solver).
|
1262 |
+
xp: PyTorch tensor with shape [C, K], where K is the number of keypoints.
|
1263 |
+
yp: PyTorch tensor with shape [C, K].
|
1264 |
+
Returns:
|
1265 |
+
The function values f(x), with shape [N, C].
|
1266 |
+
"""
|
1267 |
+
N, K = x.shape[0], xp.shape[1]
|
1268 |
+
all_x = torch.cat([x.unsqueeze(2), xp.unsqueeze(0).repeat((N, 1, 1))], dim=2)
|
1269 |
+
sorted_all_x, x_indices = torch.sort(all_x, dim=2)
|
1270 |
+
x_idx = torch.argmin(x_indices, dim=2)
|
1271 |
+
cand_start_idx = x_idx - 1
|
1272 |
+
start_idx = torch.where(
|
1273 |
+
torch.eq(x_idx, 0),
|
1274 |
+
torch.tensor(1, device=x.device),
|
1275 |
+
torch.where(
|
1276 |
+
torch.eq(x_idx, K), torch.tensor(K - 2, device=x.device), cand_start_idx,
|
1277 |
+
),
|
1278 |
+
)
|
1279 |
+
end_idx = torch.where(torch.eq(start_idx, cand_start_idx), start_idx + 2, start_idx + 1)
|
1280 |
+
start_x = torch.gather(sorted_all_x, dim=2, index=start_idx.unsqueeze(2)).squeeze(2)
|
1281 |
+
end_x = torch.gather(sorted_all_x, dim=2, index=end_idx.unsqueeze(2)).squeeze(2)
|
1282 |
+
start_idx2 = torch.where(
|
1283 |
+
torch.eq(x_idx, 0),
|
1284 |
+
torch.tensor(0, device=x.device),
|
1285 |
+
torch.where(
|
1286 |
+
torch.eq(x_idx, K), torch.tensor(K - 2, device=x.device), cand_start_idx,
|
1287 |
+
),
|
1288 |
+
)
|
1289 |
+
y_positions_expanded = yp.unsqueeze(0).expand(N, -1, -1)
|
1290 |
+
start_y = torch.gather(y_positions_expanded, dim=2, index=start_idx2.unsqueeze(2)).squeeze(2)
|
1291 |
+
end_y = torch.gather(y_positions_expanded, dim=2, index=(start_idx2 + 1).unsqueeze(2)).squeeze(2)
|
1292 |
+
cand = start_y + (x - start_x) * (end_y - start_y) / (end_x - start_x)
|
1293 |
+
return cand
|
1294 |
+
|
1295 |
+
|
1296 |
+
def expand_dims(v, dims):
|
1297 |
+
"""
|
1298 |
+
Expand the tensor `v` to the dim `dims`.
|
1299 |
+
|
1300 |
+
Args:
|
1301 |
+
`v`: a PyTorch tensor with shape [N].
|
1302 |
+
`dim`: a `int`.
|
1303 |
+
Returns:
|
1304 |
+
a PyTorch tensor with shape [N, 1, 1, ..., 1] and the total dimension is `dims`.
|
1305 |
+
"""
|
1306 |
+
return v[(...,) + (None,)*(dims - 1)]
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/logger.py
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from PIL import Image
|
3 |
+
import importlib
|
4 |
+
from datetime import datetime
|
5 |
+
import logging
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
import core.util as Util
|
9 |
+
|
10 |
+
class InfoLogger():
|
11 |
+
"""
|
12 |
+
use logging to record log, only work on GPU 0 by judging global_rank
|
13 |
+
"""
|
14 |
+
def __init__(self, opt):
|
15 |
+
self.opt = opt
|
16 |
+
self.rank = opt['global_rank']
|
17 |
+
self.phase = opt['phase']
|
18 |
+
|
19 |
+
self.setup_logger(None, opt['path']['experiments_root'], opt['phase'], level=logging.INFO, screen=False)
|
20 |
+
self.logger = logging.getLogger(opt['phase'])
|
21 |
+
self.infologger_ftns = {'info', 'warning', 'debug'}
|
22 |
+
|
23 |
+
def __getattr__(self, name):
|
24 |
+
if self.rank != 0: # info only print on GPU 0.
|
25 |
+
def wrapper(info, *args, **kwargs):
|
26 |
+
pass
|
27 |
+
return wrapper
|
28 |
+
if name in self.infologger_ftns:
|
29 |
+
print_info = getattr(self.logger, name, None)
|
30 |
+
def wrapper(info, *args, **kwargs):
|
31 |
+
print_info(info, *args, **kwargs)
|
32 |
+
return wrapper
|
33 |
+
|
34 |
+
@staticmethod
|
35 |
+
def setup_logger(logger_name, root, phase, level=logging.INFO, screen=False):
|
36 |
+
""" set up logger """
|
37 |
+
l = logging.getLogger(logger_name)
|
38 |
+
formatter = logging.Formatter(
|
39 |
+
'%(asctime)s.%(msecs)03d - %(levelname)s: %(message)s', datefmt='%y-%m-%d %H:%M:%S')
|
40 |
+
log_file = os.path.join(root, '{}.log'.format(phase))
|
41 |
+
fh = logging.FileHandler(log_file, mode='a+')
|
42 |
+
fh.setFormatter(formatter)
|
43 |
+
l.setLevel(level)
|
44 |
+
l.addHandler(fh)
|
45 |
+
if screen:
|
46 |
+
sh = logging.StreamHandler()
|
47 |
+
sh.setFormatter(formatter)
|
48 |
+
l.addHandler(sh)
|
49 |
+
|
50 |
+
class VisualWriter():
|
51 |
+
"""
|
52 |
+
use tensorboard to record visuals, support 'add_scalar', 'add_scalars', 'add_image', 'add_images', etc. funtion.
|
53 |
+
Also integrated with save results function.
|
54 |
+
"""
|
55 |
+
def __init__(self, opt, logger):
|
56 |
+
log_dir = opt['path']['tb_logger']
|
57 |
+
self.result_dir = opt['path']['results']
|
58 |
+
enabled = opt['train']['tensorboard']
|
59 |
+
self.rank = opt['global_rank']
|
60 |
+
|
61 |
+
self.writer = None
|
62 |
+
self.selected_module = ""
|
63 |
+
|
64 |
+
if enabled and self.rank==0:
|
65 |
+
log_dir = str(log_dir)
|
66 |
+
|
67 |
+
# Retrieve vizualization writer.
|
68 |
+
succeeded = False
|
69 |
+
for module in ["tensorboardX", "torch.utils.tensorboard"]:
|
70 |
+
try:
|
71 |
+
self.writer = importlib.import_module(module).SummaryWriter(log_dir)
|
72 |
+
succeeded = True
|
73 |
+
break
|
74 |
+
except ImportError:
|
75 |
+
succeeded = False
|
76 |
+
self.selected_module = module
|
77 |
+
|
78 |
+
if not succeeded:
|
79 |
+
message = "Warning: visualization (Tensorboard) is configured to use, but currently not installed on " \
|
80 |
+
"this machine. Please install TensorboardX with 'pip install tensorboardx', upgrade PyTorch to " \
|
81 |
+
"version >= 1.1 to use 'torch.utils.tensorboard' or turn off the option in the 'config.json' file."
|
82 |
+
logger.warning(message)
|
83 |
+
|
84 |
+
self.epoch = 0
|
85 |
+
self.iter = 0
|
86 |
+
self.phase = ''
|
87 |
+
|
88 |
+
self.tb_writer_ftns = {
|
89 |
+
'add_scalar', 'add_scalars', 'add_image', 'add_images', 'add_audio',
|
90 |
+
'add_text', 'add_histogram', 'add_pr_curve', 'add_embedding'
|
91 |
+
}
|
92 |
+
self.tag_mode_exceptions = {'add_histogram', 'add_embedding'}
|
93 |
+
self.custom_ftns = {'close'}
|
94 |
+
self.timer = datetime.now()
|
95 |
+
|
96 |
+
def set_iter(self, epoch, iter, phase='train'):
|
97 |
+
self.phase = phase
|
98 |
+
self.epoch = epoch
|
99 |
+
self.iter = iter
|
100 |
+
|
101 |
+
def save_images(self, results):
|
102 |
+
result_path = os.path.join(self.result_dir, self.phase)
|
103 |
+
os.makedirs(result_path, exist_ok=True)
|
104 |
+
result_path = os.path.join(result_path, str(self.epoch))
|
105 |
+
os.makedirs(result_path, exist_ok=True)
|
106 |
+
|
107 |
+
''' get names and corresponding images from results[OrderedDict] '''
|
108 |
+
try:
|
109 |
+
names = results['name']
|
110 |
+
outputs = Util.postprocess(results['result'])
|
111 |
+
for i in range(len(names)):
|
112 |
+
if os.path.exists(os.path.join(result_path, names[i])):
|
113 |
+
pass
|
114 |
+
else:
|
115 |
+
Image.fromarray(outputs[i]).save(os.path.join(result_path, names[i]))
|
116 |
+
except:
|
117 |
+
raise NotImplementedError('You must specify the context of name and result in save_current_results functions of model.')
|
118 |
+
|
119 |
+
def close(self):
|
120 |
+
self.writer.close()
|
121 |
+
print('Close the Tensorboard SummaryWriter.')
|
122 |
+
|
123 |
+
|
124 |
+
def __getattr__(self, name):
|
125 |
+
"""
|
126 |
+
If visualization is configured to use:
|
127 |
+
return add_data() methods of tensorboard with additional information (step, tag) added.
|
128 |
+
Otherwise:
|
129 |
+
return a blank function handle that does nothing
|
130 |
+
"""
|
131 |
+
if name in self.tb_writer_ftns:
|
132 |
+
add_data = getattr(self.writer, name, None)
|
133 |
+
def wrapper(tag, data, *args, **kwargs):
|
134 |
+
if add_data is not None:
|
135 |
+
# add phase(train/valid) tag
|
136 |
+
if name not in self.tag_mode_exceptions:
|
137 |
+
tag = '{}/{}'.format(self.phase, tag)
|
138 |
+
add_data(tag, data, self.iter, *args, **kwargs)
|
139 |
+
return wrapper
|
140 |
+
else:
|
141 |
+
# default action for returning methods defined in this class, set_step() for instance.
|
142 |
+
try:
|
143 |
+
attr = object.__getattr__(name)
|
144 |
+
except AttributeError:
|
145 |
+
raise AttributeError("type object '{}' has no attribute '{}'".format(self.selected_module, name))
|
146 |
+
return attr
|
147 |
+
|
148 |
+
|
149 |
+
class LogTracker:
|
150 |
+
"""
|
151 |
+
record training numerical indicators.
|
152 |
+
"""
|
153 |
+
def __init__(self, *keys, phase='train'):
|
154 |
+
self.phase = phase
|
155 |
+
self._data = pd.DataFrame(index=keys, columns=['total', 'counts', 'average'])
|
156 |
+
self.reset()
|
157 |
+
|
158 |
+
def reset(self):
|
159 |
+
for col in self._data.columns:
|
160 |
+
self._data[col].values[:] = 0
|
161 |
+
|
162 |
+
def update(self, key, value, n=1):
|
163 |
+
self._data.total[key] += value * n
|
164 |
+
self._data.counts[key] += n
|
165 |
+
self._data.average[key] = self._data.total[key] / self._data.counts[key]
|
166 |
+
|
167 |
+
def avg(self, key):
|
168 |
+
return self._data.average[key]
|
169 |
+
|
170 |
+
def result(self):
|
171 |
+
return {'{}/{}'.format(self.phase, k):v for k, v in dict(self._data.average).items()}
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/praser.py
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from collections import OrderedDict
|
3 |
+
import json
|
4 |
+
from pathlib import Path
|
5 |
+
from datetime import datetime
|
6 |
+
from functools import partial
|
7 |
+
import importlib
|
8 |
+
from types import FunctionType
|
9 |
+
import shutil
|
10 |
+
def init_obj(opt, logger, *args, default_file_name='default file', given_module=None, init_type='Network', **modify_kwargs):
|
11 |
+
"""
|
12 |
+
finds a function handle with the name given as 'name' in config,
|
13 |
+
and returns the instance initialized with corresponding args.
|
14 |
+
"""
|
15 |
+
if opt is None or len(opt)<1:
|
16 |
+
logger.info('Option is None when initialize {}'.format(init_type))
|
17 |
+
return None
|
18 |
+
|
19 |
+
''' default format is dict with name key '''
|
20 |
+
if isinstance(opt, str):
|
21 |
+
opt = {'name': opt}
|
22 |
+
logger.warning('Config is a str, converts to a dict {}'.format(opt))
|
23 |
+
|
24 |
+
name = opt['name']
|
25 |
+
''' name can be list, indicates the file and class name of function '''
|
26 |
+
if isinstance(name, list):
|
27 |
+
file_name, class_name = name[0], name[1]
|
28 |
+
else:
|
29 |
+
file_name, class_name = default_file_name, name
|
30 |
+
try:
|
31 |
+
if given_module is not None:
|
32 |
+
module = given_module
|
33 |
+
else:
|
34 |
+
module = importlib.import_module(file_name)
|
35 |
+
|
36 |
+
attr = getattr(module, class_name)
|
37 |
+
kwargs = opt.get('args', {})
|
38 |
+
kwargs.update(modify_kwargs)
|
39 |
+
''' import class or function with args '''
|
40 |
+
if isinstance(attr, type):
|
41 |
+
ret = attr(*args, **kwargs)
|
42 |
+
ret.__name__ = ret.__class__.__name__
|
43 |
+
elif isinstance(attr, FunctionType):
|
44 |
+
ret = partial(attr, *args, **kwargs)
|
45 |
+
ret.__name__ = attr.__name__
|
46 |
+
# ret = attr
|
47 |
+
logger.info('{} [{:s}() form {:s}] is created.'.format(init_type, class_name, file_name))
|
48 |
+
except:
|
49 |
+
raise NotImplementedError('{} [{:s}() form {:s}] not recognized.'.format(init_type, class_name, file_name))
|
50 |
+
return ret
|
51 |
+
|
52 |
+
|
53 |
+
def mkdirs(paths):
|
54 |
+
if isinstance(paths, str):
|
55 |
+
os.makedirs(paths, exist_ok=True)
|
56 |
+
else:
|
57 |
+
for path in paths:
|
58 |
+
os.makedirs(path, exist_ok=True)
|
59 |
+
|
60 |
+
def get_timestamp():
|
61 |
+
return datetime.now().strftime('%y%m%d_%H%M%S')
|
62 |
+
|
63 |
+
|
64 |
+
def write_json(content, fname):
|
65 |
+
fname = Path(fname)
|
66 |
+
with fname.open('wt') as handle:
|
67 |
+
json.dump(content, handle, indent=4, sort_keys=False)
|
68 |
+
|
69 |
+
class NoneDict(dict):
|
70 |
+
def __missing__(self, key):
|
71 |
+
return None
|
72 |
+
|
73 |
+
def dict_to_nonedict(opt):
|
74 |
+
""" convert to NoneDict, which return None for missing key. """
|
75 |
+
if isinstance(opt, dict):
|
76 |
+
new_opt = dict()
|
77 |
+
for key, sub_opt in opt.items():
|
78 |
+
new_opt[key] = dict_to_nonedict(sub_opt)
|
79 |
+
return NoneDict(**new_opt)
|
80 |
+
elif isinstance(opt, list):
|
81 |
+
return [dict_to_nonedict(sub_opt) for sub_opt in opt]
|
82 |
+
else:
|
83 |
+
return opt
|
84 |
+
|
85 |
+
def dict2str(opt, indent_l=1):
|
86 |
+
""" dict to string for logger """
|
87 |
+
msg = ''
|
88 |
+
for k, v in opt.items():
|
89 |
+
if isinstance(v, dict):
|
90 |
+
msg += ' ' * (indent_l * 2) + k + ':[\n'
|
91 |
+
msg += dict2str(v, indent_l + 1)
|
92 |
+
msg += ' ' * (indent_l * 2) + ']\n'
|
93 |
+
else:
|
94 |
+
msg += ' ' * (indent_l * 2) + k + ': ' + str(v) + '\n'
|
95 |
+
return msg
|
96 |
+
|
97 |
+
def parse(args):
|
98 |
+
json_str = ''
|
99 |
+
with open(args.config, 'r') as f:
|
100 |
+
for line in f:
|
101 |
+
line = line.split('//')[0] + '\n'
|
102 |
+
json_str += line
|
103 |
+
opt = json.loads(json_str, object_pairs_hook=OrderedDict)
|
104 |
+
|
105 |
+
''' replace the config context using args '''
|
106 |
+
opt['phase'] = args.phase
|
107 |
+
if args.gpu_ids is not None:
|
108 |
+
opt['gpu_ids'] = [int(id) for id in args.gpu_ids.split(',')]
|
109 |
+
if args.batch is not None:
|
110 |
+
opt['datasets'][opt['phase']]['dataloader']['args']['batch_size'] = args.batch
|
111 |
+
|
112 |
+
''' set cuda environment '''
|
113 |
+
if len(opt['gpu_ids']) > 1:
|
114 |
+
opt['distributed'] = True
|
115 |
+
else:
|
116 |
+
opt['distributed'] = False
|
117 |
+
|
118 |
+
''' update name '''
|
119 |
+
if args.debug:
|
120 |
+
opt['name'] = 'debug_{}'.format(opt['name'])
|
121 |
+
elif opt['finetune_norm']:
|
122 |
+
opt['name'] = 'finetune_{}'.format(opt['name'])
|
123 |
+
else:
|
124 |
+
opt['name'] = '{}_{}'.format(opt['phase'], opt['name'])
|
125 |
+
|
126 |
+
''' set log directory '''
|
127 |
+
experiments_root = os.path.join(opt['path']['base_dir'], '{}_{}'.format(opt['name'], get_timestamp()))
|
128 |
+
mkdirs(experiments_root)
|
129 |
+
|
130 |
+
''' save json '''
|
131 |
+
write_json(opt, '{}/config.json'.format(experiments_root))
|
132 |
+
|
133 |
+
''' change folder relative hierarchy '''
|
134 |
+
opt['path']['experiments_root'] = experiments_root
|
135 |
+
for key, path in opt['path'].items():
|
136 |
+
if 'resume' not in key and 'base' not in key and 'root' not in key:
|
137 |
+
opt['path'][key] = os.path.join(experiments_root, path)
|
138 |
+
mkdirs(opt['path'][key])
|
139 |
+
|
140 |
+
''' debug mode '''
|
141 |
+
if 'debug' in opt['name']:
|
142 |
+
opt['train'].update(opt['debug'])
|
143 |
+
|
144 |
+
''' code backup '''
|
145 |
+
for name in os.listdir('.'):
|
146 |
+
if name in ['config', 'models', 'core', 'slurm', 'data']:
|
147 |
+
shutil.copytree(name, os.path.join(opt['path']['code'], name), ignore=shutil.ignore_patterns("*.pyc", "__pycache__"))
|
148 |
+
if '.py' in name or '.sh' in name:
|
149 |
+
shutil.copy(name, opt['path']['code'])
|
150 |
+
return dict_to_nonedict(opt)
|
151 |
+
|
152 |
+
|
153 |
+
|
154 |
+
|
155 |
+
|
experiments/train_nafnet_double_encoder_splitcaCond_splitcaUnet_sigmoid_noisen3_230611_035949/code/core/util.py
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import numpy as np
|
3 |
+
import math
|
4 |
+
import torch
|
5 |
+
from torch.nn.parallel import DistributedDataParallel as DDP
|
6 |
+
from torchvision.utils import make_grid
|
7 |
+
|
8 |
+
|
9 |
+
def get_rgb(image): # CHW
|
10 |
+
image = image.mul(0.5).add_(0.5)
|
11 |
+
image = image.mul(10000).add_(0.5).clamp_(0, 10000)
|
12 |
+
image = image.permute(1, 2, 0).cpu().detach().numpy() # HWC
|
13 |
+
image = image.astype(np.uint16)
|
14 |
+
|
15 |
+
r = image[:, :, 0]
|
16 |
+
g = image[:, :, 1]
|
17 |
+
b = image[:, :, 2]
|
18 |
+
|
19 |
+
r = np.clip(r, 0, 2000)
|
20 |
+
g = np.clip(g, 0, 2000)
|
21 |
+
b = np.clip(b, 0, 2000)
|
22 |
+
|
23 |
+
rgb = np.dstack((r, g, b))
|
24 |
+
rgb = rgb - np.nanmin(rgb)
|
25 |
+
|
26 |
+
if np.nanmax(rgb) == 0:
|
27 |
+
rgb = 255 * np.ones_like(rgb)
|
28 |
+
else:
|
29 |
+
rgb = 255 * (rgb / np.nanmax(rgb))
|
30 |
+
|
31 |
+
rgb[np.isnan(rgb)] = np.nanmean(rgb)
|
32 |
+
rgb = rgb.astype(np.uint8)
|
33 |
+
return rgb
|
34 |
+
|
35 |
+
|
36 |
+
def tensor2img(tensor, out_type=np.uint8, min_max=(-1, 1)): # 可视化v2.0
|
37 |
+
'''
|
38 |
+
Converts a torch Tensor into an image Numpy array
|
39 |
+
Input: 4D(B,(3/1),H,W), 3D(C,H,W), or 2D(H,W), any range, RGB channel order
|
40 |
+
Output: 3D(H,W,C) or 2D(H,W), [0,255], np.uint8 (default)
|
41 |
+
'''
|
42 |
+
# tensor = tensor.clamp_(*min_max) # clamp
|
43 |
+
n_dim = tensor.dim()
|
44 |
+
if n_dim == 4:
|
45 |
+
n_img = len(tensor)
|
46 |
+
img_np = make_grid([torch.from_numpy(get_rgb(tensor[i])).permute(2, 0, 1) for i in range(n_img)], nrow=int(
|
47 |
+
math.sqrt(n_img)), normalize=False).numpy()
|
48 |
+
img_np = np.transpose(img_np, (1, 2, 0)) # HWC, RGB
|
49 |
+
elif n_dim == 3:
|
50 |
+
img_np = get_rgb(tensor)
|
51 |
+
elif n_dim == 2:
|
52 |
+
img_np = tensor.numpy()
|
53 |
+
else:
|
54 |
+
raise TypeError(
|
55 |
+
'Only support 4D, 3D and 2D tensor. But received with dimension: {:d}'.format(n_dim))
|
56 |
+
return img_np
|
57 |
+
|
58 |
+
|
59 |
+
# def tensor2img(tensor, out_type=np.uint8, min_max=(-1, 1)): # 可视化原作者的
|
60 |
+
# '''
|
61 |
+
# Converts a torch Tensor into an image Numpy array
|
62 |
+
# Input: 4D(B,(3/1),H,W), 3D(C,H,W), or 2D(H,W), any range, RGB channel order
|
63 |
+
# Output: 3D(H,W,C) or 2D(H,W), [0,255], np.uint8 (default)
|
64 |
+
# '''
|
65 |
+
# tensor = tensor.clamp_(*min_max) # clamp
|
66 |
+
# n_dim = tensor.dim()
|
67 |
+
# if n_dim == 4:
|
68 |
+
# n_img = len(tensor)
|
69 |
+
# img_np = make_grid(tensor[:, :3, :, :], nrow=int(math.sqrt(n_img)), normalize=False).numpy()
|
70 |
+
# img_np = np.transpose(img_np, (1, 2, 0)) # HWC, RGB
|
71 |
+
# elif n_dim == 3:
|
72 |
+
# img_np = tensor[:3, :, :].numpy()
|
73 |
+
# img_np = np.transpose(img_np, (1, 2, 0)) # HWC, RGB
|
74 |
+
# elif n_dim == 2:
|
75 |
+
# img_np = tensor.numpy()
|
76 |
+
# else:
|
77 |
+
# raise TypeError('Only support 4D, 3D and 2D tensor. But received with dimension: {:d}'.format(n_dim))
|
78 |
+
# if out_type == np.uint8:
|
79 |
+
# img_np = ((img_np+1) * 127.5).round()
|
80 |
+
# # Important. Unlike matlab, numpy.unit8() WILL NOT round by default.
|
81 |
+
# return img_np.astype(out_type).squeeze()
|
82 |
+
|
83 |
+
# def tensor2img(tensor, out_type=np.uint8, min_max=(-1, 1)): # 可视化v1.0
|
84 |
+
# '''
|
85 |
+
# Converts a torch Tensor into an image Numpy array
|
86 |
+
# Input: 4D(B,(3/1),H,W), 3D(C,H,W), or 2D(H,W), any range, RGB channel order
|
87 |
+
# Output: 3D(H,W,C) or 2D(H,W), [0,255], np.uint8 (default)
|
88 |
+
# '''
|
89 |
+
# tensor = tensor.clamp_(*min_max) # clamp
|
90 |
+
# def get_rgb_tensor(rgb):
|
91 |
+
# rgb = rgb*0.5+0.5
|
92 |
+
# rgb = rgb - torch.min(rgb)
|
93 |
+
# # treat saturated images, scale values
|
94 |
+
# if torch.max(rgb) == 0:
|
95 |
+
# rgb = 255 * torch.ones_like(rgb)
|
96 |
+
# else:
|
97 |
+
# rgb = 255 * (rgb / torch.max(rgb))
|
98 |
+
# return rgb.type(torch.uint8)
|
99 |
+
# tensor = get_rgb_tensor(tensor)
|
100 |
+
# n_dim = tensor.dim()
|
101 |
+
# if n_dim == 4:
|
102 |
+
# n_img = len(tensor)
|
103 |
+
# img_np = make_grid(tensor, nrow=int(math.sqrt(n_img)), normalize=False).numpy()
|
104 |
+
# img_np = np.transpose(img_np, (1, 2, 0)) # HWC, RGB
|
105 |
+
# elif n_dim == 3:
|
106 |
+
# img_np = tensor.numpy()
|
107 |
+
# img_np = np.transpose(img_np, (1, 2, 0)) # HWC, RGB
|
108 |
+
# elif n_dim == 2:
|
109 |
+
# img_np = tensor.numpy()
|
110 |
+
# else:
|
111 |
+
# raise TypeError('Only support 4D, 3D and 2D tensor. But received with dimension: {:d}'.format(n_dim))
|
112 |
+
# # if out_type == np.uint8:
|
113 |
+
# # img_np = ((img_np+1) * 127.5).round()
|
114 |
+
# # Important. Unlike matlab, numpy.unit8() WILL NOT round by default.
|
115 |
+
# return img_np.astype(out_type).squeeze()
|
116 |
+
|
117 |
+
def postprocess(images):
|
118 |
+
return [tensor2img(image) for image in images]
|
119 |
+
|
120 |
+
|
121 |
+
def set_seed(seed, gl_seed=0):
|
122 |
+
""" set random seed, gl_seed used in worker_init_fn function """
|
123 |
+
if seed >= 0 and gl_seed >= 0:
|
124 |
+
seed += gl_seed
|
125 |
+
torch.manual_seed(seed)
|
126 |
+
torch.cuda.manual_seed_all(seed)
|
127 |
+
np.random.seed(seed)
|
128 |
+
random.seed(seed)
|
129 |
+
|
130 |
+
''' change the deterministic and benchmark maybe cause uncertain convolution behavior.
|
131 |
+
speed-reproducibility tradeoff https://pytorch.org/docs/stable/notes/randomness.html '''
|
132 |
+
if seed >= 0 and gl_seed >= 0: # slower, more reproducible
|
133 |
+
torch.backends.cudnn.deterministic = True
|
134 |
+
torch.backends.cudnn.benchmark = False
|
135 |
+
else: # faster, less reproducible
|
136 |
+
torch.backends.cudnn.deterministic = False
|
137 |
+
torch.backends.cudnn.benchmark = True
|
138 |
+
|
139 |
+
|
140 |
+
def set_gpu(args, distributed=False, rank=0):
|
141 |
+
""" set parameter to gpu or ddp """
|
142 |
+
if args is None:
|
143 |
+
return None
|
144 |
+
if distributed and isinstance(args, torch.nn.Module):
|
145 |
+
return DDP(args.cuda(), device_ids=[rank], output_device=rank, broadcast_buffers=True, find_unused_parameters=False)
|
146 |
+
else:
|
147 |
+
return args.cuda()
|
148 |
+
|
149 |
+
|
150 |
+
def set_device(args, distributed=False, rank=0):
|
151 |
+
""" set parameter to gpu or cpu """
|
152 |
+
if torch.cuda.is_available():
|
153 |
+
if isinstance(args, list):
|
154 |
+
return (set_gpu(item, distributed, rank) for item in args)
|
155 |
+
elif isinstance(args, dict):
|
156 |
+
return {key: set_gpu(args[key], distributed, rank) for key in args}
|
157 |
+
else:
|
158 |
+
args = set_gpu(args, distributed, rank)
|
159 |
+
return args
|