-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel_128.py
999 lines (881 loc) · 49 KB
/
model_128.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
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
from __future__ import division
import os
import time
import glob
import tensorflow as tf
import numpy as np
from six.moves import xrange
from sklearn import preprocessing as pre
import scipy.io as io
import matplotlib.pyplot as plt
from ops import *
from utils import *
from saveweigths import *
class pix2pix(object):
def __init__(self, sess, image_size=256,
batch_size=1, sample_size=1, output_size=256,
gf_dim=64, df_dim=64, L1_lambda=100,
input_c_dim=11, output_c_dim=7, dataset_name='facades',
checkpoint_dir=None, sample_dir=None):
"""
Args:
sess: TensorFlow session
batch_size: The size of batch. Should be specified before training.
output_size: (optional) The resolution in pixels of the images. [256]
gf_dim: (optional) Dimension of gen filters in first conv layer. [64]
df_dim: (optional) Dimension of discrim filters in first conv layer. [64]
input_c_dim: (optional) Dimension of input image color. For grayscale input, set to 1. [3]
output_c_dim: (optional) Dimension of output image color. For grayscale input, set to 1. [3]
"""
self.sess = sess
self.is_grayscale = (input_c_dim == 1)
self.batch_size = batch_size
self.image_size = image_size
self.sample_size = sample_size
self.output_size = output_size
self.sar_root_patch = '/mnt/Data/DataBases/RS/SAR/Campo Verde/npy_format/'
self.opt_root_patch = '/mnt/Data/DataBases/RS/SAR/Campo Verde/LANDSAT/'
self.sar_name = '14_31Jul_2016.npy'
self.gf_dim = gf_dim
self.df_dim = df_dim
self.input_c_dim = input_c_dim
self.output_c_dim = output_c_dim
self.L1_lambda = L1_lambda
# batch normalization : deals with poor initialization helps gradient flow
self.d_bn1 = batch_norm(name='d_bn1')
self.d_bn2 = batch_norm(name='d_bn2')
self.d_bn3 = batch_norm(name='d_bn3')
self.g_bn_e2 = batch_norm(name='g_bn_e2')
self.g_bn_e3 = batch_norm(name='g_bn_e3')
self.g_bn_e4 = batch_norm(name='g_bn_e4')
self.g_bn_e5 = batch_norm(name='g_bn_e5')
self.g_bn_e6 = batch_norm(name='g_bn_e6')
self.g_bn_e7 = batch_norm(name='g_bn_e7')
self.g_bn_e8 = batch_norm(name='g_bn_e8')
self.g_bn_d1 = batch_norm(name='g_bn_d1')
self.g_bn_d2 = batch_norm(name='g_bn_d2')
self.g_bn_d3 = batch_norm(name='g_bn_d3')
self.g_bn_d4 = batch_norm(name='g_bn_d4')
self.g_bn_d5 = batch_norm(name='g_bn_d5')
self.g_bn_d6 = batch_norm(name='g_bn_d6')
self.g_bn_d7 = batch_norm(name='g_bn_d7')
self.g_bn_d8 = batch_norm(name='g_bn_d8')
self.dataset_name = dataset_name
self.checkpoint_dir = checkpoint_dir
self.build_model()
def build_model(self):
self.real_data = tf.placeholder(tf.float32,
[self.batch_size, self.image_size, self.image_size,
self.input_c_dim + self.output_c_dim],
name='real_A_and_B_images')
self.real_A = self.real_data[:, :, :, :self.input_c_dim]
self.real_B = self.real_data[:, :, :, self.input_c_dim:self.input_c_dim + self.output_c_dim]
self.fake_B = self.generator(self.real_A)
self.real_AB = tf.concat([self.real_A, self.real_B], 3)
self.fake_AB = tf.concat([self.real_A, self.fake_B], 3)
self.D, self.D_logits = self.discriminator(self.real_AB, reuse=False)
self.D_, self.D_logits_ = self.discriminator(self.fake_AB, reuse=True)
self.fake_B_sample = self.sampler(self.real_A)
self.d_sum = tf.summary.histogram("d", self.D)
self.d__sum = tf.summary.histogram("d_", self.D_)
# self.fake_B_sum = tf.summary.image("fake_B", self.fake_B)
self.d_loss_real = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=self.D_logits, labels=tf.ones_like(self.D)))
self.d_loss_fake = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=self.D_logits_, labels=tf.zeros_like(self.D_)))
self.g_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=self.D_logits_, labels=tf.ones_like(self.D_))) \
+ self.L1_lambda * tf.reduce_mean(tf.abs(self.real_B - self.fake_B))
self.d_loss_real_sum = tf.summary.scalar("d_loss_real", self.d_loss_real)
self.d_loss_fake_sum = tf.summary.scalar("d_loss_fake", self.d_loss_fake)
self.d_loss = self.d_loss_real + self.d_loss_fake
self.g_loss_sum = tf.summary.scalar("g_loss", self.g_loss)
self.d_loss_sum = tf.summary.scalar("d_loss", self.d_loss)
t_vars = tf.trainable_variables()
self.d_vars = [var for var in t_vars if 'd_' in var.name]
self.g_vars = [var for var in t_vars if 'g_' in var.name]
self.saver = tf.train.Saver()
# def load_random_samples(self):
# data = np.random.choice(glob('./datasets/{}/val/*.jpg'.format(self.dataset_name)), self.batch_size)
# sample = [load_data(sample_file) for sample_file in data]
#
# if (self.is_grayscale):
# sample_images = np.array(sample).astype(np.float32)[:, :, :, None]
# else:
# sample_images = np.array(sample).astype(np.float32)
# return sample_images
# def sample_model(self, sample_dir, epoch, idx):
# sample_images = self.load_random_samples()
# samples, d_loss, g_loss = self.sess.run(
# [self.fake_B_sample, self.d_loss, self.g_loss],
# feed_dict={self.real_data: sample_images}
# )
# save_images(samples, [self.batch_size, 1],
# './{}/train_{:02d}_{:04d}.png'.format(sample_dir, epoch, idx))
# print("[Sample] d_loss: {:.8f}, g_loss: {:.8f}".format(d_loss, g_loss))
def train(self, args):
"""Train pix2pix"""
d_optim = tf.train.AdamOptimizer(args.lr, beta1=args.beta1) \
.minimize(self.d_loss, var_list=self.d_vars)
g_optim = tf.train.AdamOptimizer(args.lr, beta1=args.beta1) \
.minimize(self.g_loss, var_list=self.g_vars)
init_op = tf.global_variables_initializer()
self.sess.run(init_op)
# self.g_sum = tf.summary.merge([self.d__sum,
# self.fake_B_sum, self.d_loss_fake_sum, self.g_loss_sum])
# self.d_sum = tf.summary.merge([self.d_sum, self.d_loss_real_sum, self.d_loss_sum])
self.writer = tf.summary.FileWriter("./logs", self.sess.graph)
counter = 1
start_time = time.time()
if self.load(self.checkpoint_dir):
print(" [*] Load SUCCESS")
else:
print(" [!] Load failed...")
for epoch in xrange(args.epoch):
errorD = []
errorG = []
# data = glob('./datasets/{}/train/*.jpg'.format(self.dataset_name))
# data = glob.glob('/mnt/Data/Pix2Pix_datasets/' + self.dataset_name + '/train/*.npy')
data = glob.glob('/mnt/Data/Pix2Pix_datasets/' + self.dataset_name + '_' + str(128) + '/train/*.npy')
# crear la function que devuelve la matrix de patches correspondientes ???
batch_size = 500
np.random.shuffle(data)
batch_idxs = min(len(data), args.train_size) // batch_size
for idx in xrange(0, batch_idxs):
batch_files = data[idx*batch_size:(idx+1)*batch_size]
batch_images = [load_data(batch_file) for batch_file in batch_files] # Load files from path
# print(batch_file)
for id_batch in range(len(batch_images)):
# Update D network
_, summary_str = self.sess.run([d_optim, self.d_sum],
feed_dict={ self.real_data: batch_images[id_batch:id_batch+1]})
self.writer.add_summary(summary_str, counter)
# Update G network
_ = self.sess.run([g_optim],
feed_dict={ self.real_data: batch_images[id_batch:id_batch+1] })
# self.writer.add_summary(summary_str, counter)
# Run g_optim twice to make sure that d_loss does not go to zero (different from paper)
_ = self.sess.run([g_optim],
feed_dict={ self.real_data: batch_images[id_batch:id_batch+1] })
# self.writer.add_summary(summary_str, counter)
errD_fake = self.d_loss_fake.eval({self.real_data: batch_images[id_batch:id_batch+1]})
errD_real = self.d_loss_real.eval({self.real_data: batch_images[id_batch:id_batch+1]})
errG = self.g_loss.eval({self.real_data: batch_images[id_batch:id_batch+1]})
errorD.append(errD_fake+errD_real)
errorG.append(errG)
print("Epoch: [%2d] [%4d/%4d] time: %4.4f, d_loss: %.8f, g_loss: %.8f" \
% (counter, idx, batch_idxs,
time.time() - start_time, errD_fake+errD_real, errG))
if np.mod(id_batch, 20) == 1:
# self.sample_model(args.sample_dir, epoch, idx)
# self.save(args.checkpoint_dir, counter)
print("Mean Errors-->", np.mean(errorD), np.mean(errorG))
self.save(args.checkpoint_dir, counter)
counter += 1
def discriminator(self, image, y=None, reuse=False):
with tf.variable_scope("discriminator") as scope:
# image is 256 x 256 x (input_c_dim + output_c_dim)
if reuse:
tf.get_variable_scope().reuse_variables()
else:
assert tf.get_variable_scope().reuse == False
h0 = lrelu(conv2d(image, self.df_dim, name='d_h0_conv'))
# h0 is (128 x 128 x self.df_dim)
h1 = lrelu(self.d_bn1(conv2d(h0, self.df_dim*2, name='d_h1_conv')))
# h1 is (64 x 64 x self.df_dim*2)
h2 = lrelu(self.d_bn2(conv2d(h1, self.df_dim*4, name='d_h2_conv')))
# h2 is (32x 32 x self.df_dim*4)
h3 = lrelu(self.d_bn3(conv2d(h2, self.df_dim*8, d_h=1, d_w=1, name='d_h3_conv')))
# h3 is (16 x 16 x self.df_dim*8)
h4 = linear(tf.reshape(h3, [self.batch_size, -1]), 1, 'd_h3_lin')
return tf.nn.sigmoid(h4), h4
def generator(self, image, y=None):
with tf.variable_scope("generator") as scope:
s = self.output_size
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)
# image is (256 x 256 x input_c_dim)
# print image.shape
# print e0.shape
e1 = conv2d(image, self.gf_dim, name='g_e1_conv') # 64x2x5x5+64 = 3,264
print e1.shape
# e1 is (128 x 128 x self.gf_dim)
e2 = self.g_bn_e2(conv2d(lrelu(e1), self.gf_dim*2, name='g_e2_conv')) # (2x64)x64x5x5 + (2x64) = 204,928
print e2.shape
# e2 is (64 x 64 x self.gf_dim*2)
e3 = self.g_bn_e3(conv2d(lrelu(e2), self.gf_dim*4, name='g_e3_conv')) # (4x64)x(2x64)x5x5 + (4x64) = 819,456
print e3.shape
# e3 is (32 x 32 x self.gf_dim*4)
e4 = self.g_bn_e4(conv2d(lrelu(e3), self.gf_dim*8, name='g_e4_conv')) # (8x64)x(4x64)x5x5 + (8x64) = 3,277,312
print e4.shape
# e4 is (16 x 16 x self.gf_dim*8)
e5 = self.g_bn_e5(conv2d(lrelu(e4), self.gf_dim*8, name='g_e5_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
print e5.shape
# e5 is (8 x 8 x self.gf_dim*8)
e6 = self.g_bn_e6(conv2d(lrelu(e5), self.gf_dim*8, name='g_e6_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
print e6.shape
# e6 is (4 x 4 x self.gf_dim*8)
e7 = self.g_bn_e7(conv2d(lrelu(e6), self.gf_dim*8, name='g_e7_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
print e7.shape
# e7 is (2 x 2 x self.gf_dim*8)
# e8 = self.g_bn_e8(conv2d(lrelu(e7), self.gf_dim*8, name='g_e8_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
# print e8.shape
# e8 is (1 x 1 x self.gf_dim*8)
# self.d1, self.d1_w, self.d1_b = deconv2d(tf.nn.relu(e8),
# [self.batch_size, s128, s128, self.gf_dim*8], name='g_d1', with_w=True) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
# d1 = tf.nn.dropout(self.g_bn_d1(self.d1), 0.5)
# print d1.shape
# d1 = tf.concat([d1, e7], 3)
# d1.shape
# d1 is (2 x 2 x self.gf_dim*8*2)
self.d2, self.d2_w, self.d2_b = deconv2d(tf.nn.relu(e7),
[self.batch_size, s64, s64, self.gf_dim*8], name='g_d2', with_w=True) # (2*8x64)x(8x64)x5x5 + (2*8x64) = 13,108,224
d2 = tf.nn.dropout(self.g_bn_d2(self.d2), 0.5)
print d2.shape
d2 = tf.concat([d2, e6], 3)
# d2 is (4 x 4 x self.gf_dim*8*2)
self.d3, self.d3_w, self.d3_b = deconv2d(tf.nn.relu(d2),
[self.batch_size, s32, s32, self.gf_dim*8], name='g_d3', with_w=True) # (2*8x64)x(8x64)x5x5 + (2*8x64) = 13,108,224
d3 = tf.nn.dropout(self.g_bn_d3(self.d3), 0.5)
print d2.shape
d3 = tf.concat([d3, e5], 3)
# d3 is (8 x 8 x self.gf_dim*8*2)
self.d4, self.d4_w, self.d4_b = deconv2d(tf.nn.relu(d3),
[self.batch_size, s16, s16, self.gf_dim*8], name='g_d4', with_w=True) # (2*8x64)x(8x64)x5x5 + (2*8x64) = 13,108,224
d4 = tf.nn.dropout(self.g_bn_d4(self.d4), 0.5)
print d4.shape
d4 = tf.concat([d4, e4], 3)
# d4 is (16 x 16 x self.gf_dim*8*2)
self.d5, self.d5_w, self.d5_b = deconv2d(tf.nn.relu(d4),
[self.batch_size, s8, s8, self.gf_dim*4], name='g_d5', with_w=True) # (2*4x64)x(8x64)x5x5 + (2*4x64) = 6,554,112
d5 = self.g_bn_d5(self.d5)
print d5.shape
d5 = tf.concat([d5, e3], 3)
# d5 is (32 x 32 x self.gf_dim*4*2)
self.d6, self.d6_w, self.d6_b = deconv2d(tf.nn.relu(d5),
[self.batch_size, s4, s4, self.gf_dim*2], name='g_d6', with_w=True) # (2*2x64)x(4x64)x5x5 + (2*2x64) = 1,638,656
d6 = self.g_bn_d6(self.d6)
print d6.shape
d6 = tf.concat([d6, e2], 3)
# d6 is (64 x 64 x self.gf_dim*2*2)
self.d7, self.d7_w, self.d7_b = deconv2d(tf.nn.relu(d6),
[self.batch_size, s2, s2, self.gf_dim], name='g_d7', with_w=True) # (2*1x64)x(2x64)x5x5 + (2*1x64) = 409,728
print self.d7.shape
d7 = self.g_bn_d7(self.d7)
d7 = tf.concat([d7, e1], 3)
# d7 is (128 x 128 x self.gf_dim*1*2)
self.d8, self.d8_w, self.d8_b = deconv2d(tf.nn.relu(d7),
[self.batch_size, s, s, self.output_c_dim], name='g_d8', with_w=True) # (1*1x64)x(1x7)x5x5 + (1*1x7) = 11,207
print self.d8.shape
# d8 is (256 x 256 x output_c_dim)
# d8 = self.g_bn_d8(self.d8)
# self.d9 = conv2d(lrelu(tf.nn.relu(d8)), self.output_c_dim, name='g_d9_conv')
return tf.nn.tanh(self.d8)
def sampler(self, image, y=None):
with tf.variable_scope("generator") as scope:
scope.reuse_variables()
s = self.output_size
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)
# image is (256 x 256 x input_c_dim)
# print image.shape
# print e0.shape
e1 = conv2d(image, self.gf_dim, name='g_e1_conv') # 64x2x5x5+64 = 3,264
print e1.shape
# e1 is (128 x 128 x self.gf_dim)
e2 = self.g_bn_e2(conv2d(lrelu(e1), self.gf_dim*2, name='g_e2_conv')) # (2x64)x64x5x5 + (2x64) = 204,928
print e2.shape
# e2 is (64 x 64 x self.gf_dim*2)
e3 = self.g_bn_e3(conv2d(lrelu(e2), self.gf_dim*4, name='g_e3_conv')) # (4x64)x(2x64)x5x5 + (4x64) = 819,456
print e3.shape
# e3 is (32 x 32 x self.gf_dim*4)
e4 = self.g_bn_e4(conv2d(lrelu(e3), self.gf_dim*8, name='g_e4_conv')) # (8x64)x(4x64)x5x5 + (8x64) = 3,277,312
print e4.shape
# e4 is (16 x 16 x self.gf_dim*8)
e5 = self.g_bn_e5(conv2d(lrelu(e4), self.gf_dim*8, name='g_e5_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
print e5.shape
# e5 is (8 x 8 x self.gf_dim*8)
e6 = self.g_bn_e6(conv2d(lrelu(e5), self.gf_dim*8, name='g_e6_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
print e6.shape
# e6 is (4 x 4 x self.gf_dim*8)
e7 = self.g_bn_e7(conv2d(lrelu(e6), self.gf_dim*8, name='g_e7_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
print e7.shape
# e7 is (2 x 2 x self.gf_dim*8)
# e8 = self.g_bn_e8(conv2d(lrelu(e7), self.gf_dim*8, name='g_e8_conv')) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
# print e8.shape
# e8 is (1 x 1 x self.gf_dim*8)
# self.d1, self.d1_w, self.d1_b = deconv2d(tf.nn.relu(e8),
# [self.batch_size, s128, s128, self.gf_dim*8], name='g_d1', with_w=True) # (8x64)x(8x64)x5x5 + (8x64) = 6,554,112
# d1 = tf.nn.dropout(self.g_bn_d1(self.d1), 0.5)
# print d1.shape
# d1 = tf.concat([d1, e7], 3)
# d1.shape
# d1 is (2 x 2 x self.gf_dim*8*2)
self.d2, self.d2_w, self.d2_b = deconv2d(tf.nn.relu(e7),
[self.batch_size, s64, s64, self.gf_dim*8], name='g_d2', with_w=True) # (2*8x64)x(8x64)x5x5 + (2*8x64) = 13,108,224
d2 = tf.nn.dropout(self.g_bn_d2(self.d2), 0.5)
print d2.shape
d2 = tf.concat([d2, e6], 3)
# d2 is (4 x 4 x self.gf_dim*8*2)
self.d3, self.d3_w, self.d3_b = deconv2d(tf.nn.relu(d2),
[self.batch_size, s32, s32, self.gf_dim*8], name='g_d3', with_w=True) # (2*8x64)x(8x64)x5x5 + (2*8x64) = 13,108,224
d3 = tf.nn.dropout(self.g_bn_d3(self.d3), 0.5)
print d2.shape
d3 = tf.concat([d3, e5], 3)
# d3 is (8 x 8 x self.gf_dim*8*2)
self.d4, self.d4_w, self.d4_b = deconv2d(tf.nn.relu(d3),
[self.batch_size, s16, s16, self.gf_dim*8], name='g_d4', with_w=True) # (2*8x64)x(8x64)x5x5 + (2*8x64) = 13,108,224
d4 = tf.nn.dropout(self.g_bn_d4(self.d4), 0.5)
print d4.shape
d4 = tf.concat([d4, e4], 3)
# d4 is (16 x 16 x self.gf_dim*8*2)
self.d5, self.d5_w, self.d5_b = deconv2d(tf.nn.relu(d4),
[self.batch_size, s8, s8, self.gf_dim*4], name='g_d5', with_w=True) # (2*4x64)x(8x64)x5x5 + (2*4x64) = 6,554,112
d5 = self.g_bn_d5(self.d5)
print d5.shape
d5 = tf.concat([d5, e3], 3)
# d5 is (32 x 32 x self.gf_dim*4*2)
self.d6, self.d6_w, self.d6_b = deconv2d(tf.nn.relu(d5),
[self.batch_size, s4, s4, self.gf_dim*2], name='g_d6', with_w=True) # (2*2x64)x(4x64)x5x5 + (2*2x64) = 1,638,656
d6 = self.g_bn_d6(self.d6)
print d6.shape
d6 = tf.concat([d6, e2], 3)
# d6 is (64 x 64 x self.gf_dim*2*2)
self.d7, self.d7_w, self.d7_b = deconv2d(tf.nn.relu(d6),
[self.batch_size, s2, s2, self.gf_dim], name='g_d7', with_w=True) # (2*1x64)x(2x64)x5x5 + (2*1x64) = 409,728
print self.d7.shape
d7 = self.g_bn_d7(self.d7)
d7 = tf.concat([d7, e1], 3)
# d7 is (128 x 128 x self.gf_dim*1*2)
self.d8, self.d8_w, self.d8_b = deconv2d(tf.nn.relu(d7),
[self.batch_size, s, s, self.output_c_dim], name='g_d8', with_w=True) # (1*1x64)x(1x7)x5x5 + (1*1x7) = 11,207
print self.d8.shape
# d8 is (256 x 256 x output_c_dim)
# d8 = self.g_bn_d8(self.d8)
# self.d9 = conv2d(lrelu(tf.nn.relu(d8)), self.output_c_dim, name='g_d9_conv')
return tf.nn.tanh(self.d8)
def save(self, checkpoint_dir, step):
model_name = "pix2pix.model"
model_dir = "%s_%s_%s" % (self.dataset_name, self.batch_size, self.output_size)
checkpoint_dir = os.path.join(checkpoint_dir, model_dir)
if not os.path.exists(checkpoint_dir):
os.makedirs(checkpoint_dir)
self.saver.save(self.sess,
os.path.join(checkpoint_dir, model_name),
global_step=step)
print "Saving checkpoint!"
# self.saver.save(self.sess, checkpoint_dir +'/my-model')
# self.saver.export_meta_graph(filename=checkpoint_dir +'/my-model.meta')
def load(self, checkpoint_dir):
# return False
print(" [*] Reading checkpoint...")
#
model_dir = "%s_%s_%s" % (self.dataset_name, self.batch_size, self.output_size)
checkpoint_dir = os.path.join(checkpoint_dir, model_dir)
print(checkpoint_dir)
#2832, 2665,
# new_placeholder = tf.placeholder(tf.float32, shape=[self.batch_size, 2831, 2665,
# self.input_c_dim + self.output_c_dim], name='inputs_new_name')
# self.saver = tf.train.import_meta_graph(checkpoint_dir +'/my-model.meta', input_map={"real_A_and_B_images:0": new_placeholder})
## self.saver = tf.train.import_meta_graph(checkpoint_dir +'/my-model.meta')
# self.saver.restore(self.sess, checkpoint_dir +'/my-model')
#
ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
if ckpt and ckpt.model_checkpoint_path:
ckpt_name = os.path.basename(ckpt.model_checkpoint_path)
self.saver.restore(self.sess, os.path.join(checkpoint_dir, ckpt_name))
# self.saver.export_meta_graph(filename='my-model.meta')
# print 'model convertion success'
# self.saver = tf.import_graph_def(os.path.join(checkpoint_dir, ckpt_name), input_map={"real_A_and_B_images:0": new_placeholder})
return True
else:
return False
def test(self, args):
"""Test pix2pix"""
init_op = tf.global_variables_initializer()
self.sess.run(init_op)
sample_files = sorted(glob.glob('/home/jose/Templates/Pix2Pix/pix2pix-tensorflow_jose/datasets/'+self.dataset_name+'/test/*.npy'))
# change this directoty
# sort testing input
n = [int(i) for i in map(lambda x: x.split('/')[-1].split('.npy')[0], sample_files)]
sample_files = [x for (y, x) in sorted(zip(n, sample_files))]
# load testing input
print("Loading testing images ...")
sample_images = [load_data(sample_file, is_test=True) for sample_file in sample_files]
# if (self.is_grayscale):
# sample_images = np.array(sample).astype(np.float32)[:, :, :, None]
# else:
# sample_images = np.array(sample).astype(np.float32)
sample_images = [sample_images[i:i+self.batch_size]
for i in xrange(0, len(sample_images), self.batch_size)]
sample_images = np.array(sample_images)
print(sample_images.shape)
start_time = time.time()
if self.load(self.checkpoint_dir):
print(" [*] Load SUCCESS")
else:
print(" [!] Load failed...")
for i, sample_image in enumerate(sample_images):
idx = i+1
print("sampling image ", idx)
samples = self.sess.run(
self.fake_B_sample,
feed_dict={self.real_data: sample_image}
)
print samples.shape
output_folder = '/home/jose/Templates/'
np.save(output_folder+str(i), samples.reshape(256, 256, 7))
# save_images(samples, [self.batch_size, 1],
# './{}/test_{:04d}.png'.format(args.test_dir, idx))
def generate_image(self, args):
print args
output_folder = '/home/jose/Templates/Pix2Pix/pix2pix-tensorflow_jose/'
init_op = tf.global_variables_initializer()
self.sess.run(init_op)
print(" [*] Load SUCCESS")
if self.load(self.checkpoint_dir):
print(" [*] Load SUCCESS")
else:
print(" [!] Load failed...")
print args.experiment_type
if args.experiment_type is 'case_01':
# Load images
print 'Case 01 ...'
if '11nov2015' in args.dataset_name:
print 'generating image for_' + args.dataset_name
sar_img_name = '02_10Nov_2015.npy'
opt_img_name = '20151111'
print sar_img_name, opt_img_name
elif '13dec2015' in args.dataset_name:
print 'generating image for_' + args.dataset_name
sar_img_name = '05_16Dec_2015.npy'
opt_img_name = '20151213'
print sar_img_name, opt_img_name
elif '18mar2016' in args.dataset_name:
print 'generating image for_' + args.dataset_name
sar_img_name = '09_21Mar_2016.npy'
opt_img_name = '20160318'
print sar_img_name, opt_img_name
elif '05may2016' in args.dataset_name:
print 'generating image for_' + args.dataset_name
sar_img_name = '10_08May_2016.npy'
opt_img_name = '20160505'
print sar_img_name, opt_img_name
elif '08jul2016' in args.dataset_name:
print 'generating image for_' + args.dataset_name
sar_img_name = '13_07Jul_2016.npy'
opt_img_name = '20160708'
print sar_img_name, opt_img_name
elif '24jul2016' in args.dataset_name:
print 'generating image for_' + args.dataset_name
sar_img_name = '14_31Jul_2016.npy'
opt_img_name = '20160724'
print sar_img_name, opt_img_name
else:
print "Image pair doesnt exist !!!"
return 0
# 20151111 -- 02_10Nov_2015 ok !
# 20151127 -- 03_22Nov_2015 too much clouds !
# 20151213 -- 05_16Dec_2015 ummmm, differen protocol ...
# 20160318 -- 09_21Mar_2016 ok !
# 20160505 -- 10_08May_2016 ok !
# 20160708 -- 13_07Jul_2016 ok !
# 20160724 -- 14_31Jul_2016 ok !
mask, sar, opt, cloud_mask = load_images(sar_path=self.sar_root_patch + sar_img_name,
opt_path=self.opt_root_patch + opt_img_name + '/'
)
mask_gan_path = '/mnt/Data/DataBases/RS/SAR/Campo Verde/New_Masks/TrainTestMasks/TrainTestMask_GAN.tif'
mask_gan = load_tiff_image(mask_gan_path)
np.save('mask_gan_original', mask_gan)
# mask_gan[mask_gan == 0] = 1
# mask_gan[mask_gan != 1] = 0
# mask_gan = resampler(mask_gan)
# mask = resampler(mask)
# sar = resampler(sar)
# mask_sar = sar[:, :, 0].copy()
# mask_sar[sar[:, :, 0] < 1] = 1
# mask_sar[sar[:, :, 0] == 1] = 0
sar = resampler(sar)
sar[sar > 1.0] = 1.0
mask_sar = sar[:, :, 0].copy()
mask_sar[sar[:, :, 0] < 1] = 1
mask_sar[sar[:, :, 0] == 1] = 0
mask = resampler(mask)
mask_gan = np.load('mask_gan.npy')
mask_gan[mask == 0] = 0
mask_gan[(mask != 0) * (mask_gan != 1) ] = 2
mask_gans_trn = mask_gan + mask_sar
mask_gans_trn[mask_gans_trn == 3] = 0
mask_gans_trn[mask_gans_trn == 2] = 1
np.save(output_folder + 'mask', mask)
io.savemat(output_folder + 'mask.mat', {"mask":mask})
plt.figure()
plt.imshow(mask_gans_trn)
plt.show()
num_rows, num_cols = mask.shape
# mask_gans_trn = mask_4_trn_gans(num_rows, num_cols, args.image_region)
# mask_gans_trn = mask_gans_trn * mask
# mask_gans_trn = mask_gan * mask_sar
img_source = minmaxnormalization(sar, mask_gans_trn)
num_rows, num_cols, bands = sar.shape
np.save(output_folder + self.dataset_name + '_' + sar_img_name + '_sar', sar)
np.save(output_folder + self.dataset_name + '_' + sar_img_name + '_sar_nor', img_source)
io.savemat(output_folder + self.dataset_name + '_' + sar_img_name + '_sar' + '.mat', {"sar":sar})
np.save(output_folder + self.dataset_name + '_opt', opt)
np.save(output_folder + self.dataset_name + '_cloud_mask', cloud_mask)
elif args.experiment_type is 'case_A':
# Load images
print 'Case A ...'
print 'generating image for_' + args.dataset_name
sar_path='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20160909/20160909.npy'
# opt_path='/mnt/Datos/Datasets/Quemadas/AP2_Acre/Sentinel2/',
# sar_img_name = '10_08May_2016.npy'
sar = np.load(sar_path)
sar[sar > 1.0] = 1.0
mask_sar = sar[:, :, 1].copy()
mask_sar[sar[:, :, 0] < 1] = 1
mask_sar[sar[:, :, 0] == 1] = 0
img_source = minmaxnormalization(sar, mask_sar)
num_rows, num_cols, num_bands = img_source.shape
img_source = img_source.reshape(1, num_rows, num_cols, num_bands)
fake_opt = np.zeros((num_rows, num_cols, self.output_c_dim),
dtype='float32')
s = 64
stride = self.image_size-2*s
for row in range(0, num_rows, stride):
for col in range(0, num_cols, stride):
if (row+self.image_size <= num_rows) and (col+self.image_size <= num_cols):
print row + s, row + self.image_size - s
sample_image = img_source[:, row:row+self.image_size, col:col+self.image_size]
sample = self.sess.run(self.fake_B_sample,
feed_dict={self.real_A: sample_image}
)
print sample.shape
fake_opt[row+s:row+self.image_size-s, col+s:col+self.image_size-s] = sample[0, s:self.image_size-s, s:self.image_size-s]
elif col+self.image_size <= num_cols:
sample_image = img_source[:, num_rows-self.image_size:num_rows, col:col+self.image_size]
print(sample_image.shape)
sample = self.sess.run(self.fake_B_sample,
feed_dict={self.real_A: sample_image}
)
print sample.shape
fake_opt[row+s:num_rows, col+s:col+self.image_size-s] = sample[0, self.image_size-num_rows+row+s:self.image_size, s:self.image_size-s]
elif row+self.image_size <= num_rows:
print col
sample_image = img_source[:, row:row+self.image_size, num_cols-self.image_size:num_cols]
sample = self.sess.run(self.fake_B_sample,
feed_dict={self.real_A: sample_image}
)
fake_opt[row+s:row+self.image_size-s, col+s:num_cols] = sample[0, s:self.image_size-s, self.image_size-num_cols+col+s:self.image_size]
np.save(self.dataset_name + '_fake_opt_new', fake_opt)
elif args.experiment_type is 'case_C':
# Load images
print 'Case C ...'
print 'generating image for_' + args.dataset_name
sar_path_t0='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20160909/new_20160909.npy'
sar_path_t1='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20170731/20170731.npy'
opt_path_t0='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20160825/'
opt_path_t1='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20170731/'
# opt_path='/mnt/Datos/Datasets/Quemadas/AP2_Acre/Sentinel2/',
# sar_img_name = '10_08May_2016.npy'
opt_t0 = load_sentinel2(opt_path_t0)
opt_t1 = load_sentinel2(opt_path_t1)
opt_t0[np.isnan(opt_t0)] = 0
opt_t1[np.isnan(opt_t1)] = 0
print opt_t0.shape
print opt_t1.shape
sar_t0 = np.load(sar_path_t0)
sar_t1 = np.load(sar_path_t1)
mask_gans_trn = 'ap2_train_test_mask.npy'
mask_gans_trn = np.load(mask_gans_trn)
mask_gans_trn = np.float32(mask_gans_trn)
mask_gans_trn[mask_gans_trn == 0] = 1.
mask_gans_trn[mask_gans_trn == 255] = 2.
print mask_gans_trn.shape
sar_t0[sar_t0 > 1.0] = 1.0
sar_t1[sar_t1 > 1.0] = 1.0
mask_sar = sar_t0[:, :, 1].copy()
mask_sar[sar_t0[:, :, 0] < 1] = 1
mask_sar[sar_t0[:, :, 0] == 1] = 0
mask_gans_trn = mask_gans_trn * mask_sar
sar_t0 = minmaxnormalization(sar_t0, mask_sar)
sar_t1 = minmaxnormalization(sar_t1, mask_sar)
opt_t0 = minmaxnormalization(opt_t0, mask_gans_trn)
opt_t1 = minmaxnormalization(opt_t1, mask_sar)
num_rows, num_cols, num_bands = opt_t0.shape
img_source = np.concatenate((sar_t0, sar_t1, opt_t1), axis=2)
img_source = img_source.reshape(1, num_rows, num_cols, self.input_c_dim)
fake_opt = np.zeros((num_rows, num_cols, self.output_c_dim),
dtype='float32')
s = 48
stride = self.image_size-2*s
for row in range(0, num_rows, stride):
for col in range(0, num_cols, stride):
if (row+self.image_size <= num_rows) and (col+self.image_size <= num_cols):
print row + s, row + self.image_size - s
sample_image = img_source[:, row:row + self.image_size, col:col + self.image_size]
sample = self.sess.run(self.fake_B_sample,
feed_dict={self.real_A: sample_image}
)
print sample.shape
fake_opt[row+s:row+self.image_size-s, col+s:col+self.image_size-s ]= sample[0, s:self.image_size-s, s:self.image_size-s]
elif col+self.image_size <= num_cols:
sample_image = img_source[:, num_rows-self.image_size:num_rows, col:col+self.image_size]
print(sample_image.shape)
sample = self.sess.run(self.fake_B_sample,
feed_dict={self.real_A: sample_image}
)
print sample.shape
fake_opt[row+s:num_rows, col+s:col+self.image_size-s] = sample[0, self.image_size-num_rows+row+s:self.image_size, s:self.image_size-s]
elif row+self.image_size <= num_rows:
print col
sample_image = img_source[:, row:row+self.image_size, num_cols-self.image_size:num_cols]
sample = self.sess.run(self.fake_B_sample,
feed_dict={self.real_A: sample_image}
)
fake_opt[row+s:row+self.image_size-s, col+s:num_cols] = sample[0, s:self.image_size-s, self.image_size-num_cols+col+s:self.image_size]
np.save(self.dataset_name + '_' + str(self.image_size) + '_fake_opt_new', fake_opt)
elif args.experiment_type is 'case_03':
print 'Case 03 ...'
mask_path = '/mnt/Data/DataBases/RS/SAR/Campo Verde/New_Masks/TrainTestMasks/TrainTestMask_50_50_Dec.tif'
sar_img_name = self.sar_root_patch + '13_07Jul_2016.npy'
sar = np.load(sar_img_name)
sar = np.rollaxis(sar, 0, 3)
mask = load_tiff_image(mask_path)
mask_gans_trn = mask.copy()
mask_gans_trn[mask_gans_trn!=0] = 1
sar[sar > 1.0] = 1.0
mask_sar = sar[:, :, 1].copy()
mask_sar[sar[:, :, 0] < 1] = 1
mask_sar[sar[:, :, 0] == 1] = 0
plt.figure()
plt.imshow(mask_gans_trn)
plt.show(block=True)
img_source = minmaxnormalization(sar, mask_sar)
num_rows, num_cols = mask.shape
num_rows, num_cols, bands = img_source.shape
elif args.experiment_type is 'case_04':
print 'do something'
# print self.input_c_dim, self.output_size
# SAR = np.zeros((args.batch_size, num_rows, num_cols, self.input_c_dim + self.output_c_dim), dtype='float32')
# img_source = img_source.reshape(1, num_rows, num_cols, bands)
# SAR[:, :, :, :self.input_c_dim] = img_source
# fake_opt = np.zeros((num_rows, num_cols, self.output_c_dim),
# dtype='float32')
# # fake_opt = self.sess.run(
# # self.fake_B_sample,
# # feed_dict={self.real_data: SAR}
# # )
# # np.save(output_folder + self.dataset_name + '_fake_opt_new', fake_opt)
# s = 112
# stride = self.image_size-2*s
# for row in range(0, num_rows, stride):
# for col in range(0, num_cols, stride):
# if (row+self.image_size <= num_rows) and (col+self.image_size <= num_cols):
# print col
# print row + s, row + self.image_size - s
# sample_image = SAR[:, row:row+self.image_size, col:col+self.image_size]
# sample = self.sess.run(
# self.fake_B_sample,
# feed_dict={self.real_data: sample_image}
# )
# fake_opt[row+s:row+self.image_size-s, col+s:col+self.image_size-s] = sample[0, s:self.image_size-s, s:self.image_size-s]
# elif col+self.image_size <= num_cols:
# sample_image = SAR[:, num_rows-self.image_size:num_rows, col:col+self.image_size]
# print(sample_image.shape)
# sample = self.sess.run(
# self.fake_B_sample,
# feed_dict={self.real_data: sample_image}
# )
# print sample.shape
# fake_opt[row+s:num_rows, col+s:col+self.image_size-s] = sample[0, self.image_size-num_rows+row+s:self.image_size, s:self.image_size-s]
# elif row+self.image_size <= num_rows:
# print col
# sample_image = SAR[:, row:row+self.image_size, num_cols-self.image_size:num_cols]
# sample = self.sess.run(
# self.fake_B_sample,
# feed_dict={self.real_data: sample_image}
# )
# fake_opt[row+s:row+self.image_size-s, col+s:num_cols] = sample[0, s:self.image_size-s, self.image_size-num_cols+col+s:self.image_size]
# np.save(output_folder + self.dataset_name + '_fake_opt_new', fake_opt)
# SAR = np.zeros((args.batch_size, num_rows, num_cols, self.input_c_dim + self.output_c_dim), dtype='float32')
# img_source = img_source.reshape(1, num_rows, num_cols, bands)
## img_source = np.repeat(img_source, args.batch_size, axis=0)
# SAR[:, :, :, :self.input_c_dim] = img_source
# fake_opt = np.zeros((num_rows, num_cols, self.output_c_dim),
# dtype='float32')
# fake_opt = self.sess.run(
# self.fake_B_sample,
# feed_dict={self.real_data: SAR}
# )
# np.save(output_folder + self.dataset_name + '_fake_opt_new', fake_opt)
#
# Save weigths !
# e1 = self.sess.graph.get_tensor_by_name('generator/g_e1_conv/w:0')
# eb1 = self.sess.graph.get_tensor_by_name('generator/g_e1_conv/biases:0')
# print e1.eval(), eb1.eval()
# save_weights(self.sess)
# print "weigths saved...."
# print self.input_c_dim, self.output_size
# SAR = np.zeros((args.batch_size, num_rows, num_cols, self.input_c_dim + self.output_c_dim), dtype='float32')
# img_source = img_source.reshape(1, num_rows, num_cols, bands)
## img_source = np.repeat(img_source, args.batch_size, axis=0)
# SAR[:, :, :, :self.input_c_dim] = img_source
# fake_opt = np.zeros((num_rows, num_cols, self.output_c_dim),
# dtype='float32')
# avg_img = np.zeros_like(fake_opt).astype('float32')
# stride = int(self.image_size/1)
# for row in range(0, num_rows, stride):
# for col in range(0, num_cols, stride):
# if row+self.image_size <= num_rows and col+self.image_size <= num_cols:
# sample_image = SAR[:, row:row+self.image_size, col:col+self.image_size]
# print(sample_image.shape)
#
# sample = self.sess.run(
# self.fake_B_sample,
# feed_dict={self.real_data: sample_image}
# )
# print sample.shape
## fake_opt[row:row+256, col:col+256] = sample[0].reshape(256, 256, self.output_c_dim)
# fake_opt[row:row+self.image_size, col:col+self.image_size] += sample[0]
# avg_img[row:row+self.image_size, col:col+self.image_size] += np.ones_like(sample[0])
## fake_opt[row+stride:row+self.image_size-stride, col+stride:col+self.image_size-stride] += sample[0, stride:self.image_size-stride, stride:self.image_size-stride]
## avg_img[row+stride:row+self.image_size-stride, col+stride:col+self.image_size-stride] += np.ones_like(sample[0, stride:self.image_size-stride, stride:self.image_size-stride])
## plt.figure()
## plt.imshow(fake_opt)
## plt.show()
# avg_img[avg_img == 0] = 1
# fake_opt = fake_opt/avg_img
# fake_opt[np.isnan(fake_opt)] = 0
# np.save(output_folder + '_fake_opt', fake_opt)
## np.save(output_folder + self.dataset_name + '_fake_opt', fake_opt)
## np.save(output_folder + self.dataset_name + '_fake_opt', fake_opt)
## np.save(output_folder + 'real_opt_'+self.dataset_name, opt_target)
#
## plt.figure()
## plt.imshow(avg_img[:, :, 0])
## plt.show()
def create_dataset(self, args):
if '11nov2015' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '02_10Nov_2015.npy'
opt_img_name = '20151111/'
print sar_img_name, opt_img_name
elif '13dec2015' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '05_16Dec_2015.npy'
opt_img_name = '20151213/'
print sar_img_name, opt_img_name
elif '18mar2016' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '09_21Mar_2016.npy'
opt_img_name = '20160318/'
print sar_img_name, opt_img_name
elif '05may2016' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '10_08May_2016.npy'
opt_img_name = '20160505/'
print sar_img_name, opt_img_name
elif '08jul2016' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '13_07Jul_2016.npy'
opt_img_name = '20160708/'
print sar_img_name, opt_img_name
elif '24jul2016' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '14_31Jul_2016.npy'
opt_img_name = '20160724/'
print sar_img_name, opt_img_name
elif 'May05_Jul08' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name2 = '10_08May_2016.npy'
opt_img_name2 = '20160505/'
sar_img_name1 = '13_07Jul_2016.npy'
opt_img_name1 = '20160708/'
elif '13jul2017_C03' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '/mnt/Data/DataBases/CampoVerde2017/Sentinel1/20170714.npy'
opt_img_name = '/mnt/Data/DataBases/CampoVerde2017/Sentinel2/20170713/'
print sar_img_name, opt_img_name
elif '08jul2016_multiresolution' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
sar_img_name = '13_07Jul_2016.npy'
opt_img_name = '20160708/'
print sar_img_name, opt_img_name
elif 'quemadas_ap2_case_A' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
create_dataset_case_A(
ksize=256,
dataset=self.dataset_name,
mask_path=None,
sar_path='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20160909/new_20160909.npy',
opt_path='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20160825/'
)
elif 'quemadas_ap2_case_C' in args.dataset_name:
print 'creating dataset for_' + args.dataset_name
create_dataset_case_C(
ksize=256,
dataset=self.dataset_name,
mask_path=None,
sar_path_t0='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20160909/new_20160909.npy',
sar_path_t1='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20170731/20170731.npy',
opt_path_t0='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20160825/',
opt_path_t1='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20170731/'
)
else:
print "Image pair doesnt exist !!!"
return 0
# create_dataset_case1(ksize=256,
# dataset=self.dataset_name,
# mask_path=None,
# sar_path=self.sar_root_patch + sar_img_name,
# opt_path=self.opt_root_patch + opt_img_name,
# region=args.image_region,
# num_patches = 1000,
# show=True)
# 20151111 -- 02_10Nov_2015 ok !
# 20151127 -- 03_22Nov_2015 too much clouds !
# 20160318 -- 09_21Mar_2016 ok !
# 20151213 -- 05_16Dec_2015 ummmm, differen protocol ...
# 20160505 -- 10_08May_2016 ok !
# 20160708 -- 13_07Jul_2016 ok !
# 20160724 -- 14_31Jul_2016 ok !
# create_dataset_case_A(
# ksize=256,
# dataset=self.dataset_name,
# mask_path=None,
# sar_path='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20160909/20160909.npy',
# opt_path='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20160825/'
# )
# create_dataset_case_C(ksize=256,
# dataset=self.dataset_name,
# mask_path=None,
# sar_path_t0='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20160909/20160909.npy',
# sar_path_t1='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel1/20170731/20170731.npy',
# opt_path_t0='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20160825/',
# opt_path_t1='/mnt/Data/DataBases/RS/Quemadas/AP2_Acre/Sentinel2/20170731/'
# )
# create_dataset_case3(ksize=256,
# dataset=self.dataset_name,
# mask_path=None,
# sar_path=sar_img_name,
# opt_path=opt_img_name,
# num_patches = 1000,
# show=True)
# create_dataset_case4(ksize=256,
# dataset=self.dataset_name,
# mask_path=None,
# sar_path=self.sar_root_patch + sar_img_name,
# opt_path=self.opt_root_patch + opt_img_name,
# num_patches=1000,
# show=True)
# create_dataset_case5(ksize=256,
# dataset=self.dataset_name,
# mask_path=None,
# sar_path=self.sar_root_patch + sar_img_name,
# opt_path=self.opt_root_patch + opt_img_name,
# num_patches=1000,
# show=True)
# create_dataset_case_d_multiresolution(ksize=256,
# dataset=self.dataset_name,
# mask_path=None,
# landsat_path=self.opt_root_patch + opt_img_name,
# sent2_path=self.opt_root_patch + opt_img_name,
# sent1_path=self.sar_root_patch + sar_img_name,
# region=None)
return 0