本文整理匯總了Python中mxnet.base.string_types方法的典型用法代碼示例。如果您正苦於以下問題:Python base.string_types方法的具體用法?Python base.string_types怎麽用?Python base.string_types使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mxnet.base
的用法示例。
在下文中一共展示了base.string_types方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _parse_default
# 需要導入模塊: from mxnet import base [as 別名]
# 或者: from mxnet.base import string_types [as 別名]
def _parse_default(self, target):
"""Helper function to parse default values."""
if not isinstance(target, (list, tuple)):
k, v, t = target, None, lambda x: x
elif len(target) == 1:
k, v, t = target[0], None, lambda x: x
elif len(target) == 2:
k, v, t = target[0], target[1], lambda x: x
elif len(target) > 2:
k, v, t = target[0], target[1], target[2]
else:
k = None # should raise
if not isinstance(k, string_types):
msg = "{} is not a valid target, (name, default) expected.".format(target)
raise ValueError(msg)
return k, v, t
示例2: __call__
# 需要導入模塊: from mxnet import base [as 別名]
# 或者: from mxnet.base import string_types [as 別名]
def __call__(self, attrs):
# apply custom check
if self._custom_check:
func, msg = self._custom_check
if not func(attrs):
raise RuntimeError("Check failed: {}".format(msg))
# get new op_name
if isinstance(self._op_name, string_types):
op_name = self._op_name
else:
assert callable(self._op_name), "op_name can either be string or callable"
op_name = self._op_name(attrs)
# convert attributes
new_attrs = {}
for k in attrs.keys():
if k in self._excludes:
raise NotImplementedError("Attribute {} not supported yet.".format(k))
elif k in self._ignores:
pass
elif k in self._transforms:
new_name, defaults, transform = self._parse_default(self._transforms[k])
if defaults is None:
new_attr = self._required_attr(attrs, k)
else:
new_attr = attrs.get(k, None)
if new_attr is None:
new_attrs[new_name] = defaults
else:
new_attrs[new_name] = transform(new_attr)
else:
# copy
new_attrs[k] = attrs[k]
# add extras
new_attrs.update(self._extras)
return op_name, new_attrs
示例3: _parse_bool
# 需要導入模塊: from mxnet import base [as 別名]
# 或者: from mxnet.base import string_types [as 別名]
def _parse_bool(self, value):
"""Helper function to parse default boolean values."""
if isinstance(value, string_types):
return value.strip().lower() in ['true', '1', 't', 'y', 'yes']
return bool(value)
示例4: _parse_network
# 需要導入模塊: from mxnet import base [as 別名]
# 或者: from mxnet.base import string_types [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
示例5: _parse_network
# 需要導入模塊: from mxnet import base [as 別名]
# 或者: from mxnet.base import string_types [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