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 random | |
| import matplotlib.pylab as plt | |
| import seaborn as sns | |
| sns.set_style('white') | |
| iters = 100000 | |
| sim_result = np.zeros(shape=(iters,1)) | |
| for i in range(iters): |
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 BatchGenerator(getter): | |
| while 1: | |
| for f in getter.training_images_paths: | |
| X_train = process_images([getter.train_path + '/' + fname for fname in [f]]) | |
| id_ = getter.get_id(f) | |
| y_train = np.array(getter.find_label(id_)) | |
| y_train = np.reshape(y_train,(1,37)) | |
| yield (X_train, y_train) |
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 process_images(paths): | |
| count = len(paths) | |
| arr = np.zeros(shape=(count,3,106,106)) | |
| for c, path in enumerate(paths): | |
| img = plt.imread(path).T | |
| img = img[:,106:106*3,106:106*3] #crop 424x424 -> 212x212 | |
| img = imresize(img,size=(106,106,3),interp="cubic").T # downsample to half res | |
| arr[c] = img | |
| return arr |
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 ConvBlock(layers, model, filters): | |
| for i in range(layers): | |
| model.add(ZeroPadding2D((1,1))) # zero padding of size 1 | |
| model.add(Convolution2D(filters, 3, 3, activation='relu')) # 3x3 filter size | |
| model.add(MaxPooling2D((2,2), strides=(2,2))) | |
| def FCBlock(model): | |
| model.add(Dense(4096, activation='relu')) | |
| model.add(Dropout(0.5)) | |