-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add the detext to beta dataset preparer #1874
Open
2019zhou
wants to merge
1
commit into
open-mmlab:main
Choose a base branch
from
2019zhou:dev_zhouzhou
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
detext_textdet_data_root = 'data/detext' | ||
|
||
detext_textdet_train = dict( | ||
type='OCRDataset', | ||
data_root=detext_textdet_data_root, | ||
ann_file='textdet_train.json', | ||
filter_cfg=dict(filter_empty_gt=True, min_size=32), | ||
pipeline=None) | ||
|
||
detext_textdet_test = dict( | ||
type='OCRDataset', | ||
data_root=detext_textdet_data_root, | ||
ann_file='textdet_test.json', | ||
test_mode=True, | ||
pipeline=None) |
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,14 @@ | ||
detext_textrecog_data_root = 'data/detext' | ||
|
||
detext_textrecog_train = dict( | ||
type='OCRDataset', | ||
data_root=detext_textrecog_data_root, | ||
ann_file='textrecog_train.json', | ||
pipeline=None) | ||
|
||
detext_textrecog_test = dict( | ||
type='OCRDataset', | ||
data_root=detext_textrecog_data_root, | ||
ann_file='textrecog_test.json', | ||
test_mode=True, | ||
pipeline=None) |
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,15 @@ | ||
detext_textspotting_data_root = 'data/detext' | ||
|
||
detext_textspotting_train = dict( | ||
type='OCRDataset', | ||
data_root=detext_textspotting_data_root, | ||
ann_file='textspotting_train.json', | ||
filter_cfg=dict(filter_empty_gt=True, min_size=32), | ||
pipeline=None) | ||
|
||
detext_textspotting_test = dict( | ||
type='OCRDataset', | ||
data_root=detext_textspotting_data_root, | ||
ann_file='textspotting_test.json', | ||
test_mode=True, | ||
pipeline=None) |
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,31 @@ | ||
Name: 'DETEXT' | ||
Paper: | ||
Title: A Database for Evaluating Text Extraction from Biomedical Literature Figures | ||
URL: http://cs-chan.com/doc/ESWA_2014A.pdf | ||
Venue: ESWA | ||
Year: '2015' | ||
BibTeX: '@article{article, | ||
author = {Yin, Xu-Cheng and Yang, Chun and Pei, Wei-Yi and Man, Haixia and Zhang, Jun and Learned-Miller, Erik and Yu, Hong}, | ||
year = {2015}, | ||
month = {05}, | ||
pages = {e0126200}, | ||
title = {DeTEXT: A Database for Evaluating Text Extraction from Biomedical Literature Figures}, | ||
volume = {10}, | ||
journal = {PloS one}, | ||
doi = {10.1371/journal.pone.0126200}}' | ||
Data: | ||
Website: https://rrc.cvc.uab.es/?ch=9 | ||
Language: | ||
- English | ||
Scene: | ||
- biomedical | ||
Granularity: | ||
- Word | ||
Tasks: | ||
- textrecog | ||
- textdet | ||
- textspotting | ||
License: | ||
Type: CC BY 1.0 | ||
Link: https://creativecommons.org/licenses/by/1.0/ | ||
Format: .txt |
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,63 @@ | ||
data_root = 'data/detext' | ||
cache_path = 'data/cache' | ||
|
||
train_preparer = dict( | ||
obtainer=dict( | ||
type='NaiveDataObtainer', | ||
cache_path=cache_path, | ||
files=[ | ||
dict( | ||
url='https://rrc.cvc.uab.es/downloads/' | ||
'ch9_training_images.zip', | ||
save_name='detext_textdet_train_img.zip', | ||
md5='e07161d6af1ef2f81f9ba0d2f904e377', | ||
content=['image'], | ||
mapping=[['detext_textdet_train_img', 'textdet_imgs/train']]), | ||
dict( | ||
url='https://rrc.cvc.uab.es/downloads/' | ||
'ch9_training_localization_transcription_gt.zip', | ||
save_name='detext_textdet_train_gt.zip', | ||
md5='ae4dfe155e61dcfeadd80f6b0fd15626', | ||
content=['annotation'], | ||
mapping=[['detext_textdet_train_gt', 'annotations/train']]), | ||
]), | ||
gatherer=dict( | ||
type='PairGatherer', | ||
img_suffixes=['.jpg'], | ||
rule=[r'(\w+)\.jpg', r'gt_\1.txt']), | ||
parser=dict(type='DetextDetAnnParser', encoding='utf-8-sig'), | ||
packer=dict(type='TextDetPacker'), | ||
dumper=dict(type='JsonDumper'), | ||
) | ||
|
||
test_preparer = dict( | ||
obtainer=dict( | ||
type='NaiveDataObtainer', | ||
cache_path=cache_path, | ||
files=[ | ||
dict( | ||
url='https://rrc.cvc.uab.es/downloads/' | ||
'ch9_validation_images.zip', | ||
save_name='detext_textdet_test_img.zip', | ||
md5='c6ffe0abe6f2d7b4d70e6883257308e0', | ||
content=['image'], | ||
mapping=[['detext_textdet_test_img', 'textdet_imgs/test']]), | ||
dict( | ||
url='https://rrc.cvc.uab.es/downloads/' | ||
'ch9_validation_localization_transcription_gt.zip', | ||
save_name='detext_textdet_test_gt.zip', | ||
md5='075c4b27ab2848c90ad5e87d9f922bc3', | ||
content=['annotation'], | ||
mapping=[['detext_textdet_test_gt', 'annotations/test']]), | ||
]), | ||
gatherer=dict( | ||
type='PairGatherer', | ||
img_suffixes=['.jpg', '.JPG'], | ||
rule=[r'img_(\d+)\.([jJ][pP][gG])', r'gt_img_\1.txt']), | ||
parser=dict(type='DetextDetAnnParser', encoding='utf-8-sig'), | ||
packer=dict(type='TextDetPacker'), | ||
dumper=dict(type='JsonDumper'), | ||
) | ||
|
||
delete = ['detext_textdet_train_img', 'annotations', 'detext_textdet_test_img'] | ||
config_generator = dict(type='TextDetConfigGenerator') |
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,9 @@ | ||
_base_ = ['textdet.py'] | ||
|
||
_base_.train_preparer.gatherer.img_dir = 'textdet_imgs/train' | ||
_base_.test_preparer.gatherer.img_dir = 'textdet_imgs/test' | ||
|
||
_base_.train_preparer.packer.type = 'TextRecogCropPacker' | ||
_base_.test_preparer.packer.type = 'TextRecogCropPacker' | ||
|
||
config_generator = dict(type='TextRecogConfigGenerator') |
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,8 @@ | ||
_base_ = ['textdet.py'] | ||
_base_.train_preparer.gatherer.img_dir = 'textdet_imgs/train' | ||
_base_.test_preparer.gatherer.img_dir = 'textdet_imgs/test' | ||
|
||
_base_.train_preparer.packer.type = 'TextSpottingPacker' | ||
_base_.test_preparer.packer.type = 'TextSpottingPacker' | ||
|
||
config_generator = dict(type='TextSpottingConfigGenerator') |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that |
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,68 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from typing import List, Optional, Tuple | ||
|
||
from mmocr.registry import DATA_PARSERS | ||
from mmocr.utils import bbox2poly | ||
from .base import BaseParser | ||
|
||
|
||
@DATA_PARSERS.register_module() | ||
class DetextDetAnnParser(BaseParser): | ||
"""Detext Txt Format Text Detection Annotation Parser. | ||
|
||
The original annotation format of this dataset is stored in txt files, | ||
which is formed as the following format: | ||
x1, y1, x2, y2, x3, y3, x4, y4, transcription | ||
|
||
Args: | ||
separator (str): The separator between each element in a line. Defaults | ||
to ','. | ||
ignore (str): The text to be ignored. Defaults to '###'. | ||
format (str): The format of the annotation. Defaults to | ||
'x1,y1,x2,y2,x3,y3,x4,trans'. | ||
encoding (str): The encoding of the annotation file. Defaults to | ||
'utf-8-sig'. | ||
nproc (int): The number of processes to parse the annotation. Defaults | ||
to 1. | ||
remove_strs (List[str], Optional): Used to remove redundant strings in | ||
the transcription. Defaults to None. | ||
mode (str, optional): The mode of the box converter. Supported modes | ||
are 'xywh' and 'xyxy'. Defaults to None. | ||
""" | ||
|
||
def __init__(self, | ||
separator: str = ',', | ||
ignore: str = '###', | ||
format: str = 'x1,y1,x2,y2,x3,y3,x4,y4,trans', | ||
encoding: str = 'utf-8', | ||
remove_strs: Optional[List[str]] = None, | ||
mode: str = None, | ||
**kwargs) -> None: | ||
self.sep = separator | ||
self.format = format | ||
self.encoding = encoding | ||
self.ignore = ignore | ||
self.mode = mode | ||
self.remove_strs = remove_strs | ||
super().__init__(**kwargs) | ||
|
||
def parse_file(self, img_path: str, ann_path: str) -> Tuple: | ||
"""Parse single annotation.""" | ||
instances = list() | ||
for anno in self.loader(ann_path, self.sep, self.format, | ||
self.encoding): | ||
anno = list(anno.values()) | ||
if self.remove_strs is not None: | ||
for strs in self.remove_strs: | ||
for i in range(len(anno)): | ||
if strs in anno[i]: | ||
anno[i] = anno[i].replace(strs, '') | ||
poly = list(map(float, anno[0:-1])) | ||
if self.mode is not None: | ||
poly = bbox2poly(poly, self.mode) | ||
poly = poly.tolist() | ||
text = anno[-1] | ||
instances.append( | ||
dict(poly=poly, text=text, ignore=text == self.ignore)) | ||
|
||
return img_path, instances |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As dataset preparer will generate this config, we can remove it from this PR. Same for configs/textrecog/base/datasets/detext.py and configs/textspotting/base/datasets/detext.py