コード例 #1
0
ファイル: fn.py プロジェクト: hannahaih/DALI
 def fn_wrapper(*inputs, **kwargs):
     from nvidia.dali._debug_mode import _PipelineDebug
     current_pipeline = _PipelineDebug.current()
     if getattr(current_pipeline, '_debug_on', False):
         return current_pipeline._wrap_op_call(op_wrapper, inputs, kwargs)
     else:
         return op_wrapper(*inputs, **kwargs)
コード例 #2
0
def external_source(source=None, num_outputs=None, *, cycle=None, name=None, device="cpu",
                    layout=None, dtype=None, ndim=None, cuda_stream=None, use_copy_kernel=None,
                    batch=True, **kwargs):
    """Creates a data node which is populated with data from a Python source.
The data can be provided by the ``source`` function or iterable, or it can be provided by
``pipeline.feed_input(name, data, layout, cuda_stream)`` inside ``pipeline.iter_setup``.

In the case of the GPU input, it is the user responsibility to modify the
provided GPU memory content only using provided stream (DALI schedules a copy on it
and all work is properly queued). If no stream is provided feeding input blocks until the
provided memory is copied to the internal buffer.

.. note::
    :meth:`nvidia.dali.fn.external_source` operator is partially compatible with TensorFlow
    integration via :meth:`nvidia.dali.plugin.tf.experimental.DALIDatasetWithInputs`.
    Please refer to its documentation for details.

.. note::
    To return a batch of copies of the same tensor, use :func:`nvidia.dali.types.Constant`,
    which is more performant.
    """

    from nvidia.dali._debug_mode import _PipelineDebug

    def _external_source(source=None, num_outputs=None, *, cycle=None, name=None, device="cpu",
                         layout=None, dtype=None, ndim=None, cuda_stream=None, use_copy_kernel=None,
                         batch=True, **kwargs):
        if batch is None:
            batch = True

        if num_outputs is not None:
            if source is None:
                raise ValueError(
                    "The parameter ``num_outputs`` is only valid when using ``source`` to "
                    "provide data. To feed multiple external sources in ``feed_input``, "
                    "use multiple ``external_source`` nodes.")

        op = ExternalSource(device=device, num_outputs=num_outputs, source=source, cycle=cycle,
                            layout=layout, dtype=dtype, ndim=ndim, cuda_stream=cuda_stream,
                            use_copy_kernel=use_copy_kernel, batch=batch, **kwargs)
        return op(name=name)

    # Wrapper around external_source to switch between standard and debug mode.
    current_pipeline = _PipelineDebug.current()
    if getattr(current_pipeline, '_debug_on', False):
        return current_pipeline._external_source(
            source=source, num_outputs=num_outputs, cycle=cycle, name=name, device=device,
            layout=layout, batch=batch, **kwargs)
    else:
        return _external_source(source, num_outputs, cycle=cycle, name=name, device=device,
                                layout=layout, dtype=dtype, ndim=ndim, cuda_stream=cuda_stream,
                                use_copy_kernel=use_copy_kernel, batch=batch, **kwargs)