Exemple #1
0
    def next_pair(self):
        with self.lock:
            end_of_cycle = self.params.has_key(
                'db_cycle') and self.cycle >= self.params['db_cycle']
            if end_of_cycle:
                assert (self.params['db_cycle'] > 0)
                self.cycle = 0
                self.seq_index = len(self.db_items)
                self.init_randget(self.params['read_mode'])

            self.cycle += 1
            base_trans = None if self.params[
                'image_base_trans'] is None else self.params[
                    'image_base_trans'].sample()
            self.update_seq_index()
            if self.params['output_type'] == 'single_image':
                db_item = self.db_items[self.seq_index]
                assert (isinstance(db_item, util.DBImageItem))
                player = util.ImagePlayer(db_item,
                                          base_trans,
                                          None,
                                          None,
                                          length=1)
                return player, [0], None
            elif self.params['output_type'] == 'image_pair':
                imgset_1, second_index_1 = self.db_items[self.seq_index]
                self.update_seq_index()
                imgset_2, second_index_2 = self.db_items[self.seq_index]
                while second_index_1 == second_index_2:
                    self.update_seq_index()
                    imgset_2, second_index_2 = self.db_items[self.seq_index]

                player_1 = util.VideoPlayer(imgset_1, base_trans,
                                            self.params['image_frame_trans'])
                player_2 = util.VideoPlayer(imgset_2, base_trans,
                                            self.params['image_frame_trans'])

                set_indices_1 = range(second_index_1) + range(
                    second_index_1 + 1, player_1.length)
                self.rand_gen.shuffle(set_indices_1)
                first_index_1 = set_indices_1[:self.params['k_shot']]
                set_indices_2 = range(second_index_2) + range(
                    second_index_2 + 1, player_2.length)
                self.rand_gen.shuffle(set_indices_2)
                first_index_2 = set_indices_2[:self.params['k_shot']]

                # assert(len(set_indices_1) >= self.params['k_shot'])
                # self.rand_gen.shuffle(set_indices_1)
                # first_index = set_indices[:self.params['k_shot']]
                return player_1, player_2, first_index_1, first_index_2, second_index_1
            else:
                raise Exception(
                    'Only single_image and image_pair mode are supported')
Exemple #2
0
 def next_pair(self):
     with self.lock:
         end_of_cycle = 'db_cycle' in self.params and self.cycle >= self.params['db_cycle']
         if end_of_cycle:
             assert(self.params['db_cycle'] > 0)
             self.cycle = 0
             self.seq_index = len(self.db_items)
             self.init_randget(self.params['read_mode'])
             
         self.cycle += 1
         base_trans = None if self.params['image_base_trans'] is None else self.params['image_base_trans'].sample()
         self.update_seq_index()
         if self.params['output_type'] == 'single_image':
             db_item = self.db_items[self.seq_index]
             assert(isinstance(db_item, util.DBImageItem))
             player = util.ImagePlayer(db_item, base_trans, None, None, length = 1)
             return player, [0], None
         elif self.params['output_type'] == 'image_pair':
             imgset, second_index = self.db_items[self.seq_index]
             player = util.VideoPlayer(imgset, base_trans, self.params['image_frame_trans'])
             set_indices = list(range(second_index)) + list(range(second_index+1, player.length))
             assert(len(set_indices) >= self.params['k_shot'])
             self.rand_gen.shuffle(set_indices)
             first_index = set_indices[:self.params['k_shot']]
             return player, first_index, second_index
         else:
             raise Exception('Only single_image and image_pair mode are supported')