def build_st_spline_network(input_shape): W = b = lasagne.init.Constant(0.0) num_points = 4 num_filters = 64 filter_size = (3, 3) pool_size = (2, 2) l_in = InputLayer(shape=(None, input_shape[1], input_shape[2], input_shape[3])) l_conv1 = Conv2DLayer(l_in, num_filters=num_filters, filter_size=filter_size) l_pool1 = MaxPool2DLayer(l_conv1, pool_size=pool_size) l_conv2 = Conv2DLayer(l_pool1, num_filters=num_filters, filter_size=filter_size) l_pool2 = MaxPool2DLayer(l_conv2, pool_size=pool_size) l_dense1 = DenseLayer(l_pool2, num_units=128) l_dense2 = DenseLayer(l_dense1, num_units=num_points * 2, W=W, b=b, nonlinearity=None) l_st = TPSTransformerLayer(l_in, l_dense2, control_points=num_points) l_output = ReshapeLayer(l_st, shape=([0], -1)) return l_output
def build_discriminator(input_var=None, convs=0): from lasagne.layers import (InputLayer, DenseLayer, batch_norm) from lasagne.layers.dnn import Conv2DDNNLayer as Conv2DLayer # override from lasagne.nonlinearities import LeakyRectify, sigmoid lrelu = LeakyRectify(0.2) if convs == 0: # input: (None, 1, 64, 64) layer = InputLayer(shape=(None, 1, 64, 64), input_var=input_var) # two convolutions layer = batch_norm( Conv2DLayer(layer, 64, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = batch_norm( Conv2DLayer(layer, 128, 5, stride=2, pad=2, nonlinearity=lrelu)) else: # input: (None, 1, 128, 128) layer = InputLayer(shape=(None, 1, 128, 128), input_var=input_var) # two convolutions layer = batch_norm( Conv2DLayer(layer, 64, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = batch_norm( Conv2DLayer(layer, 128, 5, stride=2, pad=2, nonlinearity=lrelu)) # fully-connected layer layer = batch_norm(DenseLayer(layer, 1024, nonlinearity=lrelu)) # output layer layer = DenseLayer(layer, 1, nonlinearity=sigmoid) print("Discriminator output:", layer.output_shape) return layer
def build_discriminator(input_var=None, dim_h=128, **kwargs): layer = InputLayer(shape=(None, 3, 32, 32), input_var=input_var) layer = Conv2DLayer(layer, dim_h, 5, stride=2, pad=2, nonlinearity=lrelu) layer = batch_norm( Conv2DLayer(layer, dim_h * 2, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = batch_norm( Conv2DLayer(layer, dim_h * 4, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = DenseLayer(layer, 1, nonlinearity=None) logger.debug('Discriminator output: {}'.format(layer.output_shape)) return layer
def build_discriminator(input_var=None): layer = InputLayer(shape=(None, 1, 28, 28), input_var=input_var) layer = batch_norm( Conv2DLayer(layer, 64, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = batch_norm( Conv2DLayer(layer, 128, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = batch_norm(DenseLayer(layer, 1024, nonlinearity=lrelu)) layer = DenseLayer(layer, 1, nonlinearity=None) logger.debug('Discriminator output: {}'.format(layer.output_shape)) return layer
def build_discriminator(input_var=None, dim_h=64): layer = InputLayer(shape=(None, 1, DIM_X, DIM_Y), input_var=input_var) layer = Conv2DLayer(layer, dim_h, 5, stride=2, pad=2, nonlinearity=lrelu) layer = Conv2DLayer(layer, dim_h * 2, 5, stride=2, pad=2, nonlinearity=lrelu) layer = DenseLayer(layer, 1024, nonlinearity=lrelu) layer = DenseLayer(layer, 1, nonlinearity=None) logger.debug('Discriminator output: {}'.format(layer.output_shape)) return layer
def build_st_network(b_size, input_shape, withdisc=True): # General Params num_filters = 64 filter_size = (3, 3) pool_size = (2, 2) # SP Param b = np.zeros((2, 3), dtype=theano.config.floatX) b[0, 0] = 1 b[1, 1] = 1 b = b.flatten() # identity transform # Localization Network l_in = InputLayer(shape=(None, input_shape[1], input_shape[2], input_shape[3])) l_conv1 = Conv2DLayer(l_in, num_filters=num_filters, filter_size=filter_size) l_pool1 = MaxPool2DLayer(l_conv1, pool_size=pool_size) l_conv2 = Conv2DLayer(l_pool1, num_filters=num_filters, filter_size=filter_size) l_pool2 = MaxPool2DLayer(l_conv2, pool_size=pool_size) l_loc = DenseLayer(l_pool2, num_units=64, W=lasagne.init.HeUniform('relu')) l_param_reg = DenseLayer(l_loc, num_units=6, b=b, nonlinearity=lasagne.nonlinearities.linear, W=lasagne.init.Constant(0.0), name='param_regressor') if withdisc: l_dis = DiscreteLayer(l_param_reg, start=Constant(-3.), stop=Constant(3.), linrange=Constant(50.)) else: l_dis = l_param_reg # Transformer Network l_trans = TransformerLayer(l_in, l_dis, downsample_factor=1.0) final = ReshapeLayer(l_trans, shape=([0], -1)) return final
def _build_middle(self, l_in, num_conv_layers=1, num_dense_layers=1, **kwargs): assert len(l_in.shape) == 4, 'InputLayer shape must be (batch_size, channels, width, height) -- ' \ 'reshape data or use RGB format?' l_bottom = l_in for i in xrange(num_conv_layers): conv_kwargs = self._extract_layer_kwargs('c', i, kwargs) if 'border_mode' not in conv_kwargs: conv_kwargs['border_mode'] = 'same' has_max_pool = conv_kwargs.pop('mp', False) l_bottom = Conv2DLayer(l_bottom, W=HeUniform(gain='relu'), **conv_kwargs) if has_max_pool: max_pool_kwargs = self._extract_layer_kwargs('m', i, kwargs) if 'pool_size' not in max_pool_kwargs: max_pool_kwargs['pool_size'] = (2, 2) l_bottom = MaxPool2DLayer(l_bottom, **max_pool_kwargs) for i in xrange(num_dense_layers): dense_kwargs = self._extract_layer_kwargs('d', i, kwargs) dropout = dense_kwargs.pop('dropout', 0.5) l_bottom = DenseLayer(l_bottom, W=HeUniform(gain='relu'), **dense_kwargs) if dropout: l_bottom = DropoutLayer(l_bottom, p=dropout) return l_bottom
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
def flow(input_layer, filter_size=3, pad=1, **kwargs): return Conv2DLayer(input_layer, num_filters=2, filter_size=filter_size, stride=1, nonlinearity=linear, pad=pad, flip_filters=False, **kwargs)
def define_patch_net(num_layers=4): net = {} print("Discriminator layer shapes:") net['input'] = ll.InputLayer(shape=(None, 3, IMAGE_SHAPE[0], IMAGE_SHAPE[1])) leaky_relu = lasagne.nonlinearities.LeakyRectify(0.2) # net['stand'] = ll.standardize(net['input'], offset=np.array([0, 0, 0], dtype='float32'), # scale=np.array([128.0, 128.0, 128.0], dtype='float32')) prev_layer_name = 'input' for i_layer in range(num_layers): layer_name = 'conv_%i' % (i_layer + 1) if i_layer != 0: net[layer_name] = batch_norm( Conv2DLayer(net[prev_layer_name], num_filters=min(512, 64 * (2**i_layer)), filter_size=(4, 4), stride=(2, 2), nonlinearity=leaky_relu)) else: net[layer_name] = batch_norm( Conv2DLayer(net[prev_layer_name], num_filters=64 * (2**i_layer), filter_size=(4, 4), stride=(2, 2), nonlinearity=leaky_relu)) print(lasagne.layers.get_output_shape(net[layer_name])) prev_layer_name = layer_name net['out'] = batch_norm( Conv2DLayer(net[prev_layer_name], filter_size=(1, 1), num_filters=1, nonlinearity=lasagne.nonlinearities.sigmoid)) print(lasagne.layers.get_output_shape(net['out'])) # net['out'] = lasagne.layers.ReshapeLayer(net['patch'], shape=(batch_size * 2, -1)) # # print(lasagne.layers.get_output_shape(net['out'])) return net
def build_discriminator(input_var=None): lrelu = LeakyRectify(0.2) layer = InputLayer(shape=(None, 8, 32, 32), input_var=input_var) # two convolutions layer = Conv2DLayer(layer, 512, 5, stride=2, pad=2, nonlinearity=lrelu) ''' layer = batch_norm(Conv2DLayer(layer, 128 * 2, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = batch_norm(Conv2DLayer(layer, 128 * 4, 5, stride=2, pad=2, nonlinearity=lrelu)) layer = batch_norm(Conv2DLayer(layer, 128 * 8, 5, stride=2, pad=2, nonlinearity=lrelu)) ''' layer = Conv2DLayer(layer, 512 * 2, 5, stride=2, pad=2, nonlinearity=lrelu) layer = Conv2DLayer(layer, 512 * 4, 5, stride=2, pad=2, nonlinearity=lrelu) #layer = Conv2DLayer(layer, 128 * 8, 5, stride=2, pad=2, nonlinearity=lrelu) layer = DenseLayer(layer, 1, nonlinearity=None) print("Discriminator output:", layer.output_shape) return layer
def build_cnn(input_var, input_shape): cnn = {} cnn["in"] = InputLayer(shape=(None, 3, input_shape[0], input_shape[1]), input_var=input_var) cnn["conv1"] = Conv2DLayer(cnn["in"], num_filters=64, stride=2, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv2"] = Conv2DLayer(cnn["conv1"], num_filters=64, stride=2, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool2"] = Pool2DLayer(cnn["conv2"], pool_size=(2, 2)) cnn["conv3"] = Conv2DLayer(cnn["pool2"], num_filters=128, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv4"] = Conv2DLayer(cnn["conv3"], num_filters=128, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool4"] = Pool2DLayer(cnn["conv4"], pool_size=(2, 2)) cnn["conv5"] = Conv2DLayer(cnn["pool4"], num_filters=256, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv6"] = Conv2DLayer(cnn["conv5"], num_filters=256, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool6"] = Pool2DLayer(cnn["conv6"], pool_size=(2, 2)) cnn["fc7"] = DenseLayer(cnn["pool6"], 4096, nonlinearity=lasagne.nonlinearities.rectify) cnn["fc7_drop"] = lasagne.layers.DropoutLayer(cnn["fc7"], p=0.5) cnn["fc8"] = DenseLayer(cnn["fc7_drop"], 4096, nonlinearity=lasagne.nonlinearities.rectify) cnn["fc8_drop"] = lasagne.layers.DropoutLayer(cnn["fc8"], p=0.5) cnn["out"] = DenseLayer(cnn["fc8_drop"], n_classes, nonlinearity=lasagne.nonlinearities.softmax) cnn["fc_mid"] = DenseLayer(cnn["pool4"], 4096, nonlinearity=lasagne.nonlinearities.rectify) cnn["out_mid"] = DenseLayer(cnn["fc_mid"], n_classes, nonlinearity=lasagne.nonlinearities.softmax) return cnn
def model_train(X_train, y_train, learning_rate=1e-4, epochs=10): l = 1000 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=64, filter_size=(4, 7)) layer4 = Conv2DLayer(layer3, num_filters=64, filter_size=(1, 7)) layer5 = Conv2DLayer(layer4, num_filters=64, filter_size=(1, 7)) layer6 = MaxPool2DLayer(layer5, pool_size=(1, 6)) layer7 = Conv2DLayer(layer6, num_filters=64, filter_size=(1, 7)) layer8 = Conv2DLayer(layer7, num_filters=64, filter_size=(1, 7)) layer9 = Conv2DLayer(layer8, num_filters=64, filter_size=(1, 7)) layer10 = MaxPool2DLayer(layer9, pool_size=(1, 6)) layer11 = Conv2DLayer(layer10, num_filters=64, filter_size=(1, 7)) layer12 = Conv2DLayer(layer11, num_filters=64, filter_size=(1, 7)) layer13 = Conv2DLayer(layer12, num_filters=64, filter_size=(1, 7)) layer14 = MaxPool2DLayer(layer13, pool_size=(1, 6)) layer14_d = DenseLayer(layer14, num_units=64) layer3_2 = DenseLayer(layer2_f, num_units=64) layer15 = ConcatLayer([layer14_d, layer3_2]) #layer15 = ConcatLayer([layer10_d,]) layer16 = DropoutLayer(layer15) layer17 = DenseLayer(layer16, num_units=32) network = DenseLayer(layer17, num_units=2, nonlinearity=None) lr = theano.shared(np.float32(learning_rate)) net = NeuralNet( network, max_epochs=epochs, update=adam, update_learning_rate=lr, regression=True, train_split=TrainSplit(eval_size=0.1), objective_loss_function=squared_error, #on_epoch_finished=[AdjustVariable(lr, target=1e-8, half_life=20)], verbose=4) net.fit(X_train, y_train) return net
def build_cnnae_network(input_shape): conv_filters = 16 filter_size = 3 pool_size = 2 encode_size = input_shape[2] * 2 l_in = InputLayer(shape=(None, input_shape[1], input_shape[2], input_shape[3])) l_conv1 = Conv2DLayer(l_in, num_filters=conv_filters, filter_size=(filter_size, filter_size), nonlinearity=None) l_pool1 = MaxPool2DLayer(l_conv1, pool_size=(pool_size, pool_size)) l_dropout1 = DropoutLayer(l_pool1, p=0.5) l_reshape1 = ReshapeLayer(l_dropout1, shape=([0], -1)) l_encode = DenseLayer(l_reshape1, name='encode', num_units=encode_size) l_decode = DenseLayer(l_encode, W=l_encode.W.T, num_units=l_reshape1.output_shape[1]) l_reshape2 = ReshapeLayer( l_decode, shape=([0], conv_filters, int(np.sqrt(l_reshape1.output_shape[1] / conv_filters)), int(np.sqrt(l_reshape1.output_shape[1] / conv_filters)))) l_unpool1 = Upscale2DLayer(l_reshape2, scale_factor=pool_size) l_de = TransposedConv2DLayer(l_unpool1, num_filters=l_conv1.input_shape[1], W=l_conv1.W, filter_size=l_conv1.filter_size, stride=l_conv1.stride, crop=l_conv1.pad, flip_filters=not l_conv1.flip_filters) l_output = ReshapeLayer(l_de, shape=([0], -1)) return l_output
def build_model(num_classes, pretrained_w_path="", input_var=None, drop_p=0.5): net = {} net['data'] = InputLayer(shape=(None, 3, 227, 227), input_var=input_var) # conv1 net['conv1'] = Conv2DLayer(net['data'], num_filters=96, filter_size=(11, 11), stride=4, nonlinearity=lasagne.nonlinearities.rectify) # pool1 net['pool1'] = MaxPool2DLayer(net['conv1'], pool_size=(3, 3), stride=2) # norm1 net['norm1'] = LocalResponseNormalization2DLayer(net['pool1'], n=5, alpha=0.0001 / 5.0, beta=0.75, k=1) # conv2 # The caffe reference model uses a parameter called group. # This parameter splits input to the convolutional layer. # The first half of the filters operate on the first half # of the input from the previous layer. Similarly, the # second half operate on the second half of the input. # # Lasagne does not have this group parameter, but we can # do it ourselves. # # see https://github.com/BVLC/caffe/issues/778 # also see https://code.google.com/p/cuda-convnet/wiki/LayerParams # before conv2 split the data # norm1 size: 23 x 23 x 96 net['conv2_data1'] = SliceLayer(net['norm1'], indices=slice(0, 48), axis=1) net['conv2_data2'] = SliceLayer(net['norm1'], indices=slice(48, 96), axis=1) # now do the convolutions net['conv2_part1'] = Conv2DLayer(net['conv2_data1'], num_filters=128, filter_size=(5, 5), pad=2) net['conv2_part2'] = Conv2DLayer(net['conv2_data2'], num_filters=128, filter_size=(5, 5), pad=2) # now combine net['conv2'] = concat((net['conv2_part1'], net['conv2_part2']), axis=1) # pool2 net['pool2'] = MaxPool2DLayer(net['conv2'], pool_size=(3, 3), stride=2) # norm2 net['norm2'] = LocalResponseNormalization2DLayer(net['pool2'], n=5, alpha=0.0001 / 5.0, beta=0.75, k=1) # conv3 # no group net['conv3'] = Conv2DLayer(net['norm2'], num_filters=384, filter_size=(3, 3), pad=1) # conv4 # group = 2 net['conv4_data1'] = SliceLayer(net['conv3'], indices=slice(0, 192), axis=1) net['conv4_data2'] = SliceLayer(net['conv3'], indices=slice(192, 384), axis=1) net['conv4_part1'] = Conv2DLayer(net['conv4_data1'], num_filters=192, filter_size=(3, 3), pad=1) net['conv4_part2'] = Conv2DLayer(net['conv4_data2'], num_filters=192, filter_size=(3, 3), pad=1) net['conv4'] = concat((net['conv4_part1'], net['conv4_part2']), axis=1) # conv5 # group 2 net['conv5_data1'] = SliceLayer(net['conv4'], indices=slice(0, 192), axis=1) net['conv5_data2'] = SliceLayer(net['conv4'], indices=slice(192, 384), axis=1) net['conv5_part1'] = Conv2DLayer(net['conv5_data1'], num_filters=128, filter_size=(3, 3), pad=1) net['conv5_part2'] = Conv2DLayer(net['conv5_data2'], num_filters=128, filter_size=(3, 3), pad=1) net['conv5'] = concat((net['conv5_part1'], net['conv5_part2']), axis=1) # pool 5 net['pool5'] = MaxPool2DLayer(net['conv5'], pool_size=(3, 3), stride=2) # fc6 net['fc6'] = DenseLayer(net['pool5'], num_units=4096, nonlinearity=lasagne.nonlinearities.rectify) # fc7 net['fc7'] = DenseLayer(DropoutLayer(net['fc6'], p=drop_p), num_units=4096, nonlinearity=lasagne.nonlinearities.rectify) # fc8 - changes: (i) num_classes, (ii) sigmoid activation net['fc8'] = DenseLayer(DropoutLayer(net['fc7'], p=drop_p), num_units=num_classes, nonlinearity=lasagne.nonlinearities.sigmoid) return net['fc8']
def build_stereo_cnn(input_var=None, in_shape_1=100, in_shape_2=150): conv_num_filters1 = 16 conv_num_filters2 = 32 conv_num_filters3 = 64 conv_num_filters4 = 128 filter_size1 = 7 filter_size2 = 5 filter_size3 = 3 filter_size4 = 3 pool_size = 2 scale_factor = 2 pad_in = 'valid' pad_out = 'full' # Input layer, as usual: network = InputLayer(shape=(None, 2, in_shape_1, in_shape_2), input_var=input_var, name="input_layer") network = batch_norm( Conv2DLayer(network, num_filters=conv_num_filters1, filter_size=(filter_size1, filter_size1), pad=pad_in, nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform(), name="conv1")) network = MaxPool2DLayer(network, pool_size=(pool_size, pool_size), name="pool1") network = batch_norm( Conv2DLayer(network, num_filters=conv_num_filters2, filter_size=(filter_size2, filter_size2), pad=pad_in, nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform(), name="conv2")) network = MaxPool2DLayer(network, pool_size=(pool_size, pool_size), name="pool2") network = batch_norm( Conv2DLayer(network, num_filters=conv_num_filters3, filter_size=(filter_size3, filter_size3), pad=pad_in, nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform(), name="conv3")) network = MaxPool2DLayer(network, pool_size=(pool_size, pool_size), name="pool3") network = batch_norm( Conv2DLayer(network, num_filters=conv_num_filters4, filter_size=(filter_size4, filter_size4), pad=pad_in, nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform(), name="conv4")) network = batch_norm( Conv2DLayer(network, num_filters=32, filter_size=(filter_size4, filter_size4), pad=pad_out, nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform(), name="deconv1")) network = Upscale2DLayer(network, scale_factor=(pool_size, pool_size), name="upscale1") network = batch_norm( Conv2DLayer(network, num_filters=16, filter_size=(filter_size3, filter_size3), pad=pad_out, nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform(), name="deconv2")) network = Upscale2DLayer(network, scale_factor=(pool_size, pool_size), name="upscale2") network = batch_norm( Conv2DLayer(network, num_filters=8, filter_size=(filter_size2, filter_size2), pad=pad_out, nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform(), name="deconv3")) network = Upscale2DLayer(network, scale_factor=(pool_size, pool_size), name="upscale3") network = batch_norm( Conv2DLayer(network, num_filters=1, filter_size=(filter_size1, filter_size1), pad=pad_out, nonlinearity=lasagne.nonlinearities.sigmoid, W=lasagne.init.GlorotUniform(), name="deconv4")) return network
def build_model(batch_size=BATCH_SIZE): """ Compile net architecture :param batch_size: batch size used for training the model :return: l_out: out-layer of network l_in: in-layer of network """ # --- input layers --- l_in = lasagne.layers.InputLayer(shape=(batch_size, INPUT_SHAPE[0], INPUT_SHAPE[1], INPUT_SHAPE[2]), name='Input') # --- conv layers --- net = Conv2DLayer(l_in, num_filters=64, filter_size=3, pad=1, W=init_conv(), nonlinearity=lasagne.nonlinearities.rectify, name='Conv') net = batch_norm(net) net = Conv2DLayer(net, num_filters=64, filter_size=3, pad=1, W=init_conv(), nonlinearity=lasagne.nonlinearities.rectify, name='Conv') net = batch_norm(net) net = lasagne.layers.MaxPool2DLayer(net, pool_size=2, name='Pool') net = lasagne.layers.DropoutLayer(net, p=0.25, name='Dropout') net = Conv2DLayer(net, num_filters=96, filter_size=3, pad=1, W=init_conv(), nonlinearity=lasagne.nonlinearities.rectify, name='Conv') net = batch_norm(net) net = Conv2DLayer(net, num_filters=96, filter_size=3, pad=0, W=init_conv(), nonlinearity=lasagne.nonlinearities.rectify, name='Conv') net = batch_norm(net) net = lasagne.layers.MaxPool2DLayer(net, pool_size=2, name='Pool') net = lasagne.layers.DropoutLayer(net, p=0.25, name='Dropout') net = Conv2DLayer(net, num_filters=256, filter_size=3, pad=0, W=init_conv(), nonlinearity=lasagne.nonlinearities.rectify, name='Conv') net = batch_norm(net) net = lasagne.layers.DropoutLayer(net, p=0.5, name='Dropout') net = Conv2DLayer(net, num_filters=256, filter_size=1, pad=0, W=init_conv(), nonlinearity=lasagne.nonlinearities.rectify, name='Conv') net = batch_norm(net) net = lasagne.layers.DropoutLayer(net, p=0.5, name='Dropout') # --- classification layers --- net = Conv2DLayer(net, num_filters=10, filter_size=1, W=init_conv(), nonlinearity=lasagne.nonlinearities.rectify, name='Conv') net = batch_norm(net) net = lasagne.layers.Pool2DLayer(net, pool_size=5, ignore_border=False, mode='average_exc_pad', name='GlobalAveragePool') l_out = lasagne.layers.FlattenLayer(net, name='Flatten') return l_out, l_in
def build_model(im1, im2, batchsize): net = {} # Input net['im1'] = InputLayer(shape=(batchsize, 1, 128, 128), input_var=im1) net['im2'] = InputLayer(shape=(batchsize, 1, 128, 128), input_var=im2) # FlowNet-S : Contraction part net['image'] = ConcatLayer([net['im1'], net['im2']]) net['conv1'] = Conv2DLayer(net['image'], num_filters=128, pad='same', filter_size=(7, 7), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['conv2'] = Conv2DLayer(net['conv1'], num_filters=128, pad='same', filter_size=(5, 5), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['conv3'] = Conv2DLayer(net['conv2'], num_filters=256, pad=2, filter_size=(5, 5), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['conv3_1'] = Conv2DLayer(net['conv3'], num_filters=256, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['conv4'] = Conv2DLayer(net['conv3_1'], num_filters=512, pad=1, filter_size=(3, 3), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['conv4_1'] = Conv2DLayer(net['conv4'], num_filters=512, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['conv5'] = Conv2DLayer(net['conv4_1'], num_filters=1024, pad=1, filter_size=(3, 3), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['conv5_1'] = Conv2DLayer(net['conv5'], num_filters=1024, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) # pd1 net['Convolution1'] = Conv2DLayer(net['conv5_1'], num_filters=2, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['deconv5'] = Deconv2DLayer(net['conv5_1'], num_filters=512, crop=1, filter_size=(4, 4), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['upsample_flow5to4'] = Deconv2DLayer(net['Convolution1'], num_filters=2, crop=1, filter_size=(4, 4), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['Concat2'] = ConcatLayer( [net['conv4_1'], net['deconv5'], net['upsample_flow5to4']]) # pd2 net['Convolution2'] = Conv2DLayer(net['Concat2'], num_filters=2, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['deconv4'] = Deconv2DLayer(net['Concat2'], num_filters=256, crop=1, filter_size=(4, 4), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['upsample_flow4to3'] = Deconv2DLayer(net['Convolution2'], num_filters=2, crop=1, filter_size=(4, 4), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['Concat3'] = ConcatLayer( [net['conv3_1'], net['deconv4'], net['upsample_flow4to3']]) # pd3 net['Convolution3'] = Conv2DLayer(net['Concat3'], num_filters=2, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['deconv3'] = Deconv2DLayer(net['Concat3'], num_filters=128, crop=1, filter_size=(4, 4), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['upsample_flow3to2'] = Deconv2DLayer(net['Convolution3'], num_filters=2, crop=1, filter_size=(4, 4), stride=2, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['Concat4'] = ConcatLayer( [net['conv2'], net['deconv3'], net['upsample_flow3to2']]) # pd4 net['coarseflow'] = Conv2DLayer(net['Concat4'], num_filters=2, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) # refinement with JSM net['warpimage'] = WarpingLayer(net['coarseflow'], net['im1']) net['jsm'] = JointSaliencyLayer(net['im2'], net['warpimage']) net['refine_input'] = ConcatLayer([net['jsm'], net['coarseflow']]) # simple form net['rf1'] = Conv2DLayer(net['refine_input'], num_filters=128, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['rf2'] = Conv2DLayer(net['rf1'], num_filters=64, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['rf3'] = Conv2DLayer(net['rf2'], num_filters=32, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) net['refineflow'] = Conv2DLayer(net['rf3'], num_filters=2, pad=1, filter_size=(3, 3), stride=1, nonlinearity=relu(leakiness=0.1), W=HeNormal(gain="relu")) return net
def build_model(batch_size=BATCH_SIZE): """ Compile net architecture """ nonlin = lasagne.nonlinearities.rectify # --- input layers --- l_in = lasagne.layers.InputLayer(shape=(None, INPUT_SHAPE[0], INPUT_SHAPE[1], INPUT_SHAPE[2]), name='Input') net = l_in nf = 64 # --- conv layers --- net = Conv2DLayer(net, num_filters=nf, filter_size=5, stride=2, pad=2, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = Conv2DLayer(net, num_filters=nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = MaxPool2DLayer(net, pool_size=2) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=2 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = Conv2DLayer(net, num_filters=2 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = MaxPool2DLayer(net, pool_size=2) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=4 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=4 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=6 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=6 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = MaxPool2DLayer(net, pool_size=2) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=8 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = Conv2DLayer(net, num_filters=8 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = MaxPool2DLayer(net, pool_size=(1, 2)) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=8 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = Conv2DLayer(net, num_filters=8 * nf, filter_size=3, stride=1, pad=1, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = MaxPool2DLayer(net, pool_size=(1, 2)) net = DropoutLayer(net, p=0.3) net = Conv2DLayer(net, num_filters=8 * nf, filter_size=3, pad=0, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = DropoutLayer(net, p=0.5) net = Conv2DLayer(net, num_filters=8 * nf, filter_size=1, pad=0, W=init_conv(gain="relu"), nonlinearity=nonlin) net = batch_norm(net, alpha=0.1) net = DropoutLayer(net, p=0.5) # --- feed forward part --- net = Conv2DLayer(net, num_filters=41, filter_size=1, W=init_conv(gain="relu"), nonlinearity=None) net = batch_norm(net, alpha=0.1) net = GlobalPoolLayer(net) net = FlattenLayer(net) net = NonlinearityLayer(net, nonlinearity=lasagne.nonlinearities.softmax) return net
def load_vgg(params_filename): cnn = {} X = theano.shared(np.zeros((1, 3, 1, 1), theano.config.floatX), name="X") cnn["in"] = InputLayer(shape=(None, 3, None, None), input_var=X) cnn["conv1_1"] = Conv2DLayer(cnn["in"], num_filters=64, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv1_2"] = Conv2DLayer(cnn["conv1_1"], num_filters=64, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool1"] = Pool2DLayer(cnn["conv1_2"], pool_size=(2, 2), stride=2, mode="average_inc_pad") cnn["conv2_1"] = Conv2DLayer(cnn["pool1"], num_filters=128, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv2_2"] = Conv2DLayer(cnn["conv2_1"], num_filters=128, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool2"] = Pool2DLayer(cnn["conv2_2"], pool_size=(2, 2), stride=2, mode="average_inc_pad") cnn["conv3_1"] = Conv2DLayer(cnn["pool2"], num_filters=256, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv3_2"] = Conv2DLayer(cnn["conv3_1"], num_filters=256, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv3_3"] = Conv2DLayer(cnn["conv3_2"], num_filters=256, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool3"] = Pool2DLayer(cnn["conv3_3"], pool_size=(2, 2), stride=2, mode="average_inc_pad") cnn["conv4_1"] = Conv2DLayer(cnn["pool3"], num_filters=512, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv4_2"] = Conv2DLayer(cnn["conv4_1"], num_filters=512, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv4_3"] = Conv2DLayer(cnn["conv4_2"], num_filters=512, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool4"] = Pool2DLayer(cnn["conv4_3"], pool_size=(2, 2), stride=2, mode="average_inc_pad") cnn["conv5_1"] = Conv2DLayer(cnn["pool4"], num_filters=512, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv5_2"] = Conv2DLayer(cnn["conv5_1"], num_filters=512, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["conv5_3"] = Conv2DLayer(cnn["conv5_2"], num_filters=512, pad=1, filter_size=(3, 3), nonlinearity=lasagne.nonlinearities.rectify) cnn["pool5"] = Pool2DLayer(cnn["conv5_3"], pool_size=(2, 2), stride=2, mode="average_inc_pad") # DenseLayers break when connectd to a net with variable input shapes on # the last two dimensions. Luckily we don't need them for the style # transfer. #cnn["fc6"] = DenseLayer(cnn["pool5"], 4096, nonlinearity=lasagne.nonlinearities.rectify) #cnn["fc6_drop"] = lasagne.layers.DropoutLayer(cnn["fc6"], p=0.5) #cnn["fc7"] = DenseLayer(cnn["fc6_drop"], 4096, nonlinearity=lasagne.nonlinearities.rectify) #cnn["fc7_drop"] = lasagne.layers.DropoutLayer(cnn["fc7"], p=0.5) #cnn["prob"] = DenseLayer(cnn["fc7_drop"], 1000, nonlinearity=lasagne.nonlinearities.softmax) params = pickle.load(open(params_filename, "rb"), encoding="bytes") for layer in cnn: if layer not in params: continue if params[layer][0].ndim == 4: cnn[layer].W.set_value(params[layer][0].astype( theano.config.floatX)) cnn[layer].b.set_value(params[layer][1].astype( theano.config.floatX)) else: assert (params[layer][0].ndim == 2) cnn[layer].W.set_value(params[layer][0].T.astype( theano.config.floatX)) cnn[layer].b.set_value(params[layer][1].astype( theano.config.floatX)) #cnn["prob"].W.set_value(params["fc8"][0].T.astype(theano.config.floatX)) #cnn["prob"].b.set_value(params["fc8"][1].astype(theano.config.floatX)) return cnn
def build_st_network_MNIST(input_shape, mins, maxs, ranges, withdisc=True): # General Params num_filters = 64 filter_size = (3, 3) pool_size = (2, 2) # SP Param b = np.zeros((2, 3), dtype=theano.config.floatX) b[0, 0] = 1 b[1, 1] = 1 b = b.flatten() # identity transform # Localization Network l_in = InputLayer(shape=(None, input_shape[1], input_shape[2], input_shape[3])) l_conv1 = Conv2DLayer(l_in, num_filters=num_filters, filter_size=filter_size) l_pool1 = MaxPool2DLayer(l_conv1, pool_size=pool_size) l_conv2 = Conv2DLayer(l_pool1, num_filters=num_filters, filter_size=filter_size) l_pool2 = MaxPool2DLayer(l_conv2, pool_size=pool_size) l_loc = DenseLayer(l_pool2, num_units=64, W=lasagne.init.HeUniform('relu')) l_param_reg = DenseLayer(l_loc, num_units=6, b=b, nonlinearity=lasagne.nonlinearities.linear, W=lasagne.init.Constant(0.0), name='param_regressor') if withdisc: l_dis = DiscreteLayer(l_param_reg, mins, maxs, ranges) else: l_dis = l_param_reg # Transformer Network l_trans = TransformerLayer(l_in, l_dis, downsample_factor=1.0) # Classification Network network = lasagne.layers.Conv2DLayer( l_trans, num_filters=32, filter_size=(5, 5), nonlinearity=lasagne.nonlinearities.rectify, W=lasagne.init.GlorotUniform()) # Expert note: Lasagne provides alternative convolutional layers that # override Theano's choice of which implementation to use; for details # please see http://lasagne.readthedocs.org/en/latest/user/tutorial.html. # Max-pooling layer of factor 2 in both dimensions: network = lasagne.layers.MaxPool2DLayer(network, pool_size=(2, 2)) # Another convolution with 32 5x5 kernels, and another 2x2 pooling: network = lasagne.layers.Conv2DLayer( network, num_filters=32, filter_size=(5, 5), nonlinearity=lasagne.nonlinearities.rectify) network = lasagne.layers.MaxPool2DLayer(network, pool_size=(2, 2)) # A fully-connected layer of 256 units with 50% dropout on its inputs: network = lasagne.layers.DenseLayer( lasagne.layers.dropout(network, p=.5), num_units=256, nonlinearity=lasagne.nonlinearities.rectify) # And, finally, the 10-unit output layer with 50% dropout on its inputs: network = lasagne.layers.DenseLayer( lasagne.layers.dropout(network, p=.5), num_units=10, nonlinearity=lasagne.nonlinearities.softmax) return network
def build_model(batch_size=BATCH_SIZE): """ Compile net architecture """ nonlin = lasagne.nonlinearities.rectify # --- input layers --- l_in = lasagne.layers.InputLayer(shape=(batch_size, INPUT_SHAPE[0], INPUT_SHAPE[1], INPUT_SHAPE[2]), name='Input') # --- conv layers --- net = Conv2DLayer(l_in, num_filters=64, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = Conv2DLayer(net, num_filters=64, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = lasagne.layers.MaxPool2DLayer(net, pool_size=2, name='Pool') net = lasagne.layers.DropoutLayer(net, p=0.25, name='Dropout') net = Conv2DLayer(net, num_filters=128, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = Conv2DLayer(net, num_filters=128, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = lasagne.layers.MaxPool2DLayer(net, pool_size=2, name='Pool') net = lasagne.layers.DropoutLayer(net, p=0.25, name='Dropout') net = Conv2DLayer(net, num_filters=256, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = Conv2DLayer(net, num_filters=256, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = Conv2DLayer(net, num_filters=256, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = Conv2DLayer(net, num_filters=256, filter_size=3, pad=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = lasagne.layers.MaxPool2DLayer(net, pool_size=2, name='Pool') net = lasagne.layers.DropoutLayer(net, p=0.25, name='Dropout') net = Conv2DLayer(net, num_filters=1024, filter_size=3, pad=0, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = lasagne.layers.DropoutLayer(net, p=0.5, name='Dropout') net = Conv2DLayer(net, num_filters=1024, filter_size=1, pad=0, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = lasagne.layers.DropoutLayer(net, p=0.5, name='Dropout') # --- feed forward part --- net = Conv2DLayer(net, num_filters=10, filter_size=1, W=init_conv(), nonlinearity=nonlin, name='Conv') net = batch_norm(net) net = lasagne.layers.Pool2DLayer(net, pool_size=2, ignore_border=False, mode='average_exc_pad', name='GlobalAveragePool') net = lasagne.layers.FlattenLayer(net, name='Flatten') return net, l_in
def build_mitosis_encoder(input_shape, encoding_size=32, withst=False): # Parameters filter_size = (3, 3) num_filters = 32 pool_size = (2, 2) # Localization Network l_input = InputLayer(shape=(None, input_shape[1], input_shape[2], input_shape[3])) l_conv1 = Conv2DLayer(l_input, num_filters=num_filters, filter_size=filter_size) l_conv2 = Conv2DLayer(l_conv1, num_filters=num_filters, filter_size=filter_size) l_pool1 = MaxPool2DLayer(l_conv2, pool_size=pool_size) l_pipe1_layer = l_pool1 # We need this # ST Network if withst: # ST Params b = np.zeros((2, 3), dtype=theano.config.floatX) b[0, 0] = 1 b[1, 1] = 1 b = b.flatten() # ST Layers st_encode1 = DenseLayer(l_pool1, num_units=50, W=lasagne.init.HeUniform('relu')) st_encode2 = DenseLayer(st_encode1, num_units=6, b=b, W=lasagne.init.Constant(0.0)) l_trans1 = TransformerLayer(l_input, st_encode2, downsample_factor=1.0) # Localization Network st_conv1 = Conv2DLayer(l_trans1, num_filters=num_filters, filter_size=filter_size) st_covn2 = Conv2DLayer(st_conv1, num_filters=num_filters, filter_size=filter_size) st_pool1 = MaxPool2DLayer(st_covn2, pool_size=pool_size) l_pipe1_layer = st_pool1 # Encoding Step l_reshape1 = ReshapeLayer(l_pipe1_layer, shape=([0], -1)) l_encode = DenseLayer(l_reshape1, num_units=encoding_size, W=lasagne.init.HeUniform('relu'), name='encoder') # Decoding Step l_decode = DenseLayer(l_encode, W=l_encode.W.T, num_units=l_reshape1.output_shape[1]) l_reshape2 = ReshapeLayer( l_decode, shape=([0], num_filters, int(np.sqrt(l_reshape1.output_shape[1] / num_filters)), int(np.sqrt(l_reshape1.output_shape[1] / num_filters)))) # Deconv Network l_unpool1 = Upscale2DLayer(l_reshape2, scale_factor=pool_size) l_deconv2 = TransposedConv2DLayer(l_unpool1, num_filters=l_conv2.input_shape[1], W=l_conv2.W, filter_size=l_conv2.filter_size, stride=l_conv2.stride, crop=l_conv2.pad, flip_filters=not l_conv2.flip_filters) l_deconv1 = TransposedConv2DLayer(l_deconv2, num_filters=l_conv1.input_shape[1], W=l_conv1.W, filter_size=l_conv1.filter_size, stride=l_conv1.stride, crop=l_conv1.pad, flip_filters=not l_conv1.flip_filters) return l_deconv1
def leaky_conv(input_layer, pad='same', **kwargs): return Conv2DLayer(input_layer, nonlinearity=leaky_rectify, pad=pad, flip_filters=False, **kwargs)