コード例 #1
0
def _load_ops():
    global _cpu_ops
    global _gpu_ops
    global _mixed_ops
    _cpu_ops = _cpu_ops.union(set(_b.RegisteredCPUOps()))
    _gpu_ops = _gpu_ops.union(set(_b.RegisteredGPUOps()))
    _mixed_ops = _mixed_ops.union(set(_b.RegisteredMixedOps()))
    _cpu_gpu_ops = _cpu_ops.union(_gpu_ops).union(_mixed_ops)
    ops_module = sys.modules[__name__]

    for op_reg_name in _cpu_gpu_ops:
        schema = _b.TryGetSchema(op_reg_name)
        make_hidden = schema.IsDocHidden() if schema else False
        op_full_name, submodule, op_name = _process_op_name(op_reg_name, make_hidden)
        module = _internal.get_submodule(ops_module, submodule)
        if not hasattr(module, op_name):
            op_class = python_op_factory(op_name, op_reg_name, op_device = "cpu")
            op_class.__module__ = module.__name__
            setattr(module, op_name, op_class)

            if op_name not in ["ExternalSource"]:
                _wrap_op(op_class, submodule)

            # The operator was inserted into nvidia.dali.ops.hidden module, let's import it here
            # so it would be usable, but not documented as coming from other module
            if make_hidden:
                parent_module = _internal.get_submodule(ops_module, submodule[:-1])
                setattr(parent_module, op_name, op_class)
コード例 #2
0
def main(argv):
    cpu_ops = set(b.RegisteredCPUOps())
    if '_TFRecordReader' in cpu_ops:
        cpu_ops.remove('_TFRecordReader')
        cpu_ops.add('TFRecordReader')
    gpu_ops = set(b.RegisteredGPUOps())
    mix_ops = set(b.RegisteredMixedOps())
    mix_ops.remove('MakeContiguous')
    support_ops = set(b.RegisteredSupportOps())
    all_ops = cpu_ops.union(gpu_ops).union(mix_ops).union(support_ops)
    op_name_max_len = len(max(all_ops, key=len))
    name_bar = op_name_max_len * '='
    formater = '{:{c}>{op_name_max_len}}  {:{c}>6}  {:{c}>6}  {:{c}>6}  {:{c}>7}\n'
    doc_table = ''
    doc_table += 'Below table lists all available operators and devices they can operate on.\n\n'
    doc_table += '.. |tick| image:: images/tick.gif\n'
    doc_table += formater.format('', '', '', '', '', op_name_max_len = op_name_max_len, c='=')
    doc_table += formater.format('Operator name', 'CPU', 'GPU', 'mixed', 'Support', op_name_max_len = op_name_max_len, c=' ')
    doc_table += formater.format('', '', '', '', '', op_name_max_len = op_name_max_len, c='=')
    for op in sorted(all_ops):
        is_cpu = '|tick|' if op in cpu_ops else ''
        is_gpu = '|tick|' if op in gpu_ops else ''
        is_mixed = '|tick|' if op in mix_ops else ''
        is_support = '|tick|' if op in support_ops else ''
        op_doc = formater.format(op, is_cpu, is_gpu, is_mixed, is_support, op_name_max_len = op_name_max_len, c=' ')
        doc_table += op_doc
    doc_table += formater.format('', '', '', '', '', op_name_max_len = op_name_max_len, c='=')
    with open(argv[0], 'w') as f:
        f.write(doc_table)
