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

model.py 19 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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
  1. from __future__ import division
  2. import os
  3. import time
  4. from glob import glob
  5. import tensorflow as tf
  6. import numpy as np
  7. from six.moves import xrange
  8. from ops import *
  9. from utils import *
  10. class DualNet(object):
  11. def __init__(self, sess, image_size=256, batch_size=1,fcn_filter_dim = 64, \
  12. A_channels = 3, B_channels = 3, dataset_name='facades', \
  13. checkpoint_dir=None, lambda_A = 20., lambda_B = 20., \
  14. sample_dir=None, loss_metric = 'L1', flip = False):
  15. self.df_dim = fcn_filter_dim
  16. self.flip = flip
  17. self.lambda_A = lambda_A
  18. self.lambda_B = lambda_B
  19. self.sess = sess
  20. self.is_grayscale_A = (A_channels == 1)
  21. self.is_grayscale_B = (B_channels == 1)
  22. self.batch_size = batch_size
  23. self.image_size = image_size
  24. self.fcn_filter_dim = fcn_filter_dim
  25. self.A_channels = A_channels
  26. self.B_channels = B_channels
  27. self.loss_metric = loss_metric
  28. self.dataset_name = dataset_name
  29. self.checkpoint_dir = checkpoint_dir
  30. #directory name for output and logs saving
  31. self.dir_name = "%s-img_sz_%s-fltr_dim_%d-%s-lambda_AB_%s_%s" % (
  32. self.dataset_name,
  33. self.image_size,
  34. self.fcn_filter_dim,
  35. self.loss_metric,
  36. self.lambda_A,
  37. self.lambda_B
  38. )
  39. self.build_model()
  40. def build_model(self):
  41. ### define place holders
  42. self.real_A = tf.placeholder(tf.float32,[self.batch_size, self.image_size, self.image_size,
  43. self.A_channels ],name='real_A')
  44. self.real_B = tf.placeholder(tf.float32, [self.batch_size, self.image_size, self.image_size,
  45. self.B_channels ], name='real_B')
  46. ### define graphs
  47. self.A2B = self.A_g_net(self.real_A, reuse = False)
  48. self.B2A = self.B_g_net(self.real_B, reuse = False)
  49. self.A2B2A = self.B_g_net(self.A2B, reuse = True)
  50. self.B2A2B = self.A_g_net(self.B2A, reuse = True)
  51. if self.loss_metric == 'L1':
  52. self.A_loss = tf.reduce_mean(tf.abs(self.A2B2A - self.real_A))
  53. self.B_loss = tf.reduce_mean(tf.abs(self.B2A2B - self.real_B))
  54. elif self.loss_metric == 'L2':
  55. self.A_loss = tf.reduce_mean(tf.square(self.A2B2A - self.real_A))
  56. self.B_loss = tf.reduce_mean(tf.square(self.B2A2B - self.real_B))
  57. self.Ad_logits_fake = self.A_d_net(self.A2B, reuse = False)
  58. self.Ad_logits_real = self.A_d_net(self.real_B, reuse = True)
  59. self.Ad_loss_real = celoss(self.Ad_logits_real, tf.ones_like(self.Ad_logits_real))
  60. self.Ad_loss_fake = celoss(self.Ad_logits_fake, tf.zeros_like(self.Ad_logits_fake))
  61. self.Ad_loss = self.Ad_loss_fake + self.Ad_loss_real
  62. self.Ag_loss = celoss(self.Ad_logits_fake, labels=tf.ones_like(self.Ad_logits_fake))+self.lambda_B * (self.B_loss )
  63. self.Bd_logits_fake = self.B_d_net(self.B2A, reuse = False)
  64. self.Bd_logits_real = self.B_d_net(self.real_A, reuse = True)
  65. self.Bd_loss_real = celoss(self.Bd_logits_real, tf.ones_like(self.Bd_logits_real))
  66. self.Bd_loss_fake = celoss(self.Bd_logits_fake, tf.zeros_like(self.Bd_logits_fake))
  67. self.Bd_loss = self.Bd_loss_fake + self.Bd_loss_real
  68. self.Bg_loss = celoss(self.Bd_logits_fake, tf.ones_like(self.Bd_logits_fake))+self.lambda_A * (self.A_loss)
  69. self.d_loss = self.Ad_loss + self.Bd_loss
  70. self.g_loss = self.Ag_loss + self.Bg_loss
  71. ## define trainable variables
  72. t_vars = tf.trainable_variables()
  73. self.A_d_vars = [var for var in t_vars if 'A_d_' in var.name]
  74. self.B_d_vars = [var for var in t_vars if 'B_d_' in var.name]
  75. self.A_g_vars = [var for var in t_vars if 'A_g_' in var.name]
  76. self.B_g_vars = [var for var in t_vars if 'B_g_' in var.name]
  77. self.d_vars = self.A_d_vars + self.B_d_vars
  78. self.g_vars = self.A_g_vars + self.B_g_vars
  79. self.saver = tf.train.Saver()
  80. def clip_trainable_vars(self, var_list):
  81. for var in var_list:
  82. self.sess.run(var.assign(tf.clip_by_value(var, -self.c, self.c)))
  83. def load_random_samples(self):
  84. #np.random.choice(
  85. sample_files =np.random.choice(glob('./datasets/{}/val/A/*.jpg'.format(self.dataset_name)),self.batch_size)
  86. sample_A_imgs = [load_data(f, image_size =self.image_size, flip = False) for f in sample_files]
  87. sample_files = np.random.choice(glob('./datasets/{}/val/B/*.jpg'.format(self.dataset_name)),self.batch_size)
  88. sample_B_imgs = [load_data(f, image_size =self.image_size, flip = False) for f in sample_files]
  89. sample_A_imgs = np.reshape(np.array(sample_A_imgs).astype(np.float32),(self.batch_size,self.image_size, self.image_size,-1))
  90. sample_B_imgs = np.reshape(np.array(sample_B_imgs).astype(np.float32),(self.batch_size,self.image_size, self.image_size,-1))
  91. return sample_A_imgs, sample_B_imgs
  92. def sample_shotcut(self, sample_dir, epoch_idx, batch_idx):
  93. sample_A_imgs,sample_B_imgs = self.load_random_samples()
  94. Ag, A2B2A_imgs, A2B_imgs = self.sess.run([self.A_loss, self.A2B2A, self.A2B], feed_dict={self.real_A: sample_A_imgs, self.real_B: sample_B_imgs})
  95. Bg, B2A2B_imgs, B2A_imgs = self.sess.run([self.B_loss, self.B2A2B, self.B2A], feed_dict={self.real_A: sample_A_imgs, self.real_B: sample_B_imgs})
  96. save_images(A2B_imgs, [self.batch_size,1], './{}/{}/{:06d}_{:04d}_A2B.jpg'.format(sample_dir,self.dir_name , epoch_idx, batch_idx))
  97. save_images(A2B2A_imgs, [self.batch_size,1], './{}/{}/{:06d}_{:04d}_A2B2A.jpg'.format(sample_dir,self.dir_name, epoch_idx, batch_idx))
  98. save_images(B2A_imgs, [self.batch_size,1], './{}/{}/{:06d}_{:04d}_B2A.jpg'.format(sample_dir,self.dir_name, epoch_idx, batch_idx))
  99. save_images(B2A2B_imgs, [self.batch_size,1], './{}/{}/{:06d}_{:04d}_B2A2B.jpg'.format(sample_dir,self.dir_name, epoch_idx, batch_idx))
  100. print("[Sample] A_loss: {:.8f}, B_loss: {:.8f}".format(Ag, Bg))
  101. def train(self, args):
  102. """Train Dual GAN"""
  103. decay = 0.9
  104. self.d_optim = tf.train.RMSPropOptimizer(args.lr, decay=decay) \
  105. .minimize(self.d_loss, var_list=self.d_vars)
  106. self.g_optim = tf.train.RMSPropOptimizer(args.lr, decay=decay) \
  107. .minimize(self.g_loss, var_list=self.g_vars)
  108. tf.global_variables_initializer().run()
  109. self.writer = tf.summary.FileWriter("./logs/"+self.dir_name, self.sess.graph)
  110. step = 1
  111. start_time = time.time()
  112. if self.load(self.checkpoint_dir):
  113. print(" [*] Load SUCCESS")
  114. else:
  115. print(" Load failed...ignored...")
  116. print(" start training...")
  117. for epoch_idx in xrange(args.epoch):
  118. data_A = glob('./datasets/{}/train/A/*.jpg'.format(self.dataset_name))
  119. data_B = glob('./datasets/{}/train/B/*.jpg'.format(self.dataset_name))
  120. np.random.shuffle(data_A)
  121. np.random.shuffle(data_B)
  122. epoch_size = min(len(data_A), len(data_B)) // (self.batch_size)
  123. print('[*] training data loaded successfully')
  124. print("#data_A: %d #data_B:%d" %(len(data_A),len(data_B)))
  125. print('[*] run optimizor...')
  126. for batch_idx in xrange(0, epoch_size):
  127. imgA_batch = self.load_training_imgs(data_A, batch_idx)
  128. imgB_batch = self.load_training_imgs(data_B, batch_idx)
  129. print("Epoch: [%2d] [%4d/%4d]"%(epoch_idx, batch_idx, epoch_size))
  130. step = step + 1
  131. self.run_optim(imgA_batch, imgB_batch, step, start_time)
  132. if np.mod(step, 100) == 1:
  133. self.sample_shotcut(args.sample_dir, epoch_idx, batch_idx)
  134. if np.mod(step, args.save_freq) == 2:
  135. self.save(args.checkpoint_dir, step)
  136. def load_training_imgs(self, files, idx):
  137. batch_files = files[idx*self.batch_size:(idx+1)*self.batch_size]
  138. batch_imgs = [load_data(f, image_size =self.image_size, flip = self.flip) for f in batch_files]
  139. batch_imgs = np.reshape(np.array(batch_imgs).astype(np.float32),(self.batch_size,self.image_size, self.image_size,-1))
  140. return batch_imgs
  141. def run_optim(self,batch_A_imgs, batch_B_imgs, counter, start_time):
  142. _, Adfake,Adreal,Bdfake,Bdreal, Ad, Bd = self.sess.run(
  143. [self.d_optim, self.Ad_loss_fake, self.Ad_loss_real, self.Bd_loss_fake, self.Bd_loss_real, self.Ad_loss, self.Bd_loss],
  144. feed_dict = {self.real_A: batch_A_imgs, self.real_B: batch_B_imgs})
  145. _, Ag, Bg, Aloss, Bloss = self.sess.run(
  146. [self.g_optim, self.Ag_loss, self.Bg_loss, self.A_loss, self.B_loss],
  147. feed_dict={ self.real_A: batch_A_imgs, self.real_B: batch_B_imgs})
  148. _, Ag, Bg, Aloss, Bloss = self.sess.run(
  149. [self.g_optim, self.Ag_loss, self.Bg_loss, self.A_loss, self.B_loss],
  150. feed_dict={ self.real_A: batch_A_imgs, self.real_B: batch_B_imgs})
  151. print("time: %4.4f, Ad: %.2f, Ag: %.2f, Bd: %.2f, Bg: %.2f, U_diff: %.5f, V_diff: %.5f" \
  152. % (time.time() - start_time, Ad,Ag,Bd,Bg, Aloss, Bloss))
  153. print("Ad_fake: %.2f, Ad_real: %.2f, Bd_fake: %.2f, Bg_real: %.2f" % (Adfake,Adreal,Bdfake,Bdreal))
  154. def A_d_net(self, imgs, y = None, reuse = False):
  155. return self.discriminator(imgs, prefix = 'A_d_', reuse = reuse)
  156. def B_d_net(self, imgs, y = None, reuse = False):
  157. return self.discriminator(imgs, prefix = 'B_d_', reuse = reuse)
  158. def discriminator(self, image, y=None, prefix='A_d_', reuse=False):
  159. # image is 256 x 256 x (input_c_dim + output_c_dim)
  160. with tf.variable_scope(tf.get_variable_scope()) as scope:
  161. if reuse:
  162. scope.reuse_variables()
  163. else:
  164. assert scope.reuse == False
  165. h0 = lrelu(conv2d(image, self.df_dim, name=prefix+'h0_conv'))
  166. # h0 is (128 x 128 x self.df_dim)
  167. h1 = lrelu(batch_norm(conv2d(h0, self.df_dim*2, name=prefix+'h1_conv'), name = prefix+'bn1'))
  168. # h1 is (64 x 64 x self.df_dim*2)
  169. h2 = lrelu(batch_norm(conv2d(h1, self.df_dim*4, name=prefix+'h2_conv'), name = prefix+ 'bn2'))
  170. # h2 is (32x 32 x self.df_dim*4)
  171. h3 = lrelu(batch_norm(conv2d(h2, self.df_dim*8, d_h=1, d_w=1, name=prefix+'h3_conv'), name = prefix+ 'bn3'))
  172. # h3 is (32 x 32 x self.df_dim*8)
  173. h4 = conv2d(h3, 1, d_h=1, d_w=1, name =prefix+'h4')
  174. return h4
  175. def A_g_net(self, imgs, reuse=False):
  176. return self.fcn(imgs, prefix='A_g_', reuse = reuse)
  177. def B_g_net(self, imgs, reuse=False):
  178. return self.fcn(imgs, prefix = 'B_g_', reuse = reuse)
  179. def fcn(self, imgs, prefix=None, reuse = False):
  180. with tf.variable_scope(tf.get_variable_scope()) as scope:
  181. if reuse:
  182. scope.reuse_variables()
  183. else:
  184. assert scope.reuse == False
  185. s = self.image_size
  186. s2, s4, s8, s16, s32, s64, s128 = int(s/2), int(s/4), int(s/8), int(s/16), int(s/32), int(s/64), int(s/128)
  187. # imgs is (256 x 256 x input_c_dim)
  188. e1 = conv2d(imgs, self.fcn_filter_dim, name=prefix+'e1_conv')
  189. # e1 is (128 x 128 x self.fcn_filter_dim)
  190. e2 = batch_norm(conv2d(lrelu(e1), self.fcn_filter_dim*2, name=prefix+'e2_conv'), name = prefix+'bn_e2')
  191. # e2 is (64 x 64 x self.fcn_filter_dim*2)
  192. e3 = batch_norm(conv2d(lrelu(e2), self.fcn_filter_dim*4, name=prefix+'e3_conv'), name = prefix+'bn_e3')
  193. # e3 is (32 x 32 x self.fcn_filter_dim*4)
  194. e4 = batch_norm(conv2d(lrelu(e3), self.fcn_filter_dim*8, name=prefix+'e4_conv'), name = prefix+'bn_e4')
  195. # e4 is (16 x 16 x self.fcn_filter_dim*8)
  196. e5 = batch_norm(conv2d(lrelu(e4), self.fcn_filter_dim*8, name=prefix+'e5_conv'), name = prefix+'bn_e5')
  197. # e5 is (8 x 8 x self.fcn_filter_dim*8)
  198. e6 = batch_norm(conv2d(lrelu(e5), self.fcn_filter_dim*8, name=prefix+'e6_conv'), name = prefix+'bn_e6')
  199. # e6 is (4 x 4 x self.fcn_filter_dim*8)
  200. e7 = batch_norm(conv2d(lrelu(e6), self.fcn_filter_dim*8, name=prefix+'e7_conv'), name = prefix+'bn_e7')
  201. # e7 is (2 x 2 x self.fcn_filter_dim*8)
  202. e8 = batch_norm(conv2d(lrelu(e7), self.fcn_filter_dim*8, name=prefix+'e8_conv'), name = prefix+'bn_e8')
  203. # e8 is (1 x 1 x self.fcn_filter_dim*8)
  204. self.d1, self.d1_w, self.d1_b = deconv2d(tf.nn.relu(e8),
  205. [self.batch_size, s128, s128, self.fcn_filter_dim*8], name=prefix+'d1', with_w=True)
  206. d1 = tf.nn.dropout(batch_norm(self.d1, name = prefix+'bn_d1'), 0.5)
  207. d1 = tf.concat([d1, e7],3)
  208. # d1 is (2 x 2 x self.fcn_filter_dim*8*2)
  209. self.d2, self.d2_w, self.d2_b = deconv2d(tf.nn.relu(d1),
  210. [self.batch_size, s64, s64, self.fcn_filter_dim*8], name=prefix+'d2', with_w=True)
  211. d2 = tf.nn.dropout(batch_norm(self.d2, name = prefix+'bn_d2'), 0.5)
  212. d2 = tf.concat([d2, e6],3)
  213. # d2 is (4 x 4 x self.fcn_filter_dim*8*2)
  214. self.d3, self.d3_w, self.d3_b = deconv2d(tf.nn.relu(d2),
  215. [self.batch_size, s32, s32, self.fcn_filter_dim*8], name=prefix+'d3', with_w=True)
  216. d3 = tf.nn.dropout(batch_norm(self.d3, name = prefix+'bn_d3'), 0.5)
  217. d3 = tf.concat([d3, e5],3)
  218. # d3 is (8 x 8 x self.fcn_filter_dim*8*2)
  219. self.d4, self.d4_w, self.d4_b = deconv2d(tf.nn.relu(d3),
  220. [self.batch_size, s16, s16, self.fcn_filter_dim*8], name=prefix+'d4', with_w=True)
  221. d4 = batch_norm(self.d4, name = prefix+'bn_d4')
  222. d4 = tf.concat([d4, e4],3)
  223. # d4 is (16 x 16 x self.fcn_filter_dim*8*2)
  224. self.d5, self.d5_w, self.d5_b = deconv2d(tf.nn.relu(d4),
  225. [self.batch_size, s8, s8, self.fcn_filter_dim*4], name=prefix+'d5', with_w=True)
  226. d5 = batch_norm(self.d5, name = prefix+'bn_d5')
  227. d5 = tf.concat([d5, e3],3)
  228. # d5 is (32 x 32 x self.fcn_filter_dim*4*2)
  229. self.d6, self.d6_w, self.d6_b = deconv2d(tf.nn.relu(d5),
  230. [self.batch_size, s4, s4, self.fcn_filter_dim*2], name=prefix+'d6', with_w=True)
  231. d6 = batch_norm(self.d6, name = prefix+'bn_d6')
  232. d6 = tf.concat([d6, e2],3)
  233. # d6 is (64 x 64 x self.fcn_filter_dim*2*2)
  234. self.d7, self.d7_w, self.d7_b = deconv2d(tf.nn.relu(d6),
  235. [self.batch_size, s2, s2, self.fcn_filter_dim], name=prefix+'d7', with_w=True)
  236. d7 = batch_norm(self.d7, name = prefix+'bn_d7')
  237. d7 = tf.concat([d7, e1],3)
  238. # d7 is (128 x 128 x self.fcn_filter_dim*1*2)
  239. if prefix == 'B_g_':
  240. self.d8, self.d8_w, self.d8_b = deconv2d(tf.nn.relu(d7),[self.batch_size, s, s, self.A_channels], name=prefix+'d8', with_w=True)
  241. elif prefix == 'A_g_':
  242. self.d8, self.d8_w, self.d8_b = deconv2d(tf.nn.relu(d7),[self.batch_size, s, s, self.B_channels], name=prefix+'d8', with_w=True)
  243. # d8 is (256 x 256 x output_c_dim)
  244. return tf.nn.tanh(self.d8)
  245. def save(self, checkpoint_dir, step):
  246. model_name = "DualNet.model"
  247. model_dir = self.dir_name
  248. checkpoint_dir = os.path.join(checkpoint_dir, model_dir)
  249. if not os.path.exists(checkpoint_dir):
  250. os.makedirs(checkpoint_dir)
  251. self.saver.save(self.sess,
  252. os.path.join(checkpoint_dir, model_name),
  253. global_step=step)
  254. def load(self, checkpoint_dir):
  255. print(" [*] Reading checkpoint...")
  256. model_dir = self.dir_name
  257. checkpoint_dir = os.path.join(checkpoint_dir, model_dir)
  258. ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
  259. if ckpt and ckpt.model_checkpoint_path:
  260. ckpt_name = os.path.basename(ckpt.model_checkpoint_path)
  261. self.saver.restore(self.sess, os.path.join(checkpoint_dir, ckpt_name))
  262. return True
  263. else:
  264. return False
  265. def test(self, args):
  266. """Test DualNet"""
  267. start_time = time.time()
  268. tf.global_variables_initializer().run()
  269. if self.load(self.checkpoint_dir):
  270. print(" [*] Load SUCCESS")
  271. test_dir = './{}/{}'.format(args.test_dir, self.dir_name)
  272. if not os.path.exists(test_dir):
  273. os.makedirs(test_dir)
  274. test_log = open(test_dir+'evaluation.txt','a')
  275. test_log.write(self.dir_name)
  276. self.test_domain(args, test_log, type = 'A')
  277. self.test_domain(args, test_log, type = 'B')
  278. test_log.close()
  279. def test_domain(self, args, test_log, type = 'A'):
  280. test_files = glob('./datasets/{}/val/{}/*.jpg'.format(self.dataset_name,type))
  281. # load testing input
  282. print("Loading testing images ...")
  283. test_imgs = [load_data(f, is_test=True, image_size =self.image_size, flip = args.flip) for f in test_files]
  284. print("#images loaded: %d"%(len(test_imgs)))
  285. test_imgs = np.reshape(np.asarray(test_imgs).astype(np.float32),(len(test_files),self.image_size, self.image_size,-1))
  286. test_imgs = [test_imgs[i*self.batch_size:(i+1)*self.batch_size]
  287. for i in xrange(0, len(test_imgs)//self.batch_size)]
  288. test_imgs = np.asarray(test_imgs)
  289. test_path = './{}/{}/'.format(args.test_dir, self.dir_name)
  290. # test input samples
  291. if type == 'A':
  292. for i in xrange(0, len(test_files)//self.batch_size):
  293. filename_o = test_files[i*self.batch_size].split('/')[-1].split('.')[0]
  294. print(filename_o)
  295. idx = i+1
  296. A_imgs = np.reshape(np.array(test_imgs[i]), (self.batch_size,self.image_size, self.image_size,-1))
  297. print("testing A image %d"%(idx))
  298. print(A_imgs.shape)
  299. A2B_imgs, A2B2A_imgs = self.sess.run(
  300. [self.A2B, self.A2B2A],
  301. feed_dict={self.real_A: A_imgs}
  302. )
  303. save_images(A_imgs, [self.batch_size, 1], test_path+filename_o+'_realA.jpg')
  304. save_images(A2B_imgs, [self.batch_size, 1], test_path+filename_o+'_A2B.jpg')
  305. save_images(A2B2A_imgs, [self.batch_size, 1], test_path+filename_o+'_A2B2A.jpg')
  306. elif type=='B':
  307. for i in xrange(0, len(test_files)//self.batch_size):
  308. filename_o = test_files[i*self.batch_size].split('/')[-1].split('.')[0]
  309. idx = i+1
  310. B_imgs = np.reshape(np.array(test_imgs[i]), (self.batch_size,self.image_size, self.image_size,-1))
  311. print("testing B image %d"%(idx))
  312. B2A_imgs, B2A2B_imgs = self.sess.run(
  313. [self.B2A, self.B2A2B],
  314. feed_dict={self.real_B:B_imgs}
  315. )
  316. save_images(B_imgs, [self.batch_size, 1],test_path+filename_o+'_realB.jpg')
  317. save_images(B2A_imgs, [self.batch_size, 1],test_path+filename_o+'_B2A.jpg')
  318. save_images(B2A2B_imgs, [self.batch_size, 1],test_path+filename_o+'_B2A2B.jpg')
Tip!

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

Comments

Loading...