def build_model(input_shape, input_var, dense=True): net = {} net['input'] = InputLayer(input_shape, input_var=input_var) net['input'].num_filters = input_shape[1] net['conv1'] = ConvLayer(net['input'], num_filters=128, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv2'] = ConvLayer(net['conv1'], num_filters=256, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['pool1'] = ConvLayer(net['conv2'], num_filters=256, filter_size=3, stride=2, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv3'] = ConvLayer(net['pool1'], num_filters=512, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['pool2'] = ConvLayer(net['conv3'], num_filters=512, filter_size=3, stride=2, nonlinearity=nonlinearities.leaky_rectify, pad='same') if dense: net['dense'] = dropout(DenseLayer(net['pool2'], num_units=1024, nonlinearity=nonlinearities.leaky_rectify), 0.5) # Deconv net['dense/inverse'] = inverse_dense_layer(net['dense'], net['dense'], net['pool2'].output_shape) net['pool2/inverse'] = inverse_convolution_strided_layer(net['dense/inverse'], net['pool2']) else: net['pool2/inverse'] = inverse_convolution_strided_layer(net['pool2'], net['pool2']) net['conv3/inverse'] = inverse_convolution_layer(net['pool2/inverse'], net['conv3']) net['pool1/inverse'] = inverse_convolution_strided_layer(net['conv3/inverse'], net['pool1']) net['conv2/inverse'] = inverse_convolution_layer(net['pool1/inverse'], net['conv2']) net['conv1/inverse'] = inverse_convolution_layer(net['conv2/inverse'], net['conv1']) net['conv0/inverse'] = ConvLayer(net['conv1/inverse'], num_filters=input_shape[1], filter_size=1, nonlinearity=nonlinearities.linear, pad='same') net['prob'] = net['conv0/inverse'] for layer in get_all_layers(net['prob']): print layer print layer.output_shape return net
def build_model_small(input_shape, input_var): net = {} net['input'] = InputLayer(input_shape, input_var=input_var) net['input'].num_filters = input_shape[1] net['conv1'] = batch_norm( ConvLayer(net['input'], num_filters=256, filter_size=11, nonlinearity=nonlinearities.leaky_rectify, pad='same')) net['pool1'] = dropout(PoolLayer(net['conv1'], 2, mode='max'), 0.5) net['conv2'] = batch_norm( ConvLayer(net['pool1'], num_filters=256, filter_size=7, nonlinearity=nonlinearities.leaky_rectify, pad='same')) net['pool2'] = dropout(PoolLayer(net['conv2'], 2, mode='max'), 0.5) net['conv3'] = batch_norm( ConvLayer(net['pool2'], num_filters=396, filter_size=5, nonlinearity=nonlinearities.leaky_rectify, pad='same')) net['pool3'] = dropout(PoolLayer(net['conv3'], 2, mode='max'), 0.5) net['conv4'] = dropout( batch_norm( ConvLayer(net['pool3'], num_filters=512, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same')), 0.5) net['conv5'] = dropout( batch_norm( ConvLayer(net['conv4'], num_filters=1024, filter_size=1, nonlinearity=nonlinearities.leaky_rectify, pad='same')), 0.5) net['dense1'] = dropout( batch_norm( DenseLayer(net['conv5'], num_units=1024, nonlinearity=nonlinearities.leaky_rectify)), 0.5) net['dense2'] = DenseLayer(net['dense1'], num_units=11, nonlinearity=nonlinearities.softmax) net['prob'] = net['dense2'] for layer in get_all_layers(net['prob']): print layer print layer.output_shape return net
def build_model_dense(input_shape, input_var): net = {} net['input'] = InputLayer(input_shape, input_var=input_var) net['input'].num_filters = input_shape[1] net['conv1'] = ConvLayer(net['input'], num_filters=256, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv2'] = ConvLayer(net['conv1'], num_filters=256, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv2/reshape'] = ReshapeLayer(net['conv2'], (-1, net['conv2'].output_shape[1] * net['conv2'].output_shape[2])) net['dense'] = dropout(DenseLayer(net['conv2/reshape'], num_units=1024, nonlinearity=nonlinearities.leaky_rectify), 0.5) net['dense/inverse'] = inverse_dense_layer(net['dense'], net['dense'], net['conv2'].output_shape) net['conv2/inverse'] = inverse_convolution_layer(net['dense/inverse'], net['conv2']) net['conv1/inverse'] = inverse_convolution_layer(net['conv2/inverse'], net['conv1']) net['conv0/inverse'] = ConvLayer(net['conv1/inverse'], num_filters=input_shape[1], filter_size=1,nonlinearity=nonlinearities.linear, pad='same') net['prob'] = net['conv0/inverse'] for layer in get_all_layers(net['prob']): print layer print layer.output_shape return net
def build_model_small(input_shape, input_var): net = {} net['input'] = InputLayer(input_shape, input_var=input_var) net['input'].num_filters = input_shape[1] net['conv1'] = batch_norm(ConvLayer(net['input'], num_filters=256, filter_size=11, nonlinearity=nonlinearities.leaky_rectify, pad='same')) net['pool1'] = dropout(PoolLayer(net['conv1'], 2, mode='max'), 0.5) net['conv2'] = batch_norm(ConvLayer(net['pool1'], num_filters=256, filter_size=7, nonlinearity=nonlinearities.leaky_rectify, pad='same')) net['pool2'] = dropout(PoolLayer(net['conv2'], 2, mode='max'), 0.5) net['conv3'] = batch_norm(ConvLayer(net['pool2'], num_filters=396, filter_size=5, nonlinearity=nonlinearities.leaky_rectify, pad='same')) net['pool3'] = dropout(PoolLayer(net['conv3'], 2, mode='max'), 0.5) net['conv4'] = dropout(batch_norm(ConvLayer(net['pool3'], num_filters=512, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same')), 0.5) net['conv5'] = dropout(batch_norm(ConvLayer(net['conv4'], num_filters=1024, filter_size=1, nonlinearity=nonlinearities.leaky_rectify,pad='same')), 0.5) net['dense1'] = dropout(batch_norm(DenseLayer(net['conv5'], num_units=1024, nonlinearity=nonlinearities.leaky_rectify)), 0.5) net['dense2'] = DenseLayer(net['dense1'], num_units=11, nonlinearity=nonlinearities.softmax) net['prob'] = net['dense2'] for layer in get_all_layers(net['prob']): print layer print layer.output_shape return net
def build_model_small(input_shape, input_var): net = {} net['input'] = InputLayer(input_shape, input_var=input_var) net['input'].num_filters = input_shape[1] net['conv1'] = ConvLayer(net['input'], num_filters=256, filter_size=11, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv2'] = ConvLayer(net['conv1'], num_filters=256, filter_size=7, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv3'] = ConvLayer(net['conv2'], num_filters=396, filter_size=5, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv4'] = ConvLayer(net['conv3'], num_filters=512, filter_size=3, nonlinearity=nonlinearities.leaky_rectify, pad='same') net['conv5'] = ConvLayer(net['conv4'], num_filters=1024, filter_size=1, nonlinearity=nonlinearities.leaky_rectify,pad='same') net['conv5/inverse'] = inverse_convolution_layer(net['conv5'], net['conv5']) net['conv4/inverse'] = inverse_convolution_layer(net['conv5/inverse'], net['conv4']) net['conv3/inverse'] = inverse_convolution_layer(net['conv4/inverse'], net['conv3']) net['conv2/inverse'] = inverse_convolution_layer(net['conv3/inverse'], net['conv2']) net['conv1/inverse'] = inverse_convolution_layer(net['conv2/inverse'], net['conv1']) net['conv0/inverse'] = ConvLayer(net['conv1/inverse'], num_filters=input_shape[1], filter_size=1,nonlinearity=nonlinearities.linear, pad='same') net['prob'] = net['conv0/inverse'] for layer in get_all_layers(net['prob']): print layer print layer.output_shape return net