Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new models, TF based, readme updated 📈
- Loading branch information
tmos
committed
Apr 15, 2017
1 parent
e32fef0
commit 7eef99a
Showing
11 changed files
with
4,696 additions
and
13,376 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
import os | ||
|
||
|
||
import keras.models as models | ||
from keras.layers.core import Layer, Dense, Dropout, Activation, Flatten, Reshape, Permute | ||
from keras.layers.convolutional import Conv2D, MaxPooling2D, UpSampling2D, Cropping2D | ||
from keras.layers.normalization import BatchNormalization | ||
|
||
from keras.layers import Conv2D, Conv2DTranspose | ||
|
||
from keras import backend as K | ||
|
||
import cv2 | ||
import numpy as np | ||
import json | ||
|
||
K.set_image_dim_ordering('th') | ||
|
||
# weight_decay = 0.0001 | ||
from keras.regularizers import l2 | ||
|
||
class Tiramisu(): | ||
|
||
|
||
|
||
def __init__(self): | ||
self.create() | ||
|
||
def DenseBlock(self, layers, filters): | ||
model = self.model | ||
for i in range(layers): | ||
model.add(BatchNormalization()) | ||
model.add(Activation('relu')) | ||
model.add(Conv2D(filters, kernel_size=(3, 3), padding='same', init="he_uniform", W_regularizer = l2(0.0001))) | ||
model.add(Dropout(0.2)) | ||
|
||
def TransitionDown(self,filters): | ||
model = self.model | ||
model.add(BatchNormalization()) | ||
model.add(Activation('relu')) | ||
model.add(Conv2D(filters, kernel_size=(1, 1), padding='same', init="he_uniform", W_regularizer = l2(0.0001))) | ||
model.add(Dropout(0.2)) | ||
model.add(MaxPooling2D(pool_size=(2, 2))) | ||
|
||
def TransitionUp(self,filters, input_shape,output_shape): | ||
model = self.model | ||
model.add(Conv2DTranspose(filters,kernel_size=(3, 3), strides=(2, 2),data_format='channels_first', output_shape=output_shape, | ||
padding='same', input_shape=input_shape, init="he_uniform", W_regularizer = l2(0.0001))) | ||
|
||
def gfactorCounterDown(self,model_self,growth_factor,block_size,previous_conv_size,block_count=5): | ||
for i in range(block_count): | ||
m = block_size * growth_factor + previous_conv_size | ||
model_self.DenseBlock(growth_factor,m) | ||
model_self.TransitionDown(growth_factor,m) | ||
|
||
def gfactorCounterUp(self,model_self,growth_factor,block_size,previous_block_size,previous_conv_size,block_count=5): | ||
# previous_conv_size = 288, since: | ||
# self.DenseBlock(4,288) # 4*12 = 48 + 288 = 336 | ||
# self.TransitionDown(288) | ||
|
||
for i in range(block_count): | ||
m = block_size * growth_factor + previous_block_size * growth_factor + previous_conv_size | ||
model_self.DenseBlock(growth_factor,m) | ||
model_self.TransitionDown(growth_factor,m) | ||
|
||
def create(self): | ||
model = self.model = models.Sequential() | ||
# cropping | ||
# model.add(Cropping2D(cropping=((68, 68), (128, 128)), input_shape=(3, 360,480))) | ||
|
||
model.add(Conv2D(48, kernel_size=(3, 3), padding='same', input_shape=(3,224,224), init="he_uniform", W_regularizer = l2(0.0001))) | ||
|
||
# (5 * 4)* 2 + 5 + 5 + 1 + 1 +1 | ||
# growth_m = 4 * 12 | ||
# previous_m = 48 | ||
self.gfactorCounterDown(self.model,12,4,48,5) | ||
# self.DenseBlock(4,96) # 4*12 = 48 + 48 = 96 | ||
# self.TransitionDown(96) | ||
# self.DenseBlock(4,144) # 4*12 = 48 + 96 = 144 | ||
# self.TransitionDown(144) | ||
# self.DenseBlock(4,192) # 4*12 = 48 + 144 = 192 | ||
# self.TransitionDown(192) | ||
# self.DenseBlock(4,240)# 4*12 = 48 + 192 = 240 | ||
# self.TransitionDown(240) | ||
# self.DenseBlock(4,288) # 4*12 = 48 + 288 = 336 | ||
# self.TransitionDown(288) | ||
|
||
self.DenseBlock(15,336) # 4 * 12 = 48 + 288 = 336 | ||
|
||
|
||
self.gfactorCounterDown(self.model,12,4,4,288,5) | ||
|
||
# self.TransitionUp(384, (384, 7, 7), (None, 384, 14, 14)) # m = 288 + 4x12 + 4x12 = 384. | ||
# self.DenseBlock(4,384) | ||
|
||
# self.TransitionUp(336, (336, 14, 14), (None, 336, 28, 28)) #m = 240 + 4x12 + 4x12 = 336 | ||
# self.DenseBlock(4,336) | ||
|
||
# self.TransitionUp(288, (288, 28, 28), (None, 288, 56, 56)) # m = 192 + 4x12 + 4x12 = 288 | ||
# self.DenseBlock(4,288) | ||
|
||
# self.TransitionUp(240, (240, 56, 56), (None, 240, 112, 112)) # m = 144 + 4x12 + 4x12 = 240 | ||
# self.DenseBlock(4,240) | ||
|
||
# self.TransitionUp(192, (192, 112, 112), (None, 192, 224, 224)) # m = 96 + 4x12 + 4x12 = 192 | ||
# self.DenseBlock(4,192) | ||
|
||
model.add(Conv2D(12, kernel_size=(3, 3), padding='same', init="he_uniform", W_regularizer = l2(0.0001))) | ||
model.add(Reshape((12, 224 * 224))) | ||
model.add(Permute((2, 1))) | ||
model.add(Activation('softmax')) | ||
model.summary() | ||
|
||
with open('tiramisu_fc_dense56_model.json', 'w') as outfile: | ||
outfile.write(json.dumps(json.loads(model.to_json()), indent=3)) | ||
|
||
Tiramisu() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
import os | ||
|
||
|
||
import keras.models as models | ||
from keras.layers.core import Layer, Dense, Dropout, Activation, Flatten, Reshape, Permute | ||
from keras.layers.convolutional import Conv2D, MaxPooling2D, UpSampling2D, Cropping2D | ||
from keras.layers.normalization import BatchNormalization | ||
|
||
from keras.layers import Conv2D, Conv2DTranspose | ||
|
||
from keras import backend as K | ||
|
||
import cv2 | ||
import numpy as np | ||
import json | ||
|
||
K.set_image_dim_ordering('tf') | ||
|
||
# weight_decay = 0.0001 | ||
from keras.regularizers import l2 | ||
|
||
class Tiramisu(): | ||
|
||
|
||
|
||
def __init__(self): | ||
self.create() | ||
|
||
def DenseBlock(self, layers, filters): | ||
model = self.model | ||
for i in range(layers): | ||
model.add(BatchNormalization(mode=0, axis=1, | ||
gamma_regularizer=l2(0.0001), | ||
beta_regularizer=l2(0.0001))) | ||
model.add(Activation('relu')) | ||
model.add(Conv2D(filters, kernel_size=(3, 3), padding='same', | ||
kernel_initializer="he_uniform", | ||
data_format='channels_last')) | ||
model.add(Dropout(0.2)) | ||
|
||
def TransitionDown(self,filters): | ||
model = self.model | ||
model.add(BatchNormalization(mode=0, axis=1, | ||
gamma_regularizer=l2(0.0001), | ||
beta_regularizer=l2(0.0001))) | ||
model.add(Activation('relu')) | ||
model.add(Conv2D(filters, kernel_size=(1, 1), padding='same', | ||
kernel_initializer="he_uniform")) | ||
model.add(Dropout(0.2)) | ||
model.add(MaxPooling2D( pool_size=(2, 2), | ||
strides=(2, 2), | ||
data_format='channels_last')) | ||
|
||
def TransitionUp(self,filters,input_shape,output_shape): | ||
model = self.model | ||
model.add(Conv2DTranspose(filters, kernel_size=(3, 3), strides=(2, 2), | ||
padding='same', | ||
output_shape=output_shape, | ||
input_shape=input_shape, | ||
kernel_initializer="he_uniform", | ||
data_format='channels_last')) | ||
|
||
|
||
def create(self): | ||
model = self.model = models.Sequential() | ||
# cropping | ||
# model.add(Cropping2D(cropping=((68, 68), (128, 128)), input_shape=(3, 360,480))) | ||
|
||
model.add(Conv2D(48, kernel_size=(3, 3), padding='same', | ||
input_shape=(224,224,3), | ||
kernel_initializer="he_uniform", | ||
kernel_regularizer = l2(0.0001), | ||
data_format='channels_last')) | ||
# (5 * 4)* 2 + 5 + 5 + 1 + 1 +1 | ||
# growth_m = 4 * 12 | ||
# previous_m = 48 | ||
self.DenseBlock(5,108) # 5*12 = 60 + 48 = 108 | ||
self.TransitionDown(108) | ||
self.DenseBlock(5,168) # 5*12 = 60 + 108 = 168 | ||
self.TransitionDown(168) | ||
self.DenseBlock(5,228) # 5*12 = 60 + 168 = 228 | ||
self.TransitionDown(228) | ||
self.DenseBlock(5,288)# 5*12 = 60 + 228 = 288 | ||
self.TransitionDown(288) | ||
self.DenseBlock(5,348) # 5*12 = 60 + 288 = 348 | ||
self.TransitionDown(348) | ||
|
||
self.DenseBlock(15,408) # m = 348 + 5*12 = 408 | ||
|
||
|
||
self.TransitionUp(468, (468, 7, 7), (None, 468, 14, 14)) # m = 348 + 5x12 + 5x12 = 468. | ||
self.DenseBlock(5,468) | ||
|
||
self.TransitionUp(408, (408, 14, 14), (None, 408, 28, 28)) # m = 288 + 5x12 + 5x12 = 408 | ||
self.DenseBlock(5,408) | ||
|
||
self.TransitionUp(348, (348, 28, 28), (None, 348, 56, 56)) # m = 228 + 5x12 + 5x12 = 348 | ||
self.DenseBlock(5,348) | ||
|
||
self.TransitionUp(288, (288, 56, 56), (None, 288, 112, 112)) # m = 168 + 5x12 + 5x12 = 288 | ||
self.DenseBlock(5,288) | ||
|
||
self.TransitionUp(228, (228, 112, 112), (None, 228, 224, 224)) # m = 108 + 5x12 + 5x12 = 228 | ||
self.DenseBlock(5,228) | ||
|
||
model.add(Conv2D(12, kernel_size=(1,1), | ||
padding='same', | ||
kernel_initializer="he_uniform", | ||
kernel_regularizer = l2(0.0001), | ||
data_format='channels_last')) | ||
|
||
model.add(Reshape((12, 224 * 224))) | ||
model.add(Permute((2, 1))) | ||
model.add(Activation('softmax')) | ||
model.summary() | ||
|
||
with open('tiramisu_fc_dense67_model_12.json', 'w') as outfile: | ||
outfile.write(json.dumps(json.loads(model.to_json()), indent=3)) | ||
|
||
Tiramisu() |
This file contains 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
This file contains 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
Oops, something went wrong.