mxnet.symbol.symbol¶
Symbolic configuration API of MXNet.
Functions
|
Creates a symbol that contains a collection of other symbols, grouped together. |
|
Creates a symbolic variable with specified name. |
|
Returns evenly spaced values within a given interval. |
|
Returns a new symbol of 2-D shpae, filled with ones on the diagonal and zeros elsewhere. |
|
Loads symbol from json string. |
|
Returns a new array of given shape and type, filled with the given value val. |
|
Compute the histogram of the input data. |
|
Given the "legs" of a right triangle, returns its hypotenuse. |
|
Return evenly spaced numbers within a specified interval. |
|
Loads symbol from a JSON file. |
|
Returns element-wise maximum of the input elements. |
|
Returns element-wise minimum of the input elements. |
|
Returns a new symbol of given shape and type, filled with ones. |
|
Returns element-wise result of base element raised to powers from exp element. |
|
Returns element-wise result of base element raised to powers from exp element. |
|
Split an array into multiple sub-arrays. |
|
Creates a symbolic variable with specified name. |
|
Returns a new symbol of given shape and type, filled with zeros. |
Classes
Symbol is symbolic graph of the mxnet. |
- mxnet.symbol.symbol.Group(symbols, create_fn=<class 'mxnet.symbol.symbol.Symbol'>)[source]¶
Creates a symbol that contains a collection of other symbols, grouped together. A classic symbol (mx.sym.Symbol) will be returned if all the symbols in the list are of that type; a numpy symbol (mx.sym.np._Symbol) will be returned if all the symbols in the list are of that type. A type error will be raised if a list of mixed classic and numpy symbols are provided.
Example
>>> a = mx.sym.Variable('a') >>> b = mx.sym.Variable('b') >>> mx.sym.Group([a,b]) <Symbol Grouped>
- class mxnet.symbol.symbol.Symbol[source]¶
Bases:
SymbolBaseSymbol is symbolic graph of the mxnet.
- abs(*args, **kwargs)[source]¶
Convenience fluent method for
abs().The arguments are the same as for
abs(), with this array as data.
- arccos(*args, **kwargs)[source]¶
Convenience fluent method for
arccos().The arguments are the same as for
arccos(), with this array as data.
- arccosh(*args, **kwargs)[source]¶
Convenience fluent method for
arccosh().The arguments are the same as for
arccosh(), with this array as data.
- arcsin(*args, **kwargs)[source]¶
Convenience fluent method for
arcsin().The arguments are the same as for
arcsin(), with this array as data.
- arcsinh(*args, **kwargs)[source]¶
Convenience fluent method for
arcsinh().The arguments are the same as for
arcsinh(), with this array as data.
- arctan(*args, **kwargs)[source]¶
Convenience fluent method for
arctan().The arguments are the same as for
arctan(), with this array as data.
- arctanh(*args, **kwargs)[source]¶
Convenience fluent method for
arctanh().The arguments are the same as for
arctanh(), with this array as data.
- argmax(*args, **kwargs)[source]¶
Convenience fluent method for
argmax().The arguments are the same as for
argmax(), with this array as data.
- argmax_channel(*args, **kwargs)[source]¶
Convenience fluent method for
argmax_channel().The arguments are the same as for
argmax_channel(), with this array as data.
- argmin(*args, **kwargs)[source]¶
Convenience fluent method for
argmin().The arguments are the same as for
argmin(), with this array as data.
- argsort(*args, **kwargs)[source]¶
Convenience fluent method for
argsort().The arguments are the same as for
argsort(), with this array as data.
- as_nd_ndarray()[source]¶
Returns self. For the convenience of conversion between legacy and np symbols.
- astype(*args, **kwargs)[source]¶
Convenience fluent method for
cast().The arguments are the same as for
cast(), with this array as data.
- attr(key)[source]¶
Returns the attribute string for corresponding input key from the symbol.
This function only works for non-grouped symbols.
Example
>>> data = mx.sym.Variable('data', attr={'mood': 'angry'}) >>> data.attr('mood') 'angry'
- attr_dict()[source]¶
Recursively gets all attributes from the symbol and its children.
Example
>>> a = mx.sym.Variable('a', attr={'a1':'a2'}) >>> b = mx.sym.Variable('b', attr={'b1':'b2'}) >>> c = a+b >>> c.attr_dict() {'a': {'a1': 'a2'}, 'b': {'b1': 'b2'}}
- Returns:
ret – There is a key in the returned dict for every child with non-empty attribute set. For each symbol, the name of the symbol is its key in the dict and the correspond value is that symbol’s attribute list (itself a dictionary).
- Return type:
Dict of str to dict
- broadcast_axes(*args, **kwargs)[source]¶
Convenience fluent method for
broadcast_axes().The arguments are the same as for
broadcast_axes(), with this array as data.
- broadcast_like(*args, **kwargs)[source]¶
Convenience fluent method for
broadcast_like().The arguments are the same as for
broadcast_like(), with this array as data.
- broadcast_to(*args, **kwargs)[source]¶
Convenience fluent method for
broadcast_to().The arguments are the same as for
broadcast_to(), with this array as data.
- cbrt(*args, **kwargs)[source]¶
Convenience fluent method for
cbrt().The arguments are the same as for
cbrt(), with this array as data.
- ceil(*args, **kwargs)[source]¶
Convenience fluent method for
ceil().The arguments are the same as for
ceil(), with this array as data.
- clip(*args, **kwargs)[source]¶
Convenience fluent method for
clip().The arguments are the same as for
clip(), with this array as data.
- cos(*args, **kwargs)[source]¶
Convenience fluent method for
cos().The arguments are the same as for
cos(), with this array as data.
- cosh(*args, **kwargs)[source]¶
Convenience fluent method for
cosh().The arguments are the same as for
cosh(), with this array as data.
- debug_str()[source]¶
Gets a debug string of symbol.
It contains Symbol output, variables and operators in the computation graph with their inputs, variables and attributes.
- Returns:
Debug string of the symbol.
- Return type:
string
Examples
>>> a = mx.sym.Variable('a') >>> b = mx.sym.sin(a) >>> c = 2 * a + b >>> d = mx.sym.FullyConnected(data=c, num_hidden=10) >>> d.debug_str() >>> print d.debug_str() Symbol Outputs: output[0]=fullyconnected0(0) Variable:a -------------------- Op:_mul_scalar, Name=_mulscalar0 Inputs: arg[0]=a(0) version=0 Attrs: scalar=2 -------------------- Op:sin, Name=sin0 Inputs: arg[0]=a(0) version=0 --------------------- Op:elemwise_add, Name=_plus0 Inputs: arg[0]=_mulscalar0(0) arg[1]=sin0(0) Variable:fullyconnected0_weight Variable:fullyconnected0_bias ----------------------------- Op:FullyConnected, Name=fullyconnected0 Inputs: arg[0]=_plus0(0) arg[1]=fullyconnected0_weight(0) version=0 arg[2]=fullyconnected0_bias(0) version=0 Attrs: num_hidden=10
- degrees(*args, **kwargs)[source]¶
Convenience fluent method for
degrees().The arguments are the same as for
degrees(), with this array as data.
- depth_to_space(*args, **kwargs)[source]¶
Convenience fluent method for
depth_to_space().The arguments are the same as for
depth_to_space(), with this array as data.
- diag(k=0, **kwargs)[source]¶
Convenience fluent method for
diag().The arguments are the same as for
diag(), with this array as data.
- eval(ctx=None, **kwargs)[source]¶
Evaluates a symbol given arguments.
The eval method combines a call to bind (which returns an executor) with a call to forward (executor method). For the common use case, where you might repeatedly evaluate with same arguments, eval is slow. In that case, you should call bind once and then repeatedly call forward. This function allows simpler syntax for less cumbersome introspection.
Example
>>> a = mx.sym.Variable('a') >>> b = mx.sym.Variable('b') >>> c = a + b >>> ex = c.eval(ctx = mx.cpu(), a = mx.nd.ones([2,3]), b = mx.nd.ones([2,3])) >>> ex [<NDArray 2x3 @cpu(0)>] >>> ex[0].asnumpy() array([[ 2., 2., 2.], [ 2., 2., 2.]], dtype=float32)
- Parameters:
ctx (Context) – The device context the generated executor to run on.
kwargs (Keyword arguments of type NDArray) – Input arguments to the symbol. All the arguments must be provided.
- Returns:
result (a list of NDArrays corresponding to the values taken by each symbol when)
evaluated on given args. When called on a single symbol (not a group),
the result will be a list with one element.
- exp(*args, **kwargs)[source]¶
Convenience fluent method for
exp().The arguments are the same as for
exp(), with this array as data.
- expand_dims(axis, inplace=False, **kwargs)[source]¶
Convenience fluent method for
expand_dims().The arguments are the same as for
expand_dims(), with this array as data.
- expm1(*args, **kwargs)[source]¶
Convenience fluent method for
expm1().The arguments are the same as for
expm1(), with this array as data.
- fix(*args, **kwargs)[source]¶
Convenience fluent method for
fix().The arguments are the same as for
fix(), with this array as data.
- flatten(inplace=False, **kwargs)[source]¶
Convenience fluent method for
flatten().The arguments are the same as for
flatten(), with this array as data.
- flip(*args, **kwargs)[source]¶
Convenience fluent method for
flip().The arguments are the same as for
flip(), with this array as data.
- floor(*args, **kwargs)[source]¶
Convenience fluent method for
floor().The arguments are the same as for
floor(), with this array as data.
- get_children()[source]¶
Gets a new grouped symbol whose output contains inputs to output nodes of the original symbol.
Example
>>> x = mx.sym.Variable('x') >>> y = mx.sym.Variable('y') >>> z = mx.sym.Variable('z') >>> a = y+z >>> b = x+a >>> b.get_children() <Symbol Grouped> >>> b.get_children().list_outputs() ['x', '_plus10_output'] >>> b.get_children().get_children().list_outputs() ['y', 'z']
- Returns:
sgroup – The children of the head node. If the symbol has no inputs then
Nonewill be returned.- Return type:
Symbol or None
- get_inputs()[source]¶
Gets a new grouped symbol sgroup. The output of sgroup is a list of inputs to this symbol.
Consider the following code:
Example
>>> a = mx.sym.var('a') >>> b = mx.sym.var('b') >>> c = a + b >>> d = c.get_inputs() >>> d <Symbol Grouped> >>> d.list_outputs() ['a', 'b']
- Returns:
sgroup – A symbol group containing all input nodes of the computation graph used to compute the symbol.
- Return type:
- get_internals()[source]¶
Gets a new grouped symbol sgroup. The output of sgroup is a list of outputs of all of the internal nodes.
Consider the following code:
Example
>>> a = mx.sym.var('a') >>> b = mx.sym.var('b') >>> c = a + b >>> d = c.get_internals() >>> d <Symbol Grouped> >>> d.list_outputs() ['a', 'b', '_plus4_output']
- Returns:
sgroup – A symbol group containing all internal and leaf nodes of the computation graph used to compute the symbol.
- Return type:
- gradient(wrt)[source]¶
Gets the autodiff of current symbol.
This function can only be used if current symbol is a loss function.
Note
This function is currently not implemented.
- Parameters:
wrt (Array of String) – keyword arguments of the symbol that the gradients are taken.
- Returns:
grad – A gradient Symbol with returns to be the corresponding gradients.
- Return type:
- infer_shape(*args, **kwargs)[source]¶
Infers the shapes of all arguments and all outputs given the known shapes of some arguments.
This function takes the known shapes of some arguments in either positional way or keyword argument way as input. It returns a tuple of None values if there is not enough information to deduce the missing shapes.
Example
>>> a = mx.sym.var('a') >>> b = mx.sym.var('b') >>> c = a + b >>> arg_shapes, out_shapes, aux_shapes = c.infer_shape(a=(3,3)) >>> arg_shapes [(3L, 3L), (3L, 3L)] >>> out_shapes [(3L, 3L)] >>> aux_shapes [] >>> c.infer_shape(a=(0,3)) # 0s in shape means unknown dimensions. So, returns None. (None, None, None)
Inconsistencies in the known shapes will cause an error to be raised. See the following example:
>>> data = mx.sym.Variable('data') >>> out = mx.sym.FullyConnected(data=data, name='fc1', num_hidden=1000) >>> out = mx.sym.Activation(data=out, act_type='relu') >>> out = mx.sym.FullyConnected(data=out, name='fc2', num_hidden=10) >>> weight_shape= (1, 100) >>> data_shape = (100, 100) >>> out.infer_shape(data=data_shape, fc1_weight=weight_shape) Error in operator fc1: Shape inconsistent, Provided=(1,100), inferred shape=(1000,100)
- Parameters:
*args – Shape of arguments in a positional way. Unknown shape can be marked as None.
**kwargs – Keyword arguments of the known shapes.
- Returns:
arg_shapes (list of tuple or None) – List of argument shapes. The order is same as the order of list_arguments().
out_shapes (list of tuple or None) – List of output shapes. The order is same as the order of list_outputs().
aux_shapes (list of tuple or None) – List of auxiliary state shapes. The order is same as the order of list_auxiliary_states().
- infer_shape_partial(*args, **kwargs)[source]¶
Infers the shape partially.
This functions works the same way as infer_shape, except that this function can return partial results.
In the following example, information about fc2 is not available. So, infer_shape will return a tuple of None values but infer_shape_partial will return partial values.
Example
>>> data = mx.sym.Variable('data') >>> prev = mx.sym.Variable('prev') >>> fc1 = mx.sym.FullyConnected(data=data, name='fc1', num_hidden=128) >>> fc2 = mx.sym.FullyConnected(data=prev, name='fc2', num_hidden=128) >>> out = mx.sym.Activation(data=mx.sym.elemwise_add(fc1, fc2), act_type='relu') >>> out.list_arguments() ['data', 'fc1_weight', 'fc1_bias', 'prev', 'fc2_weight', 'fc2_bias'] >>> out.infer_shape(data=(10,64)) (None, None, None) >>> out.infer_shape_partial(data=(10,64)) ([(10L, 64L), (128L, 64L), (128L,), (), (), ()], [(10L, 128L)], []) >>> # infers shape if you give information about fc2 >>> out.infer_shape(data=(10,64), prev=(10,128)) ([(10L, 64L), (128L, 64L), (128L,), (10L, 128L), (128L, 128L), (128L,)], [(10L, 128L)], [])
- Parameters:
*args – Shape of arguments in a positional way. Unknown shape can be marked as None
**kwargs – Keyword arguments of known shapes.
- Returns:
arg_shapes (list of tuple or None) – List of argument shapes. The order is same as the order of list_arguments().
out_shapes (list of tuple or None) – List of output shapes. The order is same as the order of list_outputs().
aux_shapes (list of tuple or None) – List of auxiliary state shapes. The order is same as the order of list_auxiliary_states().
- infer_type(*args, **kwargs)[source]¶
Infers the type of all arguments and all outputs, given the known types for some arguments.
This function takes the known types of some arguments in either positional way or keyword argument way as input. It returns a tuple of None values if there is not enough information to deduce the missing types.
Inconsistencies in the known types will cause an error to be raised.
Example
>>> a = mx.sym.var('a') >>> b = mx.sym.var('b') >>> c = a + b >>> arg_types, out_types, aux_types = c.infer_type(a='float32') >>> arg_types [<type 'numpy.float32'>, <type 'numpy.float32'>] >>> out_types [<type 'numpy.float32'>] >>> aux_types []
- Parameters:
*args – Type of known arguments in a positional way. Unknown type can be marked as None.
**kwargs – Keyword arguments of known types.
- Returns:
arg_types (list of numpy.dtype or None) – List of argument types. The order is same as the order of list_arguments().
out_types (list of numpy.dtype or None) – List of output types. The order is same as the order of list_outputs().
aux_types (list of numpy.dtype or None) – List of auxiliary state types. The order is same as the order of list_auxiliary_states().
- infer_type_partial(*args, **kwargs)[source]¶
Infers the type partially.
This functions works the same way as infer_type, except that this function can return partial results.
In the following example, information about fc2 is not available. So, infer_shape will return a tuple of None values but infer_shape_partial will return partial values.
Example
>>> data = mx.sym.Variable('data') >>> prev = mx.sym.Variable('prev') >>> casted_prev = mx.sym.cast(prev, dtype='float32') >>> out = mx.sym.Activation(data=mx.sym.elemwise_add(data, casted_prev), act_type='relu') >>> out.list_arguments() ['data', 'prev'] >>> out.infer_type(data='float32') (None, None, None) >>> out.infer_type_partial(data='float32') ([numpy.float32, None], [numpy.float32], []) >>> # infers type if you give information about prev >>> out.infer_type(data='float32', prev='float16') ([numpy.float32, numpy.float16], [numpy.float32], [])
- Parameters:
*args – Type of known arguments in a positional way. Unknown type can be marked as None.
**kwargs – Keyword arguments of known types.
- Returns:
arg_types (list of numpy.dtype or None) – List of argument types. The order is same as the order of list_arguments().
out_types (list of numpy.dtype or None) – List of output types. The order is same as the order of list_outputs().
aux_types (list of numpy.dtype or None) – List of auxiliary state types. The order is same as the order of list_auxiliary_states().
- list_arguments()[source]¶
Lists all the arguments in the symbol.
Example
>>> a = mx.sym.var('a') >>> b = mx.sym.var('b') >>> c = a + b >>> c.list_arguments ['a', 'b']
- Returns:
args – List containing the names of all the arguments required to compute the symbol.
- Return type:
list of string
- list_attr(recursive=False)[source]¶
Gets all attributes from the symbol.
Example
>>> data = mx.sym.Variable('data', attr={'mood': 'angry'}) >>> data.list_attr() {'mood': 'angry'}
- Returns:
ret – A dictionary mapping attribute keys to values.
- Return type:
Dict of str to str
- list_auxiliary_states()[source]¶
Lists all the auxiliary states in the symbol.
Example
>>> a = mx.sym.var('a') >>> b = mx.sym.var('b') >>> c = a + b >>> c.list_auxiliary_states() []
Example of auxiliary states in BatchNorm.
>>> data = mx.symbol.Variable('data') >>> weight = mx.sym.Variable(name='fc1_weight') >>> fc1 = mx.symbol.FullyConnected(data = data, weight=weight, name='fc1', num_hidden=128) >>> fc2 = mx.symbol.BatchNorm(fc1, name='batchnorm0') >>> fc2.list_auxiliary_states() ['batchnorm0_moving_mean', 'batchnorm0_moving_var']
Notes
Auxiliary states are special states of symbols that do not correspond to an argument, and are not updated by gradient descent. Common examples of auxiliary states include the moving_mean and moving_variance in BatchNorm. Most operators do not have auxiliary states.
- list_inputs()[source]¶
Lists all arguments and auxiliary states of this Symbol.
Examples
>>> bn = mx.sym.BatchNorm(name='bn') >>> bn.list_arguments() ['bn_data', 'bn_gamma', 'bn_beta'] >>> bn.list_auxiliary_states() ['bn_moving_mean', 'bn_moving_var'] >>> bn.list_inputs() ['bn_data', 'bn_gamma', 'bn_beta', 'bn_moving_mean', 'bn_moving_var']
- list_outputs()[source]¶
Lists all the outputs in the symbol.
Example
>>> a = mx.sym.var('a') >>> b = mx.sym.var('b') >>> c = a + b >>> c.list_outputs() ['_plus12_output']
- log(*args, **kwargs)[source]¶
Convenience fluent method for
log().The arguments are the same as for
log(), with this array as data.
- log10(*args, **kwargs)[source]¶
Convenience fluent method for
log10().The arguments are the same as for
log10(), with this array as data.
- log1p(*args, **kwargs)[source]¶
Convenience fluent method for
log1p().The arguments are the same as for
log1p(), with this array as data.
- log2(*args, **kwargs)[source]¶
Convenience fluent method for
log2().The arguments are the same as for
log2(), with this array as data.
- log_sigmoid(*args, **kwargs)[source]¶
Convenience fluent method for
log_sigmoid().The arguments are the same as for
log_sigmoid(), with this array as data.
- log_softmax(*args, **kwargs)[source]¶
Convenience fluent method for
log_softmax().The arguments are the same as for
log_softmax(), with this array as data.
- max(*args, **kwargs)[source]¶
Convenience fluent method for
max().The arguments are the same as for
max(), with this array as data.
- mean(*args, **kwargs)[source]¶
Convenience fluent method for
mean().The arguments are the same as for
mean(), with this array as data.
- min(*args, **kwargs)[source]¶
Convenience fluent method for
min().The arguments are the same as for
min(), with this array as data.
- mish(*args, **kwargs)[source]¶
Convenience fluent method for
mish().The arguments are the same as for
mish(), with this array as data.
- property name¶
Gets name string from the symbol, this function only works for non-grouped symbol.
- Returns:
value – The name of this symbol, returns
Nonefor grouped symbol.- Return type:
- nanprod(*args, **kwargs)[source]¶
Convenience fluent method for
nanprod().The arguments are the same as for
nanprod(), with this array as data.
- nansum(*args, **kwargs)[source]¶
Convenience fluent method for
nansum().The arguments are the same as for
nansum(), with this array as data.
- norm(*args, **kwargs)[source]¶
Convenience fluent method for
norm().The arguments are the same as for
norm(), with this array as data.
- one_hot(*args, **kwargs)[source]¶
Convenience fluent method for
one_hot().The arguments are the same as for
one_hot(), with this array as data.
- ones_like(*args, **kwargs)[source]¶
Convenience fluent method for
ones_like().The arguments are the same as for
ones_like(), with this array as data.
- optimize_for(backend, args=None, aux=None, ctx=None, shape_dict=None, type_dict=None, stype_dict=None, skip_infer=False, **kwargs)[source]¶
Partitions current symbol and optimizes it for a given backend.
The backend must be registered as a subgraph backend or as an NNVM graph pass.
- Parameters:
backend (str) – The name of backend, as registered in
SubgraphBackendRegistryargs (dict of str to NDArray, optional) – Input arguments to the symbol, required to infer shapes/types before partitioning If type is a dict of str to NDArray, then it maps the names of arguments to the corresponding NDArray. Undefined arguments’ NDArrays don’t have to be specified in the dict.
aux (dict of str to NDArray, optional) – Input auxiliary arguments to the symbol If type is a dict of str to
NDArray, then it maps the name of arguments to the correspondingNDArray.ctx (Context, optional) – Device context, used to infer stypes
shape_dict (Dict of str->tuple, optional) – Input shape dictionary. Used iff input
NDArrayis not inargs.type_dict (Dict of str->numpy.dtype, optional) – Input type dictionary. Used iff input
NDArrayis not inargs.stype_dict (Dict of str->str, optional) – Input storage type dictionary. Used iff input
NDArrayis not inargs.skip_infer (bool, optional) – If True, the optimization skips the shape, type and storage type inference pass.
kwargs (optional arguments) – Passed on to
PrePartitionandPostPartitionfunctions ofSubgraphProperty
- Returns:
out – A symbol with the partitioned graph for target backend.
- Return type:
SymbolHandle
- pad(*args, **kwargs)[source]¶
Convenience fluent method for
pad().The arguments are the same as for
pad(), with this array as data.
- pick(*args, **kwargs)[source]¶
Convenience fluent method for
pick().The arguments are the same as for
pick(), with this array as data.
- prod(*args, **kwargs)[source]¶
Convenience fluent method for
prod().The arguments are the same as for
prod(), with this array as data.
- radians(*args, **kwargs)[source]¶
Convenience fluent method for
radians().The arguments are the same as for
radians(), with this array as data.
- rcbrt(*args, **kwargs)[source]¶
Convenience fluent method for
rcbrt().The arguments are the same as for
rcbrt(), with this array as data.
- reciprocal(*args, **kwargs)[source]¶
Convenience fluent method for
reciprocal().The arguments are the same as for
reciprocal(), with this array as data.
- relu(*args, **kwargs)[source]¶
Convenience fluent method for
relu().The arguments are the same as for
relu(), with this array as data.
- repeat(*args, **kwargs)[source]¶
Convenience fluent method for
repeat().The arguments are the same as for
repeat(), with this array as data.
- reshape(*args, **kwargs)[source]¶
Convenience fluent method for
reshape().The arguments are the same as for
reshape(), with this array as data.
- reshape_like(*args, **kwargs)[source]¶
Convenience fluent method for
reshape_like().The arguments are the same as for
reshape_like(), with this array as data.
- rint(*args, **kwargs)[source]¶
Convenience fluent method for
rint().The arguments are the same as for
rint(), with this array as data.
- round(*args, **kwargs)[source]¶
Convenience fluent method for
round().The arguments are the same as for
round(), with this array as data.
- rsqrt(*args, **kwargs)[source]¶
Convenience fluent method for
rsqrt().The arguments are the same as for
rsqrt(), with this array as data.
- save(fname, remove_amp_cast=True)[source]¶
Saves symbol to a file.
You can also use pickle to do the job if you only work on python. The advantage of load/save functions is that the file contents are language agnostic. This means the model saved by one language binding can be loaded by a different language binding of MXNet. You also get the benefit of being able to directly load/save from cloud storage(S3, HDFS).
- Parameters:
See also
symbol.loadUsed to load symbol from file.
- shape_array(*args, **kwargs)[source]¶
Convenience fluent method for
shape_array().The arguments are the same as for
shape_op(), with this array as data.
- sigmoid(*args, **kwargs)[source]¶
Convenience fluent method for
sigmoid().The arguments are the same as for
sigmoid(), with this array as data.
- sign(*args, **kwargs)[source]¶
Convenience fluent method for
sign().The arguments are the same as for
sign(), with this array as data.
- sin(*args, **kwargs)[source]¶
Convenience fluent method for
sin().The arguments are the same as for
sin(), with this array as data.
- sinh(*args, **kwargs)[source]¶
Convenience fluent method for
sinh().The arguments are the same as for
sinh(), with this array as data.
- size_array(*args, **kwargs)[source]¶
Convenience fluent method for
size_array().The arguments are the same as for
size_array(), with this array as data.
- slice(*args, **kwargs)[source]¶
Convenience fluent method for
slice().The arguments are the same as for
slice(), with this array as data.
- slice_axis(*args, **kwargs)[source]¶
Convenience fluent method for
slice_axis().The arguments are the same as for
slice_axis(), with this array as data.
- slice_like(*args, **kwargs)[source]¶
Convenience fluent method for
slice_like().The arguments are the same as for
slice_like(), with this array as data.
- softmax(*args, **kwargs)[source]¶
Convenience fluent method for
softmax().The arguments are the same as for
softmax(), with this array as data.
- softmin(*args, **kwargs)[source]¶
Convenience fluent method for
softmin().The arguments are the same as for
softmin(), with this array as data.
- sort(*args, **kwargs)[source]¶
Convenience fluent method for
sort().The arguments are the same as for
sort(), with this array as data.
- space_to_depth(*args, **kwargs)[source]¶
Convenience fluent method for
space_to_depth().The arguments are the same as for
space_to_depth(), with this array as data.
- split(*args, **kwargs)[source]¶
Convenience fluent method for
split().The arguments are the same as for
split(), with this array as data.
- split_v2(*args, **kwargs)[source]¶
Convenience fluent method for
split_v2().The arguments are the same as for
split_v2(), with this array as data.
- sqrt(*args, **kwargs)[source]¶
Convenience fluent method for
sqrt().The arguments are the same as for
sqrt(), with this array as data.
- square(*args, **kwargs)[source]¶
Convenience fluent method for
square().The arguments are the same as for
square(), with this array as data.
- squeeze(axis=None, inplace=False, **kwargs)[source]¶
Convenience fluent method for
squeeze().The arguments are the same as for
squeeze(), with this array as data.
- sum(*args, **kwargs)[source]¶
Convenience fluent method for
sum().The arguments are the same as for
sum(), with this array as data.
- swapaxes(*args, **kwargs)[source]¶
Convenience fluent method for
swapaxes().The arguments are the same as for
swapaxes(), with this array as data.
- take(*args, **kwargs)[source]¶
Convenience fluent method for
take().The arguments are the same as for
take(), with this array as data.
- tan(*args, **kwargs)[source]¶
Convenience fluent method for
tan().The arguments are the same as for
tan(), with this array as data.
- tanh(*args, **kwargs)[source]¶
Convenience fluent method for
tanh().The arguments are the same as for
tanh(), with this array as data.
- tile(*args, **kwargs)[source]¶
Convenience fluent method for
tile().The arguments are the same as for
tile(), with this array as data.
- tojson(remove_amp_cast=True)[source]¶
Saves symbol to a JSON string.
See also
symbol.fromjsonUsed to load symbol from JSON string.
- topk(*args, **kwargs)[source]¶
Convenience fluent method for
topk().The arguments are the same as for
topk(), with this array as data.
- transpose(*args, **kwargs)[source]¶
Convenience fluent method for
transpose().The arguments are the same as for
transpose(), with this array as data.
- trunc(*args, **kwargs)[source]¶
Convenience fluent method for
trunc().The arguments are the same as for
trunc(), with this array as data.
- zeros_like(*args, **kwargs)[source]¶
Convenience fluent method for
zeros_like().The arguments are the same as for
zeros_like(), with this array as data.
- mxnet.symbol.symbol.Variable(name, attr=None, shape=None, lr_mult=None, wd_mult=None, dtype=None, init=None, stype=None, profiler_scope=None, **kwargs)¶
Creates a symbolic variable with specified name.
Example
>>> data = mx.sym.Variable('data', attr={'a': 'b'}) >>> data <Symbol data> >>> csr_data = mx.sym.Variable('csr_data', stype='csr') >>> csr_data <Symbol csr_data> >>> row_sparse_weight = mx.sym.Variable('weight', stype='row_sparse') >>> row_sparse_weight <Symbol weight>
- Parameters:
name (str) – Variable name.
attr (Dict of strings) – Additional attributes to set on the variable. Format {string : string}.
shape (tuple) – The shape of a variable. If specified, this will be used during the shape inference. If one has specified a different shape for this variable using a keyword argument when calling shape inference, this shape information will be ignored.
lr_mult (float) – The learning rate multiplier for input variable.
wd_mult (float) – Weight decay multiplier for input variable.
dtype (str or numpy.dtype) – The dtype for input variable. If not specified, this value will be inferred.
init (initializer (mxnet.init.*)) – Initializer for this variable to (optionally) override the default initializer.
stype (str) – The storage type of the variable, such as ‘row_sparse’, ‘csr’, ‘default’, etc
profiler_scope (str) – The profiler scope for input variable.
kwargs (Additional attribute variables) – Additional attributes must start and end with double underscores.
- Returns:
variable – A symbol corresponding to an input to the computation graph.
- Return type:
- mxnet.symbol.symbol.arange(start, stop=None, step=1.0, repeat=1, infer_range=False, name=None, dtype=None)[source]¶
Returns evenly spaced values within a given interval.
Values are generated within the half-open interval [start, stop). In other words, the interval includes start but excludes stop. The function is similar to the built-in Python function range and to numpy.arange, but returns a Symbol.
- Parameters:
start (number, optional) – Start of interval. The interval includes this value. The default start value is 0.
stop (number) – End of interval. The interval does not include this value.
step (number, optional) – Spacing between values.
repeat (int, optional) – “The repeating time of all elements. E.g repeat=3, the element a will be repeated three times –> a, a, a.
infer_range (boolean, optional) – When set to True, infer the stop position from the start, step, repeat, and output tensor size.
dtype (str or numpy.dtype, optional) – The value type of the inner value, default to
np.float32.
- Returns:
out – The created Symbol
- Return type:
- mxnet.symbol.symbol.eye(N, M=0, k=0, dtype=None, **kwargs)[source]¶
Returns a new symbol of 2-D shpae, filled with ones on the diagonal and zeros elsewhere.
- Parameters:
N (int) – Number of rows in the output.
M (int, optional) – Number of columns in the output. If 0, defaults to N.
k (int, optional) – Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.
dtype (str or numpy.dtype, optional) – The value type of the inner value, default to
np.float32.
- Returns:
out – The created Symbol.
- Return type:
- mxnet.symbol.symbol.fromjson(json_str)[source]¶
Loads symbol from json string.
See also
Symbol.tojsonUsed to save symbol into json string.
- mxnet.symbol.symbol.full(shape, val, dtype=None, **kwargs)[source]¶
Returns a new array of given shape and type, filled with the given value val.
- Parameters:
shape (int or sequence of ints) – Shape of the new array.
val (scalar) – Fill value.
dtype (str or numpy.dtype, optional) – The value type of the inner value, default to
np.float32.
- Returns:
out – The created Symbol
- Return type:
- mxnet.symbol.symbol.histogram(a, bins=10, range=None, **kwargs)[source]¶
Compute the histogram of the input data.
- Parameters:
a (NDArray) – Input data. The histogram is computed over the flattened array.
bins (int or sequence of scalars) – If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines the bin edges, including the rightmost edge, allowing for non-uniform bin widths.
range ((float, float), required if bins is an integer) – The lower and upper range of the bins. If not provided, range is simply (a.min(), a.max()). Values outside the range are ignored. The first element of the range must be less than or equal to the second. range affects the automatic bin computation as well, the range will be equally divided by the number of bins.
- Returns:
out – The created Symbol
- Return type:
- mxnet.symbol.symbol.hypot(left, right)[source]¶
Given the “legs” of a right triangle, returns its hypotenuse.
Equivalent to \(\sqrt(left^2 + right^2)\), element-wise. Both inputs can be Symbol or scalar number. Broadcasting is not supported.
- Parameters:
- Returns:
The hypotenuse of the triangle(s)
- Return type:
Symbol or scalar
Examples
>>> mx.sym.hypot(3, 4) 5.0 >>> x = mx.sym.Variable('x') >>> y = mx.sym.Variable('y') >>> z = mx.sym.hypot(x, 4) >>> z.eval(x=mx.nd.array([3,5,2]))[0].asnumpy() array([ 5., 6.40312433, 4.47213602], dtype=float32) >>> z = mx.sym.hypot(x, y) >>> z.eval(x=mx.nd.array([3,4]), y=mx.nd.array([10,2]))[0].asnumpy() array([ 10.44030666, 4.47213602], dtype=float32)
- mxnet.symbol.symbol.linspace(start, stop, num, endpoint=True, name=None, dtype=None)[source]¶
Return evenly spaced numbers within a specified interval.
Values are generated within the half-open interval [start, stop) or closed interval [start, stop] depending on whether endpoint is True or False. The function is similar to numpy.linspace, but returns a Symbol.
- Parameters:
start (number) – Start of interval.
stop (number) – End of interval, unless endpoint is set to False. In that case, the sequence consists of all but the last of num + 1 evenly spaced samples, so that stop is excluded. Note that the step size changes when endpoint is False.
num (number) – Number of samples to generate. Must be non-negative.
endpoint (bool) – If True, stop is the last sample. Otherwise, it is not included. The default is True.
dtype (str or numpy.dtype, optional) – The data type of the NDArray. The default datatype is np.float32.
- Returns:
out – The created Symbol
- Return type:
- mxnet.symbol.symbol.load(fname)[source]¶
Loads symbol from a JSON file.
You can also use pickle to do the job if you only work on python. The advantage of load/save is the file is language agnostic. This means the file saved using save can be loaded by other language binding of mxnet. You also get the benefit being able to directly load/save from cloud storage(S3, HDFS).
- Parameters:
fname (str) –
The name of the file, examples:
s3://my-bucket/path/my-s3-symbol
hdfs://my-bucket/path/my-hdfs-symbol
/path-to/my-local-symbol
- Returns:
sym – The loaded symbol.
- Return type:
See also
Symbol.saveUsed to save symbol into file.
- mxnet.symbol.symbol.maximum(left, right)[source]¶
Returns element-wise maximum of the input elements.
Both inputs can be Symbol or scalar number. Broadcasting is not supported.
- Parameters:
- Returns:
The element-wise maximum of the input symbols.
- Return type:
Symbol or scalar
Examples
>>> mx.sym.maximum(2, 3.5) 3.5 >>> x = mx.sym.Variable('x') >>> y = mx.sym.Variable('y') >>> z = mx.sym.maximum(x, 4) >>> z.eval(x=mx.nd.array([3,5,2,10]))[0].asnumpy() array([ 4., 5., 4., 10.], dtype=float32) >>> z = mx.sym.maximum(x, y) >>> z.eval(x=mx.nd.array([3,4]), y=mx.nd.array([10,2]))[0].asnumpy() array([ 10., 4.], dtype=float32)
- mxnet.symbol.symbol.minimum(left, right)[source]¶
Returns element-wise minimum of the input elements.
Both inputs can be Symbol or scalar number. Broadcasting is not supported.
- Parameters:
- Returns:
The element-wise minimum of the input symbols.
- Return type:
Symbol or scalar
Examples
>>> mx.sym.minimum(2, 3.5) 2 >>> x = mx.sym.Variable('x') >>> y = mx.sym.Variable('y') >>> z = mx.sym.minimum(x, 4) >>> z.eval(x=mx.nd.array([3,5,2,10]))[0].asnumpy() array([ 3., 4., 2., 4.], dtype=float32) >>> z = mx.sym.minimum(x, y) >>> z.eval(x=mx.nd.array([3,4]), y=mx.nd.array([10,2]))[0].asnumpy() array([ 3., 2.], dtype=float32)
- mxnet.symbol.symbol.ones(shape, dtype=None, **kwargs)[source]¶
Returns a new symbol of given shape and type, filled with ones.
- Parameters:
shape (int or sequence of ints) – Shape of the new array.
dtype (str or numpy.dtype, optional) – The value type of the inner value, default to
np.float32.
- Returns:
out – The created Symbol
- Return type:
- mxnet.symbol.symbol.pow(base, exp)[source]¶
Returns element-wise result of base element raised to powers from exp element.
Both inputs can be Symbol or scalar number. Broadcasting is not supported. Use broadcast_pow instead.
sym.pow is being deprecated, please use sym.power instead.
- Parameters:
- Returns:
The bases in x raised to the exponents in y.
- Return type:
Symbol or scalar
Examples
>>> mx.sym.pow(2, 3) 8 >>> x = mx.sym.Variable('x') >>> y = mx.sym.Variable('y') >>> z = mx.sym.pow(x, 2) >>> z.eval(x=mx.nd.array([1,2]))[0].asnumpy() array([ 1., 4.], dtype=float32) >>> z = mx.sym.pow(3, y) >>> z.eval(y=mx.nd.array([2,3]))[0].asnumpy() array([ 9., 27.], dtype=float32) >>> z = mx.sym.pow(x, y) >>> z.eval(x=mx.nd.array([3,4]), y=mx.nd.array([2,3]))[0].asnumpy() array([ 9., 64.], dtype=float32)
- mxnet.symbol.symbol.power(base, exp)[source]¶
Returns element-wise result of base element raised to powers from exp element.
Both inputs can be Symbol or scalar number. Broadcasting is not supported. Use broadcast_pow instead.
- Parameters:
- Returns:
The bases in x raised to the exponents in y.
- Return type:
Symbol or scalar
Examples
>>> mx.sym.power(2, 3) 8 >>> x = mx.sym.Variable('x') >>> y = mx.sym.Variable('y') >>> z = mx.sym.power(x, 2) >>> z.eval(x=mx.nd.array([1,2]))[0].asnumpy() array([ 1., 4.], dtype=float32) >>> z = mx.sym.power(3, y) >>> z.eval(y=mx.nd.array([2,3]))[0].asnumpy() array([ 9., 27.], dtype=float32) >>> z = mx.sym.power(x, y) >>> z.eval(x=mx.nd.array([3,4]), y=mx.nd.array([2,3]))[0].asnumpy() array([ 9., 64.], dtype=float32)
- mxnet.symbol.symbol.split_v2(ary, indices_or_sections, axis=0, squeeze_axis=False)[source]¶
Split an array into multiple sub-arrays.
- Parameters:
ary (NDArray) – Array to be divided into sub-arrays.
indices_or_sections (int or tuple of ints) – If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis. If such a split is not possible, an error is raised. If indices_or_sections is a 1-D array of sorted integers, the entries indicate where along axis the array is split. For example,
[2, 3]would, foraxis=0, result in - ary[:2] - ary[2:3] - ary[3:] If an index exceeds the dimension of the array along axis, an empty sub-array is returned correspondingly.axis (int, optional) – The axis along which to split, default is 0.
squeeze_axis (boolean, optional) – Whether to squeeze the axis of sub-arrays or not, only useful when size of the sub-arrays are 1 on the axis. Default is False.
- Returns:
out – The created Symbol
- Return type:
- mxnet.symbol.symbol.var(name, attr=None, shape=None, lr_mult=None, wd_mult=None, dtype=None, init=None, stype=None, profiler_scope=None, **kwargs)[source]¶
Creates a symbolic variable with specified name.
Example
>>> data = mx.sym.Variable('data', attr={'a': 'b'}) >>> data <Symbol data> >>> csr_data = mx.sym.Variable('csr_data', stype='csr') >>> csr_data <Symbol csr_data> >>> row_sparse_weight = mx.sym.Variable('weight', stype='row_sparse') >>> row_sparse_weight <Symbol weight>
- Parameters:
name (str) – Variable name.
attr (Dict of strings) – Additional attributes to set on the variable. Format {string : string}.
shape (tuple) – The shape of a variable. If specified, this will be used during the shape inference. If one has specified a different shape for this variable using a keyword argument when calling shape inference, this shape information will be ignored.
lr_mult (float) – The learning rate multiplier for input variable.
wd_mult (float) – Weight decay multiplier for input variable.
dtype (str or numpy.dtype) – The dtype for input variable. If not specified, this value will be inferred.
init (initializer (mxnet.init.*)) – Initializer for this variable to (optionally) override the default initializer.
stype (str) – The storage type of the variable, such as ‘row_sparse’, ‘csr’, ‘default’, etc
profiler_scope (str) – The profiler scope for input variable.
kwargs (Additional attribute variables) – Additional attributes must start and end with double underscores.
- Returns:
variable – A symbol corresponding to an input to the computation graph.
- Return type:
- mxnet.symbol.symbol.zeros(shape, dtype=None, **kwargs)[source]¶
Returns a new symbol of given shape and type, filled with zeros.
- Parameters:
shape (int or sequence of ints) – Shape of the new array.
dtype (str or numpy.dtype, optional) – The value type of the inner value, default to
np.float32.
- Returns:
out – The created Symbol.
- Return type: