Python lasagne.layers.MaxPool2DLayer() Examples
The following are 30
code examples of lasagne.layers.MaxPool2DLayer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
lasagne.layers
, or try the search function
.
Example #1
Source File: adda_network.py From adda_mnist64 with MIT License | 6 votes |
def network_classifier(self, input_var): network = {} network['classifier/input'] = InputLayer(shape=(None, 3, 64, 64), input_var=input_var, name='classifier/input') network['classifier/conv1'] = Conv2DLayer(network['classifier/input'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv1') network['classifier/pool1'] = MaxPool2DLayer(network['classifier/conv1'], pool_size=2, stride=2, pad=0, name='classifier/pool1') network['classifier/conv2'] = Conv2DLayer(network['classifier/pool1'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv2') network['classifier/pool2'] = MaxPool2DLayer(network['classifier/conv2'], pool_size=2, stride=2, pad=0, name='classifier/pool2') network['classifier/conv3'] = Conv2DLayer(network['classifier/pool2'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv3') network['classifier/pool3'] = MaxPool2DLayer(network['classifier/conv3'], pool_size=2, stride=2, pad=0, name='classifier/pool3') network['classifier/conv4'] = Conv2DLayer(network['classifier/pool3'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='classifier/conv4') network['classifier/pool4'] = MaxPool2DLayer(network['classifier/conv4'], pool_size=2, stride=2, pad=0, name='classifier/pool4') network['classifier/dense1'] = DenseLayer(network['classifier/pool4'], num_units=64, nonlinearity=rectify, name='classifier/dense1') network['classifier/output'] = DenseLayer(network['classifier/dense1'], num_units=10, nonlinearity=softmax, name='classifier/output') return network
Example #2
Source File: __init__.py From aenet with BSD 3-Clause "New" or "Revised" License | 6 votes |
def build_model(self): ''' Build Acoustic Event Net model :return: ''' # A architecture 41 classes nonlin = lasagne.nonlinearities.rectify net = {} net['input'] = InputLayer((None, feat_shape[0], feat_shape[1], feat_shape[2])) # channel, time. frequency # ----------- 1st layer group --------------- net['conv1a'] = ConvLayer(net['input'], num_filters=64, filter_size=(3, 3), stride=1, nonlinearity=nonlin) net['conv1b'] = ConvLayer(net['conv1a'], num_filters=64, filter_size=(3, 3), stride=1, nonlinearity=nonlin) net['pool1'] = MaxPool2DLayer(net['conv1b'], pool_size=(1, 2)) # (time, freq) # ----------- 2nd layer group --------------- net['conv2a'] = ConvLayer(net['pool1'], num_filters=128, filter_size=(3, 3), stride=1, nonlinearity=nonlin) net['conv2b'] = ConvLayer(net['conv2a'], num_filters=128, filter_size=(3, 3), stride=1, nonlinearity=nonlin) net['pool2'] = MaxPool2DLayer(net['conv2b'], pool_size=(2, 2)) # (time, freq) # ----------- fully connected layer group --------------- net['fc5'] = DenseLayer(net['pool2'], num_units=1024, nonlinearity=nonlin) net['fc6'] = DenseLayer(net['fc5'], num_units=1024, nonlinearity=nonlin) net['prob'] = DenseLayer(net['fc6'], num_units=41, nonlinearity=lasagne.nonlinearities.softmax) return net
Example #3
Source File: deep_conv_classification_alt51_luad10_luad10in20_brca10x2_heatmap.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = batch_norm(layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #4
Source File: models.py From diagnose-heart with MIT License | 5 votes |
def build_fcn_segmenter(input_var, shape, version=2): ret = {} if version == 2: ret['input'] = la = InputLayer(shape, input_var) ret['conv%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=8, filter_size=7)) ret['conv%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=16, filter_size=3)) ret['pool%d'%len(ret)] = la = MaxPool2DLayer(la, pool_size=2) ret['conv%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=32, filter_size=3)) ret['pool%d'%len(ret)] = la = MaxPool2DLayer(la, pool_size=2) ret['conv%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=64, filter_size=3)) ret['pool%d'%len(ret)] = la = MaxPool2DLayer(la, pool_size=2) ret['conv%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=64, filter_size=3)) ret['dec%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=64, filter_size=3, pad='full')) ret['ups%d'%len(ret)] = la = Upscale2DLayer(la, scale_factor=2) ret['dec%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=64, filter_size=3, pad='full')) ret['ups%d'%len(ret)] = la = Upscale2DLayer(la, scale_factor=2) ret['dec%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=32, filter_size=7, pad='full')) ret['ups%d'%len(ret)] = la = Upscale2DLayer(la, scale_factor=2) ret['dec%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=16, filter_size=3, pad='full')) ret['conv%d'%len(ret)] = la = bn(Conv2DLayer(la, num_filters=8, filter_size=7)) ret['output'] = la = Conv2DLayer(la, num_filters=1, filter_size=7, pad='full', nonlinearity=nn.nonlinearities.sigmoid) return ret, nn.layers.get_output(ret['output']), \ nn.layers.get_output(ret['output'], deterministic=True)
Example #5
Source File: convolutional_neural_network.py From kaggle-breast-cancer-prediction with MIT License | 5 votes |
def CNN(n_epochs): net1 = NeuralNet( layers=[ ('input', layers.InputLayer), ('conv1', layers.Conv2DLayer), # Convolutional layer. Params defined below ('pool1', layers.MaxPool2DLayer), # Like downsampling, for execution speed ('conv2', layers.Conv2DLayer), ('hidden3', layers.DenseLayer), ('output', layers.DenseLayer), ], input_shape=(None, 1, 6, 5), conv1_num_filters=8, conv1_filter_size=(3, 3), conv1_nonlinearity=lasagne.nonlinearities.rectify, pool1_pool_size=(2, 2), conv2_num_filters=12, conv2_filter_size=(1, 1), conv2_nonlinearity=lasagne.nonlinearities.rectify, hidden3_num_units=1000, output_num_units=2, output_nonlinearity=lasagne.nonlinearities.softmax, update_learning_rate=0.0001, update_momentum=0.9, max_epochs=n_epochs, verbose=0, ) return net1
Example #6
Source File: deep_conv_classification_alt64.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = batch_norm(layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #7
Source File: deep_conv_classification_alt51_luad10_luad10in20_brca10x1.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = batch_norm(layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #8
Source File: deep_conv_classification_alt57.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = (layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #9
Source File: deep_conv_classification_alt58.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = (layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #10
Source File: deep_conv_classification_alt51_heatmap.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = batch_norm(layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #11
Source File: deep_conv_classification_alt51_luad10_luad10in20_brca10x2.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = batch_norm(layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #12
Source File: deep_conv_classification_alt51_luad10in20_brca10.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = batch_norm(layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #13
Source File: deep_conv_classification_alt56.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = (layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #14
Source File: deep_conv_classification_alt55.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = (layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = (layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #15
Source File: Deopen_classification.py From Deopen with MIT License | 5 votes |
def create_network(): l = 1000 pool_size = 5 test_size1 = 13 test_size2 = 7 test_size3 = 5 kernel1 = 128 kernel2 = 128 kernel3 = 128 layer1 = InputLayer(shape=(None, 1, 4, l+1024)) layer2_1 = SliceLayer(layer1, indices=slice(0, l), axis = -1) layer2_2 = SliceLayer(layer1, indices=slice(l, None), axis = -1) layer2_3 = SliceLayer(layer2_2, indices = slice(0,4), axis = -2) layer2_f = FlattenLayer(layer2_3) layer3 = Conv2DLayer(layer2_1,num_filters = kernel1, filter_size = (4,test_size1)) layer4 = Conv2DLayer(layer3,num_filters = kernel1, filter_size = (1,test_size1)) layer5 = Conv2DLayer(layer4,num_filters = kernel1, filter_size = (1,test_size1)) layer6 = MaxPool2DLayer(layer5, pool_size = (1,pool_size)) layer7 = Conv2DLayer(layer6,num_filters = kernel2, filter_size = (1,test_size2)) layer8 = Conv2DLayer(layer7,num_filters = kernel2, filter_size = (1,test_size2)) layer9 = Conv2DLayer(layer8,num_filters = kernel2, filter_size = (1,test_size2)) layer10 = MaxPool2DLayer(layer9, pool_size = (1,pool_size)) layer11 = Conv2DLayer(layer10,num_filters = kernel3, filter_size = (1,test_size3)) layer12 = Conv2DLayer(layer11,num_filters = kernel3, filter_size = (1,test_size3)) layer13 = Conv2DLayer(layer12,num_filters = kernel3, filter_size = (1,test_size3)) layer14 = MaxPool2DLayer(layer13, pool_size = (1,pool_size)) layer14_d = DenseLayer(layer14, num_units= 256) layer3_2 = DenseLayer(layer2_f, num_units = 128) layer15 = ConcatLayer([layer14_d,layer3_2]) layer16 = DropoutLayer(layer15,p=0.5) layer17 = DenseLayer(layer16, num_units=256) network = DenseLayer(layer17, num_units= 2, nonlinearity=softmax) return network #random search to initialize the weights
Example #16
Source File: Deopen_regression.py From Deopen with MIT License | 5 votes |
def create_network(): l = 1000 pool_size = 5 test_size1 = 13 test_size2 = 7 test_size3 = 5 kernel1 = 128 kernel2 = 128 kernel3 = 128 layer1 = InputLayer(shape=(None, 1, 4, l+1024)) layer2_1 = SliceLayer(layer1, indices=slice(0, l), axis = -1) layer2_2 = SliceLayer(layer1, indices=slice(l, None), axis = -1) layer2_3 = SliceLayer(layer2_2, indices = slice(0,4), axis = -2) layer2_f = FlattenLayer(layer2_3) layer3 = Conv2DLayer(layer2_1,num_filters = kernel1, filter_size = (4,test_size1)) layer4 = Conv2DLayer(layer3,num_filters = kernel1, filter_size = (1,test_size1)) layer5 = Conv2DLayer(layer4,num_filters = kernel1, filter_size = (1,test_size1)) layer6 = MaxPool2DLayer(layer5, pool_size = (1,pool_size)) layer7 = Conv2DLayer(layer6,num_filters = kernel2, filter_size = (1,test_size2)) layer8 = Conv2DLayer(layer7,num_filters = kernel2, filter_size = (1,test_size2)) layer9 = Conv2DLayer(layer8,num_filters = kernel2, filter_size = (1,test_size2)) layer10 = MaxPool2DLayer(layer9, pool_size = (1,pool_size)) layer11 = Conv2DLayer(layer10,num_filters = kernel3, filter_size = (1,test_size3)) layer12 = Conv2DLayer(layer11,num_filters = kernel3, filter_size = (1,test_size3)) layer13 = Conv2DLayer(layer12,num_filters = kernel3, filter_size = (1,test_size3)) layer14 = MaxPool2DLayer(layer13, pool_size = (1,pool_size)) layer14_d = DenseLayer(layer14, num_units= 256) layer3_2 = DenseLayer(layer2_f, num_units = 128) layer15 = ConcatLayer([layer14_d,layer3_2]) #layer16 = DropoutLayer(layer15,p=0.5) layer17 = DenseLayer(layer15, num_units=256) network = DenseLayer(layer17, num_units= 1, nonlinearity=None) return network #random search to initialize the weights
Example #17
Source File: adda_network.py From adda_mnist64 with MIT License | 5 votes |
def network_discriminator(self, features): network = {} network['discriminator/conv2'] = Conv2DLayer(features, num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='discriminator/conv2') network['discriminator/pool2'] = MaxPool2DLayer(network['discriminator/conv2'], pool_size=2, stride=2, pad=0, name='discriminator/pool2') network['discriminator/conv3'] = Conv2DLayer(network['discriminator/pool2'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='discriminator/conv3') network['discriminator/pool3'] = MaxPool2DLayer(network['discriminator/conv3'], pool_size=2, stride=2, pad=0, name='discriminator/pool3') network['discriminator/conv4'] = Conv2DLayer(network['discriminator/pool3'], num_filters=32, filter_size=3, stride=1, pad='valid', nonlinearity=rectify, name='discriminator/conv4') network['discriminator/pool4'] = MaxPool2DLayer(network['discriminator/conv4'], pool_size=2, stride=2, pad=0, name='discriminator/pool4') network['discriminator/dense1'] = DenseLayer(network['discriminator/pool4'], num_units=64, nonlinearity=rectify, name='discriminator/dense1') network['discriminator/output'] = DenseLayer(network['discriminator/dense1'], num_units=2, nonlinearity=softmax, name='discriminator/output') return network
Example #18
Source File: eeg_cnn_lib.py From EEGLearn with GNU General Public License v2.0 | 5 votes |
def build_cnn(input_var=None, w_init=None, n_layers=(4, 2, 1), n_filters_first=32, imsize=32, n_colors=3): """ Builds a VGG style CNN network followed by a fully-connected layer and a softmax layer. Stacks are separated by a maxpool layer. Number of kernels in each layer is twice the number in previous stack. input_var: Theano variable for input to the network outputs: pointer to the output of the last layer of network (softmax) :param input_var: theano variable as input to the network :param w_init: Initial weight values :param n_layers: number of layers in each stack. An array of integers with each value corresponding to the number of layers in each stack. (e.g. [4, 2, 1] == 3 stacks with 4, 2, and 1 layers in each. :param n_filters_first: number of filters in the first layer :param imsize: Size of the image :param n_colors: Number of color channels (depth) :return: a pointer to the output of last layer """ weights = [] # Keeps the weights for all layers count = 0 # If no initial weight is given, initialize with GlorotUniform if w_init is None: w_init = [lasagne.init.GlorotUniform()] * sum(n_layers) # Input layer network = InputLayer(shape=(None, n_colors, imsize, imsize), input_var=input_var) for i, s in enumerate(n_layers): for l in range(s): network = Conv2DLayer(network, num_filters=n_filters_first * (2 ** i), filter_size=(3, 3), W=w_init[count], pad='same') count += 1 weights.append(network.W) network = MaxPool2DLayer(network, pool_size=(2, 2)) return network, weights
Example #19
Source File: models.py From drmad with MIT License | 5 votes |
def __init__(self, x, y, args): self.params_theta = [] self.params_lambda = [] self.params_weight = [] if args.dataset == 'mnist': input_size = (None, 1, 28, 28) elif args.dataset == 'cifar10': input_size = (None, 3, 32, 32) else: raise AssertionError layers = [ll.InputLayer(input_size)] self.penalty = theano.shared(np.array(0.)) #conv1 layers.append(Conv2DLayerWithReg(args, layers[-1], 20, 5)) self.add_params_to_self(args, layers[-1]) layers.append(ll.MaxPool2DLayer(layers[-1], pool_size=2, stride=2)) #conv1 layers.append(Conv2DLayerWithReg(args, layers[-1], 50, 5)) self.add_params_to_self(args, layers[-1]) layers.append(ll.MaxPool2DLayer(layers[-1], pool_size=2, stride=2)) #fc1 layers.append(DenseLayerWithReg(args, layers[-1], num_units=500)) self.add_params_to_self(args, layers[-1]) #softmax layers.append(DenseLayerWithReg(args, layers[-1], num_units=10, nonlinearity=nonlinearities.softmax)) self.add_params_to_self(args, layers[-1]) self.layers = layers self.y = ll.get_output(layers[-1], x, deterministic=False) self.prediction = T.argmax(self.y, axis=1) # self.penalty = penalty if penalty != 0. else T.constant(0.) print(self.params_lambda) # time.sleep(20) # cost function self.loss = T.mean(categorical_crossentropy(self.y, y)) self.lossWithPenalty = T.add(self.loss, self.penalty) print "loss and losswithpenalty", type(self.loss), type(self.lossWithPenalty)
Example #20
Source File: deep_conv_classification_alt51_luad10_luad10in20_brca10x1_heatmap.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 5 votes |
def build_network_from_ae(classn): input_var = T.tensor4('input_var'); target_var = T.imatrix('targets'); layer = layers.InputLayer(shape=(None, 3, PS, PS), input_var=input_var); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 100, filter_size=(5,5), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 120, filter_size=(4,4), stride=1, nonlinearity=leaky_rectify)); layer = layers.MaxPool2DLayer(layer, pool_size=(3,3), stride=2); layer = batch_norm(layers.Conv2DLayer(layer, 240, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 320, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = batch_norm(layers.Conv2DLayer(layer, 480, filter_size=(3,3), stride=1, nonlinearity=leaky_rectify)); layer = layers.Pool2DLayer(layer, pool_size=(20,20), stride=20, mode='average_inc_pad'); network = layers.DenseLayer(layer, classn, nonlinearity=sigmoid); return network, input_var, target_var;
Example #21
Source File: AED_train.py From AcousticEventDetection with MIT License | 4 votes |
def buildModel(): print "BUILDING MODEL TYPE..." #default settings filters = 64 first_stride = 2 last_filter_multiplier = 16 #input layer net = l.InputLayer((None, IM_DIM, IM_SIZE[1], IM_SIZE[0])) #conv layers net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters, filter_size=7, pad='same', stride=first_stride, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 2, filter_size=5, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 4, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 8, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * last_filter_multiplier, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) print "\tFINAL POOL OUT SHAPE:", l.get_output_shape(net) #dense layers net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.DropoutLayer(net, DROPOUT) net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.DropoutLayer(net, DROPOUT) #Classification Layer if MULTI_LABEL: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.sigmoid, W=init.HeNormal(gain=1)) else: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.softmax, W=init.HeNormal(gain=1)) print "...DONE!" #model stats print "MODEL HAS", (sum(hasattr(layer, 'W') for layer in l.get_all_layers(net))), "WEIGHTED LAYERS" print "MODEL HAS", l.count_params(net), "PARAMS" return net
Example #22
Source File: network.py From cnn_workshop with Apache License 2.0 | 4 votes |
def get_net(): return NeuralNet( layers=[ ('input', layers.InputLayer), ('conv1', Conv2DLayer), ('pool1', MaxPool2DLayer), ('dropout1', layers.DropoutLayer), ('conv2', Conv2DLayer), ('pool2', MaxPool2DLayer), ('dropout2', layers.DropoutLayer), ('conv3', Conv2DLayer), ('pool3', MaxPool2DLayer), ('dropout3', layers.DropoutLayer), ('hidden4', layers.DenseLayer), ('dropout4', layers.DropoutLayer), ('hidden5', layers.DenseLayer), ('output', layers.DenseLayer), ], input_shape=(None, 1, 96, 96), conv1_num_filters=32, conv1_filter_size=(3, 3), pool1_pool_size=(2, 2), dropout1_p=0.1, conv2_num_filters=64, conv2_filter_size=(2, 2), pool2_pool_size=(2, 2), dropout2_p=0.2, conv3_num_filters=128, conv3_filter_size=(2, 2), pool3_pool_size=(2, 2), dropout3_p=0.3, hidden4_num_units=1000, dropout4_p=0.5, hidden5_num_units=1000, output_num_units=30, output_nonlinearity=None, update_learning_rate=theano.shared(float32(0.03)), update_momentum=theano.shared(float32(0.9)), regression=True, batch_iterator_train=FlipBatchIterator(batch_size=128), on_epoch_finished=[ AdjustVariable('update_learning_rate', start=0.03, stop=0.0001), AdjustVariable('update_momentum', start=0.9, stop=0.999), EarlyStopping(patience=200), ], max_epochs=3000, verbose=1, )
Example #23
Source File: net_theano.py From visual_dynamics with MIT License | 4 votes |
def build_small_cifar10nin_net(input_shapes, **kwargs): x_shape, u_shape = input_shapes X_var = T.tensor4('X') U_var = T.matrix('U') X_diff_var = T.tensor4('X_diff') X_next_var = X_var + X_diff_var l_x0 = L.InputLayer(shape=(None,) + x_shape, input_var=X_var, name='x') l_u = L.InputLayer(shape=(None,) + u_shape, input_var=U_var, name='u') l_x1 = L.Conv2DLayer(l_x0, num_filters=192, filter_size=5, pad=2, flip_filters=False, name='x1') l_x2 = L.Conv2DLayer(l_x1, num_filters=160, filter_size=1, flip_filters=False, name='x2') l_x3 = L.Conv2DLayer(l_x2, num_filters=96, filter_size=1, flip_filters=False, name='x3') l_x4 = L.MaxPool2DLayer(l_x3, pool_size=3, stride=2, ignore_border=False, name='x4') l_x4_diff_pred = LT.BilinearLayer([l_x4, l_u], axis=2, name='x4_diff_pred') l_x4_next_pred = L.ElemwiseMergeLayer([l_x4, l_x4_diff_pred], T.add, name='x4_next_pred') l_x3_next_pred = LT.Deconv2DLayer(l_x4_next_pred, num_filters=96, filter_size=3, stride=2, nonlinearity=None, name='x3_next_pred') l_x2_next_pred = LT.Deconv2DLayer(l_x3_next_pred, num_filters=160, filter_size=1, flip_filters=False, name='x2_next_pred') l_x1_next_pred = LT.Deconv2DLayer(l_x2_next_pred, num_filters=192, filter_size=1, flip_filters=False, name='x1_next_pred') l_x0_next_pred = LT.Deconv2DLayer(l_x1_next_pred, num_filters=3, filter_size=5, pad=2, flip_filters=False, nonlinearity=None, name='x0_next_pred') loss_fn = lambda X, X_pred: ((X - X_pred) ** 2).mean(axis=0).sum() / 2. loss = loss_fn(X_next_var, lasagne.layers.get_output(l_x0_next_pred)) net_name = 'SmallCifar10ninNet' input_vars = OrderedDict([(var.name, var) for var in [X_var, U_var, X_diff_var]]) pred_layers = OrderedDict([('x0_next_pred', l_x0_next_pred)]) return net_name, input_vars, pred_layers, loss
Example #24
Source File: vgg_cnn_s.py From Recipes with MIT License | 4 votes |
def build_model(): net = {} net['input'] = InputLayer((None, 3, 224, 224)) net['conv1'] = ConvLayer(net['input'], num_filters=96, filter_size=7, stride=2, flip_filters=False) # caffe has alpha = alpha * pool_size net['norm1'] = NormLayer(net['conv1'], alpha=0.0001) net['pool1'] = PoolLayer(net['norm1'], pool_size=3, stride=3, ignore_border=False) net['conv2'] = ConvLayer(net['pool1'], num_filters=256, filter_size=5, flip_filters=False) net['pool2'] = PoolLayer(net['conv2'], pool_size=2, stride=2, ignore_border=False) net['conv3'] = ConvLayer(net['pool2'], num_filters=512, filter_size=3, pad=1, flip_filters=False) net['conv4'] = ConvLayer(net['conv3'], num_filters=512, filter_size=3, pad=1, flip_filters=False) net['conv5'] = ConvLayer(net['conv4'], num_filters=512, filter_size=3, pad=1, flip_filters=False) net['pool5'] = PoolLayer(net['conv5'], pool_size=3, stride=3, ignore_border=False) net['fc6'] = DenseLayer(net['pool5'], num_units=4096) net['drop6'] = DropoutLayer(net['fc6'], p=0.5) net['fc7'] = DenseLayer(net['drop6'], num_units=4096) net['drop7'] = DropoutLayer(net['fc7'], p=0.5) net['fc8'] = DenseLayer(net['drop7'], num_units=1000, nonlinearity=None) net['prob'] = NonlinearityLayer(net['fc8'], softmax) return net
Example #25
Source File: vgg16_lymph.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 4 votes |
def build_model(): net = {} net['input'] = InputLayer((None, 3, 224, 224)) net['conv1_1'] = ConvLayer( net['input'], 64, 3, pad=1, flip_filters=False) net['conv1_2'] = ConvLayer( net['conv1_1'], 64, 3, pad=1, flip_filters=False) net['pool1'] = PoolLayer(net['conv1_2'], 2) net['conv2_1'] = ConvLayer( net['pool1'], 128, 3, pad=1, flip_filters=False) net['conv2_2'] = ConvLayer( net['conv2_1'], 128, 3, pad=1, flip_filters=False) net['pool2'] = PoolLayer(net['conv2_2'], 2) net['conv3_1'] = ConvLayer( net['pool2'], 256, 3, pad=1, flip_filters=False) net['conv3_2'] = ConvLayer( net['conv3_1'], 256, 3, pad=1, flip_filters=False) net['conv3_3'] = ConvLayer( net['conv3_2'], 256, 3, pad=1, flip_filters=False) net['pool3'] = PoolLayer(net['conv3_3'], 2) net['conv4_1'] = ConvLayer( net['pool3'], 512, 3, pad=1, flip_filters=False) net['conv4_2'] = ConvLayer( net['conv4_1'], 512, 3, pad=1, flip_filters=False) net['conv4_3'] = ConvLayer( net['conv4_2'], 512, 3, pad=1, flip_filters=False) net['pool4'] = PoolLayer(net['conv4_3'], 2) net['conv5_1'] = ConvLayer( net['pool4'], 512, 3, pad=1, flip_filters=False) net['conv5_2'] = ConvLayer( net['conv5_1'], 512, 3, pad=1, flip_filters=False) net['conv5_3'] = ConvLayer( net['conv5_2'], 512, 3, pad=1, flip_filters=False) net['pool5'] = PoolLayer(net['conv5_3'], 2) net['fc6'] = DenseLayer(net['pool5'], num_units=4096) net['fc6_dropout'] = DropoutLayer(net['fc6'], p=0.5) net['fc7'] = DenseLayer(net['fc6_dropout'], num_units=4096) net['fc7_dropout'] = DropoutLayer(net['fc7'], p=0.5) net['fc8'] = DenseLayer( net['fc7_dropout'], num_units=1000, nonlinearity=None) net['prob'] = NonlinearityLayer(net['fc8'], softmax) output_layer = net['prob']; return output_layer
Example #26
Source File: vgg16.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 4 votes |
def build_model(): net = {} input_var = theano.tensor.tensor4('input_var'); net['input'] = InputLayer((None, 3, 224, 224), input_var=input_var) net['conv1_1'] = ConvLayer( net['input'], 64, 3, pad=1, flip_filters=False) net['conv1_2'] = ConvLayer( net['conv1_1'], 64, 3, pad=1, flip_filters=False) net['pool1'] = PoolLayer(net['conv1_2'], 2) net['conv2_1'] = ConvLayer( net['pool1'], 128, 3, pad=1, flip_filters=False) net['conv2_2'] = ConvLayer( net['conv2_1'], 128, 3, pad=1, flip_filters=False) net['pool2'] = PoolLayer(net['conv2_2'], 2) net['conv3_1'] = ConvLayer( net['pool2'], 256, 3, pad=1, flip_filters=False) net['conv3_2'] = ConvLayer( net['conv3_1'], 256, 3, pad=1, flip_filters=False) net['conv3_3'] = ConvLayer( net['conv3_2'], 256, 3, pad=1, flip_filters=False) net['pool3'] = PoolLayer(net['conv3_3'], 2) net['conv4_1'] = ConvLayer( net['pool3'], 512, 3, pad=1, flip_filters=False) net['conv4_2'] = ConvLayer( net['conv4_1'], 512, 3, pad=1, flip_filters=False) net['conv4_3'] = ConvLayer( net['conv4_2'], 512, 3, pad=1, flip_filters=False) net['pool4'] = PoolLayer(net['conv4_3'], 2) net['conv5_1'] = ConvLayer( net['pool4'], 512, 3, pad=1, flip_filters=False) net['conv5_2'] = ConvLayer( net['conv5_1'], 512, 3, pad=1, flip_filters=False) net['conv5_3'] = ConvLayer( net['conv5_2'], 512, 3, pad=1, flip_filters=False) net['pool5'] = PoolLayer(net['conv5_3'], 2) net['fc6'] = DenseLayer(net['pool5'], num_units=4096) net['fc6_dropout'] = DropoutLayer(net['fc6'], p=0.5) net['fc7'] = DenseLayer(net['fc6_dropout'], num_units=4096) net['fc7_dropout'] = DropoutLayer(net['fc7'], p=0.5) net['fc8'] = DenseLayer( net['fc7_dropout'], num_units=1000, nonlinearity=None) net['prob'] = NonlinearityLayer(net['fc8'], softmax) output_layer = net['prob']; return net, output_layer, input_var;
Example #27
Source File: vgg16_full.py From u24_lymphocyte with BSD 3-Clause "New" or "Revised" License | 4 votes |
def build_model(): net = {} input_var = theano.tensor.tensor4('input_var'); net['input'] = InputLayer((None, 3, 224, 224), input_var=input_var) net['conv1_1'] = ConvLayer( net['input'], 64, 3, pad=1, flip_filters=False) net['conv1_2'] = ConvLayer( net['conv1_1'], 64, 3, pad=1, flip_filters=False) net['pool1'] = PoolLayer(net['conv1_2'], 2) net['conv2_1'] = ConvLayer( net['pool1'], 128, 3, pad=1, flip_filters=False) net['conv2_2'] = ConvLayer( net['conv2_1'], 128, 3, pad=1, flip_filters=False) net['pool2'] = PoolLayer(net['conv2_2'], 2) net['conv3_1'] = ConvLayer( net['pool2'], 256, 3, pad=1, flip_filters=False) net['conv3_2'] = ConvLayer( net['conv3_1'], 256, 3, pad=1, flip_filters=False) net['conv3_3'] = ConvLayer( net['conv3_2'], 256, 3, pad=1, flip_filters=False) net['pool3'] = PoolLayer(net['conv3_3'], 2) net['conv4_1'] = ConvLayer( net['pool3'], 512, 3, pad=1, flip_filters=False) net['conv4_2'] = ConvLayer( net['conv4_1'], 512, 3, pad=1, flip_filters=False) net['conv4_3'] = ConvLayer( net['conv4_2'], 512, 3, pad=1, flip_filters=False) net['pool4'] = PoolLayer(net['conv4_3'], 2) net['conv5_1'] = ConvLayer( net['pool4'], 512, 3, pad=1, flip_filters=False) net['conv5_2'] = ConvLayer( net['conv5_1'], 512, 3, pad=1, flip_filters=False) net['conv5_3'] = ConvLayer( net['conv5_2'], 512, 3, pad=1, flip_filters=False) net['pool5'] = PoolLayer(net['conv5_3'], 2) net['fc6'] = DenseLayer(net['pool5'], num_units=4096) net['fc6_dropout'] = DropoutLayer(net['fc6'], p=0.5) net['fc7'] = DenseLayer(net['fc6_dropout'], num_units=4096) net['fc7_dropout'] = DropoutLayer(net['fc7'], p=0.5) net['fc8'] = DenseLayer( net['fc7_dropout'], num_units=1000, nonlinearity=None) net['prob'] = NonlinearityLayer(net['fc8'], softmax) output_layer = net['prob']; return net, output_layer, input_var;
Example #28
Source File: birdCLEF_evaluate.py From BirdCLEF2017 with MIT License | 4 votes |
def buildModel(mtype=1): print "BUILDING MODEL TYPE", mtype, "..." #default settings (Model 1) filters = 64 first_stride = 2 last_filter_multiplier = 16 #specific model type settings (see working notes for details) if mtype == 2: first_stride = 1 elif mtype == 3: filters = 32 last_filter_multiplier = 8 #input layer net = l.InputLayer((None, IM_DIM, IM_SIZE[1], IM_SIZE[0])) #conv layers net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters, filter_size=7, pad='same', stride=first_stride, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) if mtype == 2: net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters, filter_size=5, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 2, filter_size=5, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 4, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 8, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * last_filter_multiplier, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) print "\tFINAL POOL OUT SHAPE:", l.get_output_shape(net) #dense layers net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) #Classification Layer if MULTI_LABEL: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.sigmoid, W=init.HeNormal(gain=1)) else: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.softmax, W=init.HeNormal(gain=1)) print "...DONE!" #model stats print "MODEL HAS", (sum(hasattr(layer, 'W') for layer in l.get_all_layers(net))), "WEIGHTED LAYERS" print "MODEL HAS", l.count_params(net), "PARAMS" return net
Example #29
Source File: birdCLEF_test.py From BirdCLEF2017 with MIT License | 4 votes |
def buildModel(mtype=1): print "BUILDING MODEL TYPE", mtype, "..." #default settings (Model 1) filters = 64 first_stride = 2 last_filter_multiplier = 16 #specific model type settings (see working notes for details) if mtype == 2: first_stride = 1 elif mtype == 3: filters = 32 last_filter_multiplier = 8 #input layer net = l.InputLayer((None, IM_DIM, IM_SIZE[1], IM_SIZE[0])) #conv layers net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters, filter_size=7, pad='same', stride=first_stride, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) if mtype == 2: net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters, filter_size=5, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 2, filter_size=5, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 4, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 8, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * last_filter_multiplier, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) print "\tFINAL POOL OUT SHAPE:", l.get_output_shape(net) #dense layers net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) #Classification Layer if MULTI_LABEL: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.sigmoid, W=init.HeNormal(gain=1)) else: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.softmax, W=init.HeNormal(gain=1)) print "...DONE!" #model stats print "MODEL HAS", (sum(hasattr(layer, 'W') for layer in l.get_all_layers(net))), "WEIGHTED LAYERS" print "MODEL HAS", l.count_params(net), "PARAMS" return net
Example #30
Source File: birdCLEF_train.py From BirdCLEF2017 with MIT License | 4 votes |
def buildModel(mtype=1): print "BUILDING MODEL TYPE", mtype, "..." #default settings (Model 1) filters = 64 first_stride = 2 last_filter_multiplier = 16 #specific model type settings (see working notes for details) if mtype == 2: first_stride = 1 elif mtype == 3: filters = 32 last_filter_multiplier = 8 #input layer net = l.InputLayer((None, IM_DIM, IM_SIZE[1], IM_SIZE[0])) #conv layers net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters, filter_size=7, pad='same', stride=first_stride, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) if mtype == 2: net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters, filter_size=5, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 2, filter_size=5, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 4, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * 8, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) net = l.batch_norm(l.Conv2DLayer(net, num_filters=filters * last_filter_multiplier, filter_size=3, pad='same', stride=1, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.MaxPool2DLayer(net, pool_size=2) print "\tFINAL POOL OUT SHAPE:", l.get_output_shape(net) #dense layers net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.DropoutLayer(net, DROPOUT) net = l.batch_norm(l.DenseLayer(net, 512, W=init.HeNormal(gain=INIT_GAIN), nonlinearity=NONLINEARITY)) net = l.DropoutLayer(net, DROPOUT) #Classification Layer if MULTI_LABEL: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.sigmoid, W=init.HeNormal(gain=1)) else: net = l.DenseLayer(net, NUM_CLASSES, nonlinearity=nonlinearities.softmax, W=init.HeNormal(gain=1)) print "...DONE!" #model stats print "MODEL HAS", (sum(hasattr(layer, 'W') for layer in l.get_all_layers(net))), "WEIGHTED LAYERS" print "MODEL HAS", l.count_params(net), "PARAMS" return net