def inceptionB(input_layer, name, nfilt): l1 = conv2dbn( input_layer, name='%s_inceptB_1_3x3' % name, num_filters=nfilt[0][0], filter_size=3, stride=2 ) l2 = conv2dbn( input_layer, name='%s_inceptB_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1 ) l2 = conv2dbn( l2, name='%s_inceptB_2_3x3_1' % name, num_filters=nfilt[1][1], filter_size=3, pad=1 ) l2 = conv2dbn( l2, name='%s_inceptB_2_3x3_2' % name, num_filters=nfilt[1][2], filter_size=3, stride=2 ) l3 = avg_pool( input_layer, name='%s_inceptB_3p' % name, pool_size=3, stride=2, ) return nn.layers.ConcatLayer( [l1, l2, l3], name='%s_inceptB_concat' % name )
def inceptionB(input_layer, name, nfilt): l1 = conv2dbn(input_layer, name='%s_inceptB_1_3x3' % name, num_filters=nfilt[0][0], filter_size=3, stride=2) l2 = conv2dbn(input_layer, name='%s_inceptB_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1) l2 = conv2dbn(l2, name='%s_inceptB_2_3x3_1' % name, num_filters=nfilt[1][1], filter_size=3, pad=1) l2 = conv2dbn(l2, name='%s_inceptB_2_3x3_2' % name, num_filters=nfilt[1][2], filter_size=3, stride=2) l3 = avg_pool( input_layer, name='%s_inceptB_3p' % name, pool_size=3, stride=2, ) return nn.layers.ConcatLayer([l1, l2, l3], name='%s_inceptB_concat' % name)
def inceptionC(input_layer, name, nfilt): l1 = conv2dbn(input_layer, name='%s_inceptC_1_3x3' % name, num_filters=nfilt[0][0], filter_size=1) l2 = conv2dbn(input_layer, name='%s_inceptC_2_3x3' % name, num_filters=nfilt[1][0], filter_size=1) l2 = conv2dbn(l2, name='%s_inceptC_2_1x7' % name, num_filters=nfilt[1][1], filter_size=(1, 7), pad=(0, 3)) l2 = conv2dbn(l2, name='%s_inceptC_2_7x1' % name, num_filters=nfilt[1][2], filter_size=(7, 1), pad=(3, 0)) l3 = conv2dbn(input_layer, name='%s_inceptC_3_1x1' % name, num_filters=nfilt[2][0], filter_size=1) l3 = conv2dbn(l3, name='%s_inceptC_3_7x1_1' % name, num_filters=nfilt[2][1], filter_size=(7, 1), pad=(3, 0)) l3 = conv2dbn(l3, name='%s_inceptC_3_1x7_1' % name, num_filters=nfilt[2][2], filter_size=(1, 7), pad=(0, 3)) l3 = conv2dbn(l3, name='%s_inceptC_3_7x1_2' % name, num_filters=nfilt[2][3], filter_size=(7, 1), pad=(3, 0)) l3 = conv2dbn(l3, name='%s_inceptC_3_1x7_2' % name, num_filters=nfilt[2][4], filter_size=(1, 7), pad=(0, 3)) l4 = avg_pool(input_layer, name='%s_inceptC_4p' % name, pool_size=3, stride=1, pad=1) l4 = conv2dbn(l4, name='%s_inceptC_4_1x1' % name, num_filters=nfilt[3][0], filter_size=1) return nn.layers.ConcatLayer([l1, l2, l3, l4], name='%s_inceptC_concat' % name)
def inceptionC(input_layer, name, nfilt): l1 = conv2dbn( input_layer, name='%s_inceptC_1_3x3' % name, num_filters=nfilt[0][0], filter_size=1 ) l2 = conv2dbn( input_layer, name='%s_inceptC_2_3x3' % name, num_filters=nfilt[1][0], filter_size=1 ) l2 = conv2dbn( l2, name='%s_inceptC_2_1x7' % name, num_filters=nfilt[1][1], filter_size=(1, 7), pad=(0, 3) ) l2 = conv2dbn( l2, name='%s_inceptC_2_7x1' % name, num_filters=nfilt[1][2], filter_size=(7, 1), pad=(3, 0) ) l3 = conv2dbn( input_layer, name='%s_inceptC_3_1x1' % name, num_filters=nfilt[2][0], filter_size=1 ) l3 = conv2dbn( l3, name='%s_inceptC_3_7x1_1' % name, num_filters=nfilt[2][1], filter_size=(7, 1), pad=(3, 0) ) l3 = conv2dbn( l3, name='%s_inceptC_3_1x7_1' % name, num_filters=nfilt[2][2], filter_size=(1, 7), pad=(0, 3) ) l3 = conv2dbn( l3, name='%s_inceptC_3_7x1_2' % name, num_filters=nfilt[2][3], filter_size=(7, 1), pad=(3, 0) ) l3 = conv2dbn( l3, name='%s_inceptC_3_1x7_2' % name, num_filters=nfilt[2][4], filter_size=(1, 7), pad=(0, 3) ) l4 = avg_pool( input_layer, name='%s_inceptC_4p' % name, pool_size=3, stride=1, pad=1 ) l4 = conv2dbn( l4, name='%s_inceptC_4_1x1' % name, num_filters=nfilt[3][0], filter_size=1 ) return nn.layers.ConcatLayer( [l1, l2, l3, l4], name='%s_inceptC_concat' % name )
def inceptionE(input_layer, name, nfilt, pool_type): l1 = conv2dbn( input_layer, name='%s_inceptE_1_1x1' % name, num_filters=nfilt[0][0], filter_size=1 ) l2 = conv2dbn( input_layer, name='%s_inceptE_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1 ) l2a = conv2dbn( l2, name='%s_inceptE_2a_1x3' % name, num_filters=nfilt[1][1], filter_size=(1, 3), pad=(0, 1) ) l2b = conv2dbn( l2, name='%s_inceptE_2b_3x1' % name, num_filters=nfilt[1][2], filter_size=(3, 1), pad=(1, 0) ) l3 = conv2dbn( input_layer, name='%s_inceptE_3_1x1_1' % name, num_filters=nfilt[2][0], filter_size=1 ) l3 = conv2dbn( l3, name='%s_inceptE_3_1x1_2' % name, num_filters=nfilt[2][1], filter_size=3, pad=1 ) l3a = conv2dbn( l3, name='%s_inceptE_3a_1x3' % name, num_filters=nfilt[2][2], filter_size=(1, 3), pad=(0, 1) ) l3b = conv2dbn( l3, name='%s_inceptE_3b_3x1' % name, num_filters=nfilt[2][3], filter_size=(3, 1), pad=(1, 0) ) if pool_type == 'avg': l4 = avg_pool( input_layer, name='%s_inceptE_4p' % name, pool_size=3, stride=1, pad=1 ) elif pool_type == 'max': l4 = nn.layers.dnn.Pool2DDNNLayer( input_layer, name='%s_inceptE_4p' % name, pool_size=3, stride=1, pad=1, mode='max' ) else: raise ValueError('unrecognized pool_type') l4 = conv2dbn( l4, name='%s_inceptE_4_1x1' % name, num_filters=nfilt[3][0], filter_size=1 ) return nn.layers.ConcatLayer( [l1, l2a, l2b, l3a, l3b, l4], name='%s_inceptE_concat' % name )
def inceptionD(input_layer, name, nfilt): l1 = conv2dbn( input_layer, name='%s_inceptD_1_1x1' % name, num_filters=nfilt[0][0], filter_size=1 ) l1 = conv2dbn( l1, name='%s_inceptD_1_3x3' % name, num_filters=nfilt[0][1], filter_size=3, stride=2 ) l2 = conv2dbn( input_layer, name='%s_inceptD_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1 ) l2 = conv2dbn( l2, name='%s_inceptD_2_1x7' % name, num_filters=nfilt[1][1], filter_size=(1, 7), pad=(0, 3) ) l2 = conv2dbn( l2, name='%s_inceptD_2_7x1' % name, num_filters=nfilt[1][2], filter_size=(7, 1), pad=(3, 0) ) l2 = conv2dbn( l2, name='%s_inceptD_2_3x3' % name, num_filters=nfilt[1][3], filter_size=3, stride=2 ) l3 = nn.layers.dnn.Pool2DDNNLayer( input_layer, name='%s_inceptD_3p' % name, pool_size=3, stride=2, mode='max' ) return nn.layers.ConcatLayer( [l1, l2, l3], name='%s_inceptD_concat' % name )
def inceptionA(input_layer, name, nfilt): l1 = conv2dbn(input_layer, name='%s_inceptA_1_1x1' % name, num_filters=nfilt[0][0], filter_size=1) l2 = conv2dbn(input_layer, name='%s_inceptA_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1) l2 = conv2dbn(l2, name='%s_inceptA_2_5x5' % name, num_filters=nfilt[1][1], filter_size=5, pad=2) l3 = conv2dbn(input_layer, name='%s_inceptA_3_1x1' % name, num_filters=nfilt[2][0], filter_size=1) l3 = conv2dbn(l3, name='%s_inceptA_3_3x3_1' % name, num_filters=nfilt[2][1], filter_size=3, pad=1) l3 = conv2dbn(l3, name='%s_inceptA_3_3x3_2' % name, num_filters=nfilt[2][2], filter_size=3, pad=1) l4 = avg_pool( input_layer, name='%s_inceptA_4p' % name, pool_size=3, stride=1, pad=1, ) l4 = conv2dbn(l4, name='%s_inceptA_4_1x1' % name, num_filters=nfilt[3][0], filter_size=1) return nn.layers.ConcatLayer([l1, l2, l3, l4], name='%s_inceptA_concat' % name)
def inceptionA(input_layer, name, nfilt): l1 = conv2dbn( input_layer, name='%s_inceptA_1_1x1' % name, num_filters=nfilt[0][0], filter_size=1 ) l2 = conv2dbn( input_layer, name='%s_inceptA_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1 ) l2 = conv2dbn( l2, name='%s_inceptA_2_5x5' % name, num_filters=nfilt[1][1], filter_size=5, pad=2 ) l3 = conv2dbn( input_layer, name='%s_inceptA_3_1x1' % name, num_filters=nfilt[2][0], filter_size=1 ) l3 = conv2dbn( l3, name='%s_inceptA_3_3x3_1' % name, num_filters=nfilt[2][1], filter_size=3, pad=1 ) l3 = conv2dbn( l3, name='%s_inceptA_3_3x3_2' % name, num_filters=nfilt[2][2], filter_size=3, pad=1 ) l4 = avg_pool( input_layer, name='%s_inceptA_4p' % name, pool_size=3, stride=1, pad=1, ) l4 = conv2dbn( l4, name='%s_inceptA_4_1x1' % name, num_filters=nfilt[3][0], filter_size=1 ) return nn.layers.ConcatLayer( [l1, l2, l3, l4], name='%s_inceptA_concat' % name )
def inceptionD(input_layer, name, nfilt): l1 = conv2dbn(input_layer, name='%s_inceptD_1_1x1' % name, num_filters=nfilt[0][0], filter_size=1) l1 = conv2dbn(l1, name='%s_inceptD_1_3x3' % name, num_filters=nfilt[0][1], filter_size=3, stride=2) l2 = conv2dbn(input_layer, name='%s_inceptD_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1) l2 = conv2dbn(l2, name='%s_inceptD_2_1x7' % name, num_filters=nfilt[1][1], filter_size=(1, 7), pad=(0, 3)) l2 = conv2dbn(l2, name='%s_inceptD_2_7x1' % name, num_filters=nfilt[1][2], filter_size=(7, 1), pad=(3, 0)) l2 = conv2dbn(l2, name='%s_inceptD_2_3x3' % name, num_filters=nfilt[1][3], filter_size=3, stride=2) l3 = nn.layers.dnn.Pool2DDNNLayer(input_layer, name='%s_inceptD_3p' % name, pool_size=3, stride=2, mode='max') return nn.layers.ConcatLayer([l1, l2, l3], name='%s_inceptD_concat' % name)
conv_kwargs = dict( pad='same', nonlinearity=nn.nonlinearities.very_leaky_rectify ) pool_kwargs = dict( pool_size=2, ) # 256 l = nn.layers.InputLayer(name='in', shape=(None, 3, image_size, image_size)) l = conv2dbn(l, name='l1c1', num_filters=16, filter_size=(7, 7), **conv_kwargs) l = nn.layers.dnn.MaxPool2DDNNLayer(l, name='l1p', **pool_kwargs) # 128 l = conv2dbn(l, name='l2c1', num_filters=32, filter_size=(3, 3), **conv_kwargs) l = conv2dbn(l, name='l2c2', num_filters=32, filter_size=(3, 3), **conv_kwargs) l = conv2dbn(l, name='l2c3', num_filters=32, filter_size=(3, 3), **conv_kwargs) # 64 l = conv2dbn(l, name='l3c1', num_filters=64, filter_size=(3, 3), stride=2, **conv_kwargs) l = conv2dbn(l, name='l3c2', num_filters=64, filter_size=(3, 3), **conv_kwargs) l = conv2dbn(l, name='l3c3', num_filters=64, filter_size=(3, 3), **conv_kwargs) # 32 l = conv2dbn(l, name='l4c1', num_filters=128, filter_size=(3, 3), stride=2, **conv_kwargs) l = conv2dbn(l, name='l4c2', num_filters=128, filter_size=(3, 3), **conv_kwargs)
save_weights = SaveWeights(model_fname, only_best=True, pickle=False) save_training_history = SaveTrainingHistory(model_history_fname) plot_training_history = PlotTrainingHistory(model_graph_fname) early_stopping = EarlyStopping(patience=100) conv_kwargs = dict(pad='same', nonlinearity=nn.nonlinearities.very_leaky_rectify) pool_kwargs = dict(pool_size=2, ) l = nn.layers.InputLayer(name='in', shape=(None, 3, image_size, image_size)) # 256 l = conv2dbn(l, name='l1c1', num_filters=32, filter_size=(7, 7), stride=2, **conv_kwargs) l = conv2dbn(l, name='l2c1', num_filters=48, filter_size=(3, 3), **conv_kwargs) l = conv2dbn(l, name='l2c2', num_filters=48, filter_size=(3, 3), **conv_kwargs) l = conv2dbn(l, name='l2c3', num_filters=48, filter_size=(3, 3), **conv_kwargs) # 128 l = conv2dbn(l, name='l3c1', num_filters=64, filter_size=(3, 3), stride=2, **conv_kwargs) l = conv2dbn(l, name='l3c2', num_filters=64, filter_size=(3, 3), **conv_kwargs)
save_weights = SaveWeights(model_fname, only_best=True, pickle=False) save_training_history = SaveTrainingHistory(model_history_fname) plot_training_history = PlotTrainingHistory(model_graph_fname) early_stopping = EarlyStopping(patience=100) conv_kwargs = dict( pad='same', nonlinearity=nn.nonlinearities.very_leaky_rectify, ) l = nn.layers.InputLayer(name='in', shape=(None, 3, image_size, image_size)) # 256x256 l = conv2dbn(l, name='l1c1', num_filters=32, filter_size=(7, 7), stride=2, **conv_kwargs) # 128x128 l = nn.layers.dnn.MaxPool2DDNNLayer(l, name='l1p', pool_size=(3, 3), stride=2) # 64x64 for i in range(3): l = residual_block( l, name='2c%s' % i, # bottleneck=True, bottleneck_factor=4, num_filters=48, filter_size=(3, 3), num_layers=2,
save_weights = SaveWeights(model_fname, only_best=True, pickle=False) save_training_history = SaveTrainingHistory(model_history_fname) plot_training_history = PlotTrainingHistory(model_graph_fname) early_stopping = EarlyStopping(patience=100) conv_kwargs = dict( pad='same', nonlinearity=nn.nonlinearities.very_leaky_rectify, ) l = nn.layers.InputLayer(name='in', shape=(None, 3, image_size, image_size)) # 256x256 l = conv2dbn( l, name='l1c1', num_filters=32, filter_size=(7, 7), stride=2, **conv_kwargs ) # 128x128 l = nn.layers.dnn.MaxPool2DDNNLayer(l, name='l1p', pool_size=(3, 3), stride=2) # 64x64 for i in range(3): l = residual_block( l, name='2c%s' % i, # bottleneck=True, bottleneck_factor=4, num_filters=48, filter_size=(3, 3), num_layers=2, **conv_kwargs ) # 64x64
test_iterator = TestIterator(**test_iterator_kwargs) save_weights = SaveWeights(model_fname, only_best=True, pickle=False) save_training_history = SaveTrainingHistory(model_history_fname) plot_training_history = PlotTrainingHistory(model_graph_fname) early_stopping = EarlyStopping(patience=100) conv_kwargs = dict( pad='same', nonlinearity=nn.nonlinearities.very_leaky_rectify, W=nn.init.GlorotNormal(gain=1 / 3.0), ) l = nn.layers.InputLayer(name='in', shape=(None, 3, image_size, image_size)) l = conv2dbn(l, name='1c1', num_filters=32, filter_size=3, stride=2) l = conv2dbn(l, name='1c2', num_filters=32, filter_size=3) l = conv2dbn(l, name='1c3', num_filters=64, filter_size=3, pad=1) l = nn.layers.dnn.MaxPool2DDNNLayer(l, name='1p', pool_size=3, stride=2) l = nn.layers.DropoutLayer(l, name='1cdrop', p=0.1) l = conv2dbn(l, name='2c1', num_filters=80, filter_size=1) l = conv2dbn(l, name='2c2', num_filters=192, filter_size=3) l = nn.layers.dnn.MaxPool2DDNNLayer(l, name='2p', pool_size=3, stride=2) l = nn.layers.DropoutLayer(l, name='2cdrop', p=0.1) l = inceptionA(l, name='3', nfilt=((64, ), (48, 64), (64, 96, 96), (32, ))) l = nn.layers.DropoutLayer(l, name='3cdrop', p=0.1) l = inceptionA(l, name='4', nfilt=((64, ), (48, 64), (64, 96, 96), (64, ))) l = nn.layers.DropoutLayer(l, name='4cdrop', p=0.1)
test_iterator = TestIterator(**test_iterator_kwargs) save_weights = SaveWeights(model_fname, only_best=True, pickle=False) save_training_history = SaveTrainingHistory(model_history_fname) plot_training_history = PlotTrainingHistory(model_graph_fname) early_stopping = EarlyStopping(patience=100) conv_kwargs = dict( pad='same', nonlinearity=nn.nonlinearities.very_leaky_rectify, W=nn.init.GlorotNormal(gain=1 / 3.0), ) l = nn.layers.InputLayer(name='in', shape=(None, 3, image_size, image_size)) l = conv2dbn(l, name='1c1', num_filters=32, filter_size=3, stride=2) l = conv2dbn(l, name='1c2', num_filters=32, filter_size=3) l = conv2dbn(l, name='1c3', num_filters=64, filter_size=3, pad=1) l = nn.layers.dnn.MaxPool2DDNNLayer(l, name='1p', pool_size=3, stride=2) l = nn.layers.DropoutLayer(l, name='1cdrop', p=0.1) l = conv2dbn(l, name='2c1', num_filters=80, filter_size=1) l = conv2dbn(l, name='2c2', num_filters=192, filter_size=3) l = nn.layers.dnn.MaxPool2DDNNLayer(l, name='2p', pool_size=3, stride=2) l = nn.layers.DropoutLayer(l, name='2cdrop', p=0.1) l = inceptionA( l, name='3', nfilt=( (64,), (48, 64), (64, 96, 96),
def inceptionE(input_layer, name, nfilt, pool_type): l1 = conv2dbn(input_layer, name='%s_inceptE_1_1x1' % name, num_filters=nfilt[0][0], filter_size=1) l2 = conv2dbn(input_layer, name='%s_inceptE_2_1x1' % name, num_filters=nfilt[1][0], filter_size=1) l2a = conv2dbn(l2, name='%s_inceptE_2a_1x3' % name, num_filters=nfilt[1][1], filter_size=(1, 3), pad=(0, 1)) l2b = conv2dbn(l2, name='%s_inceptE_2b_3x1' % name, num_filters=nfilt[1][2], filter_size=(3, 1), pad=(1, 0)) l3 = conv2dbn(input_layer, name='%s_inceptE_3_1x1_1' % name, num_filters=nfilt[2][0], filter_size=1) l3 = conv2dbn(l3, name='%s_inceptE_3_1x1_2' % name, num_filters=nfilt[2][1], filter_size=3, pad=1) l3a = conv2dbn(l3, name='%s_inceptE_3a_1x3' % name, num_filters=nfilt[2][2], filter_size=(1, 3), pad=(0, 1)) l3b = conv2dbn(l3, name='%s_inceptE_3b_3x1' % name, num_filters=nfilt[2][3], filter_size=(3, 1), pad=(1, 0)) if pool_type == 'avg': l4 = avg_pool(input_layer, name='%s_inceptE_4p' % name, pool_size=3, stride=1, pad=1) elif pool_type == 'max': l4 = nn.layers.dnn.Pool2DDNNLayer(input_layer, name='%s_inceptE_4p' % name, pool_size=3, stride=1, pad=1, mode='max') else: raise ValueError('unrecognized pool_type') l4 = conv2dbn(l4, name='%s_inceptE_4_1x1' % name, num_filters=nfilt[3][0], filter_size=1) return nn.layers.ConcatLayer([l1, l2a, l2b, l3a, l3b, l4], name='%s_inceptE_concat' % name)