Package ai.djl.mxnet.engine
Class Symbol
java.lang.Object
ai.djl.util.NativeResource<com.sun.jna.Pointer>
ai.djl.mxnet.engine.Symbol
- All Implemented Interfaces:
AutoCloseable
public class Symbol
extends ai.djl.util.NativeResource<com.sun.jna.Pointer>
Symbol is an internal helper for symbolic model graphs used by the SymbolBlock.- See Also:
-
SymbolBlock- MXNet Symbol
-
Field Summary
Fields inherited from class ai.djl.util.NativeResource
handle -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()copy()Copies the symbol.get(int index) Returns the output symbol by index.Returns the output symbol with the given name.String[]Returns the symbol names.String[]Returns the symbol argument names.String[]Returns the MXNet auxiliary states for the symbol.Returns the symbol internals.Returns the list of names for all internal outputs.String[]Returns the symbol outputs.inferShape(ai.djl.util.PairList<String, ai.djl.ndarray.types.Shape> pairs) Infers the shapes for all parameters inside a symbol from the given input shapes.static Symbolload(MxNDManager manager, String path) Loads a symbol from a path.static SymbolloadJson(MxNDManager manager, String json) Loads a symbol from a json string.optimizeFor(String backend, ai.djl.Device device) [Experimental] Add customized optimization on the Symbol.Converts Symbol to json string for saving purpose.toString()Methods inherited from class ai.djl.util.NativeResource
getHandle, getUid, isReleased, onClose
-
Method Details
-
load
Loads a symbol from a path.- Parameters:
manager- the manager to load the symbol topath- the path to the symbol file- Returns:
- the new symbol
-
loadJson
Loads a symbol from a json string.- Parameters:
manager- the manager to load the symbol tojson- the json string of the symbol.- Returns:
- the new symbol
-
getArgNames
Returns the symbol argument names.- Returns:
- the symbol argument names
-
getAuxNames
Returns the MXNet auxiliary states for the symbol.- Returns:
- the MXNet auxiliary states for the symbol
-
getAllNames
Returns the symbol names.- Returns:
- the symbol names
-
getOutputNames
Returns the symbol outputs.- Returns:
- the symbol outputs
-
copy
Copies the symbol.- Returns:
- a new copy of the symbol
-
get
Returns the output symbol by index.- Parameters:
index- the index of the output- Returns:
- the symbol output as a new symbol
-
get
Returns the output symbol with the given name.- Parameters:
name- the name of the symbol to return- Returns:
- the output symbol
- Throws:
IllegalArgumentException- Thrown if no output matches the name
-
getInternals
Returns the symbol internals.- Returns:
- the symbol internals symbol
-
getLayerNames
Returns the list of names for all internal outputs.- Returns:
- a list of names
-
inferShape
public Map<String,ai.djl.ndarray.types.Shape> inferShape(ai.djl.util.PairList<String, ai.djl.ndarray.types.Shape> pairs) Infers the shapes for all parameters inside a symbol from the given input shapes.- Parameters:
pairs- the given input name and shape- Returns:
- a map of arguments with names and shapes
-
optimizeFor
[Experimental] Add customized optimization on the Symbol.This method can be used with EIA or TensorRT for model acceleration
- Parameters:
backend- backend namedevice- the device assigned- Returns:
- optimized Symbol
-
toJsonString
Converts Symbol to json string for saving purpose.- Returns:
- the json string
-
toString
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classai.djl.util.NativeResource<com.sun.jna.Pointer>
-