-
Notifications
You must be signed in to change notification settings - Fork 3
/
curriculums_finetune.py
129 lines (114 loc) · 5.61 KB
/
curriculums_finetune.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""
To easily reproduce experiments, and avoid passing several command line arguments, we implemented
a curriculum utility. Parameters can be set in a curriculum dictionary.
Curriculum Schema:
Numerical keys in the curriculum specify an upsample step. When the current step matches the upsample step,
the values in the corresponding dict be updated in the curriculum. Common curriculum values specified at upsamples:
batch_size: Batch Size.
num_steps: Number of samples along ray.
img_size: Generated image resolution.
batch_split: Integer number over which to divide batches and aggregate sequentially. (Used due to memory constraints)
gen_lr: Generator learnig rate.
disc_lr: Discriminator learning rate.
fov: Camera field of view
ray_start: Near clipping for camera rays.
ray_end: Far clipping for camera rays.
fade_steps: Number of steps to fade in new layer on discriminator after upsample.
h_stddev: Stddev of camera yaw in radians.
v_stddev: Stddev of camera pitch in radians.
h_mean: Mean of camera yaw in radians.
v_mean: Mean of camera yaw in radians.
sample_dist: Type of camera pose distribution. (gaussian | spherical_uniform | uniform)
topk_interval: Interval over which to fade the top k ratio.
topk_v: Minimum fraction of a batch to keep during top k training.
betas: Beta parameters for Adam.
unique_lr: Whether to use reduced LRs for mapping network.
weight_decay: Weight decay parameter.
r1_lambda: R1 regularization parameter.
latent_dim: Latent dim for Siren network in generator.
grad_clip: Grad clipping parameter.
model: Siren architecture used in generator. (SPATIALSIRENBASELINE | TALLSIREN)
generator: Generator class. (ImplicitGenerator3d)
discriminator: Discriminator class. (ProgressiveEncoderDiscriminator | ProgressiveDiscriminator)
dataset: Training dataset. (CelebA | Carla | Cats)
clamp_mode: Clamping function for Siren density output. (relu | softplus)
z_dist: Latent vector distributiion. (gaussian | uniform)
hierarchical_sample: Flag to enable hierarchical_sampling from NeRF algorithm. (Doubles the number of sampled points)
z_labmda: Weight for experimental latent code positional consistency loss.
pos_lambda: Weight parameter for experimental positional consistency loss.
last_back: Flag to fill in background color with last sampled color on ray.
"""
import math
def next_upsample_step(curriculum, current_step):
# Return the epoch when it will next upsample
current_metadata = extract_metadata(curriculum, current_step)
current_size = current_metadata['output_size']
for curriculum_step in sorted([cs for cs in curriculum.keys() if type(cs) == int]):
if curriculum_step > current_step and curriculum[curriculum_step].get('output_size', 1024) > current_size:
return curriculum_step
return float('Inf')
def last_upsample_step(curriculum, current_step):
# Returns the start epoch of the current stage, i.e. the epoch
# it last upsampled
current_metadata = extract_metadata(curriculum, current_step)
current_size = current_metadata['output_size']
for curriculum_step in sorted([cs for cs in curriculum.keys() if type(cs) == int]):
if curriculum_step <= current_step and curriculum[curriculum_step]['output_size'] == current_size:
return curriculum_step
return 0
def get_current_step(curriculum, epoch):
step = 0
for update_epoch in curriculum['update_epochs']:
if epoch >= update_epoch:
step += 1
return step
def extract_metadata(curriculum, current_step):
return_dict = {}
# process batch_size, num_steps, first sort list, then for every list...
for curriculum_step in sorted([cs for cs in curriculum.keys() if type(cs) == int], reverse=True):
if curriculum_step <= current_step:
for key, value in curriculum[curriculum_step].items():
return_dict[key] = value
break
# process other keys like dataset_path, fov and so on
for key in [k for k in curriculum.keys() if type(k) != int]:
return_dict[key] = curriculum[key]
return return_dict
CelebA = {
0: {'batch_size': 16, 'num_steps': 16, 'img_size': 64, 'output_size': 64, 'batch_split': 4, 'gen_lr': 6e-5, 'disc_lr': 2e-4, 'pos_lambda': 15, 'reproj_lambda': 1},
int(25e3): {'batch_size': 8, 'num_steps': 16, 'img_size': 64, 'output_size': 128, 'batch_split': 4, 'gen_lr': 5e-5, 'disc_lr': 2e-4, 'pos_lambda': 15, 'reproj_lambda': 1},
int(50e3): {'batch_size': 8, 'num_steps': 16, 'img_size': 64, 'output_size': 256, 'batch_split': 4, 'gen_lr': 3e-5, 'disc_lr': 1e-4, 'pos_lambda': 0, 'reproj_lambda': 1},
int(75e3): {},
'image_path': '/data/mabiao/dataset/CelebA-noB/sketch_2/*.jpg',
'parsing_path': '/data/jiangchang/CelebAMask-HQ/CelebAMaskHQ-mask/*.png',
'fov': 12,
'ray_start': 0.88,
'ray_end': 1.12,
'fade_steps': 2000,
'h_stddev': 0.3,
'v_stddev': 0.155,
'h_mean': math.pi*0.5,
'v_mean': math.pi*0.5,
'sample_dist': 'gaussian',
'topk_interval': 2000,
'topk_v': 0.6,
'betas': (0, 0.9),
'unique_lr': False,
'weight_decay': 0,
'r1_lambda': 0.2,
'latent_dim': 256,
'grad_clip': 10,
'model': 'SketchSIREN',
'generator': 'SketchGenerator',
'RGB_discriminator': 'RGBDiscriminator',
'Parsing_discriminator': 'RGBDiscriminator',
'dataset': 'CelebA',
'clamp_mode': 'relu',
'z_dist': 'gaussian',
'hierarchical_sample': True,
'stereo_auxiliary': True,
'max_mixup_ratio': 0.1,
'z_lambda': 0,
'last_back': False,
'eval_last_back': True,
}