当前位置: 首页>>代码示例>>Python>>正文


Python mxnet.sym方法代码示例

本文整理汇总了Python中mxnet.sym方法的典型用法代码示例。如果您正苦于以下问题:Python mxnet.sym方法的具体用法?Python mxnet.sym怎么用?Python mxnet.sym使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mxnet的用法示例。


在下文中一共展示了mxnet.sym方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _fix_max_min

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def _fix_max_min(self, op_name, inputs):
        """ MXNet maximum/minimum compares only two symbols at a time.
            ONNX can send more than two to compare.
            Breaking into multiple mxnet ops to compare two symbols at a time"""
        if len(inputs) > 1:
            if op_name == 'Max':
                op = mx.sym.maximum(inputs[0], inputs[1])
                for ip in inputs[2:]:
                    op = mx.sym.maximum(op, ip)
            elif op_name == 'Min':
                op = mx.sym.minimum(inputs[0], inputs[1])
                for ip in inputs[2:]:
                    op = mx.sym.minimum(op, ip)
        else:
            op = inputs[0]
        return op 
开发者ID:onnx,项目名称:onnx-mxnet,代码行数:18,代码来源:import_onnx.py

示例2: _fix_channels

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def _fix_channels(self, op, attrs, inputs):
        """A workaround for getting 'channels' or 'units' since onnx don't provide
        these attributes. We check the shape of weights provided to get the number.
        """
        if op not in [mx.sym.Convolution, mx.sym.Deconvolution, mx.sym.FullyConnected]:
            return attrs
        weight_name = self._renames[inputs[1]]
        if not weight_name in self._params:
            raise ValueError("Unable to get channels/units attr from onnx graph.")
        else:
            wshape = self._params[weight_name].shape
            assert len(wshape) >= 2, "Weights shape is invalid: {}".format(wshape)

            if op in [mx.sym.FullyConnected]:
                attrs['num_hidden'] = wshape[0]
            else:
                if op == mx.sym.Convolution:
                    # Weight shape for Conv and FC: (M x C x kH x kW) : M is number of
                    # feature maps/hidden  and C is number of channels
                    attrs['num_filter'] = wshape[0]
                elif op == mx.sym.Deconvolution:
                    # Weight shape for DeConv : (C x M x kH x kW) : M is number of
                    # feature maps/filters and C is number of channels
                    attrs['num_filter'] = wshape[1]
        return attrs 
开发者ID:onnx,项目名称:onnx-mxnet,代码行数:27,代码来源:import_onnx.py

示例3: _compute_K

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def _compute_K(self, F, X, lengthscale, variance, X2=None):
        """
        The internal interface for the actual covariance matrix computation.

        :param F: MXNet computation type <mx.sym, mx.nd>.
        :param X: the first set of inputs to the kernel.
        :type X: MXNet NDArray or MXNet Symbol
        :param X2: (optional) the second set of arguments to the kernel. If X2 is None, this computes a square
        covariance matrix of X. In other words, X2 is internally treated as X.
        :type X2: MXNet NDArray or MXNet Symbol
        :param variance: the variance parameter (scalar), which scales the whole covariance matrix.
        :type variance: MXNet NDArray or MXNet Symbol
        :param lengthscale: the lengthscale parameter.
        :type lengthscale: MXNet NDArray or MXNet Symbol
        :return: The covariance matrix.
        :rtype: MXNet NDArray or MXNet Symbol
        """
        R2 = self._compute_R2(F, X, lengthscale, variance, X2=X2)
        R = F.sqrt(F.clip(R2, 1e-14, np.inf))
        return F.broadcast_mul(
            (1+np.sqrt(5)*R+5/3.*R2)*F.exp(-np.sqrt(5)*R),
            F.expand_dims(variance, axis=-2)) 
开发者ID:amzn,项目名称:MXFusion,代码行数:24,代码来源:matern.py

