def spatial_3d_padding(x, padding=(1, 1, 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] + (2 * padding[0])), (input_shape[3] + (2 * padding[1])), (input_shape[4] + (2 * padding[2])))
  output = T.zeros(output_shape)
  indices = (slice(None), slice(None), slice(padding[0], (input_shape[2] + padding[0])), slice(padding[1], (input_shape[3] + padding[1])), slice(padding[2], (input_shape[4] + padding[2])))
 elif (dim_ordering == 'tf'):
  output_shape = (input_shape[0], (input_shape[1] + (2 * padding[0])), (input_shape[2] + (2 * padding[1])), (input_shape[3] + (2 * padding[2])), input_shape[4])
  output = T.zeros(output_shape)
  indices = (slice(None), slice(padding[0], (input_shape[1] + padding[0])), slice(padding[1], (input_shape[2] + padding[1])), slice(padding[2], (input_shape[3] + padding[2])), slice(None))
 else:
  raise ValueError('Invalid dim_ordering:', dim_ordering)
 return T.set_subtensor(output[indices], x)

def spatial_3d_padding ( x , padding = ( 1 , 1 , 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 ] + ( 2 * padding [ 0 ] ) ) , ( input_shape [ 3 ] + ( 2 * padding [ 1 ] ) ) , ( input_shape [ 4 ] + ( 2 * padding [ 2 ] ) ) ) output = T . zeros ( output_shape ) indices = ( slice ( None ) , slice ( None ) , slice ( padding [ 0 ] , ( input_shape [ 2 ] + padding [ 0 ] ) ) , slice ( padding [ 1 ] , ( input_shape [ 3 ] + padding [ 1 ] ) ) , slice ( padding [ 2 ] , ( input_shape [ 4 ] + padding [ 2 ] ) ) ) elif ( dim_ordering == 'tf' ) : output_shape = ( input_shape [ 0 ] , ( input_shape [ 1 ] + ( 2 * padding [ 0 ] ) ) , ( input_shape [ 2 ] + ( 2 * padding [ 1 ] ) ) , ( input_shape [ 3 ] + ( 2 * padding [ 2 ] ) ) , input_shape [ 4 ] ) output = T . zeros ( output_shape ) indices = ( slice ( None ) , slice ( padding [ 0 ] , ( input_shape [ 1 ] + padding [ 0 ] ) ) , slice ( padding [ 1 ] , ( input_shape [ 2 ] + padding [ 1 ] ) ) , slice ( padding [ 2 ] , ( input_shape [ 3 ] + padding [ 2 ] ) ) , slice ( None ) ) else : raise ValueError ( 'Invalid dim_ordering:' , dim_ordering ) return T . set_subtensor ( output [ indices ] , x )
pads 5d tensor with zeros for the depth .