def asymmetric_spatial_2d_padding(x, top_pad=1, bottom_pad=1, left_pad=1, right_pad=1, dim_ordering='default'):
 if (dim_ordering == 'default'):
  dim_ordering = image_dim_ordering()
 if (dim_ordering not in {'th', 'tf'}):
  raise ValueError(('Unknown dim_ordering ' + str(dim_ordering)))
 input_shape = x.shape
 if (dim_ordering == 'th'):
  output_shape = (input_shape[0], input_shape[1], ((input_shape[2] + top_pad) + bottom_pad), ((input_shape[3] + left_pad) + right_pad))
  output = T.zeros(output_shape)
  indices = (slice(None), slice(None), slice(top_pad, (input_shape[2] + top_pad)), slice(left_pad, (input_shape[3] + left_pad)))
 elif (dim_ordering == 'tf'):
  output_shape = (input_shape[0], ((input_shape[1] + top_pad) + bottom_pad), ((input_shape[2] + left_pad) + right_pad), input_shape[3])
  print output_shape
  output = T.zeros(output_shape)
  indices = (slice(None), slice(top_pad, (input_shape[1] + top_pad)), slice(left_pad, (input_shape[2] + left_pad)), slice(None))
 else:
  raise ValueError('Invalid dim_ordering:', dim_ordering)
 return T.set_subtensor(output[indices], x)

def asymmetric_spatial_2d_padding ( x , top_pad = 1 , bottom_pad = 1 , left_pad = 1 , right_pad = 1 , dim_ordering = 'default' ) : if ( dim_ordering == 'default' ) : dim_ordering = image_dim_ordering ( ) if ( dim_ordering not in { 'th' , 'tf' } ) : raise ValueError ( ( 'Unknown dim_ordering ' + str ( dim_ordering ) ) ) input_shape = x . shape if ( dim_ordering == 'th' ) : output_shape = ( input_shape [ 0 ] , input_shape [ 1 ] , ( ( input_shape [ 2 ] + top_pad ) + bottom_pad ) , ( ( input_shape [ 3 ] + left_pad ) + right_pad ) ) output = T . zeros ( output_shape ) indices = ( slice ( None ) , slice ( None ) , slice ( top_pad , ( input_shape [ 2 ] + top_pad ) ) , slice ( left_pad , ( input_shape [ 3 ] + left_pad ) ) ) elif ( dim_ordering == 'tf' ) : output_shape = ( input_shape [ 0 ] , ( ( input_shape [ 1 ] + top_pad ) + bottom_pad ) , ( ( input_shape [ 2 ] + left_pad ) + right_pad ) , input_shape [ 3 ] ) print output_shape output = T . zeros ( output_shape ) indices = ( slice ( None ) , slice ( top_pad , ( input_shape [ 1 ] + top_pad ) ) , slice ( left_pad , ( input_shape [ 2 ] + left_pad ) ) , slice ( None ) ) else : raise ValueError ( 'Invalid dim_ordering:' , dim_ordering ) return T . set_subtensor ( output [ indices ] , x )
pad the rows and columns of a 4d tensor with "top_pad" .