Esempio n. 1
0
 def pack_all(self, output_dict: Dict):
     r"""Pack the prediction results ``output_dict`` back to the
     corresponding packs.
     """
     start = 0
     for i in range(len(self.batcher.data_pack_pool)):
         output_dict_i = slice_batch(output_dict, start,
                                     self.batcher.current_batch_sources[i])
         self.pack(self.batcher.data_pack_pool[i], output_dict_i)
         start += self.batcher.current_batch_sources[i]
Esempio n. 2
0
    def pack_all(
        self,
        packs: List[PackType],
        contexts: List[Optional[Annotation]],
        output_dict: Dict[str, List[Any]],
    ):
        r"""
        Pack the prediction results contained in the `output_dict` back to the
        corresponding packs.

        Args:
            packs: The list of data packs corresponding to the output batches.
            contexts: The list of contexts corresponding to the output batches.
            output_dict: Stores the output in a specific format. The keys
                are string names that specify data. The value is a list of
                data in the shape of (batch_size, Any). There might be
                additional structures inside `Any` as specific
                implementation choices.
        """
        # Group the same pack and context into the same segments.

        # The list of (pack, context) tuple.
        pack_context_pool = []
        # Store the segments of the pack context, the len of this list should
        # be the number of segments, and the value indicates the length of
        # the segment. These will be used to slice the data batch.
        segment_lengths = []

        # Note that this will work if the elements in `contexts` are all
        # None, which means they are all the same, and will have the correct
        # behavior.
        prev_pack_context = None
        for pack_context_i in zip(packs, contexts):
            if pack_context_i != prev_pack_context:
                segment_lengths.append(1)
                prev_pack_context = pack_context_i
                pack_context_pool.append(pack_context_i)
            else:
                segment_lengths[-1] += 1

        start = 0

        for i, (pack_i, context) in enumerate(pack_context_pool):
            # The slice should correspond to the portion of the data batch
            # that should be assigned to these pack and context.
            output_dict_i = slice_batch(output_dict, start, segment_lengths[i])
            self.pack(pack_i, output_dict_i, context)
            start += segment_lengths[i]
            pack_i.add_all_remaining_entries()
Esempio n. 3
0
    def pack_all(self, packs: List[PackType], output_dict: Dict):
        r"""Pack the prediction results ``output_dict`` back to the
        corresponding packs.
        """
        data_pack_pool = []
        current_batch_sources = []
        prev_pack = None
        for pack_i in packs:
            if pack_i != prev_pack:
                current_batch_sources.append(1)
                prev_pack = pack_i
                data_pack_pool.append(pack_i)
            else:
                current_batch_sources[-1] += 1

        start = 0
        for i, pack_i in enumerate(data_pack_pool):
            output_dict_i = slice_batch(output_dict, start,
                                        current_batch_sources[i])
            self.pack(pack_i, output_dict_i)
            start += current_batch_sources[i]
            pack_i.add_all_remaining_entries()