forked from katiezzzzz/Gantastic-Earth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_video.py
More file actions
267 lines (252 loc) · 18 KB
/
make_video.py
File metadata and controls
267 lines (252 loc) · 18 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
from code_files import *
import numpy as np
import os
PATH = os.path.dirname(os.path.realpath(__file__))
Project_name = 'earth_cylinder_t_11'
Project_dir = PATH + '/trained_generators/'
wandb_name = Project_name
labels = [0, 1, 2, 3]
# define hyperparameters and architecture
ngpu = 1
z_dim = 64
lr = 0.0001
Training = 0
n_classes = 4
batch_size = 8
im_channels = 3
num_epochs = 600
img_length = 128 # size of training image
proj_path = mkdr(Project_name, Project_dir, Training)
device = torch.device("cuda:0" if(torch.cuda.is_available() and ngpu > 0) else "cpu")
# create networks
netG, netD = cgan_earth_nets(proj_path, Training, z_dim+n_classes, im_channels+n_classes)
# animate
forest_lbl = [0]
desert_lbl = [1]
sea_lbl = [2]
star_lbl = [3]
lf = 16
ratio = 3
with open(proj_path + '_noise.data', 'rb') as filehandle:
# store the data as binary data stream
noise = pickle.load(filehandle)
# test1: forest, then transit to sea, then roll in sea
# the speed currently must start with the lowest possible speed to make sure the noise has right dimension
'''
# section s5_3
imgs1, noise, netG = roll_video(proj_path, desert_lbl, netG(z_dim+n_classes, img_length), n_classes, z_dim, lf, device, ratio, n_clips=int(8/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs1.shape)
imgs2, noise, netG = transit_video(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.33, l_step_size=0.25, transit_mode='scroll')
print(imgs2.shape)
imgs3, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs3.shape)
imgs4, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='sub')
print(imgs4.shape)
imgs5, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='add')
print(imgs5.shape)
imgs6, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='sub')
print(imgs6.shape)
imgs7, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='add')
print(imgs7.shape)
imgs8, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='sub')
print(imgs8.shape)
imgs9, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='add')
print(imgs9.shape)
imgs10, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='sub')
print(imgs10.shape)
imgs11, noise, netG = change_noise(sea_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.025, method='add')
print(imgs11.shape)
imgs12, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(16/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs12.shape)
'''
'''
# section s5_2
imgs1, noise, netG = roll_video(proj_path, forest_lbl, netG(z_dim+n_classes, img_length), n_classes, z_dim, lf, device, ratio, n_clips=int(8/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs1.shape)
imgs2, noise, netG = transit_video(forest_lbl, desert_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.33, l_step_size=0.25, transit_mode='scroll')
print(imgs2.shape)
imgs3, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(36/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs3.shape)
imgs4, noise, netG = change_noise(desert_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(36/(1/0.25)), step_size=0.25, value=0.025, method='sub')
print(imgs4.shape)
imgs5, noise, netG = change_noise(desert_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(36/(1/0.25)), step_size=0.25, value=0.025, method='add')
print(imgs5.shape)
'''
'''
# section s5_1
imgs1, noise, netG = roll_video(proj_path, star_lbl, netG(z_dim+n_classes, img_length), n_classes, z_dim, lf, device, ratio, n_clips=int(4/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs1.shape)
imgs2, noise, netG = transit_video(star_lbl, forest_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.33, l_step_size=0.25, transit_mode='scroll')
print(imgs2.shape)
imgs3, noise, netG = roll_video(proj_path, forest_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs3.shape)
imgs4, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs4.shape)
imgs5, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs5.shape)
imgs6, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs6.shape)
imgs7, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs7.shape)
imgs8, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs8.shape)
imgs9, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs9.shape)
imgs10, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(108/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs10.shape)
imgs11, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(108/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs11.shape)
imgs12, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs12.shape)
imgs13, noise, netG = change_noise(forest_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(104/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs13.shape)
'''
'''
# section s4
imgs1, noise, netG = roll_video(proj_path, sea_lbl, netG(z_dim+n_classes, img_length), n_classes, z_dim, lf, device, ratio, n_clips=int(2/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs1.shape)
imgs2, noise, netG = effects(sea_lbl, star_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_num=2, l_step_size=1, z_max_num=4, effect='circles', n_circles=2)
print(imgs2.shape)
imgs3, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(66/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs3.shape)
imgs4, noise, netG = effects(sea_lbl, star_lbl, n_classes, noise, netG, lf, ratio, device, step_size=1, z_step_num=2, l_step_size=0.5, z_max_num=4, effect='circles', n_circles=3)
print(imgs4.shape)
imgs5, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=110, step_size=1, original_noise=noise)
print(imgs5.shape)
imgs6, noise, netG = effects(sea_lbl, star_lbl, n_classes, noise, netG, lf, ratio, device, step_size=2, z_step_num=2, l_step_size=0.25, z_max_num=4, effect='circles', n_circles=4)
print(imgs6.shape)
imgs7, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=29, step_size=2, original_noise=noise)
print(imgs7.shape)
imgs8, noise, netG = effects(sea_lbl, star_lbl, n_classes, noise, netG, lf, ratio, device, step_size=2, z_step_num=2, l_step_size=0.25, z_max_num=4, effect='circles', n_circles=5)
print(imgs8.shape)
imgs9, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=86, step_size=2, original_noise=noise)
print(imgs9.shape)
imgs10, noise, netG = transit_video(sea_lbl, star_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.33, l_step_size=0.25, transit_mode='scroll')
print(imgs10.shape)
imgs11, noise, netG = roll_video(proj_path, star_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs11.shape)
imgs12, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs12.shape)
imgs13, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs13.shape)
imgs14, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs14.shape)
imgs15, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs15.shape)
imgs16, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs16.shape)
imgs17, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs17.shape)
imgs18, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='sub')
print(imgs18.shape)
imgs19, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(72/(1/0.25)), step_size=0.25, value=0.02, method='add')
print(imgs19.shape)
'''
'''
# section s3
imgs1, noise, netG = roll_video(proj_path, sea_lbl, netG(z_dim+n_classes, img_length), n_classes, z_dim, lf, device, ratio, n_clips=1, step_size=2, original_noise=noise)
print(imgs1.shape)
imgs2, noise, netG = transit_video(sea_lbl, forest_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.25, l_step_size=0.25, transit_mode='uniform')
print(imgs2.shape)
imgs3, noise, netG = roll_video(proj_path, forest_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(756/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs3.shape)
imgs4, noise, netG = transit_video(forest_lbl, desert_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.25, l_step_size=0.5, transit_mode='scroll')
print(imgs4.shape)
imgs5, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(86/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs5.shape)
imgs6, noise, netG = effects(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_num=2, l_step_size=1, z_max_num=4, effect='circles', n_circles=5)
print(imgs6.shape)
imgs7, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(30/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs7.shape)
imgs8, noise, netG = effects(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_num=2, l_step_size=1, z_max_num=4, effect='circles', n_circles=5)
print(imgs8.shape)
imgs9, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(26/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs9.shape)
imgs10, noise, netG = effects(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_num=2, l_step_size=1, z_max_num=4, effect='circles', n_circles=5)
print(imgs10.shape)
imgs11, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(66/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs11.shape)
imgs12, noise, netG = transit_video(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_size=0.33, l_step_size=0.25, transit_mode='uniform')
print(imgs12.shape)
imgs13, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(64/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs13.shape)
'''
'''
# section s2
imgs1, noise, netG = roll_video(proj_path, forest_lbl, netG(z_dim+n_classes, img_length), n_classes, z_dim, lf, device, ratio, n_clips=int(5/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs1.shape)
imgs2, noise, netG = transit_video(forest_lbl, desert_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.25, l_step_size=0.2, transit_mode='uniform')
print(imgs2.shape)
imgs3, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(35/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs3.shape)
imgs4, noise, netG = effects(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_num=2, l_step_size=0.5, z_max_num=4, effect='circles', n_circles=5)
print(imgs4.shape)
imgs5, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(10/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs5.shape)
imgs6, noise, netG = effects(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_num=2, l_step_size=0.5, z_max_num=4, effect='circles', n_circles=5)
print(imgs6.shape)
imgs7, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(15/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs7.shape)
imgs8, noise, netG = effects(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_num=2, l_step_size=0.5, z_max_num=4, effect='circles', n_circles=5)
print(imgs8.shape)
imgs9, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(50/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs9.shape)
imgs10, noise, netG = transit_video(desert_lbl, sea_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_size=0.33, l_step_size=0.5, transit_mode='circular')
print(imgs10.shape)
imgs11, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(45/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs11.shape)
imgs12, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(76/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs12.shape)
imgs13, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=116, step_size=1, original_noise=noise)
print(imgs13.shape)
imgs14, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=30, step_size=2, original_noise=noise)
print(imgs14.shape)
imgs15, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=101, step_size=3, original_noise=noise)
print(imgs15.shape)
'''
'''
# section s1
imgs1, noise, netG = roll_video(proj_path, sea_lbl, netG(z_dim+n_classes, img_length), n_classes, z_dim, lf, device, ratio, n_clips=int(132/(1/0.5)), step_size=0.5)
print(imgs1.shape)
imgs2, noise, netG = effects(sea_lbl, desert_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_num=2, l_step_size=0.33, z_max_num=4, effect='circles', n_circles=5)
print(imgs2.shape)
imgs3, noise, netG = roll_video(proj_path, sea_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(22/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs3.shape)
imgs4, noise, netG = transit_video(sea_lbl, desert_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_size=0.25, l_step_size=0.16, transit_mode='uniform')
#imgs4, noise, netG = effects(forest_lbl, star_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.25, z_step_num=2, l_step_size=0.25, z_max_num=4, effect='circles', n_circles=5)
print(imgs4.shape)
imgs5, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(64/(1/0.5)), step_size=0.5, original_noise=noise)
#imgs4, noise, netG = change_noise(star_lbl, noise, netG, n_classes, z_dim, lf=lf, device=device, ratio=ratio, n_clips=15, step_size=0.25, value=0.003, method='add')
print(imgs5.shape)
imgs6, noise, netG = effects(desert_lbl, forest_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_num=2, l_step_size=0.33, z_max_num=4, effect='circles', n_circles=5)
print(imgs6.shape)
imgs7, noise, netG = roll_video(proj_path, desert_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(80/(1/0.5)), step_size=0.5, original_noise=noise)
print(imgs7.shape)
imgs8, noise, netG = transit_video(desert_lbl, forest_lbl, n_classes, noise, netG, lf, ratio, device, step_size=0.5, z_step_size=0.33, l_step_size=0.33, transit_mode='circular')
print(imgs8.shape)
imgs9, noise, netG = roll_video(proj_path, forest_lbl, netG, n_classes, z_dim, lf, device, ratio, n_clips=int(740/(1/0.25)), step_size=0.25, original_noise=noise)
print(imgs9.shape)
'''
# concatenante the imgs together and make video
imgs = np.vstack((imgs1, imgs2))
imgs = np.vstack((imgs, imgs3))
imgs = np.vstack((imgs, imgs4))
imgs = np.vstack((imgs, imgs5))
imgs = np.vstack((imgs, imgs6))
imgs = np.vstack((imgs, imgs7))
imgs = np.vstack((imgs, imgs8))
imgs = np.vstack((imgs, imgs9))
imgs = np.vstack((imgs, imgs10))
imgs = np.vstack((imgs, imgs11))
imgs = np.vstack((imgs, imgs12))
imgs = np.vstack((imgs, imgs13))
imgs = np.vstack((imgs, imgs14))
imgs = np.vstack((imgs, imgs15))
#imgs = np.vstack((imgs, imgs16))
#imgs = np.vstack((imgs, imgs17))
#imgs = np.vstack((imgs, imgs18))
#imgs = np.vstack((imgs, imgs19))
animate(proj_path, imgs, fps=24)
with open(proj_path + '_noise.data', 'wb') as filehandle:
# store the data as binary data stream
pickle.dump(noise, filehandle)