示例4: __init__

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def __init__(self,
                 num_var: int,
                 mean: nd_sym_type,
                 sigma: nd_sym_type,
                 F: ModuleType=mx.nd) -> None:
        """
        Distribution object for Multivariate Normal. Works with batches. 
        Optionally works with batches and time steps, but be consistent in usage: i.e. if using time_step,
        mean, sigma and data for log_prob must all include a time_step dimension.

        :param num_var: number of variables in distribution
        :param mean: mean for each variable,
            of shape (num_var) or
            of shape (batch_size, num_var) or
            of shape (batch_size, time_step, num_var).
        :param sigma: covariance matrix,
            of shape (num_var, num_var) or
            of shape (batch_size, num_var, num_var) or
            of shape (batch_size, time_step, num_var, num_var).
        :param (mx.nd or mx.sym) F: backend api (mx.sym if block has been hybridized).
        """
        self.num_var = num_var
        self.mean = mean
        self.sigma = sigma
        self.F = F 
开发者ID:NervanaSystems,项目名称:coach,代码行数:27,代码来源:ppo_head.py

示例5: hybrid_forward

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def hybrid_forward(self,
                       F: ModuleType,
                       x: Union[NDArray, Symbol],
                       gradient_rescaler: Union[NDArray, Symbol]) -> Tuple[Union[NDArray, Symbol], ...]:
        """ Overrides gluon.HybridBlock.hybrid_forward
        :param nd or sym F: ndarray or symbol module
        :param x: head input
        :param gradient_rescaler: gradient rescaler for partial blocking of gradient
        :return: head output
        """
        if self._onnx:
            # ONNX doesn't support BlockGrad() operator, but it's not typically needed for
            # ONNX because mostly forward calls are performed using ONNX exported network.
            grad_scaled_x = x
        else:
            grad_scaled_x = (F.broadcast_mul((1 - gradient_rescaler), F.BlockGrad(x)) +
                             F.broadcast_mul(gradient_rescaler, x))
        out = self.head(grad_scaled_x)
        return out 
开发者ID:NervanaSystems,项目名称:coach,代码行数:21,代码来源:general_network.py

示例6: test_forward_elemwise_ops

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_elemwise_ops():
    for op in ["elemwise_add", "elemwise_sub", "elemwise_mul",
               "elemwise_div", "maximum", "minimum",
               operator.lt, operator.le, operator.eq,
               operator.ne, operator.gt, operator.ge]:
        shape = (3, 4, 5)
        dtype = 'float32'
        a_np = np.random.uniform(size=shape).astype(dtype)
        b_np = np.random.uniform(size=shape).astype(dtype)
        if type(op) == str:
            mx_sym = _mx_symbol(mx.sym, op, [mx.sym.var('a'), mx.sym.var('b')])
            ref_res = _mx_symbol(mx.nd, op, [mx.nd.array(a_np), mx.nd.array(b_np)])
        else:
            mx_sym = op(mx.sym.var('a'), mx.sym.var('b'))
            ref_res = op(mx.nd.array(a_np), mx.nd.array(b_np))
        shapes = {'a': shape, 'b': shape}
        mod, _ = relay.frontend.from_mxnet(mx_sym, shapes, dtype)
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()(a_np, b_np)
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy()) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:24,代码来源:test_forward.py

示例7: test_forward_slice_axis

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_slice_axis():
    def verify(shape, axis, begin, end):
        data_np = np.random.uniform(size=shape).astype("float32")
        ref_res = mx.nd.slice_axis(mx.nd.array(data_np), axis, begin, end)
        mx_sym = mx.sym.slice_axis(mx.sym.var("data"), axis, begin, end)
        mod, _ = relay.frontend.from_mxnet(mx_sym, {"data": shape})
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()(data_np)
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())
    verify((3, 4), 0, 1, 2)
    verify((3, 4), 0, 1, None)
    verify((3, 4), 1, 0, 2)
    verify((3, 4), 1, -3, -1)
    verify((3, 4), -1, -3, -1) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:18,代码来源:test_forward.py

示例8: test_forward_slice_like

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_slice_like():
    def verify(x_shape, y_shape, axes):
        x_np = np.random.uniform(size=x_shape).astype("float32")
        y_np = np.random.uniform(size=y_shape).astype("float32")
        if axes is None:
            ref_res = mx.nd.slice_like(mx.nd.array(x_np), mx.nd.array(y_np))
            mx_sym = mx.sym.slice_like(mx.sym.var("x"), mx.sym.var("y"))
        else:
            ref_res = mx.nd.slice_like(mx.nd.array(x_np), mx.nd.array(y_np), axes=axes)
            mx_sym = mx.sym.slice_like(mx.sym.var("x"), mx.sym.var("y"), axes=axes)
        mod, _ = relay.frontend.from_mxnet(mx_sym, {"x": x_shape, "y": y_shape})
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()(x_np, y_np)
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())
    verify((3, 4), (2, 3), None)
    verify((3, 4), (2, 3), (0, 1))
    verify((3, 4), (2, 3), (0))
    verify((3, 4), (2, 3), (-1)) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:22,代码来源:test_forward.py

示例9: test_forward_squeeze

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_squeeze():
    def verify(shape, axis):
        x_np = np.random.uniform(size=shape).astype("float32")
        if axis is None:
            ref_res = mx.nd.squeeze(mx.nd.array(x_np))
            mx_sym = mx.sym.squeeze(mx.sym.var("x"))
        else:
            ref_res = mx.nd.squeeze(mx.nd.array(x_np), axis=axis)
            mx_sym = mx.sym.squeeze(mx.sym.var("x"), axis=axis)
        mod, _ = relay.frontend.from_mxnet(mx_sym, {"x": shape})
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()(x_np)
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())
    verify((1, 3, 1), None)
    verify((1, 3, 1), 0)
    verify((1, 3, 1), 2)
    verify((1, 3, 1), (0, 2)) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:21,代码来源:test_forward.py

示例10: test_forward_broadcast_axis

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_broadcast_axis():
    def verify(shape, axis, size):
        x_np = np.random.uniform(size=shape).astype("float32")
        for op in ["broadcast_axis",
                   "broadcast_axes"]:
            mx_sym = _mx_symbol(mx.sym, op, [mx.sym.var('x'),axis,size])
            ref_res = _mx_symbol(mx.nd, op, [mx.nd.array(x_np),axis,size])
            mod, _ = relay.frontend.from_mxnet(mx_sym, {"x": shape})
            for target, ctx in ctx_list():
                for kind in ["graph", "debug"]:
                    intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                    op_res = intrp.evaluate()(x_np)
                    tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())

    verify((1, 2, 1), 2, 3)
    verify((1, 2, 1), (0, 2), (2, 3)) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:18,代码来源:test_forward.py

示例11: test_forward_full

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_full():
    def verify(val, shape, dtype):
        ctx = mx.cpu()
        ref_res = mx.nd.full(shape, val, dtype=dtype)
        mx_sym = mx.sym.full(shape, val, dtype=dtype)
        mod, _ = relay.frontend.from_mxnet(mx_sym, {})
        for target, ctx in ctx_list():
            # Skip testing graph runtime because this op will be optimized out
            # by constant folding.
            for kind in ["debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()()
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())
    verify(2, (3, 4), "float32")
    verify(2, (3, 4), "int32")
    verify(3.5, (1, 3, 4), "float32") 
开发者ID:apache,项目名称:incubator-tvm,代码行数:18,代码来源:test_forward.py

示例12: test_forward_take

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_take():
    def verify(shape, indices_src, axis, mode="clip"):
        x_np = np.random.uniform(size=shape).astype("float32")
        indices_np = np.array(indices_src, dtype="float32")
        ref_res = mx.nd.take(mx.nd.array(x_np), mx.nd.array(indices_np), axis, mode)
        mx_sym = mx.sym.take(mx.sym.var("x"), mx.sym.var("y"), axis, mode)
        mod, _ = relay.frontend.from_mxnet(mx_sym, {"x": shape, "y": indices_np.shape})
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()(x_np, indices_np)
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())
    verify((2,2), [[[1,0],[0,1]]], 0)
    verify((2,2), [[[1,0],[0,1]]], 1)
    verify((4,3,5,6), [[2,1,0,0]], -2)
    verify((3,4), [-1, 5], 0)
    verify((3,4), [-1, 5], 0, mode="wrap")
    verify((3,4), [-1, 5], 1)
    verify((3,4), [-1, 5], 1, mode="wrap") 
