def convert_kernel(kernel, dim_ordering=None):
 if (dim_ordering is None):
  dim_ordering = K.image_dim_ordering()
 if (not (4 <= kernel.ndim <= 5)):
  raise ValueError('Invalid kernel shape:', kernel.shape)
 slices = [slice(None, None, (-1)) for _ in range(kernel.ndim)]
 no_flip = (slice(None, None), slice(None, None))
 if (dim_ordering == 'th'):
  slices[:2] = no_flip
 elif (dim_ordering == 'tf'):
  slices[(-2):] = no_flip
 else:
  raise ValueError('Invalid dim_ordering:', dim_ordering)
 return np.copy(kernel[slices])

def convert_kernel ( kernel , dim_ordering = None ) : if ( dim_ordering is None ) : dim_ordering = K . image_dim_ordering ( ) if ( not ( 4 <= kernel . ndim <= 5 ) ) : raise ValueError ( 'Invalid kernel shape:' , kernel . shape ) slices = [ slice ( None , None , ( - 1 ) ) for _ in range ( kernel . ndim ) ] no_flip = ( slice ( None , None ) , slice ( None , None ) ) if ( dim_ordering == 'th' ) : slices [ : 2 ] = no_flip elif ( dim_ordering == 'tf' ) : slices [ ( - 2 ) : ] = no_flip else : raise ValueError ( 'Invalid dim_ordering:' , dim_ordering ) return np . copy ( kernel [ slices ] )
converts a numpy kernel matrix from theano format to tensorflow format .