(self, config, mode, logger, seed=None, epoch=1, task='rec')
| 37 | class RatioDataSetTVResizeTest(Dataset): |
| 38 | |
| 39 | def __init__(self, config, mode, logger, seed=None, epoch=1, task='rec'): |
| 40 | super(RatioDataSetTVResizeTest, self).__init__() |
| 41 | self.ds_width = config[mode]['dataset'].get('ds_width', True) |
| 42 | global_config = config['Global'] |
| 43 | dataset_config = config[mode]['dataset'] |
| 44 | loader_config = config[mode]['loader'] |
| 45 | max_ratio = loader_config.get('max_ratio', 10) |
| 46 | min_ratio = loader_config.get('min_ratio', 1) |
| 47 | data_dir_list = dataset_config['data_dir_list'] |
| 48 | self.do_shuffle = loader_config['shuffle'] |
| 49 | self.seed = epoch |
| 50 | self.max_text_length = global_config['max_text_length'] |
| 51 | data_source_num = len(data_dir_list) |
| 52 | ratio_list = dataset_config.get('ratio_list', 1.0) |
| 53 | if isinstance(ratio_list, (float, int)): |
| 54 | ratio_list = [float(ratio_list)] * int(data_source_num) |
| 55 | assert len( |
| 56 | ratio_list |
| 57 | ) == data_source_num, 'The length of ratio_list should be the same as the file_list.' |
| 58 | self.lmdb_sets = self.load_hierarchical_lmdb_dataset( |
| 59 | data_dir_list, ratio_list) |
| 60 | for data_dir in data_dir_list: |
| 61 | logger.info('Initialize indexs of datasets:%s' % data_dir) |
| 62 | self.logger = logger |
| 63 | data_idx_order_list = self.dataset_traversal() |
| 64 | character_dict_path = global_config.get('character_dict_path', None) |
| 65 | use_space_char = global_config.get('use_space_char', False) |
| 66 | if character_dict_path is None: |
| 67 | char_test = '0123456789abcdefghijklmnopqrstuvwxyz' |
| 68 | else: |
| 69 | char_test = '' |
| 70 | with open(character_dict_path, 'rb') as fin: |
| 71 | lines = fin.readlines() |
| 72 | for line in lines: |
| 73 | line = line.decode('utf-8').strip('\n').strip('\r\n') |
| 74 | char_test += line |
| 75 | if use_space_char: |
| 76 | char_test += ' ' |
| 77 | wh_ratio, data_idx_order_list = self.get_wh_ratio( |
| 78 | data_idx_order_list, char_test) |
| 79 | self.data_idx_order_list = np.array(data_idx_order_list) |
| 80 | wh_ratio = np.around(np.array(wh_ratio)) |
| 81 | self.wh_ratio = np.clip(wh_ratio, a_min=min_ratio, a_max=max_ratio) |
| 82 | for i in range(max_ratio + 1): |
| 83 | logger.info((1 * (self.wh_ratio == i)).sum()) |
| 84 | self.wh_ratio_sort = np.argsort(self.wh_ratio) |
| 85 | self.ops = create_operators(dataset_config['transforms'], |
| 86 | global_config) |
| 87 | |
| 88 | self.need_reset = True in [x < 1 for x in ratio_list] |
| 89 | self.error = 0 |
| 90 | self.base_shape = dataset_config.get( |
| 91 | 'base_shape', [[64, 64], [96, 48], [112, 40], [128, 32]]) |
| 92 | self.base_h = dataset_config.get('base_h', 32) |
| 93 | self.interpolation = T.InterpolationMode.BICUBIC |
| 94 | transforms = [] |
| 95 | transforms.extend([ |
| 96 | T.ToTensor(), |
nothing calls this directly
no test coverage detected