Example #1
0
    def __init__(self,
                 pipelines,
                 output_map,
                 size=-1,
                 reader_name=None,
                 auto_reset=False,
                 fill_last_batch=None,
                 dynamic_shape=False,
                 last_batch_padded=False,
                 last_batch_policy=LastBatchPolicy.FILL):

        # check the assert first as _DaliBaseIterator would run the prefetch
        assert len(set(output_map)) == len(
            output_map), "output_map names should be distinct"
        self._output_categories = set(output_map)
        self.output_map = output_map

        _DaliBaseIterator.__init__(self, pipelines, size, reader_name,
                                   auto_reset, fill_last_batch,
                                   last_batch_padded, last_batch_policy)
        self._dynamic_shape = dynamic_shape

        # Use double-buffering of data batches
        self._data_batches = [None for i in range(self._num_gpus)]

        self._first_batch = None
        try:
            self._first_batch = DALIGenericIterator.__next__(self)
        except StopIteration:
            assert False, "It seems that there is no data in the pipeline. This may happen if `last_batch_policy` is set to PARTIAL and the requested batch size is greater than the shard size."
Example #2
0
    def __init__(self,
                 pipelines,
                 output_map,
                 size=-1,
                 reader_name=None,
                 auto_reset=False,
                 fill_last_batch=True,
                 dynamic_shape=False,
                 last_batch_padded=False):

        _DaliBaseIterator.__init__(self, pipelines, size, reader_name,
                                   auto_reset, fill_last_batch,
                                   last_batch_padded)
        self._dynamic_shape = dynamic_shape

        # Use double-buffering of data batches
        self._data_batches = [None for i in range(self._num_gpus)]
        assert len(set(output_map)) == len(
            output_map), "output_map names should be distinct"
        self._output_categories = set(output_map)
        self.output_map = output_map

        # We need data about the batches (like shape information),
        # so we need to run a single batch as part of setup to get that info
        for p in self._pipes:
            with p._check_api_type_scope(types.PipelineAPIType.ITERATOR):
                p.schedule_run()
        self._first_batch = None
        self._first_batch = self.next()
Example #3
0
 def __init__(self,
              pipelines,
              size=-1,
              reader_name=None,
              fill_last_batch=False,
              last_batch_padded=False,
              auto_reset=False):
     _DaliBaseIterator.__init__(self, pipelines, size, reader_name, auto_reset, fill_last_batch, last_batch_padded)
Example #4
0
    def __init__(self,
                 pipelines,
                 output_map,
                 size=-1,
                 reader_name=None,
                 auto_reset=False,
                 fill_last_batch=None,
                 dynamic_shape=False,
                 last_batch_padded=False,
                 last_batch_policy=LastBatchPolicy.FILL,
                 prepare_first_batch=True):

        normalized_map = {}
        for v in output_map:
            if isinstance(v, str):
                normalized_map[v] = 0
            else:
                normalized_map[v[0]] = v[1]
        self.normalized_map = normalized_map

        # check the assert first as _DaliBaseIterator would run the prefetch
        output_map = [isinstance(v, str) and v or v[0] for v in output_map]
        assert len(set(output_map)) == len(output_map), \
            "output_map names should be distinct"
        self.output_map = output_map

        _DaliBaseIterator.__init__(self,
                                   pipelines,
                                   size,
                                   reader_name,
                                   auto_reset,
                                   fill_last_batch,
                                   last_batch_padded,
                                   last_batch_policy,
                                   prepare_first_batch=prepare_first_batch)

        self._counter = 0

        self._first_batch = None
        if self._prepare_first_batch:
            try:
                self._first_batch = DALIGenericIterator.__next__(self)
                # call to `next` sets _ever_consumed to True but if we are just calling it from
                # here we should set if to False again
                self._ever_consumed = False
            except StopIteration:
                assert False, "It seems that there is no data in the pipeline. This may happen " \
                       "if `last_batch_policy` is set to PARTIAL and the requested batch size is " \
                       "greater than the shard size."
Example #5
0
    def __init__(self,
                 pipelines,
                 output_map,
                 size=-1,
                 reader_name=None,
                 auto_reset=False,
                 fill_last_batch=None,
                 dynamic_shape=False,
                 last_batch_padded=False,
                 last_batch_policy=LastBatchPolicy.FILL,
                 prepare_first_batch=True):

        normalized_map = {}
        for v in output_map:
            if isinstance(v, str):
                normalized_map[v] = 0
            else:
                normalized_map[v[0]] = v[1]
        self.normalized_map = normalized_map

        # check the assert first as _DaliBaseIterator would run the prefetch
        output_map = [isinstance(v, str) and v or v[0] for v in output_map]
        assert len(set(output_map)) == len(output_map), \
            "output_map names should be distinct"
        self.output_map = output_map

        _DaliBaseIterator.__init__(self,
                                   pipelines,
                                   size,
                                   reader_name,
                                   auto_reset,
                                   fill_last_batch,
                                   last_batch_padded,
                                   last_batch_policy,
                                   prepare_first_batch=prepare_first_batch)
        self._dynamic_shape = dynamic_shape

        # Use double-buffering of data batches
        self._data_batches = [None for i in range(self._num_gpus)]
        self._counter = 0

        self._first_batch = None
        if self._prepare_first_batch:
            try:
                self._first_batch = DALIGenericIterator.__next__(self)
            except StopIteration:
                assert False, "It seems that there is no data in the pipeline. This may happen if `last_batch_policy` is set to PARTIAL and the requested batch size is greater than the shard size."
Example #6
0
 def __init__(self,
              pipelines,
              size=-1,
              reader_name=None,
              fill_last_batch=None,
              last_batch_padded=False,
              auto_reset=False,
              last_batch_policy=LastBatchPolicy.FILL,
              prepare_first_batch=True):
     _DaliBaseIterator.__init__(self,
                                pipelines,
                                size,
                                reader_name,
                                auto_reset,
                                fill_last_batch,
                                last_batch_padded,
                                last_batch_policy,
                                prepare_first_batch=prepare_first_batch)
Example #7
0
    def __init__(self,
                 pipelines,
                 output_map,
                 size=-1,
                 reader_name=None,
                 auto_reset=False,
                 fill_last_batch=True,
                 dynamic_shape=False,
                 last_batch_padded=False):
        _DaliBaseIterator.__init__(self, pipelines, size, reader_name,
                                   auto_reset, fill_last_batch,
                                   last_batch_padded)
        self._dynamic_shape = dynamic_shape

        # Use double-buffering of data batches
        self._data_batches = [None for i in range(self._num_gpus)]
        self._counter = 0

        normalized_map = {}
        for v in output_map:
            if isinstance(v, str):
                normalized_map[v] = 0
            else:
                normalized_map[v[0]] = v[1]
        self.normalized_map = normalized_map

        output_map = [isinstance(v, str) and v or v[0] for v in output_map]
        assert len(set(output_map)) == len(output_map), \
            "output_map names should be distinct"
        self.output_map = output_map

        # We need data about the batches (like shape information),
        # so we need to run a single batch as part of setup to get that info
        for p in self._pipes:
            with p._check_api_type_scope(types.PipelineAPIType.ITERATOR):
                p.schedule_run()
        self._first_batch = None
        self._first_batch = DALIGenericIterator.__next__(self)