def test_not_installed(self): try: deprecation.not_installed('!@#$%^&**()')() except ImportError: pass module = deprecation.NotInstalled('!@#$%^&**()') try: module.func() except ImportError: pass
import numpy try: from onnx import mapping from onnx.backend.base import namedtupledict from onnx.helper import make_attribute from onnx.helper import make_graph from onnx.helper import make_model from onnx.helper import make_node from onnx.helper import make_tensor from onnx.helper import make_tensor_value_info from onnx.helper import printable_graph from onnx.numpy_helper import from_array except ImportError: from dragon.core.util import deprecation mapping = deprecation.NotInstalled('onnx') namedtupledict = deprecation.not_installed('onnx') make_attribute = deprecation.not_installed('onnx') make_graph = deprecation.not_installed('onnx') make_model = deprecation.not_installed('onnx') make_node = deprecation.not_installed('onnx') make_tensor = deprecation.not_installed('onnx') make_tensor_value_info = deprecation.not_installed('onnx') printable_graph = deprecation.not_installed('onnx') from_array = deprecation.not_installed('onnx') def add_attribute(node_proto, name, value): """Add a new attribute into the node proto.""" node_proto.attribute.extend([make_attribute(name, value)])
# along with the software. If not, See, # # <https://opensource.org/licenses/BSD-2-Clause> # # ------------------------------------------------------------ """Random ops.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function try: from nvidia.dali import ops except ImportError: from dragon.core.util import deprecation ops = deprecation.not_installed('nvidia.dali') class CoinFlip(object): """Sample values from a bernoulli distribution. Examples: ```python flip_rng = dali.ops.CoinFlip(0.5) value = flip_rng() ``` """ def __new__(cls, probability=0.5, **kwargs): """Create a ``CoinFlip`` operator.
from kpl_dataset.record import RecordDefine class KPLRecordMessage(object): """An enum-like class of available messages.""" BYTES = BasicType.ByteArray BYTEARRAY = BasicType.ByteArray FLOAT = BasicType.Float FLOAT64 = BasicType.Float INT = BasicType.Int INT64 = BasicType.Int STRING = BasicType.String except ImportError: from dragon.core.util import deprecation BasicType = deprecation.not_installed('kpl-dataset') RecordDefine = deprecation.not_installed('kpl-dataset') ReadOnlyDataset = deprecation.not_installed('kpl-dataset') WriteOnlyDataset = deprecation.not_installed('kpl-dataset') class KPLRecordProtocol(object): """Create a protocol for KPLRecord.""" def __new__(cls, descriptor): return cls.canonicalize(descriptor) @classmethod def canonicalize(cls, descriptor): """Canonicalize the descriptor for protocol.""" if isinstance(descriptor, dict): for k, v in descriptor.items():
# along with the software. If not, See, # # <https://opensource.org/licenses/BSD-2-Clause> # # ------------------------------------------------------------ from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy try: from onnx import TensorProto except ImportError: from dragon.core.util import deprecation TensorProto = deprecation.not_installed('ONNX') from dragon.vm.onnx.core import helper from dragon.vm.onnx.core.exporters import utils as export_util @export_util.register(['ArgMax', 'ArgMin']) def arg_reduce_exporter(op_def, context): node, const_tensors = export_util.translate(**locals()) # ONNX requires indices only, remove the values. indices = node.output[0] node.ClearField('output') node.output.extend([indices]) for arg in op_def.arg: if arg.name == 'axis': helper.add_attribute(node, 'axis', arg.i)