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


Python symbol.Symbol方法代码示例

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


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

示例1: calibrate_quantized_sym

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def calibrate_quantized_sym(qsym, th_dict):
    if th_dict is None or len(th_dict) == 0:
        return qsym
    num_layer_outputs = len(th_dict)
    layer_output_names = []
    min_vals = []
    max_vals = []
    for k, v in th_dict.items():
        layer_output_names.append(k)
        min_vals.append(v[0])
        max_vals.append(v[1])

    calibrated_sym = SymbolHandle()
    check_call(_LIB.MXSetCalibTableToQuantizedSymbol(qsym.handle,
                                                     mx_uint(num_layer_outputs),
                                                     c_str_array(layer_output_names),
                                                     c_array(ctypes.c_float, min_vals),
                                                     c_array(ctypes.c_float, max_vals),
                                                     ctypes.byref(calibrated_sym)))
    return Symbol(calibrated_sym) 
开发者ID:hey-yahei,项目名称:Quantization.MXNet,代码行数:22,代码来源:freeze.py

示例2: forward

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def forward(self, *args):
        """
        Override forward() so that number of outputs can be automatically set
        """
        outputs = super(Head, self).forward(*args)
        if isinstance(outputs, tuple):
            num_outputs = len(outputs)
        else:
            assert isinstance(outputs, NDArray) or isinstance(outputs, Symbol)
            num_outputs = 1
        if self._num_outputs is None:
            self._num_outputs = num_outputs
        else:
            assert self._num_outputs == num_outputs, 'Number of outputs cannot change ({} != {})'.format(
                self._num_outputs, num_outputs)
        assert self._num_outputs == len(self.loss().input_schema.head_outputs)
        return outputs 
开发者ID:NervanaSystems,项目名称:coach,代码行数:19,代码来源:head.py

示例3: hybrid_forward

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [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

示例4: quantize_symbol

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def quantize_symbol(sym, excluded_symbols=[], offline_params=[],
                     quantized_dtype='uint8', calib_quantize_op=False):
    """
    Quantize symbol.
    :param sym: mxnet.symbol.Symbol
        The symbol to quantize.
    :param excluded_symbols: list of str
        The names of symbols to exclude.
    :param offline_params: list of str
        The names of parameters to quantize offline.
    :param quantized_dtype: {"int8", "uint8"}
        The data type that you will quantize to.
    :param calib_quantize_op: bool
        Calibrate or not.(Only for quantization online.
    :return: mxnet.symbol.Symbol
        The symbol that has been quantized.
    """
    assert isinstance(excluded_symbols, list)
    num_excluded_symbols = len(excluded_symbols)
    # exclude = [s.handle for s in excluded_symbols]

    assert isinstance(offline_params, list)
    offline = [c_str(k) for k in offline_params]
    num_offline = len(offline)

    out = SymbolHandle()
    check_call(_LIB.MXQuantizeSymbol(sym.handle,
                                     ctypes.byref(out),
                                     mx_uint(num_excluded_symbols),
                                     c_str_array(excluded_symbols),
                                     mx_uint(num_offline),
                                     c_array(ctypes.c_char_p, offline),
                                     c_str(quantized_dtype),
                                     ctypes.c_bool(calib_quantize_op)))
    return Symbol(out) 
开发者ID:hey-yahei,项目名称:Quantization.MXNet,代码行数:37,代码来源:freeze.py

示例5: quantize_params

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def quantize_params(qsym, params):
    """
    Quantize parameters.
    :param qsym: mxnet.symbol.Symbol
        The symbol that has been quantized by function `quantize_symbol`.
    :param params: dict with (pname, value) key-value pairs.
        `pname`: str
            The name of parameter.
        `value`: mxnet.nd.NDArry
            The value of parameter with dtype "float32".
    :return: dict with (pname, value) key-value pairs.
        `pname`: str
            The name of quantized parameter.
        `value`: mxnet.nd.NDArry
            The value of the parameter with dtype "uint8" or "int8".
    """
    inputs_name = qsym.list_arguments()
    quantized_params = {}
    for name in inputs_name:
        if name.endswith('_quantize'):
            original_name = name[:-len('_quantize')]
            val, vmin, vmax = nd.contrib.quantize(data=params[original_name],
                                                  min_range=params[original_name+"_min"],
                                                  max_range=params[original_name+"_max"],
                                                  out_type="int8")
            quantized_params[name] = val
            quantized_params[name+'_min'] = vmin
            quantized_params[name+'_max'] = vmax
        elif name in params:
            quantized_params[name] = params[name]
    return quantized_params 
开发者ID:hey-yahei,项目名称:Quantization.MXNet,代码行数:33,代码来源:freeze.py

示例6: _net2pb

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def _net2pb(net):
    if isinstance(net, HybridBlock):
        # TODO(junwu): may need a more approprite way to get symbol from a HybridBlock
        if not net._cached_graph:
            raise RuntimeError(
                "Please first call net.hybridize() and then run forward with "
                "this net at least once before calling add_graph().")
        net = net._cached_graph[1]
    elif not isinstance(net, Symbol):
        raise TypeError('only accepts mxnet.gluon.HybridBlock and mxnet.symbol.Symbol '
                        'as input network, received type {}'.format(str(type(net))))
    return _sym2pb(net) 
开发者ID:awslabs,项目名称:mxboard,代码行数:14,代码来源:summary.py

示例7: _loss_output

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def _loss_output(self, outputs: List[Tuple[Union[NDArray, Symbol], str]]):
        """
        Must be called on the output from hybrid_forward().
        Saves the returned output as the schema and returns output values in a list
        :return: list of output values
        """
        output_schema = [o[1] for o in outputs]
        assert self._output_schema is None or self._output_schema == output_schema
        self._output_schema = output_schema
        return tuple(o[0] for o in outputs) 
开发者ID:NervanaSystems,项目名称:coach,代码行数:12,代码来源:head.py

示例8: loss_forward

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def loss_forward(self, F, x, *args, **kwargs) -> List[Tuple[Union[NDArray, Symbol], str]]:
        """
        Similar to hybrid_forward, but returns list of (NDArray, type_str)
        """
        raise NotImplementedError 
开发者ID:NervanaSystems,项目名称:coach,代码行数:7,代码来源:head.py

示例9: _parse_network

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def _parse_network(network, outputs, inputs, pretrained, ctx, **kwargs):
    """Parse network with specified outputs and other arguments.

    Parameters
    ----------
    network : str or HybridBlock or Symbol
        Logic chain: load from gluoncv.model_zoo if network is string.
        Convert to Symbol if network is HybridBlock
    outputs : str or iterable of str
        The name of layers to be extracted as features.
    inputs : iterable of str
        The name of input datas.
    pretrained : bool
        Use pretrained parameters as in gluon.model_zoo
    ctx : Context
        The context, e.g. mxnet.cpu(), mxnet.gpu(0).

    Returns
    -------
    inputs : list of Symbol
        Network input Symbols, usually ['data']
    outputs : list of Symbol
        Network output Symbols, usually as features
    params : ParameterDict
        Network parameters.
    """
    inputs = list(inputs) if isinstance(inputs, tuple) else inputs
    for i, inp in enumerate(inputs):
        if isinstance(inp, string_types):
            inputs[i] = mx.sym.var(inp)
        assert isinstance(inputs[i], Symbol), "Network expects inputs are Symbols."
    if len(inputs) == 1:
        inputs = inputs[0]
    else:
        inputs = mx.sym.Group(inputs)
    params = None
    prefix = ''
    if isinstance(network, string_types):
        from ..model_zoo import get_model
        network = get_model(network, pretrained=pretrained, ctx=ctx, **kwargs)
    if isinstance(network, HybridBlock):
        params = network.collect_params()
        prefix = network._prefix
        network = network(inputs)
    assert isinstance(network, Symbol), \
        "FeatureExtractor requires the network argument to be either " \
        "str, HybridBlock or Symbol, but got %s" % type(network)

    if isinstance(outputs, string_types):
        outputs = [outputs]
    assert len(outputs) > 0, "At least one outputs must be specified."
    outputs = [out if out.endswith('_output') else out + '_output' for out in outputs]
    outputs = [network.get_internals()[prefix + out] for out in outputs]
    return inputs, outputs, params 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:56,代码来源:feature.py

示例10: _parse_network

# 需要导入模块: from mxnet import symbol [as 别名]
# 或者: from mxnet.symbol import Symbol [as 别名]
def _parse_network(network, outputs, inputs, pretrained, ctx):
    """Parse network with specified outputs and other arguments.

    Parameters
    ----------
    network : str or HybridBlock or Symbol
        Logic chain: load from gluon.model_zoo.vision if network is string.
        Convert to Symbol if network is HybridBlock
    outputs : str or iterable of str
        The name of layers to be extracted as features.
    inputs : iterable of str
        The name of input datas.
    pretrained : bool
        Use pretrained parameters as in gluon.model_zoo
    ctx : Context
        The context, e.g. mxnet.cpu(), mxnet.gpu(0).

    Returns
    -------
    inputs : list of Symbol
        Network input Symbols, usually ['data']
    outputs : list of Symbol
        Network output Symbols, usually as features
    params : ParameterDict
        Network parameters.
    """
    inputs = list(inputs) if isinstance(inputs, tuple) else inputs
    for i, inp in enumerate(inputs):
        if isinstance(inp, string_types):
            inputs[i] = mx.sym.var(inp)
        assert isinstance(inputs[i], Symbol), "Network expects inputs are Symbols."
    if len(inputs) == 1:
        inputs = inputs[0]
    else:
        inputs = mx.sym.Group(inputs)
    params = None
    prefix = ''
    if isinstance(network, string_types):
        network = vision.get_model(network, pretrained=pretrained, ctx=ctx)
    if isinstance(network, HybridBlock):
        params = network.collect_params()
        prefix = network._prefix
        network = network(inputs)
    assert isinstance(network, Symbol), \
        "FeatureExtractor requires the network argument to be either " \
        "str, HybridBlock or Symbol, but got %s"%type(network)

    if isinstance(outputs, string_types):
        outputs = [outputs]
    assert len(outputs) > 0, "At least one outputs must be specified."
    outputs = [out if out.endswith('_output') else out + '_output' for out in outputs]
    outputs = [network.get_internals()[prefix + out] for out in outputs]
    return inputs, outputs, params 
开发者ID:zzdang,项目名称:cascade_rcnn_gluon,代码行数:55,代码来源:feature.py


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