Package org.nd4j.imports.graphmapper.tf
Class TFGraphMapper
- java.lang.Object
-
- org.nd4j.imports.graphmapper.tf.TFGraphMapper
-
public class TFGraphMapper extends Object
-
-
Constructor Summary
Constructors Constructor Description TFGraphMapper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static DataTypeconvertType(DataType tfType)Convert from TF proto datatype to ND4J datatypestatic INDArraygetArrayFrom(NodeDef nodeDef, GraphDef graph)Deprecated.static TFGraphMappergetInstance()Deprecated.Use static methods -importGraph(File)etcstatic INDArraygetNDArrayFromTensor(NodeDef node)Convert the tensor to an NDArray (if possible and if array is available)static StringgetNodeName(String name)Deprecated.To be removedstatic NodeDefgetNodeWithNameFromGraph(GraphDef graph, String name)Deprecated.static SameDiffimportGraph(@NonNull File f)Import a frozen TensorFlow protobuf (.pb) file from the specified filestatic SameDiffimportGraph(@NonNull File f, Map<String,TFImportOverride> importOverride, TFOpImportFilter opFilter)Import a frozen TensorFlow protobuf (.pb) file from the specified file, with optional overridesstatic SameDiffimportGraph(@NonNull InputStream is)Import a frozen TensorFlow protobuf (.pb) file, via an input streamstatic SameDiffimportGraph(@NonNull InputStream is, Map<String,TFImportOverride> importOverride, TFOpImportFilter opFilter)Import a frozen TensorFlow protobuf (.pb) file via an input stream, with optional overridesstatic SameDiffimportGraph(@NonNull GraphDef tfGraph)Import a TensorFlow model from a GraphDefstatic SameDiffimportGraph(@NonNull GraphDef tfGraph, Map<String,TFImportOverride> importOverride, TFOpImportFilter opFilter)Import a TensorFlow model from a GraphDef, with optional import overridesstatic SameDiffimportGraphTxt(@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 overridesstatic voidinitFunctionFromProperties(String mappedTfName, DifferentialFunction on, Map<String,AttrValue> attributesForNode, NodeDef node, GraphDef graph)Deprecated.To be removedprotected static booleanisControlDep(String name)static booleanisPlaceHolder(NodeDef nodeDef)Determine if the node is a placeholderstatic booleanisVariableNode(NodeDef nodeDef)Determine if the node represents a variable node (based on op name)static INDArraymapTensorProto(TensorProto tfTensor)Convert a TensorProto to an INDArrayprotected static StringstripControl(String name)protected static StringstripVarSuffix(String varName)Remove the ":1" etc suffix for a variable name to get the op name
-
-
-
Method Detail
-
getInstance
@Deprecated public static TFGraphMapper getInstance()
Deprecated.Use static methods -importGraph(File)etc
-
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 importimportOverride- Optional import override for specific ops, keyed by op nameopFilter- 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 importimportOverride- Optional import override for specific ops, keyed by op nameopFilter- 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 importimportOverride- Optional import override for specific ops, keyed by op nameopFilter- 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 GraphDefimportOverride- Optional import override for specific ops, keyed by op nameopFilter- 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
-
getNodeWithNameFromGraph
@Deprecated public static NodeDef getNodeWithNameFromGraph(GraphDef graph, String name)
Deprecated.
-
getArrayFrom
@Deprecated public static INDArray getArrayFrom(NodeDef nodeDef, GraphDef graph)
Deprecated.
-
initFunctionFromProperties
@Deprecated public static void initFunctionFromProperties(String mappedTfName, DifferentialFunction on, Map<String,AttrValue> attributesForNode, NodeDef node, GraphDef graph)
Deprecated.To be removedInit a function's attributes- Parameters:
mappedTfName- the tensorflow name to pick (sometimes ops have multiple nameson- the function to mapattributesForNode- the attributes for the nodenode-graph-
-
getNodeName
@Deprecated public static String getNodeName(String name)
Deprecated.To be removedMap 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
-
-