-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcoffee_dilated_random.py
1373 lines (1043 loc) · 61.3 KB
/
coffee_dilated_random.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
1000
import math
import random
import sys
import datetime
from os import listdir
import numpy as np
import tensorflow as tf
from PIL import Image
from sklearn.metrics import cohen_kappa_score
from sklearn.metrics import f1_score
NUM_CLASSES = 2 # coffee and non coffee
class BatchColors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def softmax(array):
return np.exp(array) / np.sum(np.exp(array), axis=0)
def print_params(list_params):
print('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
for i in range(1, len(sys.argv)):
print(list_params[i - 1] + '= ' + sys.argv[i])
print('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
def select_batch(shuffle, batch_size, it, total_size):
batch = shuffle[it:min(it + batch_size, total_size)]
if min(it + batch_size, total_size) == total_size or total_size == it + batch_size:
shuffle = np.asarray(random.sample(range(total_size), total_size))
it = 0
if len(batch) < batch_size:
diff = batch_size - len(batch)
batch_c = shuffle[it:it + diff]
batch = np.concatenate((batch, batch_c))
it = diff
else:
it += batch_size
return shuffle, batch, it
def define_multinomial_probs(values, diff_prob=2):
interval_size = values[-1] - values[0] + 1
general_prob = 1.0 / float(interval_size)
max_prob = general_prob * diff_prob # for values
probs = np.full(interval_size, (1.0 - max_prob * len(values)) / float(interval_size - len(values)))
for i in range(len(values)):
probs[values[i] - values[0]] = max_prob
return probs
def normalize_images(data, mean_full, std_full):
data[:, :, :, 0] = np.subtract(data[:, :, :, 0], mean_full[0])
data[:, :, :, 1] = np.subtract(data[:, :, :, 1], mean_full[1])
data[:, :, :, 2] = np.subtract(data[:, :, :, 2], mean_full[2])
data[:, :, :, 0] = np.divide(data[:, :, :, 0], std_full[0])
data[:, :, :, 1] = np.divide(data[:, :, :, 1], std_full[1])
data[:, :, :, 2] = np.divide(data[:, :, :, 2], std_full[2])
def compute_image_mean(data):
mean_full = np.mean(np.mean(np.mean(data, axis=0), axis=0), axis=0)
std_full = np.std(data, axis=0, ddof=1)[0, 0, :]
return mean_full, std_full
def load_imgs_torch(files):
img_data = np.empty([len(files) / 2, 500, 500, 3], dtype=np.float32)
mask_data = np.empty([len(files) / 2, 500, 500, 1], dtype=np.float32)
count_files = 0
mark_files = 0
for f in files:
i = 0
try:
file_in = open(f)
except IOError:
print(BatchColors.FAIL + "Could not open file " + f + BatchColors.ENDC)
for line in file_in:
if i == 7:
c, h, w = line.split(' ')
if i <= 16:
i = i + 1
continue
arr_chw = np.reshape(np.asarray(line.split(' '), dtype=np.float32), (int(c), int(h), int(w)))
arr_hcw = np.swapaxes(arr_chw, 0, 1)
arr_hwc = np.swapaxes(arr_hcw, 1, 2)
if mark_files % 2 == 0:
img_data[count_files, :, :, :] = arr_hwc
else:
mask_data[count_files, :, :] = np.floor(arr_hwc + 0.5)
count_files = count_files + 1
mark_files = mark_files + 1
return img_data, mask_data
def load_images_torch(path):
files = []
for f in listdir(path):
if "txt" in f and (f != "Thumbs.db" and "jpeg" not in f):
files.append(path + f)
files = sorted(files, key=str.lower)
return load_imgs_torch(files)
def create_crops(data, mask_data, crop_size, is_train, data_aug=True, data_aug_exp=False):
crops_data = []
crops_class = []
pos = []
for i in range(len(data)):
for j in range(0, len(data[i]) - 1, crop_size):
for k in range(0, len(data[i][j]) - 1, crop_size):
# Crop
crop = data[i, j:j + crop_size, k:k + crop_size, :]
if len(crop) != crop_size or len(crop[0]) != crop_size:
print(crop.size)
crops_data.append(crop)
# Class
current_class = mask_data[i, j:j + crop_size, k:k + crop_size]
crops_class.append(current_class)
if is_train is True and data_aug is True: # train
# LEFT <-> RIGHT
# CROP
mirrored_lf_crop = np.fliplr(crop)
crops_data.append(mirrored_lf_crop)
# class
mirrored_class = np.fliplr(current_class)
crops_class.append(mirrored_class)
if data_aug_exp is True:
# TOP <-> DOWN
# CROP
mirrored_ud_crop = np.flipud(crop)
crops_data.append(mirrored_ud_crop)
# class
mirrored_class = np.flipud(current_class)
crops_class.append(mirrored_class)
if is_train is False: # test
current_pos = np.zeros(2)
current_pos[0] = int(j)
current_pos[1] = int(k)
pos.append(current_pos)
if is_train is True:
return np.asarray(crops_data), np.asarray(crops_class, dtype=np.int32)
else:
return np.asarray(crops_data), np.asarray(crops_class, dtype=np.int32), pos
def create_crops_stride(data, mask_data, crop_size, stride=1, is_train=False, data_aug=True, data_aug_exp=True):
crops_data = []
crops_class = []
pos = []
for i in range(len(data)):
j = 0
count_x = 0
while j < len(data[i]): # for j in range(0,len(data[i]),stride):
k = 0
count_y = 0
while k < len(data[i][j]): # for k in range(0,len(data[i][j]),stride):
if j + crop_size <= len(data[i]) and k + crop_size <= len(data[i][j]):
# Crop
crop = data[i, j:j + crop_size, k:k + crop_size, :]
if len(crop) != crop_size or len(crop[0]) != crop_size:
print(crop.size)
crops_data.append(crop)
# Class
current_class = mask_data[i, j:j + crop_size, k:k + crop_size]
crops_class.append(current_class)
if is_train is True and data_aug is True: # train
# LEFT <-> RIGHT
# CROP
mirrored_lf_crop = np.fliplr(crop)
crops_data.append(mirrored_lf_crop)
# class
mirrored_class = np.fliplr(current_class)
crops_class.append(mirrored_class)
if data_aug_exp is True:
# TOP <-> DOWN
# CROP
mirrored_ud_crop = np.flipud(crop)
crops_data.append(mirrored_ud_crop)
# class
mirrored_class = np.flipud(current_class)
crops_class.append(mirrored_class)
if is_train is False: # test
current_pos = np.zeros(2)
current_pos[0] = int(j)
current_pos[1] = int(k)
pos.append(current_pos)
if crop_size % 2 != 0 and count_y % 2 != 0:
k += (stride + 1)
else:
k += stride
count_y += 1
if crop_size % 2 != 0 and count_x % 2 != 0:
j += (stride + 1)
else:
j += stride
count_x += 1
if is_train is True:
return np.asarray(crops_data), np.asarray(crops_class, dtype=np.int32)
else:
return np.asarray(crops_data), np.asarray(crops_class, dtype=np.int32), pos
def dynamically_create_patches(data, mask_data, crop_size, class_distribution, shuffle):
patches = []
classes = []
for i in shuffle:
if i >= 2 * len(class_distribution):
cur_pos = i - 2 * len(class_distribution)
elif i >= len(class_distribution):
cur_pos = i - len(class_distribution)
else:
cur_pos = i
cur_map = class_distribution[cur_pos][0]
cur_x = class_distribution[cur_pos][1][0]
cur_y = class_distribution[cur_pos][1][1]
patch = data[cur_map, cur_x:cur_x + crop_size, cur_y:cur_y + crop_size, :]
current_class = mask_data[cur_map, cur_x:cur_x + crop_size, cur_y:cur_y + crop_size]
if len(patch) != crop_size and len(patch[0]) != crop_size:
patch = data[cur_map, cur_x - (crop_size - len(patch)):cur_x + crop_size,
cur_y - (crop_size - len(patch[0])):cur_y + crop_size, :]
current_class = mask_data[cur_map, cur_x - (crop_size - len(current_class)):cur_x + crop_size,
cur_y - (crop_size - len(current_class[0])):cur_y + crop_size]
elif len(patch) != crop_size:
patch = data[cur_map, cur_x - (crop_size - len(patch)):cur_x + crop_size, cur_y:cur_y + crop_size, :]
current_class = mask_data[cur_map, cur_x - (crop_size - len(current_class)):cur_x + crop_size,
cur_y:cur_y + crop_size]
elif len(patch[0]) != crop_size:
patch = data[cur_map, cur_x:cur_x + crop_size, cur_y - (crop_size - len(patch[0])):cur_y + crop_size, :]
current_class = mask_data[cur_map, cur_x:cur_x + crop_size,
cur_y - (crop_size - len(current_class[0])):cur_y + crop_size]
if len(patch) != crop_size or len(patch[0]) != crop_size:
print("Error: Current patch size ", len(patch), len(patch[0]))
print(cur_x, (crop_size - len(patch)), cur_x - (crop_size - len(patch)), cur_x + crop_size, cur_y, (
crop_size - len(patch[0])), cur_y - (crop_size - len(patch[0])), cur_y + crop_size)
return
if len(current_class) != crop_size or len(current_class[0]) != crop_size:
print("Error: Current class size ", len(current_class), len(current_class[0]))
return
if i < len(class_distribution):
patches.append(patch)
classes.append(current_class)
elif i < 2 * len(class_distribution):
patches.append(np.fliplr(patch))
classes.append(np.fliplr(current_class))
elif i >= 2 * len(class_distribution):
patches.append(np.flipud(patch))
classes.append(np.flipud(current_class))
return np.asarray(patches, dtype=np.float16), np.asarray(classes, dtype=np.int8)
def create_patches_per_map(data, mask_data, crop_size, stride_crop, index, batch_size):
patches = []
classes = []
pos = []
h, w, c = data.shape
total_index = (int(((h - crop_size) / stride_crop)) + 1 if ((h - crop_size) % stride_crop) == 0 else int(
((h - crop_size) / stride_crop)) + 2)
count = 0
offset_h = int((index * batch_size) / total_index) * stride_crop
offset_w = int((index * batch_size) % total_index) * stride_crop
first = True
for j in range(offset_h, total_index * stride_crop, stride_crop):
if first is False:
offset_w = 0
for k in range(offset_w, total_index * stride_crop, stride_crop):
if first is True:
first = False
cur_x = j
cur_y = k
patch = data[cur_x:cur_x + crop_size, cur_y:cur_y + crop_size, :]
if len(patch) != crop_size and len(patch[0]) != crop_size:
cur_x = cur_x - (crop_size - len(patch))
cur_y = cur_y - (crop_size - len(patch[0]))
patch = data[cur_x:cur_x + crop_size, cur_y:cur_y + crop_size, :]
elif len(patch) != crop_size:
cur_x = cur_x - (crop_size - len(patch))
patch = data[cur_x:cur_x + crop_size, cur_y:cur_y + crop_size, :]
elif len(patch[0]) != crop_size:
cur_y = cur_y - (crop_size - len(patch[0]))
patch = data[cur_x:cur_x + crop_size, cur_y:cur_y + crop_size, :]
if len(patch) != crop_size or len(patch[0]) != crop_size:
print("Error: Current patch size ", len(patch), len(patch[0]))
count += 1
patches.append(patch)
cur_mask_patch = mask_data[cur_x:cur_x + crop_size, cur_y:cur_y + crop_size]
classes.append(cur_mask_patch)
current_pos = np.zeros(2)
current_pos[0] = int(cur_x)
current_pos[1] = int(cur_y)
pos.append(current_pos)
if count == batch_size: # when completes the batch
return np.asarray(patches), np.asarray(classes, dtype=np.int32), pos
# when its not the total size of the batch
return np.asarray(patches), np.asarray(classes, dtype=np.int32), pos
def create_mean_and_std(training_data, training_mask_data, crop_size, stride_crop):
training_patches, _ = create_crops_stride(training_data, training_mask_data, crop_size, stride=stride_crop,
is_train=True)
return compute_image_mean(training_patches)
def create_distributions_over_classes(labels, crop_size, stride_crop):
classes = [[[] for i in range(0)] for i in range(NUM_CLASSES)]
for k in range(len(labels)):
w, h, c = labels[k].shape
for i in range(0, w, stride_crop):
for j in range(0, h, stride_crop):
patch_class = np.squeeze(labels[k][i:i + crop_size, j:j + crop_size])
if patch_class.shape == (crop_size, crop_size):
count = np.bincount(patch_class.astype(int).flatten())
classes[int(np.argmax(count))].append((k, (i, j)))
return classes[0] + classes[1]
def create_prediction_map(path, all_predcs, pos, step, crop_size):
im_array = np.empty([500, 500], dtype=np.uint8)
for i in range(len(all_predcs)):
im_array[pos[i][1]:pos[i][1] + crop_size, pos[i][0]:pos[i][0] + crop_size] = all_predcs[i, :, :]
img = Image.fromarray(np.uint8(im_array * 255))
img.save(path + 'predMap_step' + str(step) + '.jpeg')
def save_map(path, step, prob_im_argmax):
img = Image.fromarray(np.uint8(prob_im_argmax * 255))
img.save(path + 'pred_map_step' + str(step) + '.jpeg')
def calc_accuracy_by_crop(true_crop, pred_crop, track_conf_matrix):
b, h, w = pred_crop.shape
_trueCrop = np.reshape(true_crop, (b, h, w))
acc = 0
local_conf_matrix = np.zeros((NUM_CLASSES, NUM_CLASSES), dtype=np.uint32)
for i in range(b):
for j in range(h):
for k in range(w):
if _trueCrop[i][j][k] == pred_crop[i][j][k]:
acc = acc + 1
track_conf_matrix[_trueCrop[i][j][k]][pred_crop[i][j][k]] += 1
local_conf_matrix[_trueCrop[i][j][k]][pred_crop[i][j][k]] += 1
_sum = 0.0
for i in range(len(local_conf_matrix)):
_sum += (local_conf_matrix[i][i] / float(np.sum(local_conf_matrix[i])) if np.sum(local_conf_matrix[i]) != 0 else 0)
acc_norm = _sum / float(NUM_CLASSES)
return acc, acc_norm, local_conf_matrix
def calc_accuracy_by_map(test_mask_data, prob_im_argmax):
b, h, w, arg = test_mask_data.shape
acc = 0
conf_matrix = np.zeros((NUM_CLASSES, NUM_CLASSES), dtype=np.uint32)
for i in range(b):
for j in range(h):
for k in range(w):
# count += 1
if test_mask_data[i][j][k][0] == prob_im_argmax[j][k]:
acc = acc + 1
conf_matrix[test_mask_data[i][j][k][0]][prob_im_argmax[j][k]] += 1
return acc, conf_matrix
def select_best_patch_size(distribution_type, values, patch_acc_loss, patch_occur, is_loss_or_acc='acc',
patch_chosen_values=None,
debug=False):
patch_occur[np.where(patch_occur == 0)] = 1
patch_mean = patch_acc_loss / patch_occur
if is_loss_or_acc == 'acc':
argmax_acc = np.argmax(softmax(patch_mean))
if distribution_type == 'multi_fixed':
cur_val = int(values[argmax_acc])
elif distribution_type == 'uniform' or distribution_type == 'multinomial':
cur_val = values[0] + argmax_acc
if patch_chosen_values is not None:
patch_chosen_values[int(argmax_acc)] += 1
if debug is True:
print('errorLoss', patch_acc_loss)
print('patch_occur', patch_occur)
print('patch_mean', patch_mean)
print('argmax_acc', argmax_acc)
print('specific', argmax_acc, patch_acc_loss[argmax_acc], patch_occur[argmax_acc], patch_mean[argmax_acc])
elif is_loss_or_acc == 'loss':
arg_sort_out = np.argsort(patch_mean)
if debug is True:
print('errorLoss', patch_acc_loss)
print('patch_occur', patch_occur)
print('patch_mean', patch_mean)
print('arg_sort_out', arg_sort_out)
if distribution_type == 'multi_fixed':
for i in range(len(values)):
if patch_occur[arg_sort_out[i]] > 0:
cur_val = int(values[arg_sort_out[i]]) # -1*(i+1)
if patch_chosen_values is not None:
patch_chosen_values[arg_sort_out[i]] += 1
if debug is True:
print('specific', arg_sort_out[i], patch_acc_loss[arg_sort_out[i]], \
patch_occur[arg_sort_out[i]], patch_mean[arg_sort_out[i]])
break
elif distribution_type == 'uniform' or distribution_type == 'multinomial':
for i in range(values[-1] - values[0] + 1):
if patch_occur[arg_sort_out[i]] > 0:
cur_val = values[0] + arg_sort_out[i]
if patch_chosen_values is not None:
patch_chosen_values[arg_sort_out[i]] += 1
if debug is True:
print('specific', arg_sort_out[i], patch_acc_loss[arg_sort_out[i]], \
patch_occur[arg_sort_out[i]], patch_mean[arg_sort_out[i]])
break
if debug is True:
print('Current patch size ', cur_val)
if patch_chosen_values is not None:
print('Distr of chosen sizes ', patch_chosen_values)
return cur_val
'''
TensorFlow
'''
def leaky_relu(x, alpha=0.1):
return tf.maximum(alpha * x, x)
def identity_initializer(scale=1.0):
def _initializer(shape, dtype=tf.float32, partition_info=None):
if len(shape) != 2 or shape[0] != shape[1]:
raise ValueError('Identity matrix initializer can only be used for 2D square matrices.')
else:
return tf.constant_op.constant(scale * np.identity(shape[0], dtype), dtype=dtype)
return _initializer
def _variable_on_cpu(name, shape, ini):
with tf.device('/cpu:0'):
var = tf.get_variable(name, shape, initializer=ini, dtype=tf.float32)
return var
def _variable_with_weight_decay(name, shape, ini, weight_decay):
var = _variable_on_cpu(name, shape, ini)
# tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32)
# tf.contrib.layers.xavier_initializer(dtype=tf.float32))
# tf.truncated_normal_initializer(stddev=stddev, dtype=tf.float32))
# orthogonal_initializer()
if weight_decay is not None:
try:
weight_decay = tf.mul(tf.nn.l2_loss(var), weight_decay, name='weight_loss')
except:
weight_decay = tf.multiply(tf.nn.l2_loss(var), weight_decay, name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var
def _batch_norm(input_data, is_training, scope=None):
# Note: is_training is tf.placeholder(tf.bool) type
return tf.cond(is_training,
lambda: tf.contrib.layers.batch_norm(input_data, is_training=True, center=False,
updates_collections=None,
scope=scope),
lambda: tf.contrib.layers.batch_norm(input_data, is_training=False, center=False,
updates_collections=None, scope=scope, reuse=True)
)
def _fc_layer(input, layer_shape, weight_decay, name, activation=None):
with tf.variable_scope(name):
weights = _variable_with_weight_decay('weights', shape=layer_shape,
ini=tf.truncated_normal_initializer(stddev=0.005, dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', layer_shape[-1], tf.constant_initializer(0.1))
fc = tf.matmul(input, weights)
fc = tf.add(fc, biases)
if activation == 'relu':
fc = tf.nn.relu(fc, name=name)
return fc
def _squeeze_excitation_layer(input_data, weight_decay, ratio, layer_name):
with tf.name_scope(layer_name) :
squeeze = tf.reduce_mean(input_data, axis=[1,2])
out_dim = squeeze.get_shape().as_list()[1]
# print(squeeze.get_shape().as_list(), out_dim)
excitation = _fc_layer(squeeze, [out_dim, out_dim/ratio], weight_decay, layer_name+'_fc1')
excitation = tf.nn.relu(excitation)
excitation = _fc_layer(excitation, [out_dim/ratio, out_dim], weight_decay, name=layer_name+'_fc2')
excitation = tf.nn.sigmoid(excitation)
excitation = tf.reshape(excitation, [-1, 1, 1, out_dim])
scale = input_data * excitation
return scale
def _conv_layer(input_data, layer_shape, name, weight_decay, is_training, rate=1, strides=None, pad='SAME',
activation='relu', batch_norm=True, has_activation=True, is_normal_conv=False,
init_func=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32)):
if strides is None:
strides = [1, 1, 1, 1]
with tf.variable_scope(name) as scope:
weights = _variable_with_weight_decay('weights', shape=layer_shape, ini=init_func, weight_decay=weight_decay)
biases = _variable_on_cpu('biases', layer_shape[-1], tf.constant_initializer(0.1))
if is_normal_conv is False:
conv_op = tf.nn.atrous_conv2d(input_data, weights, rate=rate, padding=pad)
else:
conv_op = tf.nn.conv2d(input_data, weights, strides=strides, padding=pad)
conv_act = tf.nn.bias_add(conv_op, biases)
if batch_norm is True:
conv_act = _batch_norm(conv_act, is_training, scope=scope)
if has_activation is True:
if activation == 'relu':
conv_act = tf.nn.relu(conv_act, name=name)
else:
conv_act = leaky_relu(conv_act)
return conv_act
def _squeeze_conv_layer(input_data, in_dim, out_dim, k_dim, kernel_size, name, weight_decay, is_training, rate=1,
strides=None, pad='SAME', activation='relu', batch_norm=True, has_activation=True,
is_normal_conv=False):
conv1 = _conv_layer(input_data, [1, 1, in_dim, k_dim], name + '_s1', weight_decay, is_training, rate, strides, pad,
activation, batch_norm, has_activation, is_normal_conv)
conv2_1 = _conv_layer(conv1, [1, 1, k_dim, out_dim/2], name + '_s2_1', weight_decay, is_training, rate, strides,
pad, activation, batch_norm, has_activation, is_normal_conv)
conv2_2 = _conv_layer(conv1, [kernel_size, kernel_size, k_dim, out_dim/2], name + '_s2_2', weight_decay,
is_training, rate, strides, pad, activation, batch_norm, has_activation, is_normal_conv)
try:
out = tf.concat([conv2_1, conv2_2], 3)
except:
out = tf.concat(concat_dim=3, values=[conv2_1, conv2_2])
return out
def _max_pool(input_data, kernel, strides, name, pad='SAME', debug=False):
pool = tf.nn.max_pool(input_data, ksize=kernel, strides=strides, padding=pad, name=name)
if debug:
pool = tf.Print(pool, [tf.shape(pool)], message='Shape of %s' % name)
return pool
def _avg_pool(input_data, kernel, strides, name, pad='SAME', debug=False):
pool = tf.nn.avg_pool(input_data, ksize=kernel, strides=strides, padding=pad, name=name)
if debug:
pool = tf.Print(pool, [tf.shape(pool)], message='Shape of %s' % name)
return pool
def dilated_icpr_original(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
# print x.get_shape()
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
# pool1 = _max_pool(conv1, kernel=[1, 2, 2, 1], strides=[1, 2, 2, 1], name='pool1')
conv2 = _conv_layer(conv1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=1)
# pool2 = _max_pool(conv2, kernel=[1, 2, 2, 1], strides=[1, 2, 2, 1], name='pool2')
conv3 = _conv_layer(conv2, [4, 4, 64, 128], 'conv3', weight_decay, is_training, rate=2)
# pool3 = _max_pool(conv3, kernel=[1, 2, 2, 1], strides=[1, 1, 1, 1], name='pool3')
conv4 = _conv_layer(conv3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=2)
conv5 = _conv_layer(conv4, [3, 3, 128, 256], "conv5", weight_decay, is_training, rate=4)
conv6 = _conv_layer(conv5, [3, 3, 256, 256], "conv6", weight_decay, is_training, rate=4)
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(conv6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate6_small(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
conv2 = _conv_layer(conv1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=2)
conv3 = _conv_layer(conv2, [4, 4, 64, 64], "conv3", weight_decay, is_training, rate=3)
conv4 = _conv_layer(conv3, [4, 4, 64, 128], "conv4", weight_decay, is_training, rate=4)
conv5 = _conv_layer(conv4, [3, 3, 128, 128], "conv5", weight_decay, is_training, rate=5)
conv6 = _conv_layer(conv5, [3, 3, 128, 128], "conv6", weight_decay, is_training, rate=6)
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 128, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(conv6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate6(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
conv2 = _conv_layer(conv1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=2)
conv3 = _conv_layer(conv2, [4, 4, 64, 128], "conv3", weight_decay, is_training, rate=3)
conv4 = _conv_layer(conv3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=4)
conv5 = _conv_layer(conv4, [3, 3, 128, 256], "conv5", weight_decay, is_training, rate=5)
conv6 = _conv_layer(conv5, [3, 3, 256, 256], "conv6", weight_decay, is_training, rate=6)
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(conv6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate6_avgpool(x, dropout, is_training, weight_decay, crop_size, batch_norm=True):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
pool1 = _avg_pool(conv1, kernel=[1, 5, 5, 1], strides=[1, 1, 1, 1], name='pool1')
conv2 = _conv_layer(pool1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=2)
pool2 = _avg_pool(conv2, kernel=[1, 5, 5, 1], strides=[1, 1, 1, 1], name='pool2')
conv3 = _conv_layer(pool2, [4, 4, 64, 128], "conv3", weight_decay, is_training, rate=3)
pool3 = _avg_pool(conv3, kernel=[1, 5, 5, 1], strides=[1, 1, 1, 1], name='pool3')
conv4 = _conv_layer(pool3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=4)
pool4 = _avg_pool(conv4, kernel=[1, 7, 7, 1], strides=[1, 1, 1, 1], name='pool4')
conv5 = _conv_layer(pool4, [3, 3, 128, 256], "conv5", weight_decay, is_training, rate=5)
pool5 = _avg_pool(conv5, kernel=[1, 7, 7, 1], strides=[1, 1, 1, 1], name='pool5')
conv6 = _conv_layer(pool5, [3, 3, 256, 256], "conv6", weight_decay, is_training, rate=6)
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(conv6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate6_nodilation(x, dropout, is_training, weight_decay, crop_size, batch_norm=True):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training,
batch_norm=batch_norm, is_normal_conv=True)
conv2 = _conv_layer(conv1, [5, 5, 64, 64], 'conv2', weight_decay, is_training,
batch_norm=batch_norm, is_normal_conv=True)
conv3 = _conv_layer(conv2, [4, 4, 64, 128], "conv3", weight_decay, is_training,
batch_norm=batch_norm, is_normal_conv=True)
conv4 = _conv_layer(conv3, [4, 4, 128, 128], "conv4", weight_decay, is_training,
batch_norm=batch_norm, is_normal_conv=True)
conv5 = _conv_layer(conv4, [3, 3, 128, 256], "conv5", weight_decay, is_training,
batch_norm=batch_norm, is_normal_conv=True)
conv6 = _conv_layer(conv5, [3, 3, 256, 256], "conv6", weight_decay, is_training,
batch_norm=batch_norm, is_normal_conv=True)
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(conv6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate1(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
conv2 = _conv_layer(conv1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=1)
conv3 = _conv_layer(conv2, [4, 4, 64, 128], "conv3", weight_decay, is_training, rate=1)
conv4 = _conv_layer(conv3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=1)
conv5 = _conv_layer(conv4, [3, 3, 128, 256], "conv5", weight_decay, is_training, rate=1)
conv6 = _conv_layer(conv5, [3, 3, 256, 256], "conv6", weight_decay, is_training, rate=1)
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(conv6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_vary_rate(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
conv2 = _conv_layer(conv1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=2)
conv3 = _conv_layer(conv2, [4, 4, 64, 128], "conv3", weight_decay, is_training, rate=4)
conv4 = _conv_layer(conv3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=1)
conv5 = _conv_layer(conv4, [3, 3, 128, 256], "conv5", weight_decay, is_training, rate=2)
conv6 = _conv_layer(conv5, [3, 3, 256, 256], "conv6", weight_decay, is_training, rate=4)
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(conv6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate6_densely(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 32], "conv1", weight_decay, is_training, rate=1)
conv2 = _conv_layer(conv1, [5, 5, 32, 32], 'conv2', weight_decay, is_training, rate=2)
try:
c1 = tf.concat([conv1, conv2], 3) # c1 = 32+32 = 64
except:
c1 = tf.concat(concat_dim=3, values=[conv1, conv2])
conv3 = _conv_layer(c1, [4, 4, 64, 64], "conv3", weight_decay, is_training, rate=3)
try:
c2 = tf.concat([c1, conv3], 3) # c2 = 64+64 = 128
except:
c2 = tf.concat(concat_dim=3, values=[c1, conv3])
conv4 = _conv_layer(c2, [4, 4, 128, 64], "conv4", weight_decay, is_training, rate=4)
try:
c3 = tf.concat([c2, conv4], 3) # c3 = 128+64 = 192
except:
c3 = tf.concat(concat_dim=3, values=[c2, conv4])
conv5 = _conv_layer(c3, [3, 3, 192, 128], "conv5", weight_decay, is_training, rate=5)
try:
c4 = tf.concat([c3, conv5], 3) # c4 = 192+128 = 320
except:
c4 = tf.concat(concat_dim=3, values=[c3, conv5])
conv6 = _conv_layer(c4, [3, 3, 320, 128], "conv6", weight_decay, is_training, rate=6)
try:
c5 = tf.concat([c4, conv6], 3) # c5 = 320+256 = 448
except:
c5 = tf.concat(concat_dim=3, values=[c4, conv6])
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 448, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(c5, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_grsl(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1, activation='lrelu')
pool1 = _max_pool(conv1, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool1')
conv2 = _conv_layer(pool1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=2, activation='lrelu')
pool2 = _max_pool(conv2, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool2')
conv3 = _conv_layer(pool2, [4, 4, 64, 128], 'conv3', weight_decay, is_training, rate=3, activation='lrelu')
pool3 = _max_pool(conv3, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool3')
conv4 = _conv_layer(pool3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=4, activation='lrelu')
pool4 = _max_pool(conv4, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool4')
conv5 = _conv_layer(pool4, [3, 3, 128, 256], "conv5", weight_decay, is_training, rate=5, activation='lrelu')
pool5 = _max_pool(conv5, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool5')
conv6 = _conv_layer(pool5, [3, 3, 256, 256], "conv6", weight_decay, is_training, rate=6, activation='lrelu')
pool6 = _max_pool(conv6, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool6')
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(pool6, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_grsl_rate8(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1, activation='lrelu')
pool1 = _max_pool(conv1, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool1')
conv2 = _conv_layer(pool1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=2, activation='lrelu')
pool2 = _max_pool(conv2, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool2')
conv3 = _conv_layer(pool2, [4, 4, 64, 128], 'conv3', weight_decay, is_training, rate=3, activation='lrelu')
pool3 = _max_pool(conv3, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool3')
conv4 = _conv_layer(pool3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=4, activation='lrelu')
pool4 = _max_pool(conv4, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool4')
conv5 = _conv_layer(pool4, [3, 3, 128, 192], "conv5", weight_decay, is_training, rate=5, activation='lrelu')
pool5 = _max_pool(conv5, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool5')
conv6 = _conv_layer(pool5, [3, 3, 192, 192], "conv6", weight_decay, is_training, rate=6, activation='lrelu')
pool6 = _max_pool(conv6, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool6')
conv7 = _conv_layer(pool6, [3, 3, 192, 256], "conv7", weight_decay, is_training, rate=7, activation='lrelu')
pool7 = _max_pool(conv7, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool7')
conv8 = _conv_layer(pool7, [3, 3, 256, 256], "conv8", weight_decay, is_training, rate=8, activation='lrelu')
pool8 = _max_pool(conv8, kernel=[1, 3, 3, 1], strides=[1, 1, 1, 1], name='pool8')
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(pool8, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate6_SE(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
conv2 = _conv_layer(conv1, [5, 5, 64, 64], 'conv2', weight_decay, is_training, rate=2)
se1 = _squeeze_excitation_layer(conv2, weight_decay, ratio=4, layer_name='se1')
conv3 = _conv_layer(se1, [4, 4, 64, 128], "conv3", weight_decay, is_training, rate=3)
conv4 = _conv_layer(conv3, [4, 4, 128, 128], "conv4", weight_decay, is_training, rate=4)
se2 = _squeeze_excitation_layer(conv4, weight_decay, ratio=4, layer_name='se2')
conv5 = _conv_layer(se2, [3, 3, 128, 256], "conv5", weight_decay, is_training, rate=5)
conv6 = _conv_layer(conv5, [3, 3, 256, 256], "conv6", weight_decay, is_training, rate=6)
se3 = _squeeze_excitation_layer(conv6, weight_decay, ratio=4, layer_name='se3')
with tf.variable_scope('conv_classifier') as scope:
kernel = _variable_with_weight_decay('weights', shape=[1, 1, 256, NUM_CLASSES],
ini=tf.contrib.layers.xavier_initializer_conv2d(dtype=tf.float32),
weight_decay=weight_decay)
biases = _variable_on_cpu('biases', [NUM_CLASSES], tf.constant_initializer(0.0))
conv = tf.nn.conv2d(se3, kernel, [1, 1, 1, 1], padding='SAME')
conv_classifier = tf.nn.bias_add(conv, biases, name=scope.name)
return conv_classifier
def dilated_icpr_rate6_squeeze(x, dropout, is_training, weight_decay, crop_size):
# Reshape input_data picture
x = tf.reshape(x, shape=[-1, crop_size, crop_size, 3]) # default: 25x25
conv1 = _conv_layer(x, [5, 5, 3, 64], "conv1", weight_decay, is_training, rate=1)
conv2 = _squeeze_conv_layer(conv1, 64, 64, 32, 5, 'conv2', weight_decay, is_training, rate=2)