Exemplo n.º 1
0
    def __init__(self,
                 source=None,
                 num_outputs=None,
                 batch_size=-1,
                 cycle=None,
                 name=None,
                 layout=None,
                 batch=None,
                 batch_info=None):
        if name is not None and num_outputs is not None:
            raise ValueError(
                "`num_outputs` is not compatible with named `ExternalSource`")

        callback, source_desc = _get_callback_from_source(
            source, cycle, batch_info or False)

        self._name = name
        self._layout = layout
        self._num_outputs = num_outputs
        self._batch = batch
        self._batch_size = batch_size
        self._callback = callback
        self._source_desc = source_desc
        self._batch_info = batch_info
        self._current_iter = 0
        self._current_sample = 0
        self._feed_inputs = Queue()

        if callback is not None:
            arg_count = _accepted_arg_count(callback)
            if arg_count not in [0, 1]:
                raise TypeError(
                    "External source callback must be a callable with 0 or 1 argument"
                )
            self.accepts_arg = arg_count > 0
Exemplo n.º 2
0
 def __init__(self, callback, source_desc, is_multioutput, instances=[], *,
              cuda_stream=None, use_copy_kernel=None, batch=True, parallel=False,
              prefetch_queue_depth=None, batch_info=None):
     self.instances = list(instances)  # we need a copy!
     self.utilized_instances = self.instances
     self.is_multioutput = is_multioutput
     self.callback = callback
     self.source_desc = source_desc
     self._cuda_stream = cuda_stream
     self.use_copy_kernel = use_copy_kernel
     self.batch = batch
     self.batch_info = batch_info
     # Index of a batch within the epoch that will be returned from
     # get_batch or schedule_and_receive call. Contrary to Pipeline's
     # `epoch_idx` it is tracked separately by ExternalSourceGroup due to
     # prefetching of batches in parallel mode.
     self.current_iter = 0
     self.current_sample = 0
     self.parallel = parallel
     self.prefetch_queue_depth = prefetch_queue_depth
     if callback is not None:
         arg_count = _accepted_arg_count(callback)
         if arg_count not in [0, 1]:
             raise TypeError("External source callback must be a callable with 0 or 1 argument")
         self.accepts_arg = arg_count > 0