开发者ID:apache,项目名称:incubator-tvm,代码行数:21,代码来源:test_forward.py

示例13: test_forward_gather_nd

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_gather_nd():
    def verify(xshape, yshape, y_data, error=False):
        x_data = np.random.uniform(size=xshape).astype("float32")
        ref_res = mx.nd.gather_nd(mx.nd.array(x_data), mx.nd.array(y_data))
        mx_sym = mx.sym.gather_nd(mx.sym.var("x_data"), mx.sym.var("y_data"))
        mod, _ = relay.frontend.from_mxnet(mx_sym, {"x_data": xshape, "y_data": yshape}, {"x_data": "float32", "y_data": "int32"})
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()(x_data, y_data)
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())

    verify((2, 2), (2, 3), [[1, 1, 0], [0, 1, 0]])
    verify((2, 2, 2), (2, 2), [[0, 1], [1, 0]])
    verify((3, 2, 2), (2, 2), [[0, 1], [1, 0]])
    verify((3, 2), (2, 2, 3), [[[0, 1, 2], [2, 0, 1]], [[0, 0, 0], [1, 1, 1]]])
    verify((1, 4), (1, 1), [[0]]) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:19,代码来源:test_forward.py

示例14: test_forward_grid_generator

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_grid_generator():
    def verify(shape, transform_type, target_shape):
        x = np.random.uniform(size=shape).astype("float32")
        ref_res = mx.nd.GridGenerator(mx.nd.array(x), transform_type, target_shape)
        mx_sym = mx.sym.GridGenerator(mx.sym.var("x"), transform_type, target_shape)
        shape_dict = {"x": x.shape}
        mod, _ = relay.frontend.from_mxnet(mx_sym, shape_dict)
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(
                    kind, mod=mod, ctx=ctx, target=target)
                op_res = intrp.evaluate()(x)
                tvm.testing.assert_allclose(
                    op_res.asnumpy(), ref_res.asnumpy(), rtol=1e-5, atol=1e-5)
    verify((4, 6), 'affine', (16, 32))
    verify((4, 2, 16, 16), 'warp', None)
    verify((1, 2, 16, 16), 'warp', None) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:19,代码来源:test_forward.py

示例15: test_forward_Crop

# 需要导入模块: import mxnet [as 别名]
# 或者: from mxnet import sym [as 别名]
def test_forward_Crop():
    def verify(xshape, yshape, offset=None):
        x_data = np.random.uniform(size=xshape).astype("float32")
        y_data = np.random.uniform(size=yshape).astype("float32")
        if offset is None:
            mx_sym = mx.sym.Crop(mx.sym.var("x"), mx.sym.var("y"))
            ref_res = mx.nd.Crop(mx.nd.array(x_data), mx.nd.array(y_data))
        else:
            mx_sym = mx.sym.Crop(mx.sym.var("x"), mx.sym.var("y"), offset=offset)
            ref_res = mx.nd.Crop(mx.nd.array(x_data), mx.nd.array(y_data), offset=offset)
        mod, _ = relay.frontend.from_mxnet(mx_sym, {"x": xshape, "y": yshape})
        for target, ctx in ctx_list():
            for kind in ["graph", "debug"]:
                intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
                if offset is None or offset == (0, 0):
                    op_res = intrp.evaluate()(x_data, y_data)
                else:
                    op_res = intrp.evaluate()(x_data)
                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy())
    verify((1, 3, 40, 40), (1, 3, 20, 20))
    verify((1, 3, 40, 40), (1, 3, 20, 20), (0, 0))
    verify((1, 3, 40, 40), (1, 3, 20, 20), (10, 10))
    verify((5, 32, 40, 40), (5, 32, 25, 25))
    verify((5, 32, 40, 40), (5, 32, 25, 25), (5, 5)) 
开发者ID:apache,项目名称:incubator-tvm,代码行数:26,代码来源:test_forward.py


注:本文中的mxnet.sym方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。