Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

curriculums.py 7.0 KB

You have to be logged in to leave a comment. Sign In
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
  1. """
  2. To easily reproduce experiments, and avoid passing several command line arguments, we implemented
  3. a curriculum utility. Parameters can be set in a curriculum dictionary.
  4. Curriculum Schema:
  5. Numerical keys in the curriculum specify an upsample step. When the current step matches the upsample step,
  6. the values in the corresponding dict be updated in the curriculum. Common curriculum values specified at upsamples:
  7. batch_size: Batch Size.
  8. num_steps: Number of samples along ray.
  9. img_size: Generated image resolution.
  10. batch_split: Integer number over which to divide batches and aggregate sequentially. (Used due to memory constraints)
  11. gen_lr: Generator learnig rate.
  12. disc_lr: Discriminator learning rate.
  13. fov: Camera field of view
  14. ray_start: Near clipping for camera rays.
  15. ray_end: Far clipping for camera rays.
  16. fade_steps: Number of steps to fade in new layer on discriminator after upsample.
  17. h_stddev: Stddev of camera yaw in radians.
  18. v_stddev: Stddev of camera pitch in radians.
  19. h_mean: Mean of camera yaw in radians.
  20. v_mean: Mean of camera yaw in radians.
  21. sample_dist: Type of camera pose distribution. (gaussian | spherical_uniform | uniform)
  22. topk_interval: Interval over which to fade the top k ratio.
  23. topk_v: Minimum fraction of a batch to keep during top k training.
  24. betas: Beta parameters for Adam.
  25. unique_lr: Whether to use reduced LRs for mapping network.
  26. weight_decay: Weight decay parameter.
  27. r1_lambda: R1 regularization parameter.
  28. latent_dim: Latent dim for Siren network in generator.
  29. grad_clip: Grad clipping parameter.
  30. model: Siren architecture used in generator. (SPATIALSIRENBASELINE | TALLSIREN)
  31. generator: Generator class. (ImplicitGenerator3d)
  32. discriminator: Discriminator class. (ProgressiveEncoderDiscriminator | ProgressiveDiscriminator)
  33. dataset: Training dataset. (CelebA | Carla | Cats)
  34. clamp_mode: Clamping function for Siren density output. (relu | softplus)
  35. z_dist: Latent vector distributiion. (gaussian | uniform)
  36. hierarchical_sample: Flag to enable hierarchical_sampling from NeRF algorithm. (Doubles the number of sampled points)
  37. z_labmda: Weight for experimental latent code positional consistency loss.
  38. pos_lambda: Weight parameter for experimental positional consistency loss.
  39. last_back: Flag to fill in background color with last sampled color on ray.
  40. """
  41. import math
  42. def next_upsample_step(curriculum, current_step):
  43. # Return the epoch when it will next upsample
  44. current_metadata = extract_metadata(curriculum, current_step)
  45. current_size = current_metadata['img_size']
  46. for curriculum_step in sorted([cs for cs in curriculum.keys() if type(cs) == int]):
  47. if curriculum_step > current_step and curriculum[curriculum_step].get('img_size', 512) > current_size:
  48. return curriculum_step
  49. return float('Inf')
  50. def last_upsample_step(curriculum, current_step):
  51. # Returns the start epoch of the current stage, i.e. the epoch
  52. # it last upsampled
  53. current_metadata = extract_metadata(curriculum, current_step)
  54. current_size = current_metadata['img_size']
  55. for curriculum_step in sorted([cs for cs in curriculum.keys() if type(cs) == int]):
  56. if curriculum_step <= current_step and curriculum[curriculum_step]['img_size'] == current_size:
  57. return curriculum_step
  58. return 0
  59. def get_current_step(curriculum, epoch):
  60. step = 0
  61. for update_epoch in curriculum['update_epochs']:
  62. if epoch >= update_epoch:
  63. step += 1
  64. return step
  65. def extract_metadata(curriculum, current_step):
  66. return_dict = {}
  67. for curriculum_step in sorted([cs for cs in curriculum.keys() if type(cs) == int], reverse=True):
  68. if curriculum_step <= current_step:
  69. for key, value in curriculum[curriculum_step].items():
  70. return_dict[key] = value
  71. break
  72. for key in [k for k in curriculum.keys() if type(k) != int]:
  73. return_dict[key] = curriculum[key]
  74. return return_dict
  75. CelebA = {
  76. 0: {'batch_size': 28 * 2, 'num_steps': 12, 'img_size': 64, 'batch_split': 2, 'gen_lr': 6e-5, 'disc_lr': 2e-4},
  77. int(200e3): {},
  78. 'dataset_path': '/home/ericryanchan/data/celeba/img_align_celeba/*.jpg',
  79. 'fov': 12,
  80. 'ray_start': 0.88,
  81. 'ray_end': 1.12,
  82. 'fade_steps': 10000,
  83. 'h_stddev': 0.3,
  84. 'v_stddev': 0.155,
  85. 'h_mean': math.pi*0.5,
  86. 'v_mean': math.pi*0.5,
  87. 'sample_dist': 'gaussian',
  88. 'topk_interval': 2000,
  89. 'topk_v': 0.6,
  90. 'betas': (0, 0.9),
  91. 'unique_lr': False,
  92. 'weight_decay': 0,
  93. 'r1_lambda': 0.2,
  94. 'latent_dim': 256,
  95. 'grad_clip': 10,
  96. 'model': 'SPATIALSIRENBASELINE',
  97. 'generator': 'ImplicitGenerator3d',
  98. 'discriminator': 'CCSEncoderDiscriminator',
  99. 'dataset': 'CelebA',
  100. 'clamp_mode': 'relu',
  101. 'z_dist': 'gaussian',
  102. 'hierarchical_sample': True,
  103. 'z_lambda': 0,
  104. 'pos_lambda': 15,
  105. 'last_back': False,
  106. 'eval_last_back': True,
  107. }
  108. CARLA = {
  109. 0: {'batch_size': 30, 'num_steps': 48, 'img_size': 32, 'batch_split': 1, 'gen_lr': 4e-5, 'disc_lr': 4e-4},
  110. int(10e3): {'batch_size': 14, 'num_steps': 48, 'img_size': 64, 'batch_split': 2, 'gen_lr': 2e-5, 'disc_lr': 2e-4},
  111. int(55e3): {'batch_size': 10, 'num_steps': 48, 'img_size': 128, 'batch_split': 5, 'gen_lr': 10e-6, 'disc_lr': 10e-5},
  112. int(200e3): {},
  113. 'dataset_path': '/home/marcorm/S-GAN/data/cats_bigger_than_128x128/*.jpg',
  114. 'fov': 30,
  115. 'ray_start': 0.7,
  116. 'ray_end': 1.3,
  117. 'fade_steps': 10000,
  118. 'sample_dist': 'spherical_uniform',
  119. 'h_stddev': math.pi,
  120. 'v_stddev': math.pi/4 * 85/90,
  121. 'h_mean': math.pi*0.5,
  122. 'v_mean': math.pi/4 * 85/90,
  123. 'topk_interval': 1000,
  124. 'topk_v': 1,
  125. 'betas': (0, 0.9),
  126. 'unique_lr': False,
  127. 'weight_decay': 0,
  128. 'r1_lambda': 10,
  129. 'latent_dim': 256,
  130. 'grad_clip': 1,
  131. 'model': 'TALLSIREN',
  132. 'generator': 'ImplicitGenerator3d',
  133. 'discriminator': 'ProgressiveEncoderDiscriminator',
  134. 'dataset': 'Carla',
  135. 'white_back': True,
  136. 'clamp_mode': 'relu',
  137. 'z_dist': 'gaussian',
  138. 'hierarchical_sample': True,
  139. 'z_lambda': 0,
  140. 'pos_lambda': 0,
  141. 'learnable_dist': False,
  142. }
  143. CATS = {
  144. 0: {'batch_size': 28, 'num_steps': 24, 'img_size': 64, 'batch_split': 4, 'gen_lr': 6e-5, 'disc_lr': 2e-4},
  145. int(200e3): {},
  146. 'dataset_path': '/home/ericryanchan/graf-beta/data/carla/carla/*.png',
  147. 'fov': 12,
  148. 'ray_start': 0.8,
  149. 'ray_end': 1.2,
  150. 'fade_steps': 10000,
  151. 'h_stddev': 0.5,
  152. 'v_stddev': 0.4,
  153. 'h_mean': math.pi*0.5,
  154. 'v_mean': math.pi*0.5,
  155. 'sample_dist': 'uniform',
  156. 'topk_interval': 2000,
  157. 'topk_v': 0.6,
  158. 'betas': (0, 0.9),
  159. 'unique_lr': False,
  160. 'weight_decay': 0,
  161. 'r1_lambda': 0.2,
  162. 'latent_dim': 256,
  163. 'grad_clip': 10,
  164. 'model': 'SPATIALSIRENBASELINE',
  165. 'generator': 'ImplicitGenerator3d',
  166. 'discriminator': 'StridedDiscriminator',
  167. 'dataset': 'Cats',
  168. 'clamp_mode': 'relu',
  169. 'z_dist': 'gaussian',
  170. 'hierarchical_sample': True,
  171. 'z_lambda': 0,
  172. 'pos_lambda': 0,
  173. 'last_back': False,
  174. 'eval_last_back': True,
  175. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...