<s> import numpy as np <EOL> import scipy . io <EOL> import deeppy as dp <EOL> def conv_layer ( weights , bias , border_mode ) : <EOL> return dp . Convolution ( <EOL> n_filters = weights . shape [ <NUM_LIT:0> ] , <EOL> filter_shape = weights . shape [ <NUM_LIT:2> : ] , <EOL> border_mode = border_mode , <EOL> weights = weights , <EOL> bias = bias , <EOL> ) <EOL> def pool_layer ( pool_method , border_mode ) : <EOL> return dp . Pool ( <EOL> win_shape = ( <NUM_LIT:3> , <NUM_LIT:3> ) , <EOL> strides = ( <NUM_LIT:2> , <NUM_LIT:2> ) , <EOL> method = pool_method , <EOL> border_mode = border_mode , <EOL> ) <EOL> def vgg_net ( path , pool_method = '<STR_LIT>' , border_mode = '<STR_LIT>' ) : <EOL> matconvnet = scipy . io . loadmat ( path ) <EOL> img_mean = matconvnet [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> vgg_layers = matconvnet [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> layers = [ ] <EOL> for layer in vgg_layers : <EOL> layer = layer [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> layer_type = layer [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> if layer_type == '<STR_LIT>' : <EOL> params = layer [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] <EOL> weights = params [ <NUM_LIT:0> ] <EOL> bias = params [ <NUM_LIT:1> ] <EOL> weights = np . transpose ( weights , ( <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:1> ) ) . astype ( dp . float_ ) <EOL> bias = np . reshape ( bias , ( <NUM_LIT:1> , bias . size , <NUM_LIT:1> , <NUM_LIT:1> ) ) . astype ( dp . float_ ) <EOL> layers . append ( conv_layer ( weights , bias , border_mode ) ) <EOL> elif layer_type == '<STR_LIT>' : <EOL> layers . append ( pool_layer ( pool_method , border_mode ) ) <EOL> elif layer_type == '<STR_LIT:relu>' : <EOL> layers . append ( dp . ReLU ( ) ) <EOL> elif layer_type == '<STR_LIT>' : <EOL> pass <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % layer_type ) <EOL> return layers , img_mean </s>
