public INDArray getConvParameterValues ( INDArray kerasParamValue ) throws InvalidKerasConfigurationException { INDArray paramValue ; switch ( this . getDimOrder ( ) ) { case TENSORFLOW : if ( kerasParamValue . rank ( ) == 5 ) // CNN 3D case paramValue = kerasParamValue . permute ( 4 , 3 , 0 , 1 , 2 ) ; else /* TensorFlow convolutional weights: # rows, # cols, # inputs, # outputs */ paramValue = kerasParamValue . permute ( 3 , 2 , 0 , 1 ) ; break ; case THEANO : /* Theano convolutional weights match DL4J: # outputs, # inputs, # rows, # cols * Theano's default behavior is to rotate filters by 180 degree before application. */ paramValue = kerasParamValue . dup ( ) ; for ( int i = 0 ; i < paramValue . tensorsAlongDimension ( 2 , 3 ) ; i ++ ) { //dup required since we only want data from the view not the whole array INDArray copyFilter = paramValue . tensorAlongDimension ( i , 2 , 3 ) . dup ( ) ; double [ ] flattenedFilter = copyFilter . ravel ( ) . data ( ) . asDouble ( ) ; ArrayUtils . reverse ( flattenedFilter ) ; INDArray newFilter = Nd4j . create ( flattenedFilter , copyFilter . shape ( ) ) ; //manipulating weights in place to save memory INDArray inPlaceFilter = paramValue . tensorAlongDimension ( i , 2 , 3 ) ; inPlaceFilter . muli ( 0 ) . addi ( newFilter ) ; } break ; default : throw new InvalidKerasConfigurationException ( "Unknown keras backend " + this . getDimOrder ( ) ) ; } return paramValue ; }
Return processed parameter values obtained from Keras convolutional layers .