コード例 #3
0
def main(argv):
    cpu_ops = set(b.RegisteredCPUOps())
    if '_TFRecordReader' in cpu_ops:
        cpu_ops.remove('_TFRecordReader')
        cpu_ops.add('TFRecordReader')
    gpu_ops = set(b.RegisteredGPUOps())
    mix_ops = set(b.RegisteredMixedOps())
    support_ops = set(b.RegisteredSupportOps())
    all_ops = cpu_ops.union(gpu_ops).union(mix_ops).union(support_ops)
    link_string = '_'
    op_name_max_len = len(max(all_ops, key=len)) + len(link_string)
    name_bar = op_name_max_len * '='
    formater = '{:{c}<{op_name_max_len}}  {:{c}^6}  {:{c}^6}  {:{c}^6}  {:{c}^7} {:{c}^9}\n'
    doc_table = ''
    doc_table += 'Below table lists all available operators and devices they can operate on.\n\n'
    doc_table += '.. |v| image:: images/tick.gif\n'
    doc_table += formater.format('', '', '', '', '', '', op_name_max_len = op_name_max_len, c='=')
    doc_table += formater.format('Operator name', 'CPU', 'GPU', 'Mixed', 'Support', 'Sequences', op_name_max_len = op_name_max_len, c=' ')
    doc_table += formater.format('', '', '', '', '', '', op_name_max_len = op_name_max_len, c='=')
    for op in sorted(all_ops, key=lambda v: str(v).lower()):
        schema = b.GetSchema(op)
        is_cpu = '|v|' if op in cpu_ops else ''
        is_gpu = '|v|' if op in gpu_ops else ''
        is_mixed = '|v|' if op in mix_ops else ''
        is_support = '|v|' if op in support_ops else ''
        supports_seq = '|v|' if schema.AllowsSequences() or schema.IsSequenceOperator() else ''
        op_string = op + link_string
        op_doc = formater.format(op_string, is_cpu, is_gpu, is_mixed, is_support, supports_seq, op_name_max_len = op_name_max_len, c=' ')
        doc_table += op_doc
    doc_table += formater.format('', '', '', '', '', '', op_name_max_len = op_name_max_len, c='=')
    with open(argv[0], 'w') as f:
        f.write(doc_table)
コード例 #4
0
ファイル: ops.py プロジェクト: xeransis/DALI
def _docstring_generator(cls):
    __cpu_ops = set(b.RegisteredCPUOps())
    __cpu_ops.add("TFRecordReader")
    __gpu_ops = set(b.RegisteredGPUOps())
    __mix_ops = set(b.RegisteredMixedOps())
    __support_ops = set(b.RegisteredSupportOps())
    op_name = cls.__name__
    op_dev = []
    if op_name in __cpu_ops:
        op_dev.append("'CPU'")
    if op_name in __gpu_ops:
        op_dev.append("'GPU'")
    if op_name in __mix_ops:
        op_dev.append("'mixed'")
    if op_name in __support_ops:
        op_dev.append("'support'")
    pre_doc = "This is a " + ", ".join(op_dev) + " operator\n\n"

    schema = b.GetSchema(op_name)
    # insert tag to easily link to the operator
    ret = '.. _' + op_name + ':\n\n'
    ret += pre_doc
    ret += schema.Dox()
    ret += '\n'
    if schema.IsSequenceOperator():
        ret += "\nThis operator expects sequence inputs\n"
    elif schema.AllowsSequences():
        ret += "\nThis operator allows sequence inputs\n"
    ret += """
Parameters
----------
"""
    for arg in schema.GetArgumentNames():
        dtype = schema.GetArgumentType(arg)
        arg_name_doc = "`" + arg + "` : "
        ret += (
            arg_name_doc +
            _type_name_convert_to_string(dtype, schema.IsTensorArgument(arg)))
        if schema.IsArgumentOptional(arg):
            default_value_string = schema.GetArgumentDefaultValueString(arg)
            # Evaluating empty string results in an error
            # so we need to prevent that
            if default_value_string:
                default_value = eval(default_value_string)
            else:
                default_value = default_value_string
            if dtype == DALIDataType.STRING:
                default_value = "\'" + str(default_value) + "\'"
            ret += (", optional, default = " +
                    str(_type_convert_value(dtype, default_value)))
        indent = '\n' + " " * len(arg_name_doc)
        ret += indent
        ret += schema.GetArgumentDox(arg).replace("\n", indent)
        ret += '\n'
    return ret
コード例 #5
0
def _load_ops():
    _cpugpu_ops = (set(b.RegisteredCPUOps()).union(set(
        b.RegisteredGPUOps())).union(set(b.RegisteredMixedOps())))
    _support_ops = set(b.RegisteredSupportOps())
    for op_name in _cpugpu_ops:
        setattr(sys.modules[__name__], op_name,
                python_op_factory(op_name, op_device="cpu"))
    # add support ops
    for op_name in _support_ops:
        setattr(sys.modules[__name__], op_name,
                python_op_factory(op_name, op_device="support"))
コード例 #6
0
def _load_ops():
    global _cpu_ops
    global _gpu_ops
    global _mixed_ops
    _cpu_ops = _cpu_ops.union(set(b.RegisteredCPUOps()))
    _gpu_ops = _gpu_ops.union(set(b.RegisteredGPUOps()))
    _mixed_ops = _mixed_ops.union(set(b.RegisteredMixedOps()))
    _cpu_gpu_ops = _cpu_ops.union(_gpu_ops).union(_mixed_ops)
    for op_name in _cpu_gpu_ops:
        if not hasattr(sys.modules[__name__], op_name):
            setattr(sys.modules[__name__], op_name,
                    python_op_factory(op_name, op_device="cpu"))
コード例 #7
0
def _load_ops():
    global _cpu_ops
    global _gpu_ops
    global _mixed_ops
    _cpu_ops = _cpu_ops.union(set(_b.RegisteredCPUOps()))
    _gpu_ops = _gpu_ops.union(set(_b.RegisteredGPUOps()))
    _mixed_ops = _mixed_ops.union(set(_b.RegisteredMixedOps()))
    _cpu_gpu_ops = _cpu_ops.union(_gpu_ops).union(_mixed_ops)
    for op_name in _cpu_gpu_ops:
        if not hasattr(sys.modules[__name__], op_name):
            op_class = python_op_factory(op_name, op_device="cpu")
            setattr(sys.modules[__name__], op_name, op_class)
            if op_name not in ["ExternalSource"]:
                _wrap_op(op_class)
コード例 #8
0
ファイル: ops.py プロジェクト: xuezu29/DALI
def _load_ops():
    global _cpu_ops
    global _gpu_ops
    global _mixed_ops
    global _support_ops
    _cpu_ops = _cpu_ops.union(set(b.RegisteredCPUOps()))
    _gpu_ops = _gpu_ops.union(set(b.RegisteredGPUOps()))
    _mixed_ops = _mixed_ops.union(set(b.RegisteredMixedOps()))
    _cpu_gpu_ops = _cpu_ops.union(_gpu_ops).union(_mixed_ops)
    _support_ops = _support_ops.union(set(b.RegisteredSupportOps()))
    for op_name in _cpu_gpu_ops:
        setattr(sys.modules[__name__], op_name,
                python_op_factory(op_name, op_device = "cpu"))
    # add support ops
    for op_name in _support_ops:
        setattr(sys.modules[__name__], op_name,
                python_op_factory(op_name, op_device = "support"))
コード例 #9
0
def _load_ops():
    global _cpu_ops
    global _gpu_ops
    global _mixed_ops
    _cpu_ops = _cpu_ops.union(set(_b.RegisteredCPUOps()))
    _gpu_ops = _gpu_ops.union(set(_b.RegisteredGPUOps()))
    _mixed_ops = _mixed_ops.union(set(_b.RegisteredMixedOps()))
    _cpu_gpu_ops = _cpu_ops.union(_gpu_ops).union(_mixed_ops)
    ops_module = sys.modules[__name__]

    for op_reg_name in _cpu_gpu_ops:
        op_full_name, submodule, op_name = _process_op_name(op_reg_name)
        module = _internal.get_submodule(ops_module, submodule)
        if not hasattr(module, op_name):
            op_class = python_op_factory(op_name, op_reg_name, op_device="cpu")
            op_class.__module__ = module.__name__
            setattr(module, op_name, op_class)

            if op_name not in ["ExternalSource"]:
                _wrap_op(op_class, submodule)
コード例 #10
0
                    "{}] inputs, but received {}".format(
                        type(self).__name__, self._schema.MinNumInput(),
                        self._schema.MaxNumInput(), len(inputs)))

            op_instance = _OperatorInstance(inputs, self, **kwargs)
            op_instance.generate_outputs()

            if len(op_instance.outputs) == 1:
                return op_instance.outputs[0]
            return op_instance.outputs

    Operator.__name__ = str(name)
    return Operator


_cpugpu_ops = (set(b.RegisteredCPUOps()).union(set(
    b.RegisteredGPUOps())).union(set(b.RegisteredMixedOps())))
_support_ops = set(b.RegisteredSupportOps())
for op_name in _cpugpu_ops:
    setattr(sys.modules[__name__], op_name,
            python_op_factory(op_name, op_device="cpu"))
# add support ops
for op_name in _support_ops:
    setattr(sys.modules[__name__], op_name,
            python_op_factory(op_name, op_device="support"))

# custom wrappers around ops


class TFRecordReader(with_metaclass(_DaliOperatorMeta, object)):
    def __init__(self, path, index_path, features, **kwargs):