@ Override public SameDiff importGraph ( GRAPH_TYPE tfGraph ) { SameDiff diff = SameDiff . create ( ) ; ImportState < GRAPH_TYPE , TENSOR_TYPE > importState = new ImportState <> ( ) ; importState . setSameDiff ( diff ) ; importState . setGraph ( tfGraph ) ; val variablesForGraph = variablesForGraph ( tfGraph ) ; importState . setVariables ( variablesForGraph ) ; //map the names of the nodes while accumulating the vertex ids //for each variable for ( Map . Entry < String , TENSOR_TYPE > entry : variablesForGraph . entrySet ( ) ) { if ( dataTypeForTensor ( entry . getValue ( ) ) == DataBuffer . Type . UNKNOWN ) { val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , null , new ZeroInitScheme ( ' ' ) ) ; //mark as place holder for validating resolution later. if ( isPlaceHolder ( entry . getValue ( ) ) ) { importState . getSameDiff ( ) . addAsPlaceHolder ( var . getVarName ( ) ) ; if ( var . getShape ( ) != null ) importState . getSameDiff ( ) . setOriginalPlaceHolderShape ( var . getVarName ( ) , var . getShape ( ) ) ; } continue ; } val arr = getNDArrayFromTensor ( entry . getKey ( ) , entry . getValue ( ) , tfGraph ) ; if ( arr != null ) { val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , arr ) ; //ensure the array is made available for later processing diff . associateArrayWithVariable ( arr , var ) ; } else if ( getShapeFromTensor ( entry . getValue ( ) ) == null ) { val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , null , new ZeroInitScheme ( ' ' ) ) ; //mark as place holder for validating resolution later. //note that this vertex id can still be a place holder //with a -1 shape. Just because a shape is "known" doesn't mean //that it isn't a place holder. if ( isPlaceHolder ( entry . getValue ( ) ) ) { val originalShape = getShapeFromTensor ( entry . getValue ( ) ) ; importState . getSameDiff ( ) . addAsPlaceHolder ( var . getVarName ( ) ) ; if ( var . getShape ( ) != null ) importState . getSameDiff ( ) . setOriginalPlaceHolderShape ( var . getVarName ( ) , originalShape ) ; } } else { val originalShape = getShapeFromTensor ( entry . getValue ( ) ) ; val var = importState . getSameDiff ( ) . var ( entry . getKey ( ) , originalShape ) ; //mark as place holder for validating resolution later. //note that this vertex id can still be a place holder //with a -1 shape. Just because a shape is "known" doesn't mean //that it isn't a place holder. if ( isPlaceHolder ( entry . getValue ( ) ) ) { importState . getSameDiff ( ) . addAsPlaceHolder ( var . getVarName ( ) ) ; importState . getSameDiff ( ) . setOriginalPlaceHolderShape ( var . getVarName ( ) , originalShape ) ; } } } //setup vertex ids for names //handle mapping vertex ids properly val tfNodesList = getNodeList ( tfGraph ) ; for ( NODE_TYPE tfNode : tfNodesList ) { if ( ! opsToIgnore ( ) . contains ( getOpType ( tfNode ) ) || isOpIgnoreException ( tfNode ) ) mapNodeType ( tfNode , importState ) ; } return diff ; }
This method converts given TF