-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'layoutlm' of https://github.com/KevinNuNu/mmocr into la…
…youtlm
- Loading branch information
Showing
7 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from .base import BaseDumper | ||
from .huggingface_dumper import HuggingfaceDumper | ||
from .json_dumper import JsonDumper | ||
from .lmdb_dumper import TextRecogLMDBDumper | ||
from .wild_receipt_openset_dumper import WildreceiptOpensetDumper | ||
|
||
__all__ = [ | ||
'BaseDumper', 'JsonDumper', 'WildreceiptOpensetDumper', | ||
'TextRecogLMDBDumper' | ||
'TextRecogLMDBDumper', 'HuggingfaceDumper' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
import os.path as osp | ||
from collections import defaultdict | ||
from typing import Dict | ||
|
||
from datasets import Dataset, Image | ||
|
||
from mmocr.registry import DATA_DUMPERS | ||
from .base import BaseDumper | ||
|
||
|
||
@DATA_DUMPERS.register_module() | ||
class HuggingfaceDumper(BaseDumper): | ||
"""Semantic Entity Recognition and Relation Extraction huggingface datasets | ||
format dumper.""" | ||
|
||
def dump(self, data: Dict) -> None: | ||
"""Dump data to datasets format to disk. | ||
Args: | ||
data (Dict): MMOCR format data to be dumped. | ||
""" | ||
data_list = data.get('data_list', None) | ||
filename = f'{self.task}_{self.split}.huggingface' | ||
dst_file = osp.join(self.data_root, filename) | ||
|
||
merged_dict = defaultdict(list) | ||
for d in data_list: | ||
instances = d['instances'] | ||
img_path = osp.join(self.data_root, d['img_path']) | ||
merged_dict['image'].append(img_path) | ||
for k, v in instances.items(): | ||
merged_dict[k].append(v) | ||
ds = Dataset.from_dict(merged_dict) | ||
ds = ds.cast_column('image', Image()) | ||
# save to disk | ||
ds.save_to_disk(dst_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters