This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| "Contrast Limited Adaptive Histogram Equalization" | |
| by Karel Zuiderveld, karel@cv.ruu.nl | |
| in "Graphics Gems IV", Academic Press, 1994 | |
| _Author_ -- Siladittya Manna | |
| The below implementation does not assume that the | |
| X- and Y image resolutions are an integer multiple | |
| of the X- and Y sizes of the contextual regions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def conv2d(x,numfilt,filtsz,strides=1,pad='same',act=True,name=None): | |
| x = Conv2D(numfilt,filtsz,strides,padding=pad,data_format='channels_last',use_bias=False,name=name+'conv2d')(x) | |
| x = BatchNormalization(axis=3,scale=False,name=name+'conv2d'+'bn')(x) | |
| if act: | |
| x = Activation('relu',name=name+'conv2d'+'act')(x) | |
| return x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def incresA(x,scale,name=None): | |
| pad = 'same' | |
| branch0 = conv2d(x,32,1,1,pad,True,name=name+'b0') | |
| branch1 = conv2d(x,32,1,1,pad,True,name=name+'b1_1') | |
| branch1 = conv2d(branch1,32,3,1,pad,True,name=name+'b1_2') | |
| branch2 = conv2d(x,32,1,1,pad,True,name=name+'b2_1') | |
| branch2 = conv2d(branch2,48,3,1,pad,True,name=name+'b2_2') | |
| branch2 = conv2d(branch2,64,3,1,pad,True,name=name+'b2_3') | |
| branches = [branch0,branch1,branch2] | |
| mixed = Concatenate(axis=3, name=name + '_concat')(branches) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def incresB(x,scale,name=None): | |
| pad = 'same' | |
| branch0 = conv2d(x,192,1,1,pad,True,name=name+'b0') | |
| branch1 = conv2d(x,128,1,1,pad,True,name=name+'b1_1') | |
| branch1 = conv2d(branch1,160,[1,7],1,pad,True,name=name+'b1_2') | |
| branch1 = conv2d(branch1,192,[7,1],1,pad,True,name=name+'b1_3') | |
| branches = [branch0,branch1] | |
| mixed = Concatenate(axis=3, name=name + '_mixed')(branches) | |
| filt_exp_1x1 = conv2d(mixed,1152,1,1,pad,False,name=name+'filt_exp_1x1') | |
| final_lay = Lambda(lambda inputs, scale: inputs[0] + inputs[1] * scale, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def incresC(x,scale,name=None): | |
| pad = 'same' | |
| branch0 = conv2d(x,192,1,1,pad,True,name=name+'b0') | |
| branch1 = conv2d(x,192,1,1,pad,True,name=name+'b1_1') | |
| branch1 = conv2d(branch1,224,[1,3],1,pad,True,name=name+'b1_2') | |
| branch1 = conv2d(branch1,256,[3,1],1,pad,True,name=name+'b1_3') | |
| branches = [branch0,branch1] | |
| mixed = Concatenate(axis=3, name=name + '_mixed')(branches) | |
| filt_exp_1x1 = conv2d(mixed,2048,1,1,pad,False,name=name+'fin1x1') | |
| final_lay = Lambda(lambda inputs, scale: inputs[0] + inputs[1] * scale, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| img_input = Input(shape=(256,256,3)) | |
| x = conv2d(img_input,32,3,2,'valid',True,name='conv1') | |
| x = conv2d(x,32,3,1,'valid',True,name='conv2') | |
| x = conv2d(x,64,3,1,'valid',True,name='conv3') | |
| x_11 = MaxPooling2D(3,strides=1,padding='valid',name='stem_br_11'+'_maxpool_1')(x) | |
| x_12 = conv2d(x,64,3,1,'valid',True,name='stem_br_12') | |
| x = Concatenate(axis=3, name = 'stem_concat_1')([x_11,x_12]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Inception-ResNet-A modules | |
| x = incresA(x,0.15,name='incresA_1') | |
| x = incresA(x,0.15,name='incresA_2') | |
| x = incresA(x,0.15,name='incresA_3') | |
| x = incresA(x,0.15,name='incresA_4') | |
| #35 × 35 to 17 × 17 reduction module. | |
| x_red_11 = MaxPooling2D(3,strides=2,padding='valid',name='red_maxpool_1')(x) | |
| x_red_12 = conv2d(x,384,3,2,'valid',True,name='x_red1_c1') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import pandas as pd | |
| import os | |
| from sklearn.model_selection import KFold, StratifiedKFold | |
| import tensorflow as tf | |
| from tensorflow.keras.preprocessing.image import ImageDataGenerator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| train_data = pd.read_csv('training_labels.csv') | |
| Y = train_data[['label']] | |
| kf = KFold(n_splits = 5) | |
| skf = StratifiedKFold(n_split = 5, random_state = 7, shuffle = True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| VALIDATION_ACCURACY = [] | |
| VALIDAITON_LOSS = [] | |
| save_dir = '/saved_models/' | |
| fold_var = 1 | |
| for train_index, val_index in kf.split(np.zeros(n),Y): | |
| training_data = train_data.iloc[train_index] | |
| validation_data = train_data.iloc[val_index] | |
OlderNewer