<s> import numpy as np <EOL> import theano <EOL> import theano . tensor as T <EOL> import lasagne as nn <EOL> import data <EOL> import load <EOL> import nn_plankton <EOL> import dihedral <EOL> import dihedral_fast <EOL> import tmp_dnn <EOL> import tta <EOL> validation_split_path = "<STR_LIT>" <EOL> patch_size = ( <NUM_LIT> , <NUM_LIT> ) <EOL> augmentation_params = { <EOL> '<STR_LIT>' : ( <NUM_LIT:1> / <NUM_LIT> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( - <NUM_LIT:20> , <NUM_LIT:20> ) , <EOL> '<STR_LIT>' : ( - <NUM_LIT:10> , <NUM_LIT:10> ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> batch_size = <NUM_LIT> // <NUM_LIT:4> <EOL> chunk_size = <NUM_LIT> // <NUM_LIT:4> <EOL> num_chunks_train = <NUM_LIT> <EOL> momentum = <NUM_LIT> <EOL> learning_rate_schedule = { <EOL> <NUM_LIT:0> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> <NUM_LIT> : <NUM_LIT> , <EOL> } <EOL> validate_every = <NUM_LIT:20> <EOL> save_every = <NUM_LIT:20> <EOL> def estimate_scale ( img ) : <EOL> return np . maximum ( img . shape [ <NUM_LIT:0> ] , img . shape [ <NUM_LIT:1> ] ) / <NUM_LIT> <EOL> augmentation_transforms_test = tta . build_quasirandom_transforms ( <NUM_LIT> , ** { <EOL> '<STR_LIT>' : ( <NUM_LIT:1> / <NUM_LIT> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( - <NUM_LIT:10> , <NUM_LIT:10> ) , <EOL> '<STR_LIT>' : ( - <NUM_LIT:8> , <NUM_LIT:8> ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } ) <EOL> data_loader = load . ZmuvRescaledDataLoader ( estimate_scale = estimate_scale , num_chunks_train = num_chunks_train , <EOL> patch_size = patch_size , chunk_size = chunk_size , augmentation_params = augmentation_params , <EOL> augmentation_transforms_test = augmentation_transforms_test , validation_split_path = validation_split_path ) <EOL> Conv2DLayer = tmp_dnn . Conv2DDNNLayer <EOL> MaxPool2DLayer = tmp_dnn . MaxPool2DDNNLayer <EOL> def conv ( incoming , ** kwargs ) : <EOL> return Conv2DLayer ( incoming , border_mode = "<STR_LIT>" , <EOL> W = nn_plankton . Conv2DOrthogonal ( <NUM_LIT:1.0> ) , b = nn . init . Constant ( <NUM_LIT:0.1> ) , <EOL> nonlinearity = nn_plankton . leaky_relu , untie_biases = True , <EOL> ** kwargs ) <EOL> convroll = dihedral_fast . CyclicConvRollLayer <EOL> def pool ( incoming , ** kwargs ) : <EOL> return MaxPool2DLayer ( incoming , ds = ( <NUM_LIT:3> , <NUM_LIT:3> ) , strides = ( <NUM_LIT:2> , <NUM_LIT:2> ) , ** kwargs ) <EOL> def build_model ( ) : <EOL> l0 = nn . layers . InputLayer ( ( batch_size , <NUM_LIT:1> , patch_size [ <NUM_LIT:0> ] , patch_size [ <NUM_LIT:1> ] ) ) <EOL> l0c = dihedral . CyclicSliceLayer ( l0 ) <EOL> l1 = convroll ( conv ( l0c , num_filters = <NUM_LIT:16> , filter_size = ( <NUM_LIT:7> , <NUM_LIT:7> ) , strides = ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> l2 = convroll ( conv ( l1 , num_filters = <NUM_LIT:32> , filter_size = ( <NUM_LIT:7> , <NUM_LIT:7> ) , strides = ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> l3a = convroll ( conv ( l2 , num_filters = <NUM_LIT:32> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l3b = convroll ( conv ( l3a , num_filters = <NUM_LIT:32> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l3c = convroll ( conv ( l3b , num_filters = <NUM_LIT:32> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l3d = conv ( l3c , num_filters = <NUM_LIT:64> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> l3 = convroll ( pool ( l3d ) ) <EOL> l4a = convroll ( conv ( l3 , num_filters = <NUM_LIT:64> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l4b = convroll ( conv ( l4a , num_filters = <NUM_LIT:64> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l4c = convroll ( conv ( l4b , num_filters = <NUM_LIT:64> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l4d = conv ( l4c , num_filters = <NUM_LIT> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> l4 = convroll ( pool ( l4d ) ) <EOL> l5a = convroll ( conv ( l4 , num_filters = <NUM_LIT:64> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l5b = convroll ( conv ( l5a , num_filters = <NUM_LIT:64> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l5c = convroll ( conv ( l5b , num_filters = <NUM_LIT:64> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> l5d = conv ( l5c , num_filters = <NUM_LIT> , filter_size = ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> l5 = convroll ( pool ( l5d ) ) <EOL> l5f = nn . layers . flatten ( l5 ) <EOL> l6 = nn . layers . DenseLayer ( nn . layers . dropout ( l5f , p = <NUM_LIT:0.5> ) , num_units = <NUM_LIT> , W = nn_plankton . Orthogonal ( <NUM_LIT:1.0> ) , b = nn . init . Constant ( <NUM_LIT:0.1> ) , nonlinearity = nn_plankton . leaky_relu ) <EOL> l6r = dihedral_fast . CyclicRollLayer ( l6 ) <EOL> l7 = nn . layers . DenseLayer ( nn . layers . dropout ( l6r , p = <NUM_LIT:0.5> ) , num_units = <NUM_LIT> , W = nn_plankton . Orthogonal ( <NUM_LIT:1.0> ) , b = nn . init . Constant ( <NUM_LIT:0.1> ) , nonlinearity = nn_plankton . leaky_relu ) <EOL> l7m = dihedral . CyclicPoolLayer ( l7 , pool_function = nn_plankton . rms ) <EOL> l8 = nn . layers . DenseLayer ( nn . layers . dropout ( l7m , p = <NUM_LIT:0.5> ) , num_units = data . num_classes , nonlinearity = T . nnet . softmax , W = nn_plankton . Orthogonal ( <NUM_LIT:1.0> ) ) <EOL> return [ l0 ] , l8 <EOL> def build_objective ( l_ins , l_out ) : <EOL> lambda_reg = <NUM_LIT> <EOL> params = nn . layers . get_all_non_bias_params ( l_out ) <EOL> reg_term = sum ( T . sum ( p ** <NUM_LIT:2> ) for p in params ) <EOL> def loss ( y , t ) : <EOL> return nn_plankton . log_loss ( y , t ) + lambda_reg * reg_term <EOL> return nn . objectives . Objective ( l_out , loss_function = loss ) </s>
