File size: 1,938 Bytes
24c4def
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Copyright (c) OpenMMLab. All rights reserved.
from unittest import TestCase

from mmocr.datasets import RecogTextDataset


class TestRecogTextDataset(TestCase):

    def test_txt_dataset(self):

        # test initialization
        dataset = RecogTextDataset(
            ann_file='tests/data/rec_toy_dataset/old_label.txt',
            data_prefix=dict(img_path='imgs'),
            parser_cfg=dict(
                type='LineStrParser',
                keys=['filename', 'text'],
                keys_idx=[0, 1]),
            pipeline=[])
        dataset.full_init()
        self.assertEqual(len(dataset), 10)
        self.assertEqual(len(dataset.load_data_list()), 10)

        # test load_data_list
        anno = dataset.load_data_list()
        self.assertIn(anno[0]['img_path'],
                      ['imgs/1223731.jpg', 'imgs\\1223731.jpg'])
        self.assertEqual(anno[0]['instances'][0]['text'], 'GRAND')
        self.assertIn(anno[1]['img_path'],
                      ['imgs/1223733.jpg', 'imgs\\1223733.jpg'])

        self.assertEqual(anno[1]['instances'][0]['text'], 'HOTEL')

    def test_jsonl_dataset(self):
        dataset = RecogTextDataset(
            ann_file='tests/data/rec_toy_dataset/old_label.jsonl',
            data_prefix=dict(img_path='imgs'),
            parser_cfg=dict(type='LineJsonParser', keys=['filename', 'text']),
            pipeline=[])
        dataset.full_init()
        self.assertEqual(len(dataset), 10)
        self.assertEqual(len(dataset.load_data_list()), 10)

        # test load_data_list
        anno = dataset.load_data_list()
        self.assertIn(anno[0]['img_path'],
                      ['imgs/1223731.jpg', 'imgs\\1223731.jpg'])
        self.assertEqual(anno[0]['instances'][0]['text'], 'GRAND')
        self.assertIn(anno[1]['img_path'],
                      ['imgs/1223733.jpg', 'imgs\\1223733.jpg'])
        self.assertEqual(anno[1]['instances'][0]['text'], 'HOTEL')