當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。