Class TFGraphMapper


  • public class TFGraphMapper
    extends Object
    • Constructor Detail

      • TFGraphMapper

        public TFGraphMapper()
    • Method Detail

      • importGraph

        public static SameDiff importGraph​(@NonNull
                                           @NonNull File f)
        Import a frozen TensorFlow protobuf (.pb) file from the specified file
        Parameters:
        f - Frozen TensorFlow model pb file to import
        Returns:
        Imported graph
      • importGraph

        public static SameDiff importGraph​(@NonNull
                                           @NonNull File f,
                                           Map<String,​TFImportOverride> importOverride,
                                           TFOpImportFilter opFilter)
        Import a frozen TensorFlow protobuf (.pb) file from the specified file, with optional overrides
        Parameters:
        f - Frozen TensorFlow model pb file to import
        importOverride - Optional import override for specific ops, keyed by op name
        opFilter - Optional filter - ops to exclude/ignore
        Returns:
        Imported graph
      • importGraph

        public static SameDiff importGraph​(@NonNull
                                           @NonNull InputStream is)
        Import a frozen TensorFlow protobuf (.pb) file, via an input stream
        Parameters:
        is - Stream for a frozen TensorFlow model pb file to import
        Returns:
        Imported graph
      • importGraphTxt

        public static SameDiff importGraphTxt​(@NonNull
                                              @NonNull InputStream is,
                                              Map<String,​TFImportOverride> importOverride,
                                              TFOpImportFilter opFilter)
        Import a frozen TensorFlow protobuf file in text format (.pb.txt) file via an input stream, with optional overrides
        Parameters:
        is - Stream for a frozen TensorFlow model pb file to import
        importOverride - Optional import override for specific ops, keyed by op name
        opFilter - Optional filter - ops to exclude/ignore
        Returns:
        Imported graph
      • importGraph

        public static SameDiff importGraph​(@NonNull
                                           @NonNull InputStream is,
                                           Map<String,​TFImportOverride> importOverride,
                                           TFOpImportFilter opFilter)
        Import a frozen TensorFlow protobuf (.pb) file via an input stream, with optional overrides
        Parameters:
        is - Stream for a frozen TensorFlow model pb file to import
        importOverride - Optional import override for specific ops, keyed by op name
        opFilter - Optional filter - ops to exclude/ignore
        Returns:
        Imported graph
      • importGraph

        public static SameDiff importGraph​(@NonNull
                                           @NonNull GraphDef tfGraph)
        Import a TensorFlow model from a GraphDef
        Parameters:
        tfGraph - TensorFlow model GraphDef
        Returns:
        Imported model
      • importGraph

        public static SameDiff importGraph​(@NonNull
                                           @NonNull GraphDef tfGraph,
                                           Map<String,​TFImportOverride> importOverride,
                                           TFOpImportFilter opFilter)
        Import a TensorFlow model from a GraphDef, with optional import overrides
        Parameters:
        tfGraph - TensorFlow model GraphDef
        importOverride - Optional import override for specific ops, keyed by op name
        opFilter - Optional filter - ops to exclude/ignore
        Returns:
        Imported model
      • convertType

        public static DataType convertType​(DataType tfType)
        Convert from TF proto datatype to ND4J datatype
        Parameters:
        tfType - TF datatype
        Returns:
        ND4J datatype
      • isControlDep

        protected static boolean isControlDep​(String name)
        Returns:
        True if the specified name represents a control dependency (starts with "^")
      • stripControl

        protected static String stripControl​(String name)
        Returns:
        The specified name without the leading "^" character (if any) that appears for control dependencies
      • stripVarSuffix

        protected static String stripVarSuffix​(String varName)
        Remove the ":1" etc suffix for a variable name to get the op name
        Parameters:
        varName - Variable name
        Returns:
        Variable name without any number suffix
      • getNDArrayFromTensor

        public static INDArray getNDArrayFromTensor​(NodeDef node)
        Convert the tensor to an NDArray (if possible and if array is available)
        Parameters:
        node - Node to get NDArray from
        Returns:
        NDArray
      • mapTensorProto

        public static INDArray mapTensorProto​(TensorProto tfTensor)
        Convert a TensorProto to an INDArray
        Parameters:
        tfTensor - Tensor proto
        Returns:
        INDArray
      • initFunctionFromProperties

        @Deprecated
        public static void initFunctionFromProperties​(String mappedTfName,
                                                      DifferentialFunction on,
                                                      Map<String,​AttrValue> attributesForNode,
                                                      NodeDef node,
                                                      GraphDef graph)
        Deprecated.
        To be removed
        Init a function's attributes
        Parameters:
        mappedTfName - the tensorflow name to pick (sometimes ops have multiple names
        on - the function to map
        attributesForNode - the attributes for the node
        node -
        graph -
      • getNodeName

        @Deprecated
        public static String getNodeName​(String name)
        Deprecated.
        To be removed
        Map a tensorflow node name to the samediff equivalent for import
        Parameters:
        name - the name to change
        Returns:
        the input tensorflow name
      • isVariableNode

        public static boolean isVariableNode​(NodeDef nodeDef)
        Determine if the node represents a variable node (based on op name)
        Parameters:
        nodeDef - Node to check if a variable
        Returns:
        True if a variable node
      • isPlaceHolder

        public static boolean isPlaceHolder​(NodeDef nodeDef)
        Determine if the node is a placeholder
        Parameters:
        nodeDef - Node to check
        Returns:
        True if the node is a placeholder