diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..95b81919741914b7050b79daa5223fbc518d9ea0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM docker.io/library/python:3.8.9@sha256:49d05fff9cb3b185b15ffd92d8e6bd61c20aa916133dca2e3dbe0215270faf53 +RUN mkdir app +COPY packages.txt /root/packages.txt +RUN apt-get update && xargs -r -a /root/packages.txt apt-get install -y +WORKDIR /home/user/app +RUN pip install datasets huggingface-hub +RUN apt-get update && apt-get install -y ffmpeg libsm6 libxext6 cmake libgl1-mesa-glx +RUN apt-get update && apt-get install -y git-lfs +RUN git lfs install + +RUN pip install torch torchvision torchaudio +RUN pip install openmim +RUN mim install mmcv-full +RUN mim install mmdet + +COPY requirements.txt /home/user/app/requirements.txt +RUN pip install -r requirements.txt +RUN useradd -m -u 1000 user +RUN pip install pip==22.0.2 +COPY --chown=user ./ /home/user/app diff --git a/app.py b/app.py index 2c8e231def3ec362ba295be614b8119b7f6a8388..ba0dc7c15689bf92affeb9e0672247572341bb09 100644 --- a/app.py +++ b/app.py @@ -6,13 +6,11 @@ from mmocr.utils.ocr import MMOCR # The default config path is based the current woking directory. -config_dir = os.path.join(os.path.dirname( - os.path.dirname(mmocr.__file__)), 'configs/') +config_dir = os.path.join( + os.path.dirname(__file__), 'configs/') # TODO: Put the model on HF hub. ocr = MMOCR(config_dir=config_dir) -results = ocr.readtext('demo_text_ocr.jpg', - output='.', print_result=True, imshow=True) def infer(image): # TODO: Also display bounding boxes diff --git a/configs/_base_/default_runtime.py b/configs/_base_/default_runtime.py new file mode 100644 index 0000000000000000000000000000000000000000..de7f9650ce73ba7ca633652b50df021b67498362 --- /dev/null +++ b/configs/_base_/default_runtime.py @@ -0,0 +1,17 @@ +# yapf:disable +log_config = dict( + interval=5, + hooks=[ + dict(type='TextLoggerHook') + ]) +# yapf:enable +dist_params = dict(backend='nccl') +log_level = 'INFO' +load_from = None +resume_from = None +workflow = [('train', 1)] + +# disable opencv multithreading to avoid system being overloaded +opencv_num_threads = 0 +# set multi-process start method as `fork` to speed up the training +mp_start_method = 'fork' diff --git a/configs/_base_/det_datasets/ctw1500.py b/configs/_base_/det_datasets/ctw1500.py new file mode 100644 index 0000000000000000000000000000000000000000..466ea7e1ea6871917bd6449019b48cd11c516a01 --- /dev/null +++ b/configs/_base_/det_datasets/ctw1500.py @@ -0,0 +1,18 @@ +dataset_type = 'IcdarDataset' +data_root = 'data/ctw1500' + +train = dict( + type=dataset_type, + ann_file=f'{data_root}/instances_training.json', + img_prefix=f'{data_root}/imgs', + pipeline=None) + +test = dict( + type=dataset_type, + ann_file=f'{data_root}/instances_test.json', + img_prefix=f'{data_root}/imgs', + pipeline=None) + +train_list = [train] + +test_list = [test] diff --git a/configs/_base_/det_datasets/icdar2015.py b/configs/_base_/det_datasets/icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..f711c06dce76d53b8737288c8de318e6f90ce585 --- /dev/null +++ b/configs/_base_/det_datasets/icdar2015.py @@ -0,0 +1,18 @@ +dataset_type = 'IcdarDataset' +data_root = 'data/icdar2015' + +train = dict( + type=dataset_type, + ann_file=f'{data_root}/instances_training.json', + img_prefix=f'{data_root}/imgs', + pipeline=None) + +test = dict( + type=dataset_type, + ann_file=f'{data_root}/instances_test.json', + img_prefix=f'{data_root}/imgs', + pipeline=None) + +train_list = [train] + +test_list = [test] diff --git a/configs/_base_/det_datasets/icdar2017.py b/configs/_base_/det_datasets/icdar2017.py new file mode 100644 index 0000000000000000000000000000000000000000..446ea7ef13a95be5e427994a7a61ed571d95db15 --- /dev/null +++ b/configs/_base_/det_datasets/icdar2017.py @@ -0,0 +1,18 @@ +dataset_type = 'IcdarDataset' +data_root = 'data/icdar2017' + +train = dict( + type=dataset_type, + ann_file=f'{data_root}/instances_training.json', + img_prefix=f'{data_root}/imgs', + pipeline=None) + +test = dict( + type=dataset_type, + ann_file=f'{data_root}/instances_val.json', + img_prefix=f'{data_root}/imgs', + pipeline=None) + +train_list = [train] + +test_list = [test] diff --git a/configs/_base_/det_datasets/synthtext.py b/configs/_base_/det_datasets/synthtext.py new file mode 100644 index 0000000000000000000000000000000000000000..fb9a44b3422dae5a9788d39b0901335dfc6076a9 --- /dev/null +++ b/configs/_base_/det_datasets/synthtext.py @@ -0,0 +1,18 @@ +dataset_type = 'TextDetDataset' +data_root = 'data/synthtext' + +train = dict( + type=dataset_type, + ann_file=f'{data_root}/instances_training.lmdb', + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='lmdb', + parser=dict( + type='LineJsonParser', + keys=['file_name', 'height', 'width', 'annotations'])), + img_prefix=f'{data_root}/imgs', + pipeline=None) + +train_list = [train] +test_list = [train] diff --git a/configs/_base_/det_datasets/toy_data.py b/configs/_base_/det_datasets/toy_data.py new file mode 100644 index 0000000000000000000000000000000000000000..512d1d20372a3fa3f662cc908c8cf4b66b35b797 --- /dev/null +++ b/configs/_base_/det_datasets/toy_data.py @@ -0,0 +1,41 @@ +root = 'tests/data/toy_dataset' + +# dataset with type='TextDetDataset' +train1 = dict( + type='TextDetDataset', + img_prefix=f'{root}/imgs', + ann_file=f'{root}/instances_test.txt', + loader=dict( + type='AnnFileLoader', + repeat=4, + file_format='txt', + parser=dict( + type='LineJsonParser', + keys=['file_name', 'height', 'width', 'annotations'])), + pipeline=None, + test_mode=False) + +# dataset with type='IcdarDataset' +train2 = dict( + type='IcdarDataset', + ann_file=f'{root}/instances_test.json', + img_prefix=f'{root}/imgs', + pipeline=None) + +test = dict( + type='TextDetDataset', + img_prefix=f'{root}/imgs', + ann_file=f'{root}/instances_test.txt', + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='txt', + parser=dict( + type='LineJsonParser', + keys=['file_name', 'height', 'width', 'annotations'])), + pipeline=None, + test_mode=True) + +train_list = [train1, train2] + +test_list = [test] diff --git a/configs/_base_/det_models/dbnet_r18_fpnc.py b/configs/_base_/det_models/dbnet_r18_fpnc.py new file mode 100644 index 0000000000000000000000000000000000000000..7507605d84f602dbfc0ce3b6b0519add917afe5f --- /dev/null +++ b/configs/_base_/det_models/dbnet_r18_fpnc.py @@ -0,0 +1,21 @@ +model = dict( + type='DBNet', + backbone=dict( + type='mmdet.ResNet', + depth=18, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='BN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet18'), + norm_eval=False, + style='caffe'), + neck=dict( + type='FPNC', in_channels=[64, 128, 256, 512], lateral_channels=256), + bbox_head=dict( + type='DBHead', + in_channels=256, + loss=dict(type='DBLoss', alpha=5.0, beta=10.0, bbce_loss=True), + postprocessor=dict(type='DBPostprocessor', text_repr_type='quad')), + train_cfg=None, + test_cfg=None) diff --git a/configs/_base_/det_models/dbnet_r50dcnv2_fpnc.py b/configs/_base_/det_models/dbnet_r50dcnv2_fpnc.py new file mode 100644 index 0000000000000000000000000000000000000000..1cd1f1baf011554c03c16575b69ebd94eae986b0 --- /dev/null +++ b/configs/_base_/det_models/dbnet_r50dcnv2_fpnc.py @@ -0,0 +1,23 @@ +model = dict( + type='DBNet', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='BN', requires_grad=True), + norm_eval=False, + style='pytorch', + dcn=dict(type='DCNv2', deform_groups=1, fallback_on_stride=False), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + stage_with_dcn=(False, True, True, True)), + neck=dict( + type='FPNC', in_channels=[256, 512, 1024, 2048], lateral_channels=256), + bbox_head=dict( + type='DBHead', + in_channels=256, + loss=dict(type='DBLoss', alpha=5.0, beta=10.0, bbce_loss=True), + postprocessor=dict(type='DBPostprocessor', text_repr_type='quad')), + train_cfg=None, + test_cfg=None) diff --git a/configs/_base_/det_models/dbnetpp_r50dcnv2_fpnc.py b/configs/_base_/det_models/dbnetpp_r50dcnv2_fpnc.py new file mode 100644 index 0000000000000000000000000000000000000000..f8eaf2ffd6efe9fa4ad63f5dc208f9b134a38380 --- /dev/null +++ b/configs/_base_/det_models/dbnetpp_r50dcnv2_fpnc.py @@ -0,0 +1,28 @@ +model = dict( + type='DBNet', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='BN', requires_grad=True), + norm_eval=False, + style='pytorch', + dcn=dict(type='DCNv2', deform_groups=1, fallback_on_stride=False), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + stage_with_dcn=(False, True, True, True)), + neck=dict( + type='FPNC', + in_channels=[256, 512, 1024, 2048], + lateral_channels=256, + asf_cfg=dict(attention_type='ScaleChannelSpatial')), + bbox_head=dict( + type='DBHead', + in_channels=256, + loss=dict(type='DBLoss', alpha=5.0, beta=10.0, bbce_loss=True), + postprocessor=dict( + type='DBPostprocessor', text_repr_type='quad', + epsilon_ratio=0.002)), + train_cfg=None, + test_cfg=None) diff --git a/configs/_base_/det_models/drrg_r50_fpn_unet.py b/configs/_base_/det_models/drrg_r50_fpn_unet.py new file mode 100644 index 0000000000000000000000000000000000000000..78156cca6030bcf7ac12b75287342915882eb0b3 --- /dev/null +++ b/configs/_base_/det_models/drrg_r50_fpn_unet.py @@ -0,0 +1,21 @@ +model = dict( + type='DRRG', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='BN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + norm_eval=True, + style='caffe'), + neck=dict( + type='FPN_UNet', in_channels=[256, 512, 1024, 2048], out_channels=32), + bbox_head=dict( + type='DRRGHead', + in_channels=32, + text_region_thr=0.3, + center_region_thr=0.4, + loss=dict(type='DRRGLoss'), + postprocessor=dict(type='DRRGPostprocessor', link_thr=0.80))) diff --git a/configs/_base_/det_models/fcenet_r50_fpn.py b/configs/_base_/det_models/fcenet_r50_fpn.py new file mode 100644 index 0000000000000000000000000000000000000000..3c2bd12b6295858895c53e5e1700df3962a8a7d5 --- /dev/null +++ b/configs/_base_/det_models/fcenet_r50_fpn.py @@ -0,0 +1,33 @@ +model = dict( + type='FCENet', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='BN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + norm_eval=False, + style='pytorch'), + neck=dict( + type='mmdet.FPN', + in_channels=[512, 1024, 2048], + out_channels=256, + add_extra_convs='on_output', + num_outs=3, + relu_before_extra_convs=True, + act_cfg=None), + bbox_head=dict( + type='FCEHead', + in_channels=256, + scales=(8, 16, 32), + fourier_degree=5, + loss=dict(type='FCELoss', num_sample=50), + postprocessor=dict( + type='FCEPostprocessor', + text_repr_type='quad', + num_reconstr_points=50, + alpha=1.2, + beta=1.0, + score_thr=0.3))) diff --git a/configs/_base_/det_models/fcenet_r50dcnv2_fpn.py b/configs/_base_/det_models/fcenet_r50dcnv2_fpn.py new file mode 100644 index 0000000000000000000000000000000000000000..8e76e39a6e8088ac20671f72fc5ed8448b21250b --- /dev/null +++ b/configs/_base_/det_models/fcenet_r50dcnv2_fpn.py @@ -0,0 +1,35 @@ +model = dict( + type='FCENet', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='BN', requires_grad=True), + norm_eval=True, + style='pytorch', + dcn=dict(type='DCNv2', deform_groups=2, fallback_on_stride=False), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + stage_with_dcn=(False, True, True, True)), + neck=dict( + type='mmdet.FPN', + in_channels=[512, 1024, 2048], + out_channels=256, + add_extra_convs='on_output', + num_outs=3, + relu_before_extra_convs=True, + act_cfg=None), + bbox_head=dict( + type='FCEHead', + in_channels=256, + scales=(8, 16, 32), + fourier_degree=5, + loss=dict(type='FCELoss', num_sample=50), + postprocessor=dict( + type='FCEPostprocessor', + text_repr_type='poly', + num_reconstr_points=50, + alpha=1.0, + beta=2.0, + score_thr=0.3))) diff --git a/configs/_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem.py b/configs/_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem.py new file mode 100644 index 0000000000000000000000000000000000000000..843fd36fc60682706503120f16866ba511cf7310 --- /dev/null +++ b/configs/_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem.py @@ -0,0 +1,126 @@ +# model settings +model = dict( + type='OCRMaskRCNN', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type='BN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + norm_eval=True, + style='pytorch'), + neck=dict( + type='mmdet.FPN', + in_channels=[256, 512, 1024, 2048], + out_channels=256, + num_outs=5), + rpn_head=dict( + type='RPNHead', + in_channels=256, + feat_channels=256, + anchor_generator=dict( + type='AnchorGenerator', + scales=[4], + ratios=[0.17, 0.44, 1.13, 2.90, 7.46], + strides=[4, 8, 16, 32, 64]), + bbox_coder=dict( + type='DeltaXYWHBBoxCoder', + target_means=[.0, .0, .0, .0], + target_stds=[1.0, 1.0, 1.0, 1.0]), + loss_cls=dict( + type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0), + loss_bbox=dict(type='L1Loss', loss_weight=1.0)), + roi_head=dict( + type='StandardRoIHead', + bbox_roi_extractor=dict( + type='SingleRoIExtractor', + roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0), + out_channels=256, + featmap_strides=[4, 8, 16, 32]), + bbox_head=dict( + type='Shared2FCBBoxHead', + in_channels=256, + fc_out_channels=1024, + roi_feat_size=7, + num_classes=1, + bbox_coder=dict( + type='DeltaXYWHBBoxCoder', + target_means=[0., 0., 0., 0.], + target_stds=[0.1, 0.1, 0.2, 0.2]), + reg_class_agnostic=False, + loss_cls=dict( + type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), + loss_bbox=dict(type='L1Loss', loss_weight=1.0)), + mask_roi_extractor=dict( + type='SingleRoIExtractor', + roi_layer=dict(type='RoIAlign', output_size=14, sampling_ratio=0), + out_channels=256, + featmap_strides=[4, 8, 16, 32]), + mask_head=dict( + type='FCNMaskHead', + num_convs=4, + in_channels=256, + conv_out_channels=256, + num_classes=1, + loss_mask=dict( + type='CrossEntropyLoss', use_mask=True, loss_weight=1.0))), + + # model training and testing settings + train_cfg=dict( + rpn=dict( + assigner=dict( + type='MaxIoUAssigner', + pos_iou_thr=0.7, + neg_iou_thr=0.3, + min_pos_iou=0.3, + match_low_quality=True, + ignore_iof_thr=-1, + gpu_assign_thr=50), + sampler=dict( + type='RandomSampler', + num=256, + pos_fraction=0.5, + neg_pos_ub=-1, + add_gt_as_proposals=False), + allowed_border=-1, + pos_weight=-1, + debug=False), + rpn_proposal=dict( + nms_across_levels=False, + nms_pre=2000, + nms_post=1000, + max_per_img=1000, + nms=dict(type='nms', iou_threshold=0.7), + min_bbox_size=0), + rcnn=dict( + assigner=dict( + type='MaxIoUAssigner', + pos_iou_thr=0.5, + neg_iou_thr=0.5, + min_pos_iou=0.5, + match_low_quality=True, + ignore_iof_thr=-1), + sampler=dict( + type='OHEMSampler', + num=512, + pos_fraction=0.25, + neg_pos_ub=-1, + add_gt_as_proposals=True), + mask_size=28, + pos_weight=-1, + debug=False)), + test_cfg=dict( + rpn=dict( + nms_across_levels=False, + nms_pre=1000, + nms_post=1000, + max_per_img=1000, + nms=dict(type='nms', iou_threshold=0.7), + min_bbox_size=0), + rcnn=dict( + score_thr=0.05, + nms=dict(type='nms', iou_threshold=0.5), + max_per_img=100, + mask_thr_binary=0.5))) diff --git a/configs/_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem_poly.py b/configs/_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem_poly.py new file mode 100644 index 0000000000000000000000000000000000000000..abbac26851d4eeef04fa904c8e69c50a58c2b54d --- /dev/null +++ b/configs/_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem_poly.py @@ -0,0 +1,126 @@ +# model settings +model = dict( + type='OCRMaskRCNN', + text_repr_type='poly', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type='BN', requires_grad=True), + norm_eval=True, + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + style='pytorch'), + neck=dict( + type='mmdet.FPN', + in_channels=[256, 512, 1024, 2048], + out_channels=256, + num_outs=5), + rpn_head=dict( + type='RPNHead', + in_channels=256, + feat_channels=256, + anchor_generator=dict( + type='AnchorGenerator', + scales=[4], + ratios=[0.17, 0.44, 1.13, 2.90, 7.46], + strides=[4, 8, 16, 32, 64]), + bbox_coder=dict( + type='DeltaXYWHBBoxCoder', + target_means=[.0, .0, .0, .0], + target_stds=[1.0, 1.0, 1.0, 1.0]), + loss_cls=dict( + type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0), + loss_bbox=dict(type='L1Loss', loss_weight=1.0)), + roi_head=dict( + type='StandardRoIHead', + bbox_roi_extractor=dict( + type='SingleRoIExtractor', + roi_layer=dict(type='RoIAlign', output_size=7, sample_num=0), + out_channels=256, + featmap_strides=[4, 8, 16, 32]), + bbox_head=dict( + type='Shared2FCBBoxHead', + in_channels=256, + fc_out_channels=1024, + roi_feat_size=7, + num_classes=80, + bbox_coder=dict( + type='DeltaXYWHBBoxCoder', + target_means=[0., 0., 0., 0.], + target_stds=[0.1, 0.1, 0.2, 0.2]), + reg_class_agnostic=False, + loss_cls=dict( + type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), + loss_bbox=dict(type='L1Loss', loss_weight=1.0)), + mask_roi_extractor=dict( + type='SingleRoIExtractor', + roi_layer=dict(type='RoIAlign', output_size=14, sample_num=0), + out_channels=256, + featmap_strides=[4, 8, 16, 32]), + mask_head=dict( + type='FCNMaskHead', + num_convs=4, + in_channels=256, + conv_out_channels=256, + num_classes=80, + loss_mask=dict( + type='CrossEntropyLoss', use_mask=True, loss_weight=1.0))), + # model training and testing settings + train_cfg=dict( + rpn=dict( + assigner=dict( + type='MaxIoUAssigner', + pos_iou_thr=0.7, + neg_iou_thr=0.3, + min_pos_iou=0.3, + match_low_quality=True, + ignore_iof_thr=-1), + sampler=dict( + type='RandomSampler', + num=256, + pos_fraction=0.5, + neg_pos_ub=-1, + add_gt_as_proposals=False), + allowed_border=-1, + pos_weight=-1, + debug=False), + rpn_proposal=dict( + nms_across_levels=False, + nms_pre=2000, + nms_post=1000, + max_per_img=1000, + nms=dict(type='nms', iou_threshold=0.7), + min_bbox_size=0), + rcnn=dict( + assigner=dict( + type='MaxIoUAssigner', + pos_iou_thr=0.5, + neg_iou_thr=0.5, + min_pos_iou=0.5, + match_low_quality=True, + ignore_iof_thr=-1, + gpu_assign_thr=50), + sampler=dict( + type='OHEMSampler', + num=512, + pos_fraction=0.25, + neg_pos_ub=-1, + add_gt_as_proposals=True), + mask_size=28, + pos_weight=-1, + debug=False)), + test_cfg=dict( + rpn=dict( + nms_across_levels=False, + nms_pre=1000, + nms_post=1000, + max_per_img=1000, + nms=dict(type='nms', iou_threshold=0.7), + min_bbox_size=0), + rcnn=dict( + score_thr=0.05, + nms=dict(type='nms', iou_threshold=0.5), + max_per_img=100, + mask_thr_binary=0.5))) diff --git a/configs/_base_/det_models/panet_r18_fpem_ffm.py b/configs/_base_/det_models/panet_r18_fpem_ffm.py new file mode 100644 index 0000000000000000000000000000000000000000..a69a4d87603275bc1f89b5f58c722d79274e4fd7 --- /dev/null +++ b/configs/_base_/det_models/panet_r18_fpem_ffm.py @@ -0,0 +1,43 @@ +model_poly = dict( + type='PANet', + backbone=dict( + type='mmdet.ResNet', + depth=18, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='SyncBN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet18'), + norm_eval=True, + style='caffe'), + neck=dict(type='FPEM_FFM', in_channels=[64, 128, 256, 512]), + bbox_head=dict( + type='PANHead', + in_channels=[128, 128, 128, 128], + out_channels=6, + loss=dict(type='PANLoss'), + postprocessor=dict(type='PANPostprocessor', text_repr_type='poly')), + train_cfg=None, + test_cfg=None) + +model_quad = dict( + type='PANet', + backbone=dict( + type='mmdet.ResNet', + depth=18, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='SyncBN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet18'), + norm_eval=True, + style='caffe'), + neck=dict(type='FPEM_FFM', in_channels=[64, 128, 256, 512]), + bbox_head=dict( + type='PANHead', + in_channels=[128, 128, 128, 128], + out_channels=6, + loss=dict(type='PANLoss'), + postprocessor=dict(type='PANPostprocessor', text_repr_type='quad')), + train_cfg=None, + test_cfg=None) diff --git a/configs/_base_/det_models/panet_r50_fpem_ffm.py b/configs/_base_/det_models/panet_r50_fpem_ffm.py new file mode 100644 index 0000000000000000000000000000000000000000..4d8812532c73f8945097de8262b539d0109055df --- /dev/null +++ b/configs/_base_/det_models/panet_r50_fpem_ffm.py @@ -0,0 +1,21 @@ +model = dict( + type='PANet', + pretrained='torchvision://resnet50', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=1, + norm_cfg=dict(type='BN', requires_grad=True), + norm_eval=True, + style='caffe'), + neck=dict(type='FPEM_FFM', in_channels=[256, 512, 1024, 2048]), + bbox_head=dict( + type='PANHead', + in_channels=[128, 128, 128, 128], + out_channels=6, + loss=dict(type='PANLoss', speedup_bbox_thr=32), + postprocessor=dict(type='PANPostprocessor', text_repr_type='poly')), + train_cfg=None, + test_cfg=None) diff --git a/configs/_base_/det_models/psenet_r50_fpnf.py b/configs/_base_/det_models/psenet_r50_fpnf.py new file mode 100644 index 0000000000000000000000000000000000000000..a3aff0d1325d3b9e25b5ed095cea28d313f611a0 --- /dev/null +++ b/configs/_base_/det_models/psenet_r50_fpnf.py @@ -0,0 +1,51 @@ +model_poly = dict( + type='PSENet', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='SyncBN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + norm_eval=True, + style='caffe'), + neck=dict( + type='FPNF', + in_channels=[256, 512, 1024, 2048], + out_channels=256, + fusion_type='concat'), + bbox_head=dict( + type='PSEHead', + in_channels=[256], + out_channels=7, + loss=dict(type='PSELoss'), + postprocessor=dict(type='PSEPostprocessor', text_repr_type='poly')), + train_cfg=None, + test_cfg=None) + +model_quad = dict( + type='PSENet', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='SyncBN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + norm_eval=True, + style='caffe'), + neck=dict( + type='FPNF', + in_channels=[256, 512, 1024, 2048], + out_channels=256, + fusion_type='concat'), + bbox_head=dict( + type='PSEHead', + in_channels=[256], + out_channels=7, + loss=dict(type='PSELoss'), + postprocessor=dict(type='PSEPostprocessor', text_repr_type='quad')), + train_cfg=None, + test_cfg=None) diff --git a/configs/_base_/det_models/textsnake_r50_fpn_unet.py b/configs/_base_/det_models/textsnake_r50_fpn_unet.py new file mode 100644 index 0000000000000000000000000000000000000000..7d74f376b8c635451a3036e780ffc88e7640bf2c --- /dev/null +++ b/configs/_base_/det_models/textsnake_r50_fpn_unet.py @@ -0,0 +1,22 @@ +model = dict( + type='TextSnake', + backbone=dict( + type='mmdet.ResNet', + depth=50, + num_stages=4, + out_indices=(0, 1, 2, 3), + frozen_stages=-1, + norm_cfg=dict(type='BN', requires_grad=True), + init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50'), + norm_eval=True, + style='caffe'), + neck=dict( + type='FPN_UNet', in_channels=[256, 512, 1024, 2048], out_channels=32), + bbox_head=dict( + type='TextSnakeHead', + in_channels=32, + loss=dict(type='TextSnakeLoss'), + postprocessor=dict( + type='TextSnakePostprocessor', text_repr_type='poly')), + train_cfg=None, + test_cfg=None) diff --git a/configs/_base_/det_pipelines/dbnet_pipeline.py b/configs/_base_/det_pipelines/dbnet_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..40eee02db3b68d5682841532d1122c92bdca2a65 --- /dev/null +++ b/configs/_base_/det_pipelines/dbnet_pipeline.py @@ -0,0 +1,88 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +train_pipeline_r18 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='ImgAug', + args=[['Fliplr', 0.5], + dict(cls='Affine', rotate=[-10, 10]), ['Resize', [0.5, 3.0]]]), + dict(type='EastRandomCrop', target_size=(640, 640)), + dict(type='DBNetTargets', shrink_ratio=0.4), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask'], + visualize=dict(flag=False, boundary_key='gt_shrink')), + dict( + type='Collect', + keys=['img', 'gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask']) +] + +test_pipeline_1333_736 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=(1333, 736), # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] + +# for dbnet_r50dcnv2_fpnc +img_norm_cfg_r50dcnv2 = dict( + mean=[122.67891434, 116.66876762, 104.00698793], + std=[58.395, 57.12, 57.375], + to_rgb=True) + +train_pipeline_r50dcnv2 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg_r50dcnv2), + dict( + type='ImgAug', + args=[['Fliplr', 0.5], + dict(cls='Affine', rotate=[-10, 10]), ['Resize', [0.5, 3.0]]]), + dict(type='EastRandomCrop', target_size=(640, 640)), + dict(type='DBNetTargets', shrink_ratio=0.4), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask'], + visualize=dict(flag=False, boundary_key='gt_shrink')), + dict( + type='Collect', + keys=['img', 'gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask']) +] + +test_pipeline_4068_1024 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=(4068, 1024), # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg_r50dcnv2), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] diff --git a/configs/_base_/det_pipelines/drrg_pipeline.py b/configs/_base_/det_pipelines/drrg_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..09189b51cda03d4557d58f5193366caeaf71bcc9 --- /dev/null +++ b/configs/_base_/det_pipelines/drrg_pipeline.py @@ -0,0 +1,60 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +train_pipeline = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='RandomScaling', size=800, scale=(0.75, 2.5)), + dict( + type='RandomCropFlip', crop_ratio=0.5, iter_num=1, min_area_ratio=0.2), + dict( + type='RandomCropPolyInstances', + instance_key='gt_masks', + crop_ratio=0.8, + min_side_ratio=0.3), + dict( + type='RandomRotatePolyInstances', + rotate_ratio=0.5, + max_angle=60, + pad_with_fixed_color=False), + dict(type='SquareResizePad', target_size=800, pad_ratio=0.6), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='DRRGTargets'), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=[ + 'gt_text_mask', 'gt_center_region_mask', 'gt_mask', + 'gt_top_height_map', 'gt_bot_height_map', 'gt_sin_map', + 'gt_cos_map', 'gt_comp_attribs' + ], + visualize=dict(flag=False, boundary_key='gt_text_mask')), + dict( + type='Collect', + keys=[ + 'img', 'gt_text_mask', 'gt_center_region_mask', 'gt_mask', + 'gt_top_height_map', 'gt_bot_height_map', 'gt_sin_map', + 'gt_cos_map', 'gt_comp_attribs' + ]) +] + +test_pipeline = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=(1024, 640), # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] diff --git a/configs/_base_/det_pipelines/fcenet_pipeline.py b/configs/_base_/det_pipelines/fcenet_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..badb4536b10bd74760fdf519fe03f5c8d2bd7767 --- /dev/null +++ b/configs/_base_/det_pipelines/fcenet_pipeline.py @@ -0,0 +1,118 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +# for icdar2015 +leval_prop_range_icdar2015 = ((0, 0.4), (0.3, 0.7), (0.6, 1.0)) +train_pipeline_icdar2015 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict( + type='ColorJitter', + brightness=32.0 / 255, + saturation=0.5, + contrast=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='RandomScaling', size=800, scale=(3. / 4, 5. / 2)), + dict( + type='RandomCropFlip', crop_ratio=0.5, iter_num=1, min_area_ratio=0.2), + dict( + type='RandomCropPolyInstances', + instance_key='gt_masks', + crop_ratio=0.8, + min_side_ratio=0.3), + dict( + type='RandomRotatePolyInstances', + rotate_ratio=0.5, + max_angle=30, + pad_with_fixed_color=False), + dict(type='SquareResizePad', target_size=800, pad_ratio=0.6), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='Pad', size_divisor=32), + dict( + type='FCENetTargets', + fourier_degree=5, + level_proportion_range=leval_prop_range_icdar2015), + dict( + type='CustomFormatBundle', + keys=['p3_maps', 'p4_maps', 'p5_maps'], + visualize=dict(flag=False, boundary_key=None)), + dict(type='Collect', keys=['img', 'p3_maps', 'p4_maps', 'p5_maps']) +] + +img_scale_icdar2015 = (2260, 2260) +test_pipeline_icdar2015 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_icdar2015, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] + +# for ctw1500 +leval_prop_range_ctw1500 = ((0, 0.25), (0.2, 0.65), (0.55, 1.0)) +train_pipeline_ctw1500 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict( + type='ColorJitter', + brightness=32.0 / 255, + saturation=0.5, + contrast=0.5), + dict(type='Normalize', **img_norm_cfg), + dict(type='RandomScaling', size=800, scale=(3. / 4, 5. / 2)), + dict( + type='RandomCropFlip', crop_ratio=0.5, iter_num=1, min_area_ratio=0.2), + dict( + type='RandomCropPolyInstances', + instance_key='gt_masks', + crop_ratio=0.8, + min_side_ratio=0.3), + dict( + type='RandomRotatePolyInstances', + rotate_ratio=0.5, + max_angle=30, + pad_with_fixed_color=False), + dict(type='SquareResizePad', target_size=800, pad_ratio=0.6), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='Pad', size_divisor=32), + dict( + type='FCENetTargets', + fourier_degree=5, + level_proportion_range=leval_prop_range_ctw1500), + dict( + type='CustomFormatBundle', + keys=['p3_maps', 'p4_maps', 'p5_maps'], + visualize=dict(flag=False, boundary_key=None)), + dict(type='Collect', keys=['img', 'p3_maps', 'p4_maps', 'p5_maps']) +] + +img_scale_ctw1500 = (1080, 736) +test_pipeline_ctw1500 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_ctw1500, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] diff --git a/configs/_base_/det_pipelines/maskrcnn_pipeline.py b/configs/_base_/det_pipelines/maskrcnn_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..fff3e071ea115843752f34de8141fa982b8ad14b --- /dev/null +++ b/configs/_base_/det_pipelines/maskrcnn_pipeline.py @@ -0,0 +1,57 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +train_pipeline = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict(type='LoadAnnotations', with_bbox=True, with_mask=True), + dict( + type='ScaleAspectJitter', + img_scale=None, + keep_ratio=False, + resize_type='indep_sample_in_range', + scale_range=(640, 2560)), + dict(type='RandomFlip', flip_ratio=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='RandomCropInstances', + target_size=(640, 640), + mask_type='union_all', + instance_key='gt_masks'), + dict(type='Pad', size_divisor=32), + dict(type='DefaultFormatBundle'), + dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_masks']), +] + +# for ctw1500 +img_scale_ctw1500 = (1600, 1600) +test_pipeline_ctw1500 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_ctw1500, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='RandomFlip'), + dict(type='Normalize', **img_norm_cfg), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] + +# for icdar2015 +img_scale_icdar2015 = (1920, 1920) +test_pipeline_icdar2015 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_icdar2015, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='RandomFlip'), + dict(type='Normalize', **img_norm_cfg), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] diff --git a/configs/_base_/det_pipelines/panet_pipeline.py b/configs/_base_/det_pipelines/panet_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..eae50de4fab0536d114509854f9250c0d613cb3c --- /dev/null +++ b/configs/_base_/det_pipelines/panet_pipeline.py @@ -0,0 +1,156 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +# for ctw1500 +img_scale_train_ctw1500 = [(3000, 640)] +shrink_ratio_train_ctw1500 = (1.0, 0.7) +target_size_train_ctw1500 = (640, 640) +train_pipeline_ctw1500 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='ScaleAspectJitter', + img_scale=img_scale_train_ctw1500, + ratio_range=(0.7, 1.3), + aspect_ratio_range=(0.9, 1.1), + multiscale_mode='value', + keep_ratio=False), + # shrink_ratio is from big to small. The 1st must be 1.0 + dict(type='PANetTargets', shrink_ratio=shrink_ratio_train_ctw1500), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='RandomRotateTextDet'), + dict( + type='RandomCropInstances', + target_size=target_size_train_ctw1500, + instance_key='gt_kernels'), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_kernels', 'gt_mask'], + visualize=dict(flag=False, boundary_key='gt_kernels')), + dict(type='Collect', keys=['img', 'gt_kernels', 'gt_mask']) +] + +img_scale_test_ctw1500 = (3000, 640) +test_pipeline_ctw1500 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_test_ctw1500, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] + +# for icdar2015 +img_scale_train_icdar2015 = [(3000, 736)] +shrink_ratio_train_icdar2015 = (1.0, 0.5) +target_size_train_icdar2015 = (736, 736) +train_pipeline_icdar2015 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='ScaleAspectJitter', + img_scale=img_scale_train_icdar2015, + ratio_range=(0.7, 1.3), + aspect_ratio_range=(0.9, 1.1), + multiscale_mode='value', + keep_ratio=False), + dict(type='PANetTargets', shrink_ratio=shrink_ratio_train_icdar2015), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='RandomRotateTextDet'), + dict( + type='RandomCropInstances', + target_size=target_size_train_icdar2015, + instance_key='gt_kernels'), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_kernels', 'gt_mask'], + visualize=dict(flag=False, boundary_key='gt_kernels')), + dict(type='Collect', keys=['img', 'gt_kernels', 'gt_mask']) +] + +img_scale_test_icdar2015 = (1333, 736) +test_pipeline_icdar2015 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_test_icdar2015, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] + +# for icdar2017 +img_scale_train_icdar2017 = [(3000, 800)] +shrink_ratio_train_icdar2017 = (1.0, 0.5) +target_size_train_icdar2017 = (800, 800) +train_pipeline_icdar2017 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='ScaleAspectJitter', + img_scale=img_scale_train_icdar2017, + ratio_range=(0.7, 1.3), + aspect_ratio_range=(0.9, 1.1), + multiscale_mode='value', + keep_ratio=False), + dict(type='PANetTargets', shrink_ratio=shrink_ratio_train_icdar2017), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='RandomRotateTextDet'), + dict( + type='RandomCropInstances', + target_size=target_size_train_icdar2017, + instance_key='gt_kernels'), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_kernels', 'gt_mask'], + visualize=dict(flag=False, boundary_key='gt_kernels')), + dict(type='Collect', keys=['img', 'gt_kernels', 'gt_mask']) +] + +img_scale_test_icdar2017 = (1333, 800) +test_pipeline_icdar2017 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_test_icdar2017, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] diff --git a/configs/_base_/det_pipelines/psenet_pipeline.py b/configs/_base_/det_pipelines/psenet_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..fd99dc3c2eb14921bbbf64ae861e5e5d6aa55c66 --- /dev/null +++ b/configs/_base_/det_pipelines/psenet_pipeline.py @@ -0,0 +1,70 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +train_pipeline = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='ScaleAspectJitter', + img_scale=[(3000, 736)], + ratio_range=(0.5, 3), + aspect_ratio_range=(1, 1), + multiscale_mode='value', + long_size_bound=1280, + short_size_bound=640, + resize_type='long_short_bound', + keep_ratio=False), + dict(type='PSENetTargets'), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='RandomRotateTextDet'), + dict( + type='RandomCropInstances', + target_size=(640, 640), + instance_key='gt_kernels'), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_kernels', 'gt_mask'], + visualize=dict(flag=False, boundary_key='gt_kernels')), + dict(type='Collect', keys=['img', 'gt_kernels', 'gt_mask']) +] + +# for ctw1500 +img_scale_test_ctw1500 = (1280, 1280) +test_pipeline_ctw1500 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_test_ctw1500, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] + +# for icdar2015 +img_scale_test_icdar2015 = (2240, 2240) +test_pipeline_icdar2015 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=img_scale_test_icdar2015, # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] diff --git a/configs/_base_/det_pipelines/textsnake_pipeline.py b/configs/_base_/det_pipelines/textsnake_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..dc4b44819e5c3f3f725df096903fc0a809313913 --- /dev/null +++ b/configs/_base_/det_pipelines/textsnake_pipeline.py @@ -0,0 +1,65 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) + +train_pipeline = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='RandomCropPolyInstances', + instance_key='gt_masks', + crop_ratio=0.65, + min_side_ratio=0.3), + dict( + type='RandomRotatePolyInstances', + rotate_ratio=0.5, + max_angle=20, + pad_with_fixed_color=False), + dict( + type='ScaleAspectJitter', + img_scale=[(3000, 736)], # unused + ratio_range=(0.7, 1.3), + aspect_ratio_range=(0.9, 1.1), + multiscale_mode='value', + long_size_bound=800, + short_size_bound=480, + resize_type='long_short_bound', + keep_ratio=False), + dict(type='SquareResizePad', target_size=800, pad_ratio=0.6), + dict(type='RandomFlip', flip_ratio=0.5, direction='horizontal'), + dict(type='TextSnakeTargets'), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=[ + 'gt_text_mask', 'gt_center_region_mask', 'gt_mask', + 'gt_radius_map', 'gt_sin_map', 'gt_cos_map' + ], + visualize=dict(flag=False, boundary_key='gt_text_mask')), + dict( + type='Collect', + keys=[ + 'img', 'gt_text_mask', 'gt_center_region_mask', 'gt_mask', + 'gt_radius_map', 'gt_sin_map', 'gt_cos_map' + ]) +] + +test_pipeline = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='MultiScaleFlipAug', + img_scale=(1333, 736), # used by Resize + flip=False, + transforms=[ + dict(type='Resize', keep_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='ImageToTensor', keys=['img']), + dict(type='Collect', keys=['img']), + ]) +] diff --git a/configs/_base_/recog_datasets/MJ_train.py b/configs/_base_/recog_datasets/MJ_train.py new file mode 100644 index 0000000000000000000000000000000000000000..be42cc47035d02403a036330eb0af7d0058b8675 --- /dev/null +++ b/configs/_base_/recog_datasets/MJ_train.py @@ -0,0 +1,21 @@ +# Text Recognition Training set, including: +# Synthetic Datasets: Syn90k + +train_root = 'data/mixture/Syn90k' + +train_img_prefix = f'{train_root}/mnt/ramdisk/max/90kDICT32px' +train_ann_file = f'{train_root}/label.lmdb' + +train = dict( + type='OCRDataset', + img_prefix=train_img_prefix, + ann_file=train_ann_file, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='lmdb', + parser=dict(type='LineJsonParser', keys=['filename', 'text'])), + pipeline=None, + test_mode=False) + +train_list = [train] diff --git a/configs/_base_/recog_datasets/ST_MJ_alphanumeric_train.py b/configs/_base_/recog_datasets/ST_MJ_alphanumeric_train.py new file mode 100644 index 0000000000000000000000000000000000000000..5fc1abac0a48b9deef3ac41353dc24d3748d2426 --- /dev/null +++ b/configs/_base_/recog_datasets/ST_MJ_alphanumeric_train.py @@ -0,0 +1,31 @@ +# Text Recognition Training set, including: +# Synthetic Datasets: SynthText, Syn90k +# Both annotations are filtered so that +# only alphanumeric terms are left + +train_root = 'data/mixture' + +train_img_prefix1 = f'{train_root}/Syn90k/mnt/ramdisk/max/90kDICT32px' +train_ann_file1 = f'{train_root}/Syn90k/label.lmdb' + +train1 = dict( + type='OCRDataset', + img_prefix=train_img_prefix1, + ann_file=train_ann_file1, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='lmdb', + parser=dict(type='LineJsonParser', keys=['filename', 'text'])), + pipeline=None, + test_mode=False) + +train_img_prefix2 = f'{train_root}/SynthText/' + \ + 'synthtext/SynthText_patch_horizontal' +train_ann_file2 = f'{train_root}/SynthText/alphanumeric_label.lmdb' + +train2 = {key: value for key, value in train1.items()} +train2['img_prefix'] = train_img_prefix2 +train2['ann_file'] = train_ann_file2 + +train_list = [train1, train2] diff --git a/configs/_base_/recog_datasets/ST_MJ_train.py b/configs/_base_/recog_datasets/ST_MJ_train.py new file mode 100644 index 0000000000000000000000000000000000000000..aedccc9df54829c2b841ba47882dea0cbcc8b23d --- /dev/null +++ b/configs/_base_/recog_datasets/ST_MJ_train.py @@ -0,0 +1,29 @@ +# Text Recognition Training set, including: +# Synthetic Datasets: SynthText, Syn90k + +train_root = 'data/mixture' + +train_img_prefix1 = f'{train_root}/Syn90k/mnt/ramdisk/max/90kDICT32px' +train_ann_file1 = f'{train_root}/Syn90k/label.lmdb' + +train1 = dict( + type='OCRDataset', + img_prefix=train_img_prefix1, + ann_file=train_ann_file1, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='lmdb', + parser=dict(type='LineJsonParser', keys=['filename', 'text'])), + pipeline=None, + test_mode=False) + +train_img_prefix2 = f'{train_root}/SynthText/' + \ + 'synthtext/SynthText_patch_horizontal' +train_ann_file2 = f'{train_root}/SynthText/label.lmdb' + +train2 = {key: value for key, value in train1.items()} +train2['img_prefix'] = train_img_prefix2 +train2['ann_file'] = train_ann_file2 + +train_list = [train1, train2] diff --git a/configs/_base_/recog_datasets/ST_SA_MJ_real_train.py b/configs/_base_/recog_datasets/ST_SA_MJ_real_train.py new file mode 100644 index 0000000000000000000000000000000000000000..87dab3352d92c3105684908f50b9b8f6bcc71a16 --- /dev/null +++ b/configs/_base_/recog_datasets/ST_SA_MJ_real_train.py @@ -0,0 +1,81 @@ +# Text Recognition Training set, including: +# Synthetic Datasets: SynthText, SynthAdd, Syn90k +# Real Dataset: IC11, IC13, IC15, COCO-Test, IIIT5k + +train_prefix = 'data/mixture' + +train_img_prefix1 = f'{train_prefix}/icdar_2011' +train_img_prefix2 = f'{train_prefix}/icdar_2013' +train_img_prefix3 = f'{train_prefix}/icdar_2015' +train_img_prefix4 = f'{train_prefix}/coco_text' +train_img_prefix5 = f'{train_prefix}/IIIT5K' +train_img_prefix6 = f'{train_prefix}/SynthText_Add' +train_img_prefix7 = f'{train_prefix}/SynthText' +train_img_prefix8 = f'{train_prefix}/Syn90k' + +train_ann_file1 = f'{train_prefix}/icdar_2011/train_label.txt', +train_ann_file2 = f'{train_prefix}/icdar_2013/train_label.txt', +train_ann_file3 = f'{train_prefix}/icdar_2015/train_label.txt', +train_ann_file4 = f'{train_prefix}/coco_text/train_label.txt', +train_ann_file5 = f'{train_prefix}/IIIT5K/train_label.txt', +train_ann_file6 = f'{train_prefix}/SynthText_Add/label.txt', +train_ann_file7 = f'{train_prefix}/SynthText/shuffle_labels.txt', +train_ann_file8 = f'{train_prefix}/Syn90k/shuffle_labels.txt' + +train1 = dict( + type='OCRDataset', + img_prefix=train_img_prefix1, + ann_file=train_ann_file1, + loader=dict( + type='AnnFileLoader', + repeat=20, + file_format='txt', + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=False) + +train2 = {key: value for key, value in train1.items()} +train2['img_prefix'] = train_img_prefix2 +train2['ann_file'] = train_ann_file2 + +train3 = {key: value for key, value in train1.items()} +train3['img_prefix'] = train_img_prefix3 +train3['ann_file'] = train_ann_file3 + +train4 = {key: value for key, value in train1.items()} +train4['img_prefix'] = train_img_prefix4 +train4['ann_file'] = train_ann_file4 + +train5 = {key: value for key, value in train1.items()} +train5['img_prefix'] = train_img_prefix5 +train5['ann_file'] = train_ann_file5 + +train6 = dict( + type='OCRDataset', + img_prefix=train_img_prefix6, + ann_file=train_ann_file6, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='txt', + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=False) + +train7 = {key: value for key, value in train6.items()} +train7['img_prefix'] = train_img_prefix7 +train7['ann_file'] = train_ann_file7 + +train8 = {key: value for key, value in train6.items()} +train8['img_prefix'] = train_img_prefix8 +train8['ann_file'] = train_ann_file8 + +train_list = [train1, train2, train3, train4, train5, train6, train7, train8] diff --git a/configs/_base_/recog_datasets/ST_SA_MJ_train.py b/configs/_base_/recog_datasets/ST_SA_MJ_train.py new file mode 100644 index 0000000000000000000000000000000000000000..bc272bf9fad66ab89de3dd672618a7ae01c142f7 --- /dev/null +++ b/configs/_base_/recog_datasets/ST_SA_MJ_train.py @@ -0,0 +1,48 @@ +# Text Recognition Training set, including: +# Synthetic Datasets: SynthText, Syn90k + +train_root = 'data/mixture' + +train_img_prefix1 = f'{train_root}/Syn90k/mnt/ramdisk/max/90kDICT32px' +train_ann_file1 = f'{train_root}/Syn90k/label.lmdb' + +train1 = dict( + type='OCRDataset', + img_prefix=train_img_prefix1, + ann_file=train_ann_file1, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='lmdb', + parser=dict(type='LineJsonParser', keys=['filename', 'text'])), + pipeline=None, + test_mode=False) + +train_img_prefix2 = f'{train_root}/SynthText/' + \ + 'synthtext/SynthText_patch_horizontal' +train_ann_file2 = f'{train_root}/SynthText/label.lmdb' + +train_img_prefix3 = f'{train_root}/SynthText_Add' +train_ann_file3 = f'{train_root}/SynthText_Add/label.txt' + +train2 = {key: value for key, value in train1.items()} +train2['img_prefix'] = train_img_prefix2 +train2['ann_file'] = train_ann_file2 + +train3 = dict( + type='OCRDataset', + img_prefix=train_img_prefix3, + ann_file=train_ann_file3, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='txt', + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=False) + +train_list = [train1, train2, train3] diff --git a/configs/_base_/recog_datasets/ST_charbox_train.py b/configs/_base_/recog_datasets/ST_charbox_train.py new file mode 100644 index 0000000000000000000000000000000000000000..45d50d0d151fca5c4e9118d1f6b1f094f8a51324 --- /dev/null +++ b/configs/_base_/recog_datasets/ST_charbox_train.py @@ -0,0 +1,23 @@ +# Text Recognition Training set, including: +# Synthetic Datasets: SynthText (with character level boxes) + +train_img_root = 'data/mixture' + +train_img_prefix = f'{train_img_root}/SynthText' + +train_ann_file = f'{train_img_root}/SynthText/instances_train.txt' + +train = dict( + type='OCRSegDataset', + img_prefix=train_img_prefix, + ann_file=train_ann_file, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='txt', + parser=dict( + type='LineJsonParser', keys=['file_name', 'annotations', 'text'])), + pipeline=None, + test_mode=False) + +train_list = [train] diff --git a/configs/_base_/recog_datasets/academic_test.py b/configs/_base_/recog_datasets/academic_test.py new file mode 100644 index 0000000000000000000000000000000000000000..888ab3d3be5b40e15596086d4af567bd37f6ec05 --- /dev/null +++ b/configs/_base_/recog_datasets/academic_test.py @@ -0,0 +1,57 @@ +# Text Recognition Testing set, including: +# Regular Datasets: IIIT5K, SVT, IC13 +# Irregular Datasets: IC15, SVTP, CT80 + +test_root = 'data/mixture' + +test_img_prefix1 = f'{test_root}/IIIT5K/' +test_img_prefix2 = f'{test_root}/svt/' +test_img_prefix3 = f'{test_root}/icdar_2013/' +test_img_prefix4 = f'{test_root}/icdar_2015/' +test_img_prefix5 = f'{test_root}/svtp/' +test_img_prefix6 = f'{test_root}/ct80/' + +test_ann_file1 = f'{test_root}/IIIT5K/test_label.txt' +test_ann_file2 = f'{test_root}/svt/test_label.txt' +test_ann_file3 = f'{test_root}/icdar_2013/test_label_1015.txt' +test_ann_file4 = f'{test_root}/icdar_2015/test_label.txt' +test_ann_file5 = f'{test_root}/svtp/test_label.txt' +test_ann_file6 = f'{test_root}/ct80/test_label.txt' + +test1 = dict( + type='OCRDataset', + img_prefix=test_img_prefix1, + ann_file=test_ann_file1, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='txt', + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=True) + +test2 = {key: value for key, value in test1.items()} +test2['img_prefix'] = test_img_prefix2 +test2['ann_file'] = test_ann_file2 + +test3 = {key: value for key, value in test1.items()} +test3['img_prefix'] = test_img_prefix3 +test3['ann_file'] = test_ann_file3 + +test4 = {key: value for key, value in test1.items()} +test4['img_prefix'] = test_img_prefix4 +test4['ann_file'] = test_ann_file4 + +test5 = {key: value for key, value in test1.items()} +test5['img_prefix'] = test_img_prefix5 +test5['ann_file'] = test_ann_file5 + +test6 = {key: value for key, value in test1.items()} +test6['img_prefix'] = test_img_prefix6 +test6['ann_file'] = test_ann_file6 + +test_list = [test1, test2, test3, test4, test5, test6] diff --git a/configs/_base_/recog_datasets/seg_toy_data.py b/configs/_base_/recog_datasets/seg_toy_data.py new file mode 100644 index 0000000000000000000000000000000000000000..7f0b7d8f4c520ec7847d69743d8e430b8795b656 --- /dev/null +++ b/configs/_base_/recog_datasets/seg_toy_data.py @@ -0,0 +1,34 @@ +prefix = 'tests/data/ocr_char_ann_toy_dataset/' + +train = dict( + type='OCRSegDataset', + img_prefix=f'{prefix}/imgs', + ann_file=f'{prefix}/instances_train.txt', + loader=dict( + type='AnnFileLoader', + repeat=100, + file_format='txt', + parser=dict( + type='LineJsonParser', keys=['file_name', 'annotations', 'text'])), + pipeline=None, + test_mode=True) + +test = dict( + type='OCRDataset', + img_prefix=f'{prefix}/imgs', + ann_file=f'{prefix}/instances_test.txt', + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='txt', + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=True) + +train_list = [train] + +test_list = [test] diff --git a/configs/_base_/recog_datasets/toy_data.py b/configs/_base_/recog_datasets/toy_data.py new file mode 100755 index 0000000000000000000000000000000000000000..259f14943c027f2719ebf30858ee9572ff5584ea --- /dev/null +++ b/configs/_base_/recog_datasets/toy_data.py @@ -0,0 +1,54 @@ +dataset_type = 'OCRDataset' + +root = 'tests/data/ocr_toy_dataset' +img_prefix = f'{root}/imgs' +train_anno_file1 = f'{root}/label.txt' + +train1 = dict( + type=dataset_type, + img_prefix=img_prefix, + ann_file=train_anno_file1, + loader=dict( + type='AnnFileLoader', + repeat=100, + file_format='txt', + file_storage_backend='disk', + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=False) + +train_anno_file2 = f'{root}/label.lmdb' +train2 = dict( + type=dataset_type, + img_prefix=img_prefix, + ann_file=train_anno_file2, + loader=dict( + type='AnnFileLoader', + repeat=100, + file_format='lmdb', + file_storage_backend='disk', + parser=dict(type='LineJsonParser', keys=['filename', 'text'])), + pipeline=None, + test_mode=False) + +test_anno_file1 = f'{root}/label.lmdb' +test = dict( + type=dataset_type, + img_prefix=img_prefix, + ann_file=test_anno_file1, + loader=dict( + type='AnnFileLoader', + repeat=1, + file_format='lmdb', + file_storage_backend='disk', + parser=dict(type='LineJsonParser', keys=['filename', 'text'])), + pipeline=None, + test_mode=True) + +train_list = [train1, train2] + +test_list = [test] diff --git a/configs/_base_/recog_models/abinet.py b/configs/_base_/recog_models/abinet.py new file mode 100644 index 0000000000000000000000000000000000000000..19c6b66731f0b205741037ece8d6b49f91d0110b --- /dev/null +++ b/configs/_base_/recog_models/abinet.py @@ -0,0 +1,70 @@ +# num_chars depends on the configuration of label_convertor. The actual +# dictionary size is 36 + 1 (). +# TODO: Automatically update num_chars based on the configuration of +# label_convertor +num_chars = 37 +max_seq_len = 26 + +label_convertor = dict( + type='ABIConvertor', + dict_type='DICT36', + with_unknown=False, + with_padding=False, + lower=True, +) + +model = dict( + type='ABINet', + backbone=dict(type='ResNetABI'), + encoder=dict( + type='ABIVisionModel', + encoder=dict( + type='TransformerEncoder', + n_layers=3, + n_head=8, + d_model=512, + d_inner=2048, + dropout=0.1, + max_len=8 * 32, + ), + decoder=dict( + type='ABIVisionDecoder', + in_channels=512, + num_channels=64, + attn_height=8, + attn_width=32, + attn_mode='nearest', + use_result='feature', + num_chars=num_chars, + max_seq_len=max_seq_len, + init_cfg=dict(type='Xavier', layer='Conv2d')), + ), + decoder=dict( + type='ABILanguageDecoder', + d_model=512, + n_head=8, + d_inner=2048, + n_layers=4, + dropout=0.1, + detach_tokens=True, + use_self_attn=False, + pad_idx=num_chars - 1, + num_chars=num_chars, + max_seq_len=max_seq_len, + init_cfg=None), + fuser=dict( + type='ABIFuser', + d_model=512, + num_chars=num_chars, + init_cfg=None, + max_seq_len=max_seq_len, + ), + loss=dict( + type='ABILoss', + enc_weight=1.0, + dec_weight=1.0, + fusion_weight=1.0, + num_classes=num_chars), + label_convertor=label_convertor, + max_seq_len=max_seq_len, + iter_size=3) diff --git a/configs/_base_/recog_models/crnn.py b/configs/_base_/recog_models/crnn.py new file mode 100644 index 0000000000000000000000000000000000000000..b316c6a8a7f4f79c0cff3062583391b746f3cad8 --- /dev/null +++ b/configs/_base_/recog_models/crnn.py @@ -0,0 +1,12 @@ +label_convertor = dict( + type='CTCConvertor', dict_type='DICT36', with_unknown=False, lower=True) + +model = dict( + type='CRNNNet', + preprocessor=None, + backbone=dict(type='VeryDeepVgg', leaky_relu=False, input_channels=1), + encoder=None, + decoder=dict(type='CRNNDecoder', in_channels=512, rnn_flag=True), + loss=dict(type='CTCLoss'), + label_convertor=label_convertor, + pretrained=None) diff --git a/configs/_base_/recog_models/crnn_tps.py b/configs/_base_/recog_models/crnn_tps.py new file mode 100644 index 0000000000000000000000000000000000000000..9719eb3c521cee55beee1711a73bd29a07d10366 --- /dev/null +++ b/configs/_base_/recog_models/crnn_tps.py @@ -0,0 +1,18 @@ +# model +label_convertor = dict( + type='CTCConvertor', dict_type='DICT36', with_unknown=False, lower=True) + +model = dict( + type='CRNNNet', + preprocessor=dict( + type='TPSPreprocessor', + num_fiducial=20, + img_size=(32, 100), + rectified_img_size=(32, 100), + num_img_channel=1), + backbone=dict(type='VeryDeepVgg', leaky_relu=False, input_channels=1), + encoder=None, + decoder=dict(type='CRNNDecoder', in_channels=512, rnn_flag=True), + loss=dict(type='CTCLoss'), + label_convertor=label_convertor, + pretrained=None) diff --git a/configs/_base_/recog_models/master.py b/configs/_base_/recog_models/master.py new file mode 100644 index 0000000000000000000000000000000000000000..39eaef248e132f7ccd6675b63ba21ef41e350c3b --- /dev/null +++ b/configs/_base_/recog_models/master.py @@ -0,0 +1,61 @@ +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +model = dict( + type='MASTER', + backbone=dict( + type='ResNet', + in_channels=3, + stem_channels=[64, 128], + block_cfgs=dict( + type='BasicBlock', + plugins=dict( + cfg=dict( + type='GCAModule', + ratio=0.0625, + n_head=1, + pooling_type='att', + is_att_scale=False, + fusion_type='channel_add'), + position='after_conv2')), + arch_layers=[1, 2, 5, 3], + arch_channels=[256, 256, 512, 512], + strides=[1, 1, 1, 1], + plugins=[ + dict( + cfg=dict(type='Maxpool2d', kernel_size=2, stride=(2, 2)), + stages=(True, True, False, False), + position='before_stage'), + dict( + cfg=dict(type='Maxpool2d', kernel_size=(2, 1), stride=(2, 1)), + stages=(False, False, True, False), + position='before_stage'), + dict( + cfg=dict( + type='ConvModule', + kernel_size=3, + stride=1, + padding=1, + norm_cfg=dict(type='BN'), + act_cfg=dict(type='ReLU')), + stages=(True, True, True, True), + position='after_stage') + ], + init_cfg=[ + dict(type='Kaiming', layer='Conv2d'), + dict(type='Constant', val=1, layer='BatchNorm2d'), + ]), + encoder=None, + decoder=dict( + type='MasterDecoder', + d_model=512, + n_head=8, + attn_drop=0., + ffn_drop=0., + d_inner=2048, + n_layers=3, + feat_pe_drop=0.2, + feat_size=6 * 40), + loss=dict(type='TFLoss', reduction='mean'), + label_convertor=label_convertor, + max_seq_len=30) diff --git a/configs/_base_/recog_models/nrtr_modality_transform.py b/configs/_base_/recog_models/nrtr_modality_transform.py new file mode 100644 index 0000000000000000000000000000000000000000..3c2e87f4318959d3fb6c1c84c11360ff3dbd4eb1 --- /dev/null +++ b/configs/_base_/recog_models/nrtr_modality_transform.py @@ -0,0 +1,11 @@ +label_convertor = dict( + type='AttnConvertor', dict_type='DICT36', with_unknown=True, lower=True) + +model = dict( + type='NRTR', + backbone=dict(type='NRTRModalityTransform'), + encoder=dict(type='NRTREncoder', n_layers=12), + decoder=dict(type='NRTRDecoder'), + loss=dict(type='TFLoss'), + label_convertor=label_convertor, + max_seq_len=40) diff --git a/configs/_base_/recog_models/robust_scanner.py b/configs/_base_/recog_models/robust_scanner.py new file mode 100644 index 0000000000000000000000000000000000000000..4cc2fa108855a102e1f4e48b6f94bac3b7f7d644 --- /dev/null +++ b/configs/_base_/recog_models/robust_scanner.py @@ -0,0 +1,24 @@ +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +hybrid_decoder = dict(type='SequenceAttentionDecoder') + +position_decoder = dict(type='PositionAttentionDecoder') + +model = dict( + type='RobustScanner', + backbone=dict(type='ResNet31OCR'), + encoder=dict( + type='ChannelReductionEncoder', + in_channels=512, + out_channels=128, + ), + decoder=dict( + type='RobustScannerDecoder', + dim_input=512, + dim_model=128, + hybrid_decoder=hybrid_decoder, + position_decoder=position_decoder), + loss=dict(type='SARLoss'), + label_convertor=label_convertor, + max_seq_len=30) diff --git a/configs/_base_/recog_models/sar.py b/configs/_base_/recog_models/sar.py new file mode 100755 index 0000000000000000000000000000000000000000..8438d9b921f5124c52fcd9ff566e28cddeb33041 --- /dev/null +++ b/configs/_base_/recog_models/sar.py @@ -0,0 +1,24 @@ +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +model = dict( + type='SARNet', + backbone=dict(type='ResNet31OCR'), + encoder=dict( + type='SAREncoder', + enc_bi_rnn=False, + enc_do_rnn=0.1, + enc_gru=False, + ), + decoder=dict( + type='ParallelSARDecoder', + enc_bi_rnn=False, + dec_bi_rnn=False, + dec_do_rnn=0, + dec_gru=False, + pred_dropout=0.1, + d_k=512, + pred_concat=True), + loss=dict(type='SARLoss'), + label_convertor=label_convertor, + max_seq_len=30) diff --git a/configs/_base_/recog_models/satrn.py b/configs/_base_/recog_models/satrn.py new file mode 100644 index 0000000000000000000000000000000000000000..f7a6de8637c77a18a930e032bfb752434b173ba4 --- /dev/null +++ b/configs/_base_/recog_models/satrn.py @@ -0,0 +1,11 @@ +label_convertor = dict( + type='AttnConvertor', dict_type='DICT36', with_unknown=True, lower=True) + +model = dict( + type='SATRN', + backbone=dict(type='ShallowCNN'), + encoder=dict(type='SatrnEncoder'), + decoder=dict(type='TFDecoder'), + loss=dict(type='TFLoss'), + label_convertor=label_convertor, + max_seq_len=40) diff --git a/configs/_base_/recog_models/seg.py b/configs/_base_/recog_models/seg.py new file mode 100644 index 0000000000000000000000000000000000000000..291e547ff45de81ddd512bf04ce0af7957b89ae7 --- /dev/null +++ b/configs/_base_/recog_models/seg.py @@ -0,0 +1,21 @@ +label_convertor = dict( + type='SegConvertor', dict_type='DICT36', with_unknown=True, lower=True) + +model = dict( + type='SegRecognizer', + backbone=dict( + type='ResNet31OCR', + layers=[1, 2, 5, 3], + channels=[32, 64, 128, 256, 512, 512], + out_indices=[0, 1, 2, 3], + stage4_pool_cfg=dict(kernel_size=2, stride=2), + last_stage_pool=True), + neck=dict( + type='FPNOCR', in_channels=[128, 256, 512, 512], out_channels=256), + head=dict( + type='SegHead', + in_channels=256, + upsample_param=dict(scale_factor=2.0, mode='nearest')), + loss=dict( + type='SegLoss', seg_downsample_ratio=1.0, seg_with_loss_weight=True), + label_convertor=label_convertor) diff --git a/configs/_base_/recog_pipelines/abinet_pipeline.py b/configs/_base_/recog_pipelines/abinet_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..3a54dfe6a8c310ab74f9a01b4671d7288436d0a7 --- /dev/null +++ b/configs/_base_/recog_pipelines/abinet_pipeline.py @@ -0,0 +1,96 @@ +img_norm_cfg = dict(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=32, + min_width=128, + max_width=128, + keep_aspect_ratio=False, + width_downsample_ratio=0.25), + dict( + type='RandomWrapper', + p=0.5, + transforms=[ + dict( + type='OneOfWrapper', + transforms=[ + dict( + type='RandomRotateTextDet', + max_angle=15, + ), + dict( + type='TorchVisionWrapper', + op='RandomAffine', + degrees=15, + translate=(0.3, 0.3), + scale=(0.5, 2.), + shear=(-45, 45), + ), + dict( + type='TorchVisionWrapper', + op='RandomPerspective', + distortion_scale=0.5, + p=1, + ), + ]) + ], + ), + dict( + type='RandomWrapper', + p=0.25, + transforms=[ + dict(type='PyramidRescale'), + dict( + type='Albu', + transforms=[ + dict(type='GaussNoise', var_limit=(20, 20), p=0.5), + dict(type='MotionBlur', blur_limit=6, p=0.5), + ]), + ]), + dict( + type='RandomWrapper', + p=0.25, + transforms=[ + dict( + type='TorchVisionWrapper', + op='ColorJitter', + brightness=0.5, + saturation=0.5, + contrast=0.5, + hue=0.1), + ]), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'img_shape', 'text', 'valid_ratio', + 'resize_shape' + ]), +] +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiRotateAugOCR', + rotate_degrees=[0, 90, 270], + transforms=[ + dict( + type='ResizeOCR', + height=32, + min_width=128, + max_width=128, + keep_aspect_ratio=False, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'img_shape', 'valid_ratio', + 'resize_shape', 'img_norm_cfg', 'ori_filename' + ]), + ]) +] diff --git a/configs/_base_/recog_pipelines/crnn_pipeline.py b/configs/_base_/recog_pipelines/crnn_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..3173eac695d40ac95e9929896cf82c753624b073 --- /dev/null +++ b/configs/_base_/recog_pipelines/crnn_pipeline.py @@ -0,0 +1,35 @@ +img_norm_cfg = dict(mean=[127], std=[127]) + +train_pipeline = [ + dict(type='LoadImageFromFile', color_type='grayscale'), + dict( + type='ResizeOCR', + height=32, + min_width=100, + max_width=100, + keep_aspect_ratio=False), + dict(type='Normalize', **img_norm_cfg), + dict(type='DefaultFormatBundle'), + dict( + type='Collect', + keys=['img'], + meta_keys=['filename', 'resize_shape', 'text', 'valid_ratio']), +] +test_pipeline = [ + dict(type='LoadImageFromFile', color_type='grayscale'), + dict( + type='ResizeOCR', + height=32, + min_width=32, + max_width=None, + keep_aspect_ratio=True), + dict(type='Normalize', **img_norm_cfg), + dict(type='DefaultFormatBundle'), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'resize_shape', 'valid_ratio', 'img_norm_cfg', + 'ori_filename', 'img_shape', 'ori_shape' + ]), +] diff --git a/configs/_base_/recog_pipelines/crnn_tps_pipeline.py b/configs/_base_/recog_pipelines/crnn_tps_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..3a2eea55a739206c11ae876ba82e9c2f6ea1ff6d --- /dev/null +++ b/configs/_base_/recog_pipelines/crnn_tps_pipeline.py @@ -0,0 +1,37 @@ +img_norm_cfg = dict(mean=[0.5], std=[0.5]) + +train_pipeline = [ + dict(type='LoadImageFromFile', color_type='grayscale'), + dict( + type='ResizeOCR', + height=32, + min_width=100, + max_width=100, + keep_aspect_ratio=False), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'text', 'valid_ratio' + ]), +] +test_pipeline = [ + dict(type='LoadImageFromFile', color_type='grayscale'), + dict( + type='ResizeOCR', + height=32, + min_width=32, + max_width=100, + keep_aspect_ratio=False), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'valid_ratio', + 'img_norm_cfg', 'ori_filename', 'img_shape' + ]), +] diff --git a/configs/_base_/recog_pipelines/master_pipeline.py b/configs/_base_/recog_pipelines/master_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..2071df4f665932dacd4a827e418603996fb562c8 --- /dev/null +++ b/configs/_base_/recog_pipelines/master_pipeline.py @@ -0,0 +1,42 @@ +img_norm_cfg = dict(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=48, + min_width=48, + max_width=160, + keep_aspect_ratio=True), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'img_shape', 'text', 'valid_ratio', + 'resize_shape' + ]), +] +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiRotateAugOCR', + rotate_degrees=[0, 90, 270], + transforms=[ + dict( + type='ResizeOCR', + height=48, + min_width=48, + max_width=160, + keep_aspect_ratio=True), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'img_shape', 'valid_ratio', + 'img_norm_cfg', 'ori_filename', 'resize_shape' + ]), + ]) +] diff --git a/configs/_base_/recog_pipelines/nrtr_pipeline.py b/configs/_base_/recog_pipelines/nrtr_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..71a19804309aa6692970b5eef642eddf87770559 --- /dev/null +++ b/configs/_base_/recog_pipelines/nrtr_pipeline.py @@ -0,0 +1,38 @@ +img_norm_cfg = dict(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=32, + min_width=32, + max_width=160, + keep_aspect_ratio=True, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'text', 'valid_ratio' + ]), +] + +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=32, + min_width=32, + max_width=160, + keep_aspect_ratio=True), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'valid_ratio', + 'img_norm_cfg', 'ori_filename', 'img_shape' + ]) +] diff --git a/configs/_base_/recog_pipelines/sar_pipeline.py b/configs/_base_/recog_pipelines/sar_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..f43ded30f5b7fb54c302a442483b07ca8bf8af69 --- /dev/null +++ b/configs/_base_/recog_pipelines/sar_pipeline.py @@ -0,0 +1,43 @@ +img_norm_cfg = dict(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=48, + min_width=48, + max_width=160, + keep_aspect_ratio=True, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'text', 'valid_ratio' + ]), +] +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiRotateAugOCR', + rotate_degrees=[0, 90, 270], + transforms=[ + dict( + type='ResizeOCR', + height=48, + min_width=48, + max_width=160, + keep_aspect_ratio=True, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'valid_ratio', + 'img_norm_cfg', 'ori_filename', 'img_shape' + ]), + ]) +] diff --git a/configs/_base_/recog_pipelines/satrn_pipeline.py b/configs/_base_/recog_pipelines/satrn_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..f191c5235a08eeae7d1e61002c00eccbdac39ed4 --- /dev/null +++ b/configs/_base_/recog_pipelines/satrn_pipeline.py @@ -0,0 +1,44 @@ +img_norm_cfg = dict(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=32, + min_width=100, + max_width=100, + keep_aspect_ratio=False, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'img_shape', 'text', 'valid_ratio', + 'resize_shape' + ]), +] +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiRotateAugOCR', + rotate_degrees=[0, 90, 270], + transforms=[ + dict( + type='ResizeOCR', + height=32, + min_width=100, + max_width=100, + keep_aspect_ratio=False, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'img_shape', 'valid_ratio', + 'resize_shape', 'img_norm_cfg', 'ori_filename' + ]), + ]) +] diff --git a/configs/_base_/recog_pipelines/seg_pipeline.py b/configs/_base_/recog_pipelines/seg_pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..378474dfb5341ec93e73bb61047c43ba72d5e127 --- /dev/null +++ b/configs/_base_/recog_pipelines/seg_pipeline.py @@ -0,0 +1,66 @@ +img_norm_cfg = dict(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) + +gt_label_convertor = dict( + type='SegConvertor', dict_type='DICT36', with_unknown=True, lower=True) + +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='RandomPaddingOCR', + max_ratio=[0.15, 0.2, 0.15, 0.2], + box_type='char_quads'), + dict(type='OpencvToPil'), + dict( + type='RandomRotateImageBox', + min_angle=-17, + max_angle=17, + box_type='char_quads'), + dict(type='PilToOpencv'), + dict( + type='ResizeOCR', + height=64, + min_width=64, + max_width=512, + keep_aspect_ratio=True), + dict( + type='OCRSegTargets', + label_convertor=gt_label_convertor, + box_type='char_quads'), + dict(type='RandomRotateTextDet', rotate_ratio=0.5, max_angle=15), + dict(type='ColorJitter', brightness=0.4, contrast=0.4, saturation=0.4), + dict(type='ToTensorOCR'), + dict(type='FancyPCA'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='CustomFormatBundle', + keys=['gt_kernels'], + visualize=dict(flag=False, boundary_key=None), + call_super=False), + dict( + type='Collect', + keys=['img', 'gt_kernels'], + meta_keys=['filename', 'ori_shape', 'resize_shape']) +] + +test_img_norm_cfg = dict( + mean=[x * 255 for x in img_norm_cfg['mean']], + std=[x * 255 for x in img_norm_cfg['std']]) + +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=64, + min_width=64, + max_width=None, + keep_aspect_ratio=True), + dict(type='Normalize', **test_img_norm_cfg), + dict(type='DefaultFormatBundle'), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'resize_shape', 'img_norm_cfg', 'ori_filename', + 'img_shape', 'ori_shape' + ]) +] diff --git a/configs/_base_/schedules/schedule_adadelta_18e.py b/configs/_base_/schedules/schedule_adadelta_18e.py new file mode 100644 index 0000000000000000000000000000000000000000..33f7960c51bf7d0f2b5bc03e8707a85a01e000fd --- /dev/null +++ b/configs/_base_/schedules/schedule_adadelta_18e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='Adadelta', lr=0.5) +optimizer_config = dict(grad_clip=dict(max_norm=0.5)) +# learning policy +lr_config = dict(policy='step', step=[8, 14, 16]) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=18) +checkpoint_config = dict(interval=1) diff --git a/configs/_base_/schedules/schedule_adadelta_5e.py b/configs/_base_/schedules/schedule_adadelta_5e.py new file mode 100644 index 0000000000000000000000000000000000000000..ad996d65f8aca131023d34712e2d960bf6928cce --- /dev/null +++ b/configs/_base_/schedules/schedule_adadelta_5e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='Adadelta', lr=1.0) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[]) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=5) +checkpoint_config = dict(interval=1) diff --git a/configs/_base_/schedules/schedule_adam_600e.py b/configs/_base_/schedules/schedule_adam_600e.py new file mode 100644 index 0000000000000000000000000000000000000000..a77dc52004ba597b4ba7f2df13a96e123c4029ab --- /dev/null +++ b/configs/_base_/schedules/schedule_adam_600e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='Adam', lr=1e-3) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='poly', power=0.9) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=600) +checkpoint_config = dict(interval=100) diff --git a/configs/_base_/schedules/schedule_adam_step_12e.py b/configs/_base_/schedules/schedule_adam_step_12e.py new file mode 100644 index 0000000000000000000000000000000000000000..c92289d3b7a69015afc51c9a248744bae5ec9197 --- /dev/null +++ b/configs/_base_/schedules/schedule_adam_step_12e.py @@ -0,0 +1,12 @@ +# optimizer +optimizer = dict(type='Adam', lr=4e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict( + policy='step', + warmup='linear', + warmup_iters=100, + warmup_ratio=1.0 / 3, + step=[11]) +runner = dict(type='EpochBasedRunner', max_epochs=12) +checkpoint_config = dict(interval=1) diff --git a/configs/_base_/schedules/schedule_adam_step_20e.py b/configs/_base_/schedules/schedule_adam_step_20e.py new file mode 100644 index 0000000000000000000000000000000000000000..81fb92cb4a35491493a4a76e22c86c5b804ec329 --- /dev/null +++ b/configs/_base_/schedules/schedule_adam_step_20e.py @@ -0,0 +1,14 @@ +# optimizer +optimizer = dict(type='Adam', lr=1e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict( + policy='step', + step=[16, 18], + warmup='linear', + warmup_iters=1, + warmup_ratio=0.001, + warmup_by_epoch=True) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=20) +checkpoint_config = dict(interval=1) diff --git a/configs/_base_/schedules/schedule_adam_step_5e.py b/configs/_base_/schedules/schedule_adam_step_5e.py new file mode 100644 index 0000000000000000000000000000000000000000..371a3781bfe51ab0b9d841a3911bfe00c4e85197 --- /dev/null +++ b/configs/_base_/schedules/schedule_adam_step_5e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='Adam', lr=1e-3) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[3, 4]) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=5) +checkpoint_config = dict(interval=1) diff --git a/configs/_base_/schedules/schedule_adam_step_600e.py b/configs/_base_/schedules/schedule_adam_step_600e.py new file mode 100644 index 0000000000000000000000000000000000000000..5daa2d4cf5ee79e48de7d984fcfdbc336f885a96 --- /dev/null +++ b/configs/_base_/schedules/schedule_adam_step_600e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='Adam', lr=1e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[200, 400]) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=600) +checkpoint_config = dict(interval=100) diff --git a/configs/_base_/schedules/schedule_adam_step_6e.py b/configs/_base_/schedules/schedule_adam_step_6e.py new file mode 100644 index 0000000000000000000000000000000000000000..5b33a2f924e502fc3a7f53f080a43fae983bb00c --- /dev/null +++ b/configs/_base_/schedules/schedule_adam_step_6e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='Adam', lr=1e-3) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[3, 4]) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=6) +checkpoint_config = dict(interval=1) diff --git a/configs/_base_/schedules/schedule_sgd_100k_iters.py b/configs/_base_/schedules/schedule_sgd_100k_iters.py new file mode 100644 index 0000000000000000000000000000000000000000..df2a3300f057145757b5164ec062b58e9d2f96c6 --- /dev/null +++ b/configs/_base_/schedules/schedule_sgd_100k_iters.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='SGD', lr=0.007, momentum=0.9, weight_decay=0.0001) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='poly', power=0.9, min_lr=1e-7, by_epoch=False) +# running settings +runner = dict(type='IterBasedRunner', max_iters=100000) +checkpoint_config = dict(interval=10000) diff --git a/configs/_base_/schedules/schedule_sgd_1200e.py b/configs/_base_/schedules/schedule_sgd_1200e.py new file mode 100644 index 0000000000000000000000000000000000000000..bc7fbf69b42b11ea9b8ae4d14216d2fcf20e717c --- /dev/null +++ b/configs/_base_/schedules/schedule_sgd_1200e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='SGD', lr=0.007, momentum=0.9, weight_decay=0.0001) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='poly', power=0.9, min_lr=1e-7, by_epoch=True) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=1200) +checkpoint_config = dict(interval=100) diff --git a/configs/_base_/schedules/schedule_sgd_1500e.py b/configs/_base_/schedules/schedule_sgd_1500e.py new file mode 100644 index 0000000000000000000000000000000000000000..3368175eceafdd019087461c51643a08e2e06d95 --- /dev/null +++ b/configs/_base_/schedules/schedule_sgd_1500e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='SGD', lr=1e-3, momentum=0.90, weight_decay=5e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='poly', power=0.9, min_lr=1e-7, by_epoch=True) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=1500) +checkpoint_config = dict(interval=100) diff --git a/configs/_base_/schedules/schedule_sgd_160e.py b/configs/_base_/schedules/schedule_sgd_160e.py new file mode 100644 index 0000000000000000000000000000000000000000..985b8f63b3cb34f04ff55b298b44a53568a50ae8 --- /dev/null +++ b/configs/_base_/schedules/schedule_sgd_160e.py @@ -0,0 +1,13 @@ +# optimizer +optimizer = dict(type='SGD', lr=0.08, momentum=0.9, weight_decay=0.0001) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict( + policy='step', + warmup='linear', + warmup_iters=500, + warmup_ratio=0.001, + step=[80, 128]) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=160) +checkpoint_config = dict(interval=10) diff --git a/configs/_base_/schedules/schedule_sgd_600e.py b/configs/_base_/schedules/schedule_sgd_600e.py new file mode 100644 index 0000000000000000000000000000000000000000..ed57b422ded5d302f758ff570187e7b1db809adf --- /dev/null +++ b/configs/_base_/schedules/schedule_sgd_600e.py @@ -0,0 +1,8 @@ +# optimizer +optimizer = dict(type='SGD', lr=1e-3, momentum=0.99, weight_decay=5e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[200, 400]) +# running settings +runner = dict(type='EpochBasedRunner', max_epochs=600) +checkpoint_config = dict(interval=100) diff --git a/configs/kie/sdmgr/README.md b/configs/kie/sdmgr/README.md new file mode 100644 index 0000000000000000000000000000000000000000..645696b75c76e496c394a8f6773a8fa8a0d939da --- /dev/null +++ b/configs/kie/sdmgr/README.md @@ -0,0 +1,52 @@ +# SDMGR + +> [Spatial Dual-Modality Graph Reasoning for Key Information Extraction](https://arxiv.org/abs/2103.14470) + + + +## Abstract + +Key information extraction from document images is of paramount importance in office automation. Conventional template matching based approaches fail to generalize well to document images of unseen templates, and are not robust against text recognition errors. In this paper, we propose an end-to-end Spatial Dual-Modality Graph Reasoning method (SDMG-R) to extract key information from unstructured document images. We model document images as dual-modality graphs, nodes of which encode both the visual and textual features of detected text regions, and edges of which represent the spatial relations between neighboring text regions. The key information extraction is solved by iteratively propagating messages along graph edges and reasoning the categories of graph nodes. In order to roundly evaluate our proposed method as well as boost the future research, we release a new dataset named WildReceipt, which is collected and annotated tailored for the evaluation of key information extraction from document images of unseen templates in the wild. It contains 25 key information categories, a total of about 69000 text boxes, and is about 2 times larger than the existing public datasets. Extensive experiments validate that all information including visual features, textual features and spatial relations can benefit key information extraction. It has been shown that SDMG-R can effectively extract key information from document images of unseen templates, and obtain new state-of-the-art results on the recent popular benchmark SROIE and our WildReceipt. Our code and dataset will be publicly released. + +
+ +
+ +## Results and models + +### WildReceipt + +| Method | Modality | Macro F1-Score | Download | +| :--------------------------------------------------------------------: | :--------------: | :------------: | :--------------------------------------------------------------------------------------------------: | +| [sdmgr_unet16](/configs/kie/sdmgr/sdmgr_unet16_60e_wildreceipt.py) | Visual + Textual | 0.888 | [model](https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_unet16_60e_wildreceipt_20210520-7489e6de.pth) \| [log](https://download.openmmlab.com/mmocr/kie/sdmgr/20210520_132236.log.json) | +| [sdmgr_novisual](/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt.py) | Textual | 0.870 | [model](https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_novisual_60e_wildreceipt_20210517-a44850da.pth) \| [log](https://download.openmmlab.com/mmocr/kie/sdmgr/20210517_205829.log.json) | + +```{note} +1. For `sdmgr_novisual`, images are not needed for training and testing. So fake `img_prefix` can be used in configs. As well, fake `file_name` can be used in annotation files. +``` + +### WildReceiptOpenset + +| Method | Modality | Edge F1-Score | Node Macro F1-Score | Node Micro F1-Score | Download | +| :-------------------------------------------------------------------: | :------: | :-----------: | :-----------------: | :-----------------: | :----------------------------------------------------------------------: | +| [sdmgr_novisual](/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt_openset.py) | Textual | 0.786 | 0.926 | 0.935 | [model](https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_novisual_60e_wildreceipt_openset_20210917-d236b3ea.pth) \| [log](https://download.openmmlab.com/mmocr/kie/sdmgr/20210917_050824.log.json) | + +```{note} +1. In the case of openset, the number of node categories is unknown or unfixed, and more node category can be added. +2. To show that our method can handle openset problem, we modify the ground truth of `WildReceipt` to `WildReceiptOpenset`. The `nodes` are just classified into 4 classes: `background, key, value, others`, while adding `edge` labels for each box. +3. The model is used to predict whether two nodes are a pair connecting by a valid edge. +4. You can learn more about the key differences between CloseSet and OpenSet annotations in our [tutorial](tutorials/kie_closeset_openset.md). +``` + +## Citation + +```bibtex +@misc{sun2021spatial, + title={Spatial Dual-Modality Graph Reasoning for Key Information Extraction}, + author={Hongbin Sun and Zhanghui Kuang and Xiaoyu Yue and Chenhao Lin and Wayne Zhang}, + year={2021}, + eprint={2103.14470}, + archivePrefix={arXiv}, + primaryClass={cs.CV} +} +``` diff --git a/configs/kie/sdmgr/metafile.yml b/configs/kie/sdmgr/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..f1a9695991156ae658e40f1aa2ab1dba06da2e9c --- /dev/null +++ b/configs/kie/sdmgr/metafile.yml @@ -0,0 +1,39 @@ +Collections: +- Name: SDMGR + Metadata: + Training Data: KIEDataset + Training Techniques: + - Adam + Training Resources: 1x GeForce GTX 1080 Ti + Architecture: + - UNet + - SDMGRHead + Paper: + URL: https://arxiv.org/abs/2103.14470.pdf + Title: 'Spatial Dual-Modality Graph Reasoning for Key Information Extraction' + README: configs/kie/sdmgr/README.md + +Models: + - Name: sdmgr_unet16_60e_wildreceipt + In Collection: SDMGR + Config: configs/kie/sdmgr/sdmgr_unet16_60e_wildreceipt.py + Metadata: + Training Data: wildreceipt + Results: + - Task: Key Information Extraction + Dataset: wildreceipt + Metrics: + macro_f1: 0.876 + Weights: https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_unet16_60e_wildreceipt_20210405-16a47642.pth + + - Name: sdmgr_novisual_60e_wildreceipt + In Collection: SDMGR + Config: configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt.py + Metadata: + Training Data: wildreceipt + Results: + - Task: Key Information Extraction + Dataset: wildreceipt + Metrics: + macro_f1: 0.864 + Weights: https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_novisual_60e_wildreceipt_20210405-07bc26ad.pth diff --git a/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt.py b/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt.py new file mode 100644 index 0000000000000000000000000000000000000000..220135a0b037909599fbaf77c75b06f48f8b1ba7 --- /dev/null +++ b/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt.py @@ -0,0 +1,98 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) +max_scale, min_scale = 1024, 512 + +train_pipeline = [ + dict(type='LoadAnnotations'), + dict( + type='ResizeNoImg', img_scale=(max_scale, min_scale), keep_ratio=True), + dict(type='KIEFormatBundle'), + dict( + type='Collect', + keys=['img', 'relations', 'texts', 'gt_bboxes', 'gt_labels'], + meta_keys=('filename', 'ori_texts')) +] +test_pipeline = [ + dict(type='LoadAnnotations'), + dict( + type='ResizeNoImg', img_scale=(max_scale, min_scale), keep_ratio=True), + dict(type='KIEFormatBundle'), + dict( + type='Collect', + keys=['img', 'relations', 'texts', 'gt_bboxes'], + meta_keys=('filename', 'ori_texts', 'img_norm_cfg', 'ori_filename', + 'img_shape')) +] + +dataset_type = 'KIEDataset' +data_root = 'data/wildreceipt' + +loader = dict( + type='HardDiskLoader', + repeat=1, + parser=dict( + type='LineJsonParser', + keys=['file_name', 'height', 'width', 'annotations'])) + +train = dict( + type=dataset_type, + ann_file=f'{data_root}/train.txt', + pipeline=train_pipeline, + img_prefix=data_root, + loader=loader, + dict_file=f'{data_root}/dict.txt', + test_mode=False) +test = dict( + type=dataset_type, + ann_file=f'{data_root}/test.txt', + pipeline=test_pipeline, + img_prefix=data_root, + loader=loader, + dict_file=f'{data_root}/dict.txt', + test_mode=True) + +data = dict( + samples_per_gpu=4, + workers_per_gpu=1, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=train, + val=test, + test=test) + +evaluation = dict( + interval=1, + metric='macro_f1', + metric_options=dict( + macro_f1=dict( + ignores=[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 25]))) + +model = dict( + type='SDMGR', + backbone=dict(type='UNet', base_channels=16), + bbox_head=dict( + type='SDMGRHead', visual_dim=16, num_chars=92, num_classes=26), + visual_modality=False, + train_cfg=None, + test_cfg=None, + class_list=f'{data_root}/class_list.txt') + +optimizer = dict(type='Adam', weight_decay=0.0001) +optimizer_config = dict(grad_clip=None) +lr_config = dict( + policy='step', + warmup='linear', + warmup_iters=1, + warmup_ratio=1, + step=[40, 50]) +total_epochs = 60 + +checkpoint_config = dict(interval=1) +log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')]) +dist_params = dict(backend='nccl') +log_level = 'INFO' +load_from = None +resume_from = None +workflow = [('train', 1)] + +find_unused_parameters = True diff --git a/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt_openset.py b/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt_openset.py new file mode 100644 index 0000000000000000000000000000000000000000..b295bd13c3b098d4e8e25b1e7fc42c4bbf5ff5f1 --- /dev/null +++ b/configs/kie/sdmgr/sdmgr_novisual_60e_wildreceipt_openset.py @@ -0,0 +1,84 @@ +_base_ = ['../../_base_/default_runtime.py'] + +model = dict( + type='SDMGR', + backbone=dict(type='UNet', base_channels=16), + bbox_head=dict( + type='SDMGRHead', visual_dim=16, num_chars=92, num_classes=4), + visual_modality=False, + train_cfg=None, + test_cfg=None, + class_list=None, + openset=True) + +optimizer = dict(type='Adam', weight_decay=0.0001) +optimizer_config = dict(grad_clip=None) +lr_config = dict( + policy='step', + warmup='linear', + warmup_iters=1, + warmup_ratio=1, + step=[40, 50]) +total_epochs = 60 + +train_pipeline = [ + dict(type='LoadAnnotations'), + dict(type='ResizeNoImg', img_scale=(1024, 512), keep_ratio=True), + dict(type='KIEFormatBundle'), + dict( + type='Collect', + keys=['img', 'relations', 'texts', 'gt_bboxes', 'gt_labels'], + meta_keys=('filename', 'ori_filename', 'ori_texts')) +] +test_pipeline = [ + dict(type='LoadAnnotations'), + dict(type='ResizeNoImg', img_scale=(1024, 512), keep_ratio=True), + dict(type='KIEFormatBundle'), + dict( + type='Collect', + keys=['img', 'relations', 'texts', 'gt_bboxes'], + meta_keys=('filename', 'ori_filename', 'ori_texts', 'ori_bboxes', + 'img_norm_cfg', 'ori_filename', 'img_shape')) +] + +dataset_type = 'OpensetKIEDataset' +data_root = 'data/wildreceipt' + +loader = dict( + type='HardDiskLoader', + repeat=1, + parser=dict( + type='LineJsonParser', + keys=['file_name', 'height', 'width', 'annotations'])) + +train = dict( + type=dataset_type, + ann_file=f'{data_root}/openset_train.txt', + pipeline=train_pipeline, + img_prefix=data_root, + link_type='one-to-many', + loader=loader, + dict_file=f'{data_root}/dict.txt', + test_mode=False) +test = dict( + type=dataset_type, + ann_file=f'{data_root}/openset_test.txt', + pipeline=test_pipeline, + img_prefix=data_root, + link_type='one-to-many', + loader=loader, + dict_file=f'{data_root}/dict.txt', + test_mode=True) + +data = dict( + samples_per_gpu=4, + workers_per_gpu=1, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=train, + val=test, + test=test) + +evaluation = dict(interval=1, metric='openset_f1', metric_options=None) + +find_unused_parameters = True diff --git a/configs/kie/sdmgr/sdmgr_unet16_60e_wildreceipt.py b/configs/kie/sdmgr/sdmgr_unet16_60e_wildreceipt.py new file mode 100644 index 0000000000000000000000000000000000000000..f073064affebe05d3830e18d76453c1cceb0f1a1 --- /dev/null +++ b/configs/kie/sdmgr/sdmgr_unet16_60e_wildreceipt.py @@ -0,0 +1,105 @@ +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) +max_scale, min_scale = 1024, 512 + +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict(type='LoadAnnotations'), + dict(type='Resize', img_scale=(max_scale, min_scale), keep_ratio=True), + dict(type='RandomFlip', flip_ratio=0.), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='KIEFormatBundle'), + dict( + type='Collect', + keys=['img', 'relations', 'texts', 'gt_bboxes', 'gt_labels']) +] +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict(type='LoadAnnotations'), + dict(type='Resize', img_scale=(max_scale, min_scale), keep_ratio=True), + dict(type='RandomFlip', flip_ratio=0.), + dict(type='Normalize', **img_norm_cfg), + dict(type='Pad', size_divisor=32), + dict(type='KIEFormatBundle'), + dict( + type='Collect', + keys=['img', 'relations', 'texts', 'gt_bboxes'], + meta_keys=[ + 'img_norm_cfg', 'img_shape', 'ori_filename', 'filename', + 'ori_texts' + ]) +] + +dataset_type = 'KIEDataset' +data_root = 'data/wildreceipt' + +loader = dict( + type='HardDiskLoader', + repeat=1, + parser=dict( + type='LineJsonParser', + keys=['file_name', 'height', 'width', 'annotations'])) + +train = dict( + type=dataset_type, + ann_file=f'{data_root}/train.txt', + pipeline=train_pipeline, + img_prefix=data_root, + loader=loader, + dict_file=f'{data_root}/dict.txt', + test_mode=False) +test = dict( + type=dataset_type, + ann_file=f'{data_root}/test.txt', + pipeline=test_pipeline, + img_prefix=data_root, + loader=loader, + dict_file=f'{data_root}/dict.txt', + test_mode=True) + +data = dict( + samples_per_gpu=4, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=train, + val=test, + test=test) + +evaluation = dict( + interval=1, + metric='macro_f1', + metric_options=dict( + macro_f1=dict( + ignores=[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 25]))) + +model = dict( + type='SDMGR', + backbone=dict(type='UNet', base_channels=16), + bbox_head=dict( + type='SDMGRHead', visual_dim=16, num_chars=92, num_classes=26), + visual_modality=True, + train_cfg=None, + test_cfg=None, + class_list=f'{data_root}/class_list.txt') + +optimizer = dict(type='Adam', weight_decay=0.0001) +optimizer_config = dict(grad_clip=None) +lr_config = dict( + policy='step', + warmup='linear', + warmup_iters=1, + warmup_ratio=1, + step=[40, 50]) +total_epochs = 60 + +checkpoint_config = dict(interval=1) +log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')]) +dist_params = dict(backend='nccl') +log_level = 'INFO' +load_from = None +resume_from = None +workflow = [('train', 1)] + +find_unused_parameters = True diff --git a/configs/ner/bert_softmax/README.md b/configs/ner/bert_softmax/README.md new file mode 100644 index 0000000000000000000000000000000000000000..650d18c4d56406e5f064085229f49875f5b4aea5 --- /dev/null +++ b/configs/ner/bert_softmax/README.md @@ -0,0 +1,47 @@ +# Bert + +> [Bert: Pre-training of deep bidirectional transformers for language understanding](https://arxiv.org/abs/1810.04805) + + + +## Abstract + +We introduce a new language representation model called BERT, which stands for Bidirectional Encoder Representations from Transformers. Unlike recent language representation models, BERT is designed to pre-train deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers. As a result, the pre-trained BERT model can be fine-tuned with just one additional output layer to create state-of-the-art models for a wide range of tasks, such as question answering and language inference, without substantial task-specific architecture modifications. +BERT is conceptually simple and empirically powerful. It obtains new state-of-the-art results on eleven natural language processing tasks, including pushing the GLUE score to 80.5% (7.7% point absolute improvement), MultiNLI accuracy to 86.7% (4.6% absolute improvement), SQuAD v1.1 question answering Test F1 to 93.2 (1.5 point absolute improvement) and SQuAD v2.0 Test F1 to 83.1 (5.1 point absolute improvement). + + + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | text_num | entity_num | +| :---------: | :------: | :--------: | +| CLUENER2020 | 10748 | 23338 | + +### Test Dataset + +| testset | text_num | entity_num | +| :---------: | :------: | :--------: | +| CLUENER2020 | 1343 | 2982 | + +## Results and models + +| Method | Pretrain | Precision | Recall | F1-Score | Download | +| :-------------------------------------------------------: | :----------------------------------------------------------: | :-------: | :----: | :------: | :----------------------------------------------------------: | +| [bert_softmax](/configs/ner/bert_softmax/bert_softmax_cluener_18e.py) | [pretrain](https://download.openmmlab.com/mmocr/ner/bert_softmax/bert_pretrain.pth) | 0.7885 | 0.7998 | 0.7941 | [model](https://download.openmmlab.com/mmocr/ner/bert_softmax/bert_softmax_cluener-eea70ea2.pth) \| [log](https://download.openmmlab.com/mmocr/ner/bert_softmax/20210514_172645.log.json) | + +## Citation + +```bibtex +@article{devlin2018bert, + title={Bert: Pre-training of deep bidirectional transformers for language understanding}, + author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina}, + journal={arXiv preprint arXiv:1810.04805}, + year={2018} +} +``` diff --git a/configs/ner/bert_softmax/bert_softmax_cluener_18e.py b/configs/ner/bert_softmax/bert_softmax_cluener_18e.py new file mode 100755 index 0000000000000000000000000000000000000000..5fd85d9a858236f4feb8903e3f4bf95f9eccaf94 --- /dev/null +++ b/configs/ner/bert_softmax/bert_softmax_cluener_18e.py @@ -0,0 +1,70 @@ +_base_ = [ + '../../_base_/schedules/schedule_adadelta_18e.py', + '../../_base_/default_runtime.py' +] + +categories = [ + 'address', 'book', 'company', 'game', 'government', 'movie', 'name', + 'organization', 'position', 'scene' +] + +test_ann_file = 'data/cluener2020/dev.json' +train_ann_file = 'data/cluener2020/train.json' +vocab_file = 'data/cluener2020/vocab.txt' + +max_len = 128 +loader = dict( + type='HardDiskLoader', + repeat=1, + parser=dict(type='LineJsonParser', keys=['text', 'label'])) + +ner_convertor = dict( + type='NerConvertor', + annotation_type='bio', + vocab_file=vocab_file, + categories=categories, + max_len=max_len) + +test_pipeline = [ + dict(type='NerTransform', label_convertor=ner_convertor, max_len=max_len), + dict(type='ToTensorNER') +] + +train_pipeline = [ + dict(type='NerTransform', label_convertor=ner_convertor, max_len=max_len), + dict(type='ToTensorNER') +] +dataset_type = 'NerDataset' + +train = dict( + type=dataset_type, + ann_file=train_ann_file, + loader=loader, + pipeline=train_pipeline, + test_mode=False) + +test = dict( + type=dataset_type, + ann_file=test_ann_file, + loader=loader, + pipeline=test_pipeline, + test_mode=True) +data = dict( + samples_per_gpu=8, workers_per_gpu=2, train=train, val=test, test=test) + +evaluation = dict(interval=1, metric='f1-score') + +model = dict( + type='NerClassifier', + encoder=dict( + type='BertEncoder', + max_position_embeddings=512, + init_cfg=dict( + type='Pretrained', + checkpoint='https://download.openmmlab.com/mmocr/ner/' + 'bert_softmax/bert_pretrain.pth')), + decoder=dict(type='FCDecoder'), + loss=dict(type='MaskedCrossEntropyLoss'), + label_convertor=ner_convertor) + +test_cfg = None diff --git a/configs/textdet/dbnet/README.md b/configs/textdet/dbnet/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d2007c72ec2b45e70d30c6edea128b7e0be2baca --- /dev/null +++ b/configs/textdet/dbnet/README.md @@ -0,0 +1,33 @@ +# DBNet + +> [Real-time Scene Text Detection with Differentiable Binarization](https://arxiv.org/abs/1911.08947) + + + +## Abstract + +Recently, segmentation-based methods are quite popular in scene text detection, as the segmentation results can more accurately describe scene text of various shapes such as curve text. However, the post-processing of binarization is essential for segmentation-based detection, which converts probability maps produced by a segmentation method into bounding boxes/regions of text. In this paper, we propose a module named Differentiable Binarization (DB), which can perform the binarization process in a segmentation network. Optimized along with a DB module, a segmentation network can adaptively set the thresholds for binarization, which not only simplifies the post-processing but also enhances the performance of text detection. Based on a simple segmentation network, we validate the performance improvements of DB on five benchmark datasets, which consistently achieves state-of-the-art results, in terms of both detection accuracy and speed. In particular, with a light-weight backbone, the performance improvements by DB are significant so that we can look for an ideal tradeoff between detection accuracy and efficiency. Specifically, with a backbone of ResNet-18, our detector achieves an F-measure of 82.8, running at 62 FPS, on the MSRA-TD500 dataset. + +
+ +
+ +## Results and models + +### ICDAR2015 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :---------------------------------------: | :-------------------------------------------------: | :-------------: | :------------: | :-----: | :-------: | :----: | :-------: | :---: | :-----------------------------------------: | +| [DBNet_r18](/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py) | ImageNet | ICDAR2015 Train | ICDAR2015 Test | 1200 | 736 | 0.731 | 0.871 | 0.795 | [model](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnet_r18_fpnc_sbn_1200e_icdar2015_20210329-ba3ab597.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnet_r18_fpnc_sbn_1200e_icdar2015_20210329-ba3ab597.log.json) | +| [DBNet_r50dcn](/configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_1200e_icdar2015.py) | [Synthtext](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnet_r50dcnv2_fpnc_sbn_2e_synthtext_20210325-aa96e477.pth) | ICDAR2015 Train | ICDAR2015 Test | 1200 | 1024 | 0.814 | 0.868 | 0.840 | [model](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnet_r50dcnv2_fpnc_sbn_1200e_icdar2015_20211025-9fe3b590.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnet_r50dcnv2_fpnc_sbn_1200e_icdar2015_20211025-9fe3b590.log.json) | + +## Citation + +```bibtex +@article{Liao_Wan_Yao_Chen_Bai_2020, + title={Real-Time Scene Text Detection with Differentiable Binarization}, + journal={Proceedings of the AAAI Conference on Artificial Intelligence}, + author={Liao, Minghui and Wan, Zhaoyi and Yao, Cong and Chen, Kai and Bai, Xiang}, + year={2020}, + pages={11474-11481}} +``` diff --git a/configs/textdet/dbnet/dbnet_r18_fpnc_100k_iters_synthtext.py b/configs/textdet/dbnet/dbnet_r18_fpnc_100k_iters_synthtext.py new file mode 100644 index 0000000000000000000000000000000000000000..78a2bbbf87405a052690546681db127bd93ff738 --- /dev/null +++ b/configs/textdet/dbnet/dbnet_r18_fpnc_100k_iters_synthtext.py @@ -0,0 +1,59 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_100k_iters.py', + '../../_base_/det_models/dbnet_r18_fpnc.py', + '../../_base_/det_datasets/synthtext.py', + '../../_base_/det_pipelines/dbnet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +img_norm_cfg = dict( + mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) +train_pipeline_r18 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg), + dict( + type='ImgAug', + args=[['Fliplr', 0.5], + dict(cls='Affine', rotate=[-10, 10]), ['Resize', [0.5, 3.0]]], + clip_invalid_ploys=False), + dict(type='EastRandomCrop', target_size=(640, 640)), + dict(type='DBNetTargets', shrink_ratio=0.4), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask'], + visualize=dict(flag=False, boundary_key='gt_shrink')), + dict( + type='Collect', + keys=['img', 'gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask']) +] +test_pipeline_1333_736 = {{_base_.test_pipeline_1333_736}} + +data = dict( + samples_per_gpu=16, + workers_per_gpu=8, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_r18), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_1333_736), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_1333_736)) + +evaluation = dict(interval=999999, metric='hmean-iou') # do not evaluate diff --git a/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py b/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..467903fef4604dedfd1efbeaa011de0a32dcea74 --- /dev/null +++ b/configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_1200e.py', + '../../_base_/det_models/dbnet_r18_fpnc.py', + '../../_base_/det_datasets/icdar2015.py', + '../../_base_/det_pipelines/dbnet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_r18 = {{_base_.train_pipeline_r18}} +test_pipeline_1333_736 = {{_base_.test_pipeline_1333_736}} + +data = dict( + samples_per_gpu=16, + workers_per_gpu=8, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_r18), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_1333_736), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_1333_736)) + +evaluation = dict(interval=100, metric='hmean-iou') diff --git a/configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_100k_iters_synthtext.py b/configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_100k_iters_synthtext.py new file mode 100644 index 0000000000000000000000000000000000000000..0ccd22c9b0675062571ed971a16dd75958ac03e0 --- /dev/null +++ b/configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_100k_iters_synthtext.py @@ -0,0 +1,61 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_100k_iters.py', + '../../_base_/det_models/dbnet_r50dcnv2_fpnc.py', + '../../_base_/det_datasets/synthtext.py', + '../../_base_/det_pipelines/dbnet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +img_norm_cfg_r50dcnv2 = dict( + mean=[122.67891434, 116.66876762, 104.00698793], + std=[58.395, 57.12, 57.375], + to_rgb=True) +train_pipeline_r50dcnv2 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg_r50dcnv2), + dict( + type='ImgAug', + args=[['Fliplr', 0.5], + dict(cls='Affine', rotate=[-10, 10]), ['Resize', [0.5, 3.0]]], + clip_invalid_ploys=False), + dict(type='EastRandomCrop', target_size=(640, 640)), + dict(type='DBNetTargets', shrink_ratio=0.4), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask'], + visualize=dict(flag=False, boundary_key='gt_shrink')), + dict( + type='Collect', + keys=['img', 'gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask']) +] +test_pipeline_4068_1024 = {{_base_.test_pipeline_4068_1024}} + +data = dict( + samples_per_gpu=16, + workers_per_gpu=8, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_r50dcnv2), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024)) + +evaluation = dict(interval=999999, metric='hmean-iou') # do not evaluate diff --git a/configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_1200e_icdar2015.py b/configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_1200e_icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..251b7bc2faaaa254766e0902c4238b2917f0d230 --- /dev/null +++ b/configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_1200e_icdar2015.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_1200e.py', + '../../_base_/det_models/dbnet_r50dcnv2_fpnc.py', + '../../_base_/det_datasets/icdar2015.py', + '../../_base_/det_pipelines/dbnet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_r50dcnv2 = {{_base_.train_pipeline_r50dcnv2}} +test_pipeline_4068_1024 = {{_base_.test_pipeline_4068_1024}} + +load_from = 'checkpoints/textdet/dbnet/res50dcnv2_synthtext.pth' + +data = dict( + samples_per_gpu=8, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_r50dcnv2), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024)) + +evaluation = dict(interval=100, metric='hmean-iou') diff --git a/configs/textdet/dbnet/metafile.yml b/configs/textdet/dbnet/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..c6abdbca61d760a0e6d275e5188312ef86fd055e --- /dev/null +++ b/configs/textdet/dbnet/metafile.yml @@ -0,0 +1,40 @@ +Collections: +- Name: DBNet + Metadata: + Training Data: ICDAR2015 + Training Techniques: + - SGD with Momentum + - Weight Decay + Training Resources: 1x GeForce GTX 1080 Ti + Architecture: + - ResNet + - FPNC + Paper: + URL: https://arxiv.org/pdf/1911.08947.pdf + Title: 'Real-time Scene Text Detection with Differentiable Binarization' + README: configs/textdet/dbnet/README.md + +Models: + - Name: dbnet_r18_fpnc_1200e_icdar2015 + In Collection: DBNet + Config: configs/textdet/dbnet/dbnet_r18_fpnc_1200e_icdar2015.py + Metadata: + Training Data: ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2015 + Metrics: + hmean-iou: 0.795 + Weights: https://download.openmmlab.com/mmocr/textdet/dbnet/dbnet_r18_fpnc_sbn_1200e_icdar2015_20210329-ba3ab597.pth + + - Name: dbnet_r50dcnv2_fpnc_1200e_icdar2015 + In Collection: DBNet + Config: configs/textdet/dbnet/dbnet_r50dcnv2_fpnc_1200e_icdar2015.py + Metadata: + Training Data: ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2015 + Metrics: + hmean-iou: 0.840 + Weights: https://download.openmmlab.com/mmocr/textdet/dbnet/dbnet_r50dcnv2_fpnc_sbn_1200e_icdar2015_20211025-9fe3b590.pth diff --git a/configs/textdet/dbnetpp/README.md b/configs/textdet/dbnetpp/README.md new file mode 100644 index 0000000000000000000000000000000000000000..995254cb89c1b88bb3698d9d550f8e0ac7ba69f6 --- /dev/null +++ b/configs/textdet/dbnetpp/README.md @@ -0,0 +1,33 @@ +# DBNetpp + +> [Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion](https://arxiv.org/abs/2202.10304) + + + +## Abstract + +Recently, segmentation-based scene text detection methods have drawn extensive attention in the scene text detection field, because of their superiority in detecting the text instances of arbitrary shapes and extreme aspect ratios, profiting from the pixel-level descriptions. However, the vast majority of the existing segmentation-based approaches are limited to their complex post-processing algorithms and the scale robustness of their segmentation models, where the post-processing algorithms are not only isolated to the model optimization but also time-consuming and the scale robustness is usually strengthened by fusing multi-scale feature maps directly. In this paper, we propose a Differentiable Binarization (DB) module that integrates the binarization process, one of the most important steps in the post-processing procedure, into a segmentation network. Optimized along with the proposed DB module, the segmentation network can produce more accurate results, which enhances the accuracy of text detection with a simple pipeline. Furthermore, an efficient Adaptive Scale Fusion (ASF) module is proposed to improve the scale robustness by fusing features of different scales adaptively. By incorporating the proposed DB and ASF with the segmentation network, our proposed scene text detector consistently achieves state-of-the-art results, in terms of both detection accuracy and speed, on five standard benchmarks. + +
+ +
+ +## Results and models + +### ICDAR2015 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :---------------------------------------: | :-------------------------------------------------: | :-------------: | :------------: | :-----: | :-------: | :----: | :-------: | :---: | :-----------------------------------------: | +| [DBNetpp_r50dcn](/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015.py) | [Synthtext](/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_100k_iter_synthtext.py) ([model](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnetpp_r50dcnv2_fpnc_100k_iter_synthtext-20220502-db297554.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnetpp_r50dcnv2_fpnc_100k_iter_synthtext-20220502-db297554.log.json)) | ICDAR2015 Train | ICDAR2015 Test | 1200 | 1024 | 0.822 | 0.901 | 0.860 | [model](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015-20220502-d7a76fff.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/dbnet/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015-20220502-d7a76fff.log.json) | + +## Citation + +```bibtex +@article{liao2022real, + title={Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion}, + author={Liao, Minghui and Zou, Zhisheng and Wan, Zhaoyi and Yao, Cong and Bai, Xiang}, + journal={IEEE Transactions on Pattern Analysis and Machine Intelligence}, + year={2022}, + publisher={IEEE} +} +``` diff --git a/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_100k_iter_synthtext.py b/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_100k_iter_synthtext.py new file mode 100644 index 0000000000000000000000000000000000000000..5f3835ea998e5195b471671a8685c0032733b0a2 --- /dev/null +++ b/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_100k_iter_synthtext.py @@ -0,0 +1,62 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_100k_iters.py', + '../../_base_/det_models/dbnetpp_r50dcnv2_fpnc.py', + '../../_base_/det_datasets/synthtext.py', + '../../_base_/det_pipelines/dbnet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +img_norm_cfg_r50dcnv2 = dict( + mean=[122.67891434, 116.66876762, 104.00698793], + std=[58.395, 57.12, 57.375], + to_rgb=True) +train_pipeline_r50dcnv2 = [ + dict(type='LoadImageFromFile', color_type='color_ignore_orientation'), + dict( + type='LoadTextAnnotations', + with_bbox=True, + with_mask=True, + poly2mask=False), + dict(type='ColorJitter', brightness=32.0 / 255, saturation=0.5), + dict(type='Normalize', **img_norm_cfg_r50dcnv2), + dict( + type='ImgAug', + args=[['Fliplr', 0.5], + dict(cls='Affine', rotate=[-10, 10]), ['Resize', [0.5, 3.0]]], + clip_invalid_ploys=False), + dict(type='EastRandomCrop', target_size=(640, 640)), + dict(type='DBNetTargets', shrink_ratio=0.4), + dict(type='Pad', size_divisor=32), + dict( + type='CustomFormatBundle', + keys=['gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask'], + visualize=dict(flag=False, boundary_key='gt_shrink')), + dict( + type='Collect', + keys=['img', 'gt_shrink', 'gt_shrink_mask', 'gt_thr', 'gt_thr_mask']) +] + +test_pipeline_4068_1024 = {{_base_.test_pipeline_4068_1024}} + +data = dict( + samples_per_gpu=16, + workers_per_gpu=8, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_r50dcnv2), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024)) + +evaluation = dict(interval=200000, metric='hmean-iou') # do not evaluate diff --git a/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015.py b/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..bc6ab78cacc3f5b62549dfcf8c93cc0cc5c3a6ac --- /dev/null +++ b/configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015.py @@ -0,0 +1,39 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_1200e.py', + '../../_base_/det_models/dbnetpp_r50dcnv2_fpnc.py', + '../../_base_/det_datasets/icdar2015.py', + '../../_base_/det_pipelines/dbnet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_r50dcnv2 = {{_base_.train_pipeline_r50dcnv2}} +test_pipeline_4068_1024 = {{_base_.test_pipeline_4068_1024}} + +load_from = 'checkpoints/textdet/dbnetpp/res50dcnv2_synthtext.pth' + +data = dict( + samples_per_gpu=32, + workers_per_gpu=8, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_r50dcnv2), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_4068_1024)) + +evaluation = dict( + interval=100, + metric='hmean-iou', + save_best='0_hmean-iou:hmean', + rule='greater') diff --git a/configs/textdet/dbnetpp/metafile.yml b/configs/textdet/dbnetpp/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..b40571c11faf09bad058709ec333b9445f48b4f3 --- /dev/null +++ b/configs/textdet/dbnetpp/metafile.yml @@ -0,0 +1,28 @@ +Collections: +- Name: DBNetpp + Metadata: + Training Data: ICDAR2015 + Training Techniques: + - SGD with Momentum + - Weight Decay + Training Resources: 1x Nvidia A100 + Architecture: + - ResNet + - FPNC + Paper: + URL: https://arxiv.org/abs/2202.10304 + Title: 'Real-Time Scene Text Detection with Differentiable Binarization and Adaptive Scale Fusion' + README: configs/textdet/dbnetpp/README.md + +Models: + - Name: dbnetpp_r50dcnv2_fpnc_1200e_icdar2015.py + In Collection: DBNetpp + Config: configs/textdet/dbnetpp/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015.py + Metadata: + Training Data: ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2015 + Metrics: + hmean-iou: 0.860 + Weights: https://download.openmmlab.com/mmocr/textdet/dbnet/dbnetpp_r50dcnv2_fpnc_1200e_icdar2015-20220502-d7a76fff.pth diff --git a/configs/textdet/drrg/README.md b/configs/textdet/drrg/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2f2beb1b757ccbf2dd2e41a70769d963b098264d --- /dev/null +++ b/configs/textdet/drrg/README.md @@ -0,0 +1,37 @@ +# DRRG + +> [Deep relational reasoning graph network for arbitrary shape text detection](https://arxiv.org/abs/2003.07493) + + + +## Abstract + +Arbitrary shape text detection is a challenging task due to the high variety and complexity of scenes texts. In this paper, we propose a novel unified relational reasoning graph network for arbitrary shape text detection. In our method, an innovative local graph bridges a text proposal model via Convolutional Neural Network (CNN) and a deep relational reasoning network via Graph Convolutional Network (GCN), making our network end-to-end trainable. To be concrete, every text instance will be divided into a series of small rectangular components, and the geometry attributes (e.g., height, width, and orientation) of the small components will be estimated by our text proposal model. Given the geometry attributes, the local graph construction model can roughly establish linkages between different text components. For further reasoning and deducing the likelihood of linkages between the component and its neighbors, we adopt a graph-based network to perform deep relational reasoning on local graphs. Experiments on public available datasets demonstrate the state-of-the-art performance of our method. + +
+ +
+ +## Results and models + +### CTW1500 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :-------------------------------------------------: | :--------------: | :-----------: | :----------: | :-----: | :-------: | :-----------: | :-----------: | :-----------: | :---------------------------------------------------: | +| [DRRG](configs/textdet/drrg/drrg_r50_fpn_unet_1200e_ctw1500.py) | ImageNet | CTW1500 Train | CTW1500 Test | 1200 | 640 | 0.822 (0.791) | 0.858 (0.862) | 0.840 (0.825) | [model](https://download.openmmlab.com/mmocr/textdet/drrg/drrg_r50_fpn_unet_1200e_ctw1500_20211022-fb30b001.pth) \\ [log](https://download.openmmlab.com/mmocr/textdet/drrg/20210511_234719.log) | + +```{note} +We've upgraded our IoU backend from `Polygon3` to `shapely`. There are some performance differences for some models due to the backends' different logics to handle invalid polygons (more info [here](https://github.com/open-mmlab/mmocr/issues/465)). **New evaluation result is presented in brackets** and new logs will be uploaded soon. +``` + +## Citation + +```bibtex +@article{zhang2020drrg, + title={Deep relational reasoning graph network for arbitrary shape text detection}, + author={Zhang, Shi-Xue and Zhu, Xiaobin and Hou, Jie-Bo and Liu, Chang and Yang, Chun and Wang, Hongfa and Yin, Xu-Cheng}, + booktitle={CVPR}, + pages={9699-9708}, + year={2020} +} +``` diff --git a/configs/textdet/drrg/drrg_r50_fpn_unet_1200e_ctw1500.py b/configs/textdet/drrg/drrg_r50_fpn_unet_1200e_ctw1500.py new file mode 100644 index 0000000000000000000000000000000000000000..7121ef83297d3a1976c9b62d2b47f0b5ba52bd66 --- /dev/null +++ b/configs/textdet/drrg/drrg_r50_fpn_unet_1200e_ctw1500.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_1200e.py', + '../../_base_/det_models/drrg_r50_fpn_unet.py', + '../../_base_/det_datasets/ctw1500.py', + '../../_base_/det_pipelines/drrg_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=4, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=20, metric='hmean-iou') diff --git a/configs/textdet/drrg/metafile.yml b/configs/textdet/drrg/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..8e7224eb352d419fc65637d6b0fc17d6cc4230d8 --- /dev/null +++ b/configs/textdet/drrg/metafile.yml @@ -0,0 +1,27 @@ +Collections: +- Name: DRRG + Metadata: + Training Data: SCUT-CTW1500 + Training Techniques: + - SGD with Momentum + Training Resources: 1x GeForce GTX 3090 + Architecture: + - ResNet + - FPN_UNet + Paper: + URL: https://arxiv.org/abs/2003.07493.pdf + Title: 'Deep Relational Reasoning Graph Network for Arbitrary Shape Text Detection' + README: configs/textdet/drrg/README.md + +Models: + - Name: drrg_r50_fpn_unet_1200e_ctw1500 + In Collection: DRRG + Config: configs/textdet/drrg/drrg_r50_fpn_unet_1200e_ctw1500.py + Metadata: + Training Data: CTW1500 + Results: + - Task: Text Detection + Dataset: CTW1500 + Metrics: + hmean-iou: 0.840 + Weights: https://download.openmmlab.com/mmocr/textdet/drrg/drrg_r50_fpn_unet_1200e_ctw1500_20211022-fb30b001.pth diff --git a/configs/textdet/fcenet/README.md b/configs/textdet/fcenet/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f1acd2b1d8daa4557b16c8375b8c1ab4aa36cf6c --- /dev/null +++ b/configs/textdet/fcenet/README.md @@ -0,0 +1,38 @@ +# FCENet + +> [Fourier Contour Embedding for Arbitrary-Shaped Text Detection](https://arxiv.org/abs/2104.10442) + + + +## Abstract + +One of the main challenges for arbitrary-shaped text detection is to design a good text instance representation that allows networks to learn diverse text geometry variances. Most of existing methods model text instances in image spatial domain via masks or contour point sequences in the Cartesian or the polar coordinate system. However, the mask representation might lead to expensive post-processing, while the point sequence one may have limited capability to model texts with highly-curved shapes. To tackle these problems, we model text instances in the Fourier domain and propose one novel Fourier Contour Embedding (FCE) method to represent arbitrary shaped text contours as compact signatures. We further construct FCENet with a backbone, feature pyramid networks (FPN) and a simple post-processing with the Inverse Fourier Transformation (IFT) and Non-Maximum Suppression (NMS). Different from previous methods, FCENet first predicts compact Fourier signatures of text instances, and then reconstructs text contours via IFT and NMS during test. Extensive experiments demonstrate that FCE is accurate and robust to fit contours of scene texts even with highly-curved shapes, and also validate the effectiveness and the good generalization of FCENet for arbitrary-shaped text detection. Furthermore, experimental results show that our FCENet is superior to the state-of-the-art (SOTA) methods on CTW1500 and Total-Text, especially on challenging highly-curved text subset. + +
+ +
+ +## Results and models + +### CTW1500 + +| Method | Backbone | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :-------------------------------------------------: | :--------------: | :--------------: | :-----------: | :----------: | :-----: | :---------: | :----: | :-------: | :---: | :----------------------------------------------------: | +| [FCENet](/configs/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500.py) | ResNet50 + DCNv2 | ImageNet | CTW1500 Train | CTW1500 Test | 1500 | (736, 1080) | 0.828 | 0.875 | 0.851 | [model](https://download.openmmlab.com/mmocr/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500_20211022-e326d7ec.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/fcenet/20210511_181328.log.json) | + +### ICDAR2015 + +| Method | Backbone | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :-------------------------------------------------------: | :------: | :--------------: | :----------: | :-------: | :-----: | :----------: | :----: | :-------: | :---: | :---------------------------------------------------------: | +| [FCENet](/configs/textdet/fcenet/fcenet_r50_fpn_1500e_icdar2015.py) | ResNet50 | ImageNet | IC15 Train | IC15 Test | 1500 | (2260, 2260) | 0.819 | 0.880 | 0.849 | [model](https://download.openmmlab.com/mmocr/textdet/fcenet/fcenet_r50_fpn_1500e_icdar2015_20211022-daefb6ed.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/fcenet/20210601_222655.log.json) | + +## Citation + +```bibtex +@InProceedings{zhu2021fourier, + title={Fourier Contour Embedding for Arbitrary-Shaped Text Detection}, + author={Yiqin Zhu and Jianyong Chen and Lingyu Liang and Zhanghui Kuang and Lianwen Jin and Wayne Zhang}, + year={2021}, + booktitle = {CVPR} + } +``` diff --git a/configs/textdet/fcenet/fcenet_r50_fpn_1500e_icdar2015.py b/configs/textdet/fcenet/fcenet_r50_fpn_1500e_icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..d4a9c642307466c86f667d64bbeb4057db571b66 --- /dev/null +++ b/configs/textdet/fcenet/fcenet_r50_fpn_1500e_icdar2015.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_1500e.py', + '../../_base_/det_models/fcenet_r50_fpn.py', + '../../_base_/det_datasets/icdar2015.py', + '../../_base_/det_pipelines/fcenet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_icdar2015 = {{_base_.train_pipeline_icdar2015}} +test_pipeline_icdar2015 = {{_base_.test_pipeline_icdar2015}} + +data = dict( + samples_per_gpu=8, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_icdar2015), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500.py b/configs/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500.py new file mode 100644 index 0000000000000000000000000000000000000000..44bbfcd55a2efc29f441e06fb33079a48de61905 --- /dev/null +++ b/configs/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_1500e.py', + '../../_base_/det_models/fcenet_r50dcnv2_fpn.py', + '../../_base_/det_datasets/ctw1500.py', + '../../_base_/det_pipelines/fcenet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_ctw1500 = {{_base_.train_pipeline_ctw1500}} +test_pipeline_ctw1500 = {{_base_.test_pipeline_ctw1500}} + +data = dict( + samples_per_gpu=6, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_ctw1500), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/fcenet/metafile.yml b/configs/textdet/fcenet/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..7b60e518e2b28f281ea799179848cfb53e065d1c --- /dev/null +++ b/configs/textdet/fcenet/metafile.yml @@ -0,0 +1,38 @@ +Collections: +- Name: FCENet + Metadata: + Training Data: SCUT-CTW1500 + Training Techniques: + - SGD with Momentum + Training Resources: 1x GeForce GTX 2080 Ti + Architecture: + - ResNet with DCNv2 + - FPN + Paper: + URL: https://arxiv.org/abs/2002.02709.pdf + Title: 'FourierNet: Compact mask representation for instance segmentation using differentiable shape decoders' + README: configs/textdet/fcenet/README.md + +Models: + - Name: fcenet_r50dcnv2_fpn_1500e_ctw1500 + In Collection: FCENet + Config: configs/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500.py + Metadata: + Training Data: CTW1500 + Results: + - Task: Text Detection + Dataset: CTW1500 + Metrics: + hmean-iou: 0.851 + Weights: https://download.openmmlab.com/mmocr/textdet/fcenet/fcenet_r50dcnv2_fpn_1500e_ctw1500_20211022-e326d7ec.pth + - Name: fcenet_r50_fpn_1500e_icdar2015 + In Collection: FCENet + Config: configs/textdet/fcenet/fcenet_r50_fpn_1500e_icdar2015.py + Metadata: + Training Data: ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2015 + Metrics: + hmean-iou: 0.849 + Weights: https://download.openmmlab.com/mmocr/textdet/fcenet/fcenet_r50_fpn_1500e_icdar2015_20211022-daefb6ed.pth diff --git a/configs/textdet/maskrcnn/README.md b/configs/textdet/maskrcnn/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c6ef17e7659558a4f41834f4614d58caddcbe208 --- /dev/null +++ b/configs/textdet/maskrcnn/README.md @@ -0,0 +1,49 @@ +# Mask R-CNN + +> [Mask R-CNN](https://arxiv.org/abs/1703.06870) + + + +## Abstract + +We present a conceptually simple, flexible, and general framework for object instance segmentation. Our approach efficiently detects objects in an image while simultaneously generating a high-quality segmentation mask for each instance. The method, called Mask R-CNN, extends Faster R-CNN by adding a branch for predicting an object mask in parallel with the existing branch for bounding box recognition. Mask R-CNN is simple to train and adds only a small overhead to Faster R-CNN, running at 5 fps. Moreover, Mask R-CNN is easy to generalize to other tasks, e.g., allowing us to estimate human poses in the same framework. We show top results in all three tracks of the COCO suite of challenges, including instance segmentation, bounding-box object detection, and person keypoint detection. Without bells and whistles, Mask R-CNN outperforms all existing, single-model entries on every task, including the COCO 2016 challenge winners. We hope our simple and effective approach will serve as a solid baseline and help ease future research in instance-level recognition. + +
+ +
+ +## Results and models + +### CTW1500 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :----------------------------------------------------------: | :--------------: | :-----------: | :----------: | :-----: | :-------: | :----: | :-------: | :---: | :-------------------------------------------------------------: | +| [MaskRCNN](/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500.py) | ImageNet | CTW1500 Train | CTW1500 Test | 160 | 1600 | 0.753 | 0.712 | 0.732 | [model](https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500_20210219-96497a76.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500_20210219-96497a76.log.json) | + +### ICDAR2015 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :--------------------------------------------------------: | :--------------: | :-------------: | :------------: | :-----: | :-------: | :----: | :-------: | :---: | :-----------------------------------------------------------: | +| [MaskRCNN](/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015.py) | ImageNet | ICDAR2015 Train | ICDAR2015 Test | 160 | 1920 | 0.783 | 0.872 | 0.825 | [model](https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015_20210219-8eb340a3.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015_20210219-8eb340a3.log.json) | + +### ICDAR2017 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :---------------------------------------------------------: | :--------------: | :-------------: | :-----------: | :-----: | :-------: | :----: | :-------: | :---: | :-----------------------------------------------------------: | +| [MaskRCNN](/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017.py) | ImageNet | ICDAR2017 Train | ICDAR2017 Val | 160 | 1600 | 0.754 | 0.827 | 0.789 | [model](https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017_20210218-c6ec3ebb.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017_20210218-c6ec3ebb.log.json) | + +```{note} +We tuned parameters with the techniques in [Pyramid Mask Text Detector](https://arxiv.org/abs/1903.11800) +``` + +## Citation + +```bibtex +@INPROCEEDINGS{8237584, + author={K. {He} and G. {Gkioxari} and P. {Dollár} and R. {Girshick}}, + booktitle={2017 IEEE International Conference on Computer Vision (ICCV)}, + title={Mask R-CNN}, + year={2017}, + pages={2980-2988}, + doi={10.1109/ICCV.2017.322}} +``` diff --git a/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500.py b/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500.py new file mode 100644 index 0000000000000000000000000000000000000000..beeb1853d9f1067b9f1882d389d3ae83f88e3308 --- /dev/null +++ b/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem_poly.py', + '../../_base_/schedules/schedule_sgd_160e.py', + '../../_base_/det_datasets/ctw1500.py', + '../../_base_/det_pipelines/maskrcnn_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline_ctw1500 = {{_base_.test_pipeline_ctw1500}} + +data = dict( + samples_per_gpu=8, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015.py b/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..5feb0c61ff2738338527e1aceaa569051a655cf8 --- /dev/null +++ b/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem.py', + '../../_base_/schedules/schedule_sgd_160e.py', + '../../_base_/det_datasets/icdar2015.py', + '../../_base_/det_pipelines/maskrcnn_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline_icdar2015 = {{_base_.test_pipeline_icdar2015}} + +data = dict( + samples_per_gpu=8, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017.py b/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017.py new file mode 100644 index 0000000000000000000000000000000000000000..e22571e74511bab4303138f0e4816687fadac69e --- /dev/null +++ b/configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/det_models/ocr_mask_rcnn_r50_fpn_ohem.py', + '../../_base_/schedules/schedule_sgd_160e.py', + '../../_base_/det_datasets/icdar2017.py', + '../../_base_/det_pipelines/maskrcnn_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline_icdar2015 = {{_base_.test_pipeline_icdar2015}} + +data = dict( + samples_per_gpu=8, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/maskrcnn/metafile.yml b/configs/textdet/maskrcnn/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..90a2e3c3d33888beba652bf02c4cc1ae685eb24c --- /dev/null +++ b/configs/textdet/maskrcnn/metafile.yml @@ -0,0 +1,53 @@ +Collections: +- Name: Mask R-CNN + Metadata: + Training Data: ICDAR SCUT-CTW1500 + Training Techniques: + - SGD with Momentum + - Weight Decay + Training Resources: 8x GeForce GTX 1080 Ti + Architecture: + - ResNet + - FPN + - RPN + Paper: + URL: https://arxiv.org/pdf/1703.06870.pdf + Title: 'Mask R-CNN' + README: configs/textdet/maskrcnn/README.md + +Models: + - Name: mask_rcnn_r50_fpn_160e_ctw1500 + In Collection: Mask R-CNN + Config: configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500.py + Metadata: + Training Data: CTW1500 + Results: + - Task: Text Detection + Dataset: CTW1500 + Metrics: + hmean: 0.732 + Weights: https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_ctw1500_20210219-96497a76.pth + + - Name: mask_rcnn_r50_fpn_160e_icdar2015 + In Collection: Mask R-CNN + Config: configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015.py + Metadata: + Training Data: ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2015 + Metrics: + hmean: 0.825 + Weights: https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2015_20210219-8eb340a3.pth + + - Name: mask_rcnn_r50_fpn_160e_icdar2017 + In Collection: Mask R-CNN + Config: configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017.py + Metadata: + Training Data: ICDAR2017 + Results: + - Task: Text Detection + Dataset: ICDAR2017 + Metrics: + hmean: 0.789 + Weights: https://download.openmmlab.com/mmocr/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017_20210218-c6ec3ebb.pth diff --git a/configs/textdet/panet/README.md b/configs/textdet/panet/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b7cdf2f061996dbcd4da3a1db582545d6dc2a48f --- /dev/null +++ b/configs/textdet/panet/README.md @@ -0,0 +1,43 @@ +# PANet + +> [Efficient and Accurate Arbitrary-Shaped Text Detection with Pixel Aggregation Network](https://arxiv.org/abs/1908.05900) + + + +## Abstract + +Scene text detection, an important step of scene text reading systems, has witnessed rapid development with convolutional neural networks. Nonetheless, two main challenges still exist and hamper its deployment to real-world applications. The first problem is the trade-off between speed and accuracy. The second one is to model the arbitrary-shaped text instance. Recently, some methods have been proposed to tackle arbitrary-shaped text detection, but they rarely take the speed of the entire pipeline into consideration, which may fall short in practical this http URL this paper, we propose an efficient and accurate arbitrary-shaped text detector, termed Pixel Aggregation Network (PAN), which is equipped with a low computational-cost segmentation head and a learnable post-processing. More specifically, the segmentation head is made up of Feature Pyramid Enhancement Module (FPEM) and Feature Fusion Module (FFM). FPEM is a cascadable U-shaped module, which can introduce multi-level information to guide the better segmentation. FFM can gather the features given by the FPEMs of different depths into a final feature for segmentation. The learnable post-processing is implemented by Pixel Aggregation (PA), which can precisely aggregate text pixels by predicted similarity vectors. Experiments on several standard benchmarks validate the superiority of the proposed PAN. It is worth noting that our method can achieve a competitive F-measure of 79.9% at 84.2 FPS on CTW1500. + +
+ +
+ +## Results and models + +### CTW1500 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :-------------------------------------------------: | :--------------: | :-----------: | :----------: | :-----: | :-------: | :-----------: | :-----------: | :-----------: | :---------------------------------------------------: | +| [PANet](https://github.com/open-mmlab/mmocr/blob/main/configs/textdet/panet/panet_r18_fpem_ffm_600e_ctw1500.py) | ImageNet | CTW1500 Train | CTW1500 Test | 600 | 640 | 0.776 (0.717) | 0.838 (0.835) | 0.806 (0.801) | [model](https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_ctw1500_20210219-3b3a9aa3.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_ctw1500_20210219-3b3a9aa3.log.json) | + +### ICDAR2015 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :------------------------------------------------: | :--------------: | :-------------: | :------------: | :-----: | :-------: | :----------: | :----------: | :-----------: | :--------------------------------------------------: | +| [PANet](https://github.com/open-mmlab/mmocr/blob/main/configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py) | ImageNet | ICDAR2015 Train | ICDAR2015 Test | 600 | 736 | 0.734 (0.74) | 0.856 (0.86) | 0.791 (0.795) | [model](https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_icdar2015_20210219-42dbe46a.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_icdar2015_20210219-42dbe46a.log.json) | + +```{note} +We've upgraded our IoU backend from `Polygon3` to `shapely`. There are some performance differences for some models due to the backends' different logics to handle invalid polygons (more info [here](https://github.com/open-mmlab/mmocr/issues/465)). **New evaluation result is presented in brackets** and new logs will be uploaded soon. +``` + +## Citation + +```bibtex +@inproceedings{WangXSZWLYS19, + author={Wenhai Wang and Enze Xie and Xiaoge Song and Yuhang Zang and Wenjia Wang and Tong Lu and Gang Yu and Chunhua Shen}, + title={Efficient and Accurate Arbitrary-Shaped Text Detection With Pixel Aggregation Network}, + booktitle={ICCV}, + pages={8439--8448}, + year={2019} + } +``` diff --git a/configs/textdet/panet/metafile.yml b/configs/textdet/panet/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..945f521adcfc78c90583dce354e5db120c3d39f1 --- /dev/null +++ b/configs/textdet/panet/metafile.yml @@ -0,0 +1,39 @@ +Collections: +- Name: PANet + Metadata: + Training Data: ICDAR SCUT-CTW1500 + Training Techniques: + - Adam + Training Resources: 8x GeForce GTX 1080 Ti + Architecture: + - ResNet + - FPEM_FFM + Paper: + URL: https://arxiv.org/pdf/1803.01534.pdf + Title: 'Path Aggregation Network for Instance Segmentation' + README: configs/textdet/panet/README.md + +Models: + - Name: panet_r18_fpem_ffm_600e_ctw1500 + In Collection: PANet + Config: configs/textdet/panet/panet_r18_fpem_ffm_600e_ctw1500.py + Metadata: + Training Data: CTW1500 + Results: + - Task: Text Detection + Dataset: CTW1500 + Metrics: + hmean-iou: 0.806 + Weights: https://download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_ctw1500_20210219-3b3a9aa3.pth + + - Name: panet_r18_fpem_ffm_600e_icdar2015 + In Collection: PANet + Config: configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py + Metadata: + Training Data: ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2015 + Metrics: + hmean-iou: 0.791 + Weights: https://no.download.openmmlab.com/mmocr/textdet/panet/panet_r18_fpem_ffm_sbn_600e_icdar2015_20210219-42dbe46a.pth diff --git a/configs/textdet/panet/panet_r18_fpem_ffm_600e_ctw1500.py b/configs/textdet/panet/panet_r18_fpem_ffm_600e_ctw1500.py new file mode 100644 index 0000000000000000000000000000000000000000..91d23af68417b0c589964f0908d4de60dfcfc4e4 --- /dev/null +++ b/configs/textdet/panet/panet_r18_fpem_ffm_600e_ctw1500.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_600e.py', + '../../_base_/det_models/panet_r18_fpem_ffm.py', + '../../_base_/det_datasets/ctw1500.py', + '../../_base_/det_pipelines/panet_pipeline.py' +] + +model = {{_base_.model_poly}} + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_ctw1500 = {{_base_.train_pipeline_ctw1500}} +test_pipeline_ctw1500 = {{_base_.test_pipeline_ctw1500}} + +data = dict( + samples_per_gpu=2, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_ctw1500), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py b/configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..1183974024cf33d814f635ddb1454895fbd3c02c --- /dev/null +++ b/configs/textdet/panet/panet_r18_fpem_ffm_600e_icdar2015.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_600e.py', + '../../_base_/det_models/panet_r18_fpem_ffm.py', + '../../_base_/det_datasets/icdar2015.py', + '../../_base_/det_pipelines/panet_pipeline.py' +] + +model = {{_base_.model_quad}} + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_icdar2015 = {{_base_.train_pipeline_icdar2015}} +test_pipeline_icdar2015 = {{_base_.test_pipeline_icdar2015}} + +data = dict( + samples_per_gpu=8, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_icdar2015), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/panet/panet_r50_fpem_ffm_600e_icdar2017.py b/configs/textdet/panet/panet_r50_fpem_ffm_600e_icdar2017.py new file mode 100644 index 0000000000000000000000000000000000000000..0e9768d4742e845a45bd343d70bd06f3cb0e4fcb --- /dev/null +++ b/configs/textdet/panet/panet_r50_fpem_ffm_600e_icdar2017.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_600e.py', + '../../_base_/det_models/panet_r50_fpem_ffm.py', + '../../_base_/det_datasets/icdar2017.py', + '../../_base_/det_pipelines/panet_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline_icdar2017 = {{_base_.train_pipeline_icdar2017}} +test_pipeline_icdar2017 = {{_base_.test_pipeline_icdar2017}} + +data = dict( + samples_per_gpu=4, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline_icdar2017), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2017), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2017)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/psenet/README.md b/configs/textdet/psenet/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b4293a3ce823c5dd285fda86dbc47b41465129b3 --- /dev/null +++ b/configs/textdet/psenet/README.md @@ -0,0 +1,44 @@ +# PSENet + +> [Shape robust text detection with progressive scale expansion network](https://arxiv.org/abs/1903.12473) + + + +## Abstract + +Scene text detection has witnessed rapid progress especially with the recent development of convolutional neural networks. However, there still exists two challenges which prevent the algorithm into industry applications. On the one hand, most of the state-of-art algorithms require quadrangle bounding box which is in-accurate to locate the texts with arbitrary shape. On the other hand, two text instances which are close to each other may lead to a false detection which covers both instances. Traditionally, the segmentation-based approach can relieve the first problem but usually fail to solve the second challenge. To address these two challenges, in this paper, we propose a novel Progressive Scale Expansion Network (PSENet), which can precisely detect text instances with arbitrary shapes. More specifically, PSENet generates the different scale of kernels for each text instance, and gradually expands the minimal scale kernel to the text instance with the complete shape. Due to the fact that there are large geometrical margins among the minimal scale kernels, our method is effective to split the close text instances, making it easier to use segmentation-based methods to detect arbitrary-shaped text instances. Extensive experiments on CTW1500, Total-Text, ICDAR 2015 and ICDAR 2017 MLT validate the effectiveness of PSENet. Notably, on CTW1500, a dataset full of long curve texts, PSENet achieves a F-measure of 74.3% at 27 FPS, and our best F-measure (82.2%) outperforms state-of-art algorithms by 6.6%. The code will be released in the future. + +
+ +
+ +## Results and models + +### CTW1500 + +| Method | Backbone | Extra Data | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :------------------------------------------------: | :------: | :--------: | :-----------: | :----------: | :-----: | :-------: | :-----------: | :-----------: | :-----------: | :--------------------------------------------------: | +| [PSENet-4s](configs/textdet/psenet/psenet_r50_fpnf_600e_ctw1500.py) | ResNet50 | - | CTW1500 Train | CTW1500 Test | 600 | 1280 | 0.728 (0.717) | 0.849 (0.852) | 0.784 (0.779) | [model](https://download.openmmlab.com/mmocr/textdet/psenet/psenet_r50_fpnf_600e_ctw1500_20210401-216fed50.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/psenet/20210401_215421.log.json) | + +### ICDAR2015 + +| Method | Backbone | Extra Data | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :----------------------------------: | :------: | :---------------------------------------: | :----------: | :-------: | :-----: | :-------: | :-----------: | :-----------: | :-----------: | :-------------------------------------: | +| [PSENet-4s](configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2015.py) | ResNet50 | - | IC15 Train | IC15 Test | 600 | 2240 | 0.784 (0.753) | 0.831 (0.867) | 0.807 (0.806) | [model](https://download.openmmlab.com/mmocr/textdet/psenet/psenet_r50_fpnf_600e_icdar2015-c6131f0d.pth) \| [log](https://download.openmmlab.com/mmocr/textdet/psenet/20210331_214145.log.json) | +| [PSENet-4s](configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2015.py) | ResNet50 | pretrain on IC17 MLT [model](https://download.openmmlab.com/mmocr/textdet/psenet/psenet_r50_fpnf_600e_icdar2017_as_pretrain-3bd6056c.pth) | IC15 Train | IC15 Test | 600 | 2240 | 0.834 | 0.861 | 0.847 | [model](https://download.openmmlab.com/mmocr/textdet/psenet/psenet_r50_fpnf_600e_icdar2015_pretrain-eefd8fe6.pth) \| [log](<>) | + +```{note} +We've upgraded our IoU backend from `Polygon3` to `shapely`. There are some performance differences for some models due to the backends' different logics to handle invalid polygons (more info [here](https://github.com/open-mmlab/mmocr/issues/465)). **New evaluation result is presented in brackets** and new logs will be uploaded soon. +``` + +## Citation + +```bibtex +@inproceedings{wang2019shape, + title={Shape robust text detection with progressive scale expansion network}, + author={Wang, Wenhai and Xie, Enze and Li, Xiang and Hou, Wenbo and Lu, Tong and Yu, Gang and Shao, Shuai}, + booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition}, + pages={9336--9345}, + year={2019} +} +``` diff --git a/configs/textdet/psenet/metafile.yml b/configs/textdet/psenet/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..40ec1dd0de63b8055f3399506355629ee32f2ab9 --- /dev/null +++ b/configs/textdet/psenet/metafile.yml @@ -0,0 +1,51 @@ +Collections: +- Name: PSENet + Metadata: + Training Data: ICDAR SCUT-CTW1500 + Training Techniques: + - Adam + Training Resources: 8x GeForce GTX 1080 Ti + Architecture: + - ResNet + - FPNF + Paper: + URL: https://arxiv.org/abs/1806.02559.pdf + Title: 'Shape Robust Text Detection with Progressive Scale Expansion Network' + README: configs/textdet/psenet/README.md + +Models: + - Name: psenet_r50_fpnf_600e_ctw1500 + In Collection: PSENet + Config: configs/textdet/psenet/psenet_r50_fpnf_600e_ctw1500.py + Metadata: + Training Data: CTW1500 + Results: + - Task: Text Detection + Dataset: CTW1500 + Metrics: + hmean-iou: 0.784 + Weights: https://download.openmmlab.com/mmocr/textdet/psenet/psenet_r50_fpnf_600e_ctw1500_20210401-216fed50.pth + + - Name: psenet_r50_fpnf_600e_icdar2015 + In Collection: PSENet + Config: configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2015.py + Metadata: + Training Data: ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2015 + Metrics: + hmean-iou: 0.807 + Weights: https://download.openmmlab.com/mmocr/textdet/psenet/psenet_r50_fpnf_600e_icdar2015-c6131f0d.pth + + - Name: psenet_r50_fpnf_600e_icdar2015 + In Collection: PSENet + Config: configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2015.py + Metadata: + Training Data: ICDAR2017 ICDAR2015 + Results: + - Task: Text Detection + Dataset: ICDAR2017 ICDAR2015 + Metrics: + hmean-iou: 0.847 + Weights: https://download.openmmlab.com/mmocr/textdet/psenet/psenet_r50_fpnf_600e_icdar2015_pretrain-eefd8fe6.pth diff --git a/configs/textdet/psenet/psenet_r50_fpnf_600e_ctw1500.py b/configs/textdet/psenet/psenet_r50_fpnf_600e_ctw1500.py new file mode 100644 index 0000000000000000000000000000000000000000..483a2b2e1e7e584dfba26c7c5f506ce544953db8 --- /dev/null +++ b/configs/textdet/psenet/psenet_r50_fpnf_600e_ctw1500.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_600e.py', + '../../_base_/det_models/psenet_r50_fpnf.py', + '../../_base_/det_datasets/ctw1500.py', + '../../_base_/det_pipelines/psenet_pipeline.py' +] + +model = {{_base_.model_poly}} + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline_ctw1500 = {{_base_.test_pipeline_ctw1500}} + +data = dict( + samples_per_gpu=2, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_ctw1500)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2015.py b/configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2015.py new file mode 100644 index 0000000000000000000000000000000000000000..fbaacc19b19f6f8284eb65c7d2d2aa95e8051427 --- /dev/null +++ b/configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2015.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_600e.py', + '../../_base_/det_models/psenet_r50_fpnf.py', + '../../_base_/det_datasets/icdar2015.py', + '../../_base_/det_pipelines/psenet_pipeline.py' +] + +model = {{_base_.model_quad}} + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline_icdar2015 = {{_base_.test_pipeline_icdar2015}} + +data = dict( + samples_per_gpu=8, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2017.py b/configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2017.py new file mode 100644 index 0000000000000000000000000000000000000000..ca3d1105b5e6bdc9e47afa21dd3bc0b7d2ebd8d7 --- /dev/null +++ b/configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2017.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_600e.py', + '../../_base_/det_models/psenet_r50_fpnf.py', + '../../_base_/det_datasets/icdar2017.py', + '../../_base_/det_pipelines/psenet_pipeline.py' +] + +model = {{_base_.model_quad}} + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline_icdar2015 = {{_base_.test_pipeline_icdar2015}} + +data = dict( + samples_per_gpu=8, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline_icdar2015)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textdet/textsnake/README.md b/configs/textdet/textsnake/README.md new file mode 100644 index 0000000000000000000000000000000000000000..be7f3fe7bb15f5610669e937179adca7210039b8 --- /dev/null +++ b/configs/textdet/textsnake/README.md @@ -0,0 +1,33 @@ +# Textsnake + +> [TextSnake: A Flexible Representation for Detecting Text of Arbitrary Shapes](https://arxiv.org/abs/1807.01544) + + + +## Abstract + +Driven by deep neural networks and large scale datasets, scene text detection methods have progressed substantially over the past years, continuously refreshing the performance records on various standard benchmarks. However, limited by the representations (axis-aligned rectangles, rotated rectangles or quadrangles) adopted to describe text, existing methods may fall short when dealing with much more free-form text instances, such as curved text, which are actually very common in real-world scenarios. To tackle this problem, we propose a more flexible representation for scene text, termed as TextSnake, which is able to effectively represent text instances in horizontal, oriented and curved forms. In TextSnake, a text instance is described as a sequence of ordered, overlapping disks centered at symmetric axes, each of which is associated with potentially variable radius and orientation. Such geometry attributes are estimated via a Fully Convolutional Network (FCN) model. In experiments, the text detector based on TextSnake achieves state-of-the-art or comparable performance on Total-Text and SCUT-CTW1500, the two newly published benchmarks with special emphasis on curved text in natural images, as well as the widely-used datasets ICDAR 2015 and MSRA-TD500. Specifically, TextSnake outperforms the baseline on Total-Text by more than 40% in F-measure. + +
+ +
+ +## Results and models + +### CTW1500 + +| Method | Pretrained Model | Training set | Test set | #epochs | Test size | Recall | Precision | Hmean | Download | +| :----------------------------------------------------------: | :--------------: | :-----------: | :----------: | :-----: | :-------: | :----: | :-------: | :---: | :-------------------------------------------------------------: | +| [TextSnake](/configs/textdet/textsnake/textsnake_r50_fpn_unet_600e_ctw1500.py) | ImageNet | CTW1500 Train | CTW1500 Test | 1200 | 736 | 0.795 | 0.840 | 0.817 | [model](https://download.openmmlab.com/mmocr/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500-27f65b64.pth) \| [log](<>) | + +## Citation + +```bibtex +@article{long2018textsnake, + title={TextSnake: A Flexible Representation for Detecting Text of Arbitrary Shapes}, + author={Long, Shangbang and Ruan, Jiaqiang and Zhang, Wenjie and He, Xin and Wu, Wenhao and Yao, Cong}, + booktitle={ECCV}, + pages={20-36}, + year={2018} +} +``` diff --git a/configs/textdet/textsnake/metafile.yml b/configs/textdet/textsnake/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..9be247b84304df68df199c61592972aaf0b30fc9 --- /dev/null +++ b/configs/textdet/textsnake/metafile.yml @@ -0,0 +1,27 @@ +Collections: +- Name: TextSnake + Metadata: + Training Data: SCUT-CTW1500 + Training Techniques: + - SGD with Momentum + Training Resources: 8x GeForce GTX 1080 Ti + Architecture: + - ResNet + - FPN_UNet + Paper: + URL: https://arxiv.org/abs/1807.01544.pdf + Title: 'TextSnake: A Flexible Representation for Detecting Text of Arbitrary Shapes' + README: configs/textdet/textsnake/README.md + +Models: + - Name: textsnake_r50_fpn_unet_1200e_ctw1500 + In Collection: TextSnake + Config: configs/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500.py + Metadata: + Training Data: CTW1500 + Results: + - Task: Text Detection + Dataset: CTW1500 + Metrics: + hmean-iou: 0.817 + Weights: https://download.openmmlab.com/mmocr/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500-27f65b64.pth diff --git a/configs/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500.py b/configs/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500.py new file mode 100644 index 0000000000000000000000000000000000000000..045e89a3bb1fa44ff33da1d2b8b32b42e396c58b --- /dev/null +++ b/configs/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_sgd_1200e.py', + '../../_base_/det_models/textsnake_r50_fpn_unet.py', + '../../_base_/det_datasets/ctw1500.py', + '../../_base_/det_pipelines/textsnake_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=4, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=10, metric='hmean-iou') diff --git a/configs/textrecog/abinet/README.md b/configs/textrecog/abinet/README.md new file mode 100644 index 0000000000000000000000000000000000000000..40d8fdb7c7b62490de46fc4c411c495b6f1c8588 --- /dev/null +++ b/configs/textrecog/abinet/README.md @@ -0,0 +1,59 @@ +# ABINet + +> [Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition](https://arxiv.org/abs/2103.06495) + + + +## Abstract + +Linguistic knowledge is of great benefit to scene text recognition. However, how to effectively model linguistic rules in end-to-end deep networks remains a research challenge. In this paper, we argue that the limited capacity of language models comes from: 1) implicitly language modeling; 2) unidirectional feature representation; and 3) language model with noise input. Correspondingly, we propose an autonomous, bidirectional and iterative ABINet for scene text recognition. Firstly, the autonomous suggests to block gradient flow between vision and language models to enforce explicitly language modeling. Secondly, a novel bidirectional cloze network (BCN) as the language model is proposed based on bidirectional feature representation. Thirdly, we propose an execution manner of iterative correction for language model which can effectively alleviate the impact of noise input. Additionally, based on the ensemble of iterative predictions, we propose a self-training method which can learn from unlabeled images effectively. Extensive experiments indicate that ABINet has superiority on low-quality images and achieves state-of-the-art results on several mainstream benchmarks. Besides, the ABINet trained with ensemble self-training shows promising improvement in realizing human-level recognition. + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | note | +| :-------: | :----------: | :--------: | :----------: | +| Syn90k | 8919273 | 1 | synth | +| SynthText | 7239272 | 1 | alphanumeric | + +### Test Dataset + +| testset | instance_num | note | +| :-----: | :----------: | :-------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular | +| CT80 | 288 | irregular | + +## Results and models + +| methods | pretrained | | Regular Text | | | Irregular Text | | download | +| :------------------------------------------------: | :----------------------------------------------------: | :----: | :----------: | :--: | :--: | :------------: | :--: | :--------------------------------------------------- | +| | | IIIT5K | SVT | IC13 | IC15 | SVTP | CT80 | | +| [ABINet-Vision](https://github.com/open-mmlab/mmocr/tree/master/configs/textrecog/abinet/abinet_vision_only_academic.py) | - | 94.7 | 91.7 | 93.6 | 83.0 | 85.1 | 86.5 | [model](https://download.openmmlab.com/mmocr/textrecog/abinet/abinet_vision_only_academic-e6b9ea89.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/abinet/20211201_195512.log) | +| [ABINet](https://github.com/open-mmlab/mmocr/tree/master/configs/textrecog/abinet/abinet_academic.py) | [Pretrained](https://download.openmmlab.com/mmocr/textrecog/abinet/abinet_pretrain-1bed979b.pth) | 95.7 | 94.6 | 95.7 | 85.1 | 90.4 | 90.3 | [model](https://download.openmmlab.com/mmocr/textrecog/abinet/abinet_academic-f718abf6.pth) \| [log1](https://download.openmmlab.com/mmocr/textrecog/abinet/20211210_095832.log) \| [log2](https://download.openmmlab.com/mmocr/textrecog/abinet/20211213_131724.log) | + +```{note} +1. ABINet allows its encoder to run and be trained without decoder and fuser. Its encoder is designed to recognize texts as a stand-alone model and therefore can work as an independent text recognizer. We release it as ABINet-Vision. +2. Facts about the pretrained model: MMOCR does not have a systematic pipeline to pretrain the language model (LM) yet, thus the weights of LM are converted from [the official pretrained model](https://github.com/FangShancheng/ABINet). The weights of ABINet-Vision are directly used as the vision model of ABINet. +3. Due to some technical issues, the training process of ABINet was interrupted at the 13th epoch and we resumed it later. Both logs are released for full reference. +4. The model architecture in the logs looks slightly different from the final released version, since it was refactored afterward. However, both architectures are essentially equivalent. +``` + +## Citation + +```bibtex +@article{fang2021read, + title={Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition}, + author={Fang, Shancheng and Xie, Hongtao and Wang, Yuxin and Mao, Zhendong and Zhang, Yongdong}, + booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition}, + year={2021} +} +``` diff --git a/configs/textrecog/abinet/abinet_academic.py b/configs/textrecog/abinet/abinet_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..4abb87a6ee576a6c8a299d30baf4fee2ae56a1bf --- /dev/null +++ b/configs/textrecog/abinet/abinet_academic.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_20e.py', + '../../_base_/recog_pipelines/abinet_pipeline.py', + '../../_base_/recog_models/abinet.py', + # '../../_base_/recog_datasets/ST_MJ_alphanumeric_train.py', + '../../_base_/recog_datasets/toy_data.py' + # '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=192, + workers_per_gpu=8, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/abinet/abinet_vision_only_academic.py b/configs/textrecog/abinet/abinet_vision_only_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..318144d2418c7e77568d4915d72f01882835ba94 --- /dev/null +++ b/configs/textrecog/abinet/abinet_vision_only_academic.py @@ -0,0 +1,81 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_20e.py', + '../../_base_/recog_pipelines/abinet_pipeline.py', + '../../_base_/recog_datasets/toy_data.py' + # '../../_base_/recog_datasets/ST_MJ_alphanumeric_train.py', + # '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +# Model +num_chars = 37 +max_seq_len = 26 +label_convertor = dict( + type='ABIConvertor', + dict_type='DICT36', + with_unknown=False, + with_padding=False, + lower=True, +) + +model = dict( + type='ABINet', + backbone=dict(type='ResNetABI'), + encoder=dict( + type='ABIVisionModel', + encoder=dict( + type='TransformerEncoder', + n_layers=3, + n_head=8, + d_model=512, + d_inner=2048, + dropout=0.1, + max_len=8 * 32, + ), + decoder=dict( + type='ABIVisionDecoder', + in_channels=512, + num_channels=64, + attn_height=8, + attn_width=32, + attn_mode='nearest', + use_result='feature', + num_chars=num_chars, + max_seq_len=max_seq_len, + init_cfg=dict(type='Xavier', layer='Conv2d')), + ), + loss=dict( + type='ABILoss', + enc_weight=1.0, + dec_weight=1.0, + fusion_weight=1.0, + num_classes=num_chars), + label_convertor=label_convertor, + max_seq_len=max_seq_len, + iter_size=1) + +data = dict( + samples_per_gpu=192, + workers_per_gpu=8, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/abinet/metafile.yml b/configs/textrecog/abinet/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..14b5561019191aac73ad3bf63c5dc331f66972fe --- /dev/null +++ b/configs/textrecog/abinet/metafile.yml @@ -0,0 +1,87 @@ +Collections: +- Name: ABINet + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adam + Epochs: 20 + Batch Size: 1536 + Training Resources: 8x Tesla V100 + Architecture: + - ResNetABI + - ABIVisionModel + - ABILanguageDecoder + - ABIFuser + Paper: + URL: https://arxiv.org/pdf/2103.06495.pdf + Title: 'Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition' + README: configs/textrecog/abinet/README.md + +Models: + - Name: abinet_vision_only_academic + In Collection: ABINet + Config: configs/textrecog/abinet/abinet_vision_only_academic.py + Metadata: + Training Data: + - SynthText + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 94.7 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 91.7 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 93.6 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 83.0 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 85.1 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 86.5 + Weights: https://download.openmmlab.com/mmocr/textrecog/abinet/abinet_vision_only_academic-e6b9ea89.pth + + - Name: abinet_academic + In Collection: ABINet + Config: configs/textrecog/abinet/abinet_academic.py + Metadata: + Training Data: + - SynthText + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 95.7 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 94.6 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 95.7 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 85.1 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 90.4 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 90.3 + Weights: https://download.openmmlab.com/mmocr/textrecog/abinet/abinet_academic-f718abf6.pth diff --git a/configs/textrecog/crnn/README.md b/configs/textrecog/crnn/README.md new file mode 100644 index 0000000000000000000000000000000000000000..52232587e512eb53f16e652e3f3afd0a53686faf --- /dev/null +++ b/configs/textrecog/crnn/README.md @@ -0,0 +1,50 @@ +# CRNN + +> [An end-to-end trainable neural network for image-based sequence recognition and its application to scene text recognition](https://arxiv.org/abs/1507.05717) + + + +## Abstract + +Image-based sequence recognition has been a long-standing research topic in computer vision. In this paper, we investigate the problem of scene text recognition, which is among the most important and challenging tasks in image-based sequence recognition. A novel neural network architecture, which integrates feature extraction, sequence modeling and transcription into a unified framework, is proposed. Compared with previous systems for scene text recognition, the proposed architecture possesses four distinctive properties: (1) It is end-to-end trainable, in contrast to most of the existing algorithms whose components are separately trained and tuned. (2) It naturally handles sequences in arbitrary lengths, involving no character segmentation or horizontal scale normalization. (3) It is not confined to any predefined lexicon and achieves remarkable performances in both lexicon-free and lexicon-based scene text recognition tasks. (4) It generates an effective yet much smaller model, which is more practical for real-world application scenarios. The experiments on standard benchmarks, including the IIIT-5K, Street View Text and ICDAR datasets, demonstrate the superiority of the proposed algorithm over the prior arts. Moreover, the proposed algorithm performs well in the task of image-based music score recognition, which evidently verifies the generality of it. + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | note | +| :------: | :----------: | :--------: | :---: | +| Syn90k | 8919273 | 1 | synth | + +### Test Dataset + +| testset | instance_num | note | +| :-----: | :----------: | :-------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular | +| CT80 | 288 | irregular | + +## Results and models + +| methods | | Regular Text | | | | Irregular Text | | download | +| :------------------------------------------------------: | :----: | :----------: | :--: | :-: | :--: | :------------: | :--: | :-----------------------------------------------------------------------------------------------: | +| methods | IIIT5K | SVT | IC13 | | IC15 | SVTP | CT80 | | +| [CRNN](/configs/textrecog/crnn/crnn_academic_dataset.py) | 80.5 | 81.5 | 86.5 | | 54.1 | 59.1 | 55.6 | [model](https://download.openmmlab.com/mmocr/textrecog/crnn/crnn_academic-a723a1c5.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/crnn/20210326_111035.log.json) | + +## Citation + +```bibtex +@article{shi2016end, + title={An end-to-end trainable neural network for image-based sequence recognition and its application to scene text recognition}, + author={Shi, Baoguang and Bai, Xiang and Yao, Cong}, + journal={IEEE transactions on pattern analysis and machine intelligence}, + year={2016} +} +``` diff --git a/configs/textrecog/crnn/crnn_academic_dataset.py b/configs/textrecog/crnn/crnn_academic_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..b8288cb5a1cb48ddc6b32e988b45305e01e76df5 --- /dev/null +++ b/configs/textrecog/crnn/crnn_academic_dataset.py @@ -0,0 +1,35 @@ +_base_ = [ + '../../_base_/default_runtime.py', '../../_base_/recog_models/crnn.py', + '../../_base_/recog_pipelines/crnn_pipeline.py', + '../../_base_/recog_datasets/MJ_train.py', + '../../_base_/recog_datasets/academic_test.py', + '../../_base_/schedules/schedule_adadelta_5e.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=64, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') + +cudnn_benchmark = True diff --git a/configs/textrecog/crnn/crnn_toy_dataset.py b/configs/textrecog/crnn/crnn_toy_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..f61c68afe285e4d1943cbcbb8ede1fe965a99a4b --- /dev/null +++ b/configs/textrecog/crnn/crnn_toy_dataset.py @@ -0,0 +1,47 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_pipelines/crnn_pipeline.py', + '../../_base_/recog_datasets/toy_data.py', + '../../_base_/schedules/schedule_adadelta_5e.py' +] + +label_convertor = dict( + type='CTCConvertor', dict_type='DICT36', with_unknown=True, lower=True) + +model = dict( + type='CRNNNet', + preprocessor=None, + backbone=dict(type='VeryDeepVgg', leaky_relu=False, input_channels=1), + encoder=None, + decoder=dict(type='CRNNDecoder', in_channels=512, rnn_flag=True), + loss=dict(type='CTCLoss'), + label_convertor=label_convertor, + pretrained=None) + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=32, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') + +cudnn_benchmark = True diff --git a/configs/textrecog/crnn/metafile.yml b/configs/textrecog/crnn/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..c7b058c6a27d8a627788d702bc4ee942713ad7db --- /dev/null +++ b/configs/textrecog/crnn/metafile.yml @@ -0,0 +1,37 @@ +Collections: +- Name: CRNN + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adadelta + Epochs: 5 + Batch Size: 256 + Training Resources: 4x GeForce GTX 1080 Ti + Architecture: + - VeryDeepVgg + - CRNNDecoder + Paper: + URL: https://arxiv.org/pdf/1507.05717.pdf + Title: 'An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to Scene Text Recognition' + README: configs/textrecog/crnn/README.md + +Models: + - Name: crnn_academic_dataset + In Collection: CRNN + Config: configs/textrecog/crnn/crnn_academic_dataset.py + Metadata: + Training Data: Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 80.5 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 81.5 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 86.5 + Weights: https://download.openmmlab.com/mmocr/textrecog/crnn/crnn_academic-a723a1c5.pth diff --git a/configs/textrecog/master/README.md b/configs/textrecog/master/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ce89cc2911e26813c9d594b0a8dbab7f88db5d37 --- /dev/null +++ b/configs/textrecog/master/README.md @@ -0,0 +1,52 @@ +# MASTER + +> [MASTER: Multi-aspect non-local network for scene text recognition](https://arxiv.org/abs/1910.02562) + + + +## Abstract + +Attention-based scene text recognizers have gained huge success, which leverages a more compact intermediate representation to learn 1d- or 2d- attention by a RNN-based encoder-decoder architecture. However, such methods suffer from attention-drift problem because high similarity among encoded features leads to attention confusion under the RNN-based local attention mechanism. Moreover, RNN-based methods have low efficiency due to poor parallelization. To overcome these problems, we propose the MASTER, a self-attention based scene text recognizer that (1) not only encodes the input-output attention but also learns self-attention which encodes feature-feature and target-target relationships inside the encoder and decoder and (2) learns a more powerful and robust intermediate representation to spatial distortion, and (3) owns a great training efficiency because of high training parallelization and a high-speed inference because of an efficient memory-cache mechanism. Extensive experiments on various benchmarks demonstrate the superior performance of our MASTER on both regular and irregular scene text. + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | source | +| :-------: | :----------: | :--------: | :----: | +| SynthText | 7266686 | 1 | synth | +| SynthAdd | 1216889 | 1 | synth | +| Syn90k | 8919273 | 1 | synth | + +### Test Dataset + +| testset | instance_num | type | +| :-----: | :----------: | :-------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular | +| CT80 | 288 | irregular | + +## Results and Models + +| Methods | Backbone | | Regular Text | | | | Irregular Text | | download | +| :------------------------------------------------------------: | :-----------: | :----: | :----------: | :---: | :-: | :---: | :------------: | :---: | :-------------------------------------------------------------------------: | +| | | IIIT5K | SVT | IC13 | | IC15 | SVTP | CT80 | | +| [MASTER](/configs/textrecog/master/master_r31_12e_ST_MJ_SA.py) | R31-GCAModule | 95.27 | 89.8 | 95.17 | | 77.03 | 82.95 | 89.93 | [model](https://download.openmmlab.com/mmocr/textrecog/master/master_r31_12e_ST_MJ_SA-787edd36.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/master/master_r31_12e_ST_MJ_SA-787edd36.log.json) | + +## Citation + +```bibtex +@article{Lu2021MASTER, + title={{MASTER}: Multi-Aspect Non-local Network for Scene Text Recognition}, + author={Ning Lu and Wenwen Yu and Xianbiao Qi and Yihao Chen and Ping Gong and Rong Xiao and Xiang Bai}, + journal={Pattern Recognition}, + year={2021} +} +``` diff --git a/configs/textrecog/master/master_r31_12e_ST_MJ_SA.py b/configs/textrecog/master/master_r31_12e_ST_MJ_SA.py new file mode 100644 index 0000000000000000000000000000000000000000..88f4dbeae79584720134969a9ff1179e0352471d --- /dev/null +++ b/configs/textrecog/master/master_r31_12e_ST_MJ_SA.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', '../../_base_/recog_models/master.py', + '../../_base_/schedules/schedule_adam_step_12e.py', + '../../_base_/recog_pipelines/master_pipeline.py', + '../../_base_/recog_datasets/ST_SA_MJ_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=512, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=128), + test_dataloader=dict(samples_per_gpu=128), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/master/master_toy_dataset.py b/configs/textrecog/master/master_toy_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..3d0440240a28a2d64b2f0442cae7d628a7542f42 --- /dev/null +++ b/configs/textrecog/master/master_toy_dataset.py @@ -0,0 +1,30 @@ +_base_ = [ + '../../_base_/default_runtime.py', '../../_base_/recog_models/master.py', + '../../_base_/schedules/schedule_adam_step_12e.py', + '../../_base_/recog_pipelines/master_pipeline.py', + '../../_base_/recog_datasets/toy_data.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + workers_per_gpu=2, + samples_per_gpu=8, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/master/metafile.yml b/configs/textrecog/master/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..1eb6b11e2835a2c9ca1f8f5f15a7509351871bcb --- /dev/null +++ b/configs/textrecog/master/metafile.yml @@ -0,0 +1,52 @@ +Collections: + - Name: MASTER + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adam + Epochs: 12 + Batch Size: 512 + Training Resources: 4x Tesla A100 + Architecture: + - ResNet31-GCAModule + - MASTERDecoder + Paper: + URL: https://arxiv.org/abs/1910.02562 + Title: "MASTER: Multi-Aspect Non-local Network for Scene Text Recognition" + README: configs/textrecog/master/README.md + +Models: + - Name: master_academic + In Collection: MASTER + Config: configs/textrecog/master/master_r31_12e_ST_MJ_SA.py + Metadata: + Training Data: + - SynthText + - SynthAdd + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 95.27 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 89.8 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 95.17 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 77.03 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 82.95 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 89.93 + Weights: https://download.openmmlab.com/mmocr/textrecog/master/master_r31_12e_ST_MJ_SA-787edd36.pth diff --git a/configs/textrecog/nrtr/README.md b/configs/textrecog/nrtr/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f64af8923d9b81493478fc458f93a19786abd0f7 --- /dev/null +++ b/configs/textrecog/nrtr/README.md @@ -0,0 +1,66 @@ +# NRTR + +> [NRTR: A No-Recurrence Sequence-to-Sequence Model For Scene Text Recognition](https://arxiv.org/abs/1806.00926) + + + +## Abstract + +Scene text recognition has attracted a great many researches due to its importance to various applications. Existing methods mainly adopt recurrence or convolution based networks. Though have obtained good performance, these methods still suffer from two limitations: slow training speed due to the internal recurrence of RNNs, and high complexity due to stacked convolutional layers for long-term feature extraction. This paper, for the first time, proposes a no-recurrence sequence-to-sequence text recognizer, named NRTR, that dispenses with recurrences and convolutions entirely. NRTR follows the encoder-decoder paradigm, where the encoder uses stacked self-attention to extract image features, and the decoder applies stacked self-attention to recognize texts based on encoder output. NRTR relies solely on self-attention mechanism thus could be trained with more parallelization and less complexity. Considering scene image has large variation in text and background, we further design a modality-transform block to effectively transform 2D input images to 1D sequences, combined with the encoder to extract more discriminative features. NRTR achieves state-of-the-art or highly competitive performance on both regular and irregular benchmarks, while requires only a small fraction of training time compared to the best model from the literature (at least 8 times faster). + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | source | +| :-------: | :----------: | :--------: | :----: | +| SynthText | 7266686 | 1 | synth | +| Syn90k | 8919273 | 1 | synth | + +### Test Dataset + +| testset | instance_num | type | +| :-----: | :----------: | :-------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular | +| CT80 | 288 | irregular | + +## Results and Models + +| Methods | Backbone | | Regular Text | | | | Irregular Text | | download | +| :-------------------------------------------------------------: | :----------: | :----: | :----------: | :--: | :-: | :--: | :------------: | :--: | :----------------------------------------------------------------------------: | +| | | IIIT5K | SVT | IC13 | | IC15 | SVTP | CT80 | | +| [NRTR](/configs/textrecog/nrtr/nrtr_r31_1by16_1by8_academic.py) | R31-1/16-1/8 | 94.7 | 87.3 | 94.3 | | 73.5 | 78.9 | 85.1 | [model](https://download.openmmlab.com/mmocr/textrecog/nrtr/nrtr_r31_1by16_1by8_academic_20211124-f60cebf4.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/nrtr/20211124_002420.log.json) | +| [NRTR](/configs/textrecog/nrtr/nrtr_r31_1by8_1by4_academic.py) | R31-1/8-1/4 | 95.2 | 90.0 | 94.0 | | 74.1 | 79.4 | 88.2 | [model](https://download.openmmlab.com/mmocr/textrecog/nrtr/nrtr_r31_1by8_1by4_academic_20211123-e1fdb322.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/nrtr/20211123_232151.log.json) | + +```{note} + +- For backbone `R31-1/16-1/8`: + - The output consists of 92 classes, including 26 lowercase letters, 26 uppercase letters, 28 symbols, 10 digital numbers, 1 unknown token and 1 end-of-sequence token. + - The encoder-block number is 6. + - `1/16-1/8` means the height of feature from backbone is 1/16 of input image, where 1/8 for width. +- For backbone `R31-1/8-1/4`: + - The output consists of 92 classes, including 26 lowercase letters, 26 uppercase letters, 28 symbols, 10 digital numbers, 1 unknown token and 1 end-of-sequence token. + - The encoder-block number is 6. + - `1/8-1/4` means the height of feature from backbone is 1/8 of input image, where 1/4 for width. +``` + +## Citation + +```bibtex +@inproceedings{sheng2019nrtr, + title={NRTR: A no-recurrence sequence-to-sequence model for scene text recognition}, + author={Sheng, Fenfen and Chen, Zhineng and Xu, Bo}, + booktitle={2019 International Conference on Document Analysis and Recognition (ICDAR)}, + pages={781--786}, + year={2019}, + organization={IEEE} +} +``` diff --git a/configs/textrecog/nrtr/metafile.yml b/configs/textrecog/nrtr/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..7d5ca150109386635eba9f3739891d2b58955634 --- /dev/null +++ b/configs/textrecog/nrtr/metafile.yml @@ -0,0 +1,86 @@ +Collections: +- Name: NRTR + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adam + Epochs: 6 + Batch Size: 6144 + Training Resources: 48x GeForce GTX 1080 Ti + Architecture: + - CNN + - NRTREncoder + - NRTRDecoder + Paper: + URL: https://arxiv.org/pdf/1806.00926.pdf + Title: 'NRTR: A No-Recurrence Sequence-to-Sequence Model For Scene Text Recognition' + README: configs/textrecog/nrtr/README.md + +Models: + - Name: nrtr_r31_1by16_1by8_academic + In Collection: NRTR + Config: configs/textrecog/nrtr/nrtr_r31_1by16_1by8_academic.py + Metadata: + Training Data: + - SynthText + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 94.7 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 87.3 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 94.3 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 73.5 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 78.9 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 85.1 + Weights: https://download.openmmlab.com/mmocr/textrecog/nrtr/nrtr_r31_1by16_1by8_academic_20211124-f60cebf4.pth + + - Name: nrtr_r31_1by8_1by4_academic + In Collection: NRTR + Config: configs/textrecog/nrtr/nrtr_r31_1by8_1by4_academic.py + Metadata: + Training Data: + - SynthText + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 95.2 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 90.0 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 94.0 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 74.1 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 79.4 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 88.2 + Weights: https://download.openmmlab.com/mmocr/textrecog/nrtr/nrtr_r31_1by8_1by4_academic_20211123-e1fdb322.pth diff --git a/configs/textrecog/nrtr/nrtr_modality_transform_academic.py b/configs/textrecog/nrtr/nrtr_modality_transform_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..471926ba998640123ff356c146dc8bbdb9b3c261 --- /dev/null +++ b/configs/textrecog/nrtr/nrtr_modality_transform_academic.py @@ -0,0 +1,32 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_models/nrtr_modality_transform.py', + '../../_base_/schedules/schedule_adam_step_6e.py', + '../../_base_/recog_datasets/ST_MJ_train.py', + '../../_base_/recog_datasets/academic_test.py', + '../../_base_/recog_pipelines/nrtr_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=128, + workers_per_gpu=4, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/nrtr/nrtr_modality_transform_toy_dataset.py b/configs/textrecog/nrtr/nrtr_modality_transform_toy_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..1bb350fc3f49418f2841df2d65f183c34e08db0e --- /dev/null +++ b/configs/textrecog/nrtr/nrtr_modality_transform_toy_dataset.py @@ -0,0 +1,31 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_models/nrtr_modality_transform.py', + '../../_base_/schedules/schedule_adam_step_6e.py', + '../../_base_/recog_datasets/toy_data.py', + '../../_base_/recog_pipelines/nrtr_pipeline.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=16, + workers_per_gpu=2, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/nrtr/nrtr_r31_1by16_1by8_academic.py b/configs/textrecog/nrtr/nrtr_r31_1by16_1by8_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..b7adc0d30cda5e5556821ff941d6e00dcd3b4ba7 --- /dev/null +++ b/configs/textrecog/nrtr/nrtr_r31_1by16_1by8_academic.py @@ -0,0 +1,48 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_6e.py', + '../../_base_/recog_pipelines/nrtr_pipeline.py', + '../../_base_/recog_datasets/ST_MJ_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +model = dict( + type='NRTR', + backbone=dict( + type='ResNet31OCR', + layers=[1, 2, 5, 3], + channels=[32, 64, 128, 256, 512, 512], + stage4_pool_cfg=dict(kernel_size=(2, 1), stride=(2, 1)), + last_stage_pool=True), + encoder=dict(type='NRTREncoder'), + decoder=dict(type='NRTRDecoder'), + loss=dict(type='TFLoss'), + label_convertor=label_convertor, + max_seq_len=40) + +data = dict( + samples_per_gpu=128, + workers_per_gpu=4, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/nrtr/nrtr_r31_1by8_1by4_academic.py b/configs/textrecog/nrtr/nrtr_r31_1by8_1by4_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..397122b55ea57df647a6bb5097973e0eebf4979d --- /dev/null +++ b/configs/textrecog/nrtr/nrtr_r31_1by8_1by4_academic.py @@ -0,0 +1,48 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_6e.py', + '../../_base_/recog_pipelines/nrtr_pipeline.py', + '../../_base_/recog_datasets/ST_MJ_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +model = dict( + type='NRTR', + backbone=dict( + type='ResNet31OCR', + layers=[1, 2, 5, 3], + channels=[32, 64, 128, 256, 512, 512], + stage4_pool_cfg=dict(kernel_size=(2, 1), stride=(2, 1)), + last_stage_pool=False), + encoder=dict(type='NRTREncoder'), + decoder=dict(type='NRTRDecoder'), + loss=dict(type='TFLoss'), + label_convertor=label_convertor, + max_seq_len=40) + +data = dict( + samples_per_gpu=64, + workers_per_gpu=4, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/robust_scanner/README.md b/configs/textrecog/robust_scanner/README.md new file mode 100644 index 0000000000000000000000000000000000000000..165ef248c56640f55772ac5c1d2aae29e69d42e8 --- /dev/null +++ b/configs/textrecog/robust_scanner/README.md @@ -0,0 +1,61 @@ +# RobustScanner + +> [RobustScanner: Dynamically Enhancing Positional Clues for Robust Text Recognition](https://arxiv.org/abs/2007.07542) + + + +## Abstract + +The attention-based encoder-decoder framework has recently achieved impressive results for scene text recognition, and many variants have emerged with improvements in recognition quality. However, it performs poorly on contextless texts (e.g., random character sequences) which is unacceptable in most of real application scenarios. In this paper, we first deeply investigate the decoding process of the decoder. We empirically find that a representative character-level sequence decoder utilizes not only context information but also positional information. Contextual information, which the existing approaches heavily rely on, causes the problem of attention drift. To suppress such side-effect, we propose a novel position enhancement branch, and dynamically fuse its outputs with those of the decoder attention module for scene text recognition. Specifically, it contains a position aware module to enable the encoder to output feature vectors encoding their own spatial positions, and an attention module to estimate glimpses using the positional clue (i.e., the current decoding time step) only. The dynamic fusion is conducted for more robust feature via an element-wise gate mechanism. Theoretically, our proposed method, dubbed \\emph{RobustScanner}, decodes individual characters with dynamic ratio between context and positional clues, and utilizes more positional ones when the decoding sequences with scarce context, and thus is robust and practical. Empirically, it has achieved new state-of-the-art results on popular regular and irregular text recognition benchmarks while without much performance drop on contextless benchmarks, validating its robustness in both contextual and contextless application scenarios. + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | source | +| :--------: | :----------: | :--------: | :------------------------: | +| icdar_2011 | 3567 | 20 | real | +| icdar_2013 | 848 | 20 | real | +| icdar2015 | 4468 | 20 | real | +| coco_text | 42142 | 20 | real | +| IIIT5K | 2000 | 20 | real | +| SynthText | 2400000 | 1 | synth | +| SynthAdd | 1216889 | 1 | synth, 1.6m in [\[1\]](#1) | +| Syn90k | 2400000 | 1 | synth | + +### Test Dataset + +| testset | instance_num | type | +| :-----: | :----------: | :---------------------------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular, 639 in [\[1\]](#1) | +| CT80 | 288 | irregular | + +## Results and Models + +| Methods | GPUs | | Regular Text | | | | Irregular Text | | download | +| :------------------------------------------------------------------------: | :--: | :----: | :----------: | :--: | :-: | :--: | :------------: | :--: | :-------------------------------------------------------------------------: | +| | | IIIT5K | SVT | IC13 | | IC15 | SVTP | CT80 | | +| [RobustScanner](configs/textrecog/robust_scanner/robustscanner_r31_academic.py) | 16 | 95.1 | 89.2 | 93.1 | | 77.8 | 80.3 | 90.3 | [model](https://download.openmmlab.com/mmocr/textrecog/robustscanner/robustscanner_r31_academic-5f05874f.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/robustscanner/20210401_170932.log.json) | + +## References + +\[1\] Li, Hui and Wang, Peng and Shen, Chunhua and Zhang, Guyu. Show, attend and read: A simple and strong baseline for irregular text recognition. In AAAI 2019. + +## Citation + +```bibtex +@inproceedings{yue2020robustscanner, + title={RobustScanner: Dynamically Enhancing Positional Clues for Robust Text Recognition}, + author={Yue, Xiaoyu and Kuang, Zhanghui and Lin, Chenhao and Sun, Hongbin and Zhang, Wayne}, + booktitle={European Conference on Computer Vision}, + year={2020} +} +``` diff --git a/configs/textrecog/robust_scanner/metafile.yml b/configs/textrecog/robust_scanner/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..95892543d9bc81bf45b08aecdb4e139c90490100 --- /dev/null +++ b/configs/textrecog/robust_scanner/metafile.yml @@ -0,0 +1,58 @@ +Collections: +- Name: RobustScanner + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adam + Epochs: 5 + Batch Size: 1024 + Training Resources: 16x GeForce GTX 1080 Ti + Architecture: + - ResNet31OCR + - ChannelReductionEncoder + - RobustScannerDecoder + Paper: + URL: https://arxiv.org/pdf/2007.07542.pdf + Title: 'RobustScanner: Dynamically Enhancing Positional Clues for Robust Text Recognition' + README: configs/textrecog/robust_scanner/README.md + +Models: + - Name: robustscanner_r31_academic + In Collection: RobustScanner + Config: configs/textrecog/robust_scanner/robustscanner_r31_academic.py + Metadata: + Training Data: + - ICDAR2011 + - ICDAR2013 + - ICDAR2015 + - COCO text + - IIIT5K + - SynthText + - SynthAdd + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 95.1 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 89.2 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 93.1 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 77.8 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 80.3 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 90.3 + Weights: https://download.openmmlab.com/mmocr/textrecog/robustscanner/robustscanner_r31_academic-5f05874f.pth diff --git a/configs/textrecog/robust_scanner/robustscanner_r31_academic.py b/configs/textrecog/robust_scanner/robustscanner_r31_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..65a980b61684dee9929b7800ee82b4461ed2fc40 --- /dev/null +++ b/configs/textrecog/robust_scanner/robustscanner_r31_academic.py @@ -0,0 +1,34 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_models/robust_scanner.py', + '../../_base_/schedules/schedule_adam_step_5e.py', + '../../_base_/recog_pipelines/sar_pipeline.py', + '../../_base_/recog_datasets/ST_SA_MJ_real_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=64, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/sar/README.md b/configs/textrecog/sar/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f7046aea44e5a6e36267bda38379eedbf6441319 --- /dev/null +++ b/configs/textrecog/sar/README.md @@ -0,0 +1,82 @@ +# SAR + +> [Show, Attend and Read: A Simple and Strong Baseline for Irregular Text Recognition](https://arxiv.org/abs/1811.00751) + + + +## Abstract + +Recognizing irregular text in natural scene images is challenging due to the large variance in text appearance, such as curvature, orientation and distortion. Most existing approaches rely heavily on sophisticated model designs and/or extra fine-grained annotations, which, to some extent, increase the difficulty in algorithm implementation and data collection. In this work, we propose an easy-to-implement strong baseline for irregular scene text recognition, using off-the-shelf neural network components and only word-level annotations. It is composed of a 31-layer ResNet, an LSTM-based encoder-decoder framework and a 2-dimensional attention module. Despite its simplicity, the proposed method is robust and achieves state-of-the-art performance on both regular and irregular scene text recognition benchmarks. + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | source | +| :--------: | :----------: | :--------: | :------------------------: | +| icdar_2011 | 3567 | 20 | real | +| icdar_2013 | 848 | 20 | real | +| icdar2015 | 4468 | 20 | real | +| coco_text | 42142 | 20 | real | +| IIIT5K | 2000 | 20 | real | +| SynthText | 2400000 | 1 | synth | +| SynthAdd | 1216889 | 1 | synth, 1.6m in [\[1\]](#1) | +| Syn90k | 2400000 | 1 | synth | + +### Test Dataset + +| testset | instance_num | type | +| :-----: | :----------: | :---------------------------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular, 639 in [\[1\]](#1) | +| CT80 | 288 | irregular | + +## Results and Models + +| Methods | Backbone | Decoder | | Regular Text | | | | Irregular Text | | download | +| :----------------------------------------------------------: | :---------: | :------------------: | :----: | :----------: | :--: | :-: | :--: | :------------: | :--: | :------------------------------------------------------------: | +| | | | IIIT5K | SVT | IC13 | | IC15 | SVTP | CT80 | | +| [SAR](/configs/textrecog/sar/sar_r31_parallel_decoder_academic.py) | R31-1/8-1/4 | ParallelSARDecoder | 95.0 | 89.6 | 93.7 | | 79.0 | 82.2 | 88.9 | [model](https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/sar/20210327_154129.log.json) | +| [SAR](configs/textrecog/sar/sar_r31_sequential_decoder_academic.py) | R31-1/8-1/4 | SequentialSARDecoder | 95.2 | 88.7 | 92.4 | | 78.2 | 81.9 | 89.6 | [model](https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_sequential_decoder_academic-d06c9a8e.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/sar/20210330_105728.log.json) | + +## Chinese Dataset + +## Results and Models + +| Methods | Backbone | Decoder | | download | +| :---------------------------------------------------------------: | :---------: | :----------------: | :-: | :-----------------------------------------------------------------------------------------------------: | +| [SAR](/configs/textrecog/sar/sar_r31_parallel_decoder_chinese.py) | R31-1/8-1/4 | ParallelSARDecoder | | [model](https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_chineseocr_20210507-b4be8214.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/sar/20210506_225557.log.json) \| [dict](https://download.openmmlab.com/mmocr/textrecog/sar/dict_printed_chinese_english_digits.txt) | + +```{note} + +- `R31-1/8-1/4` means the height of feature from backbone is 1/8 of input image, where 1/4 for width. +- We did not use beam search during decoding. +- We implemented two kinds of decoder. Namely, `ParallelSARDecoder` and `SequentialSARDecoder`. + - `ParallelSARDecoder`: Parallel decoding during training with `LSTM` layer. It would be faster. + - `SequentialSARDecoder`: Sequential Decoding during training with `LSTMCell`. It would be easier to understand. +- For train dataset. + - We did not construct distinct data groups (20 groups in [[1]](#1)) to train the model group-by-group since it would render model training too complicated. + - Instead, we randomly selected `2.4m` patches from `Syn90k`, `2.4m` from `SynthText` and `1.2m` from `SynthAdd`, and grouped all data together. See [config](https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_academic.py) for details. +- We used 48 GPUs with `total_batch_size = 64 * 48` in the experiment above to speedup training, while keeping the `initial lr = 1e-3` unchanged. +``` + +## Citation + +```bibtex +@inproceedings{li2019show, + title={Show, attend and read: A simple and strong baseline for irregular text recognition}, + author={Li, Hui and Wang, Peng and Shen, Chunhua and Zhang, Guyu}, + booktitle={Proceedings of the AAAI Conference on Artificial Intelligence}, + volume={33}, + number={01}, + pages={8610--8617}, + year={2019} +} +``` diff --git a/configs/textrecog/sar/metafile.yml b/configs/textrecog/sar/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..9f4115817efefb8b5f9c9bbdcebdaf33411febea --- /dev/null +++ b/configs/textrecog/sar/metafile.yml @@ -0,0 +1,98 @@ +Collections: +- Name: SAR + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adam + Training Resources: 48x GeForce GTX 1080 Ti + Epochs: 5 + Batch Size: 3072 + Architecture: + - ResNet31OCR + - SAREncoder + - ParallelSARDecoder + Paper: + URL: https://arxiv.org/pdf/1811.00751.pdf + Title: 'Show, Attend and Read:A Simple and Strong Baseline for Irregular Text Recognition' + README: configs/textrecog/sar/README.md + +Models: + - Name: sar_r31_parallel_decoder_academic + In Collection: SAR + Config: configs/textrecog/sar/sar_r31_parallel_decoder_academic.py + Metadata: + Training Data: + - ICDAR2011 + - ICDAR2013 + - ICDAR2015 + - COCO text + - IIIT5K + - SynthText + - SynthAdd + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 95.0 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 89.6 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 93.7 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 79.0 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 82.2 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 88.9 + Weights: https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth + + - Name: sar_r31_sequential_decoder_academic + In Collection: SAR + Config: configs/textrecog/sar/sar_r31_sequential_decoder_academic.py + Metadata: + Training Data: + - ICDAR2011 + - ICDAR2013 + - ICDAR2015 + - COCO text + - IIIT5K + - SynthText + - SynthAdd + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 95.2 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 88.7 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 92.4 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 78.2 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 81.9 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 89.6 + Weights: https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_sequential_decoder_academic-d06c9a8e.pth diff --git a/configs/textrecog/sar/sar_r31_parallel_decoder_academic.py b/configs/textrecog/sar/sar_r31_parallel_decoder_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..983378118b4d589f531a7f401a06d238966a45d4 --- /dev/null +++ b/configs/textrecog/sar/sar_r31_parallel_decoder_academic.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', '../../_base_/recog_models/sar.py', + '../../_base_/schedules/schedule_adam_step_5e.py', + '../../_base_/recog_pipelines/sar_pipeline.py', + '../../_base_/recog_datasets/ST_SA_MJ_real_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=64, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/sar/sar_r31_parallel_decoder_chinese.py b/configs/textrecog/sar/sar_r31_parallel_decoder_chinese.py new file mode 100644 index 0000000000000000000000000000000000000000..58856312705bcc757550ca84f97a097f80f9be24 --- /dev/null +++ b/configs/textrecog/sar/sar_r31_parallel_decoder_chinese.py @@ -0,0 +1,128 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_5e.py' +] + +dict_file = 'data/chineseocr/labels/dict_printed_chinese_english_digits.txt' +label_convertor = dict( + type='AttnConvertor', dict_file=dict_file, with_unknown=True) + +model = dict( + type='SARNet', + backbone=dict(type='ResNet31OCR'), + encoder=dict( + type='SAREncoder', + enc_bi_rnn=False, + enc_do_rnn=0.1, + enc_gru=False, + ), + decoder=dict( + type='ParallelSARDecoder', + enc_bi_rnn=False, + dec_bi_rnn=False, + dec_do_rnn=0, + dec_gru=False, + pred_dropout=0.1, + d_k=512, + pred_concat=True), + loss=dict(type='SARLoss'), + label_convertor=label_convertor, + max_seq_len=30) + +img_norm_cfg = dict(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) +train_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='ResizeOCR', + height=48, + min_width=48, + max_width=256, + keep_aspect_ratio=True, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'text', 'valid_ratio' + ]), +] +test_pipeline = [ + dict(type='LoadImageFromFile'), + dict( + type='MultiRotateAugOCR', + rotate_degrees=[0, 90, 270], + transforms=[ + dict( + type='ResizeOCR', + height=48, + min_width=48, + max_width=256, + keep_aspect_ratio=True, + width_downsample_ratio=0.25), + dict(type='ToTensorOCR'), + dict(type='NormalizeOCR', **img_norm_cfg), + dict( + type='Collect', + keys=['img'], + meta_keys=[ + 'filename', 'ori_shape', 'resize_shape', 'valid_ratio' + ]), + ]) +] + +dataset_type = 'OCRDataset' + +train_prefix = 'data/chinese/' + +train_ann_file = train_prefix + 'labels/train.txt' + +train = dict( + type=dataset_type, + img_prefix=train_prefix, + ann_file=train_ann_file, + loader=dict( + type='HardDiskLoader', + repeat=1, + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=False) + +test_prefix = 'data/chineseocr/' + +test_ann_file = test_prefix + 'labels/test.txt' + +test = dict( + type=dataset_type, + img_prefix=test_prefix, + ann_file=test_ann_file, + loader=dict( + type='HardDiskLoader', + repeat=1, + parser=dict( + type='LineStrParser', + keys=['filename', 'text'], + keys_idx=[0, 1], + separator=' ')), + pipeline=None, + test_mode=False) + +data = dict( + samples_per_gpu=40, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', datasets=[train], + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', datasets=[test], pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', datasets=[test], pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/sar/sar_r31_parallel_decoder_toy_dataset.py b/configs/textrecog/sar/sar_r31_parallel_decoder_toy_dataset.py new file mode 100755 index 0000000000000000000000000000000000000000..40688d1290080c010beccc271214e5b246b45a32 --- /dev/null +++ b/configs/textrecog/sar/sar_r31_parallel_decoder_toy_dataset.py @@ -0,0 +1,30 @@ +_base_ = [ + '../../_base_/default_runtime.py', '../../_base_/recog_models/sar.py', + '../../_base_/schedules/schedule_adam_step_5e.py', + '../../_base_/recog_pipelines/sar_pipeline.py', + '../../_base_/recog_datasets/toy_data.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + workers_per_gpu=2, + samples_per_gpu=8, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/sar/sar_r31_sequential_decoder_academic.py b/configs/textrecog/sar/sar_r31_sequential_decoder_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..46ca259b3abb8863348f8eef71b0126f77e269eb --- /dev/null +++ b/configs/textrecog/sar/sar_r31_sequential_decoder_academic.py @@ -0,0 +1,58 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/schedules/schedule_adam_step_5e.py', + '../../_base_/recog_pipelines/sar_pipeline.py', + '../../_base_/recog_datasets/ST_SA_MJ_real_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +model = dict( + type='SARNet', + backbone=dict(type='ResNet31OCR'), + encoder=dict( + type='SAREncoder', + enc_bi_rnn=False, + enc_do_rnn=0.1, + enc_gru=False, + ), + decoder=dict( + type='SequentialSARDecoder', + enc_bi_rnn=False, + dec_bi_rnn=False, + dec_do_rnn=0, + dec_gru=False, + pred_dropout=0.1, + d_k=512, + pred_concat=True), + loss=dict(type='SARLoss'), + label_convertor=label_convertor, + max_seq_len=30) + +data = dict( + samples_per_gpu=64, + workers_per_gpu=2, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/satrn/README.md b/configs/textrecog/satrn/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4bb92f3fc9d37d0c1a9563769b645d20fc598eb2 --- /dev/null +++ b/configs/textrecog/satrn/README.md @@ -0,0 +1,51 @@ +# SATRN + +> [On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention](https://arxiv.org/abs/1910.04396) + + + +## Abstract + +Scene text recognition (STR) is the task of recognizing character sequences in natural scenes. While there have been great advances in STR methods, current methods still fail to recognize texts in arbitrary shapes, such as heavily curved or rotated texts, which are abundant in daily life (e.g. restaurant signs, product labels, company logos, etc). This paper introduces a novel architecture to recognizing texts of arbitrary shapes, named Self-Attention Text Recognition Network (SATRN), which is inspired by the Transformer. SATRN utilizes the self-attention mechanism to describe two-dimensional (2D) spatial dependencies of characters in a scene text image. Exploiting the full-graph propagation of self-attention, SATRN can recognize texts with arbitrary arrangements and large inter-character spacing. As a result, SATRN outperforms existing STR models by a large margin of 5.7 pp on average in "irregular text" benchmarks. We provide empirical analyses that illustrate the inner mechanisms and the extent to which the model is applicable (e.g. rotated and multi-line text). We will open-source the code. + +
+ +
+ +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | source | +| :-------: | :----------: | :--------: | :----: | +| SynthText | 7266686 | 1 | synth | +| Syn90k | 8919273 | 1 | synth | + +### Test Dataset + +| testset | instance_num | type | +| :-----: | :----------: | :-------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular | +| CT80 | 288 | irregular | + +## Results and Models + +| Methods | | Regular Text | | | | Irregular Text | | download | +| :----------------------------------------------------: | :----: | :----------: | :--: | :-: | :--: | :------------: | :--: | :-------------------------------------------------------------------------------------------------: | +| | IIIT5K | SVT | IC13 | | IC15 | SVTP | CT80 | | +| [Satrn](/configs/textrecog/satrn/satrn_academic.py) | 96.1 | 93.5 | 95.7 | | 84.1 | 88.5 | 90.3 | [model](https://download.openmmlab.com/mmocr/textrecog/satrn/satrn_academic_20211009-cb8b1580.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/satrn/20210809_093244.log.json) | +| [Satrn_small](/configs/textrecog/satrn/satrn_small.py) | 94.7 | 91.3 | 95.4 | | 81.9 | 85.9 | 86.5 | [model](https://download.openmmlab.com/mmocr/textrecog/satrn/satrn_small_20211009-2cf13355.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/satrn/20210811_053047.log.json) | + +## Citation + +```bibtex +@article{junyeop2019recognizing, + title={On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention}, + author={Junyeop Lee, Sungrae Park, Jeonghun Baek, Seong Joon Oh, Seonghyeon Kim, Hwalsuk Lee}, + year={2019} +} +``` diff --git a/configs/textrecog/satrn/metafile.yml b/configs/textrecog/satrn/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..5dd03fe550617330589c2880d88734a1fb3a4b3a --- /dev/null +++ b/configs/textrecog/satrn/metafile.yml @@ -0,0 +1,86 @@ +Collections: +- Name: SATRN + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adam + Training Resources: 8x Tesla V100 + Epochs: 6 + Batch Size: 512 + Architecture: + - ShallowCNN + - SatrnEncoder + - TFDecoder + Paper: + URL: https://arxiv.org/pdf/1910.04396.pdf + Title: 'On Recognizing Texts of Arbitrary Shapes with 2D Self-Attention' + README: configs/textrecog/satrn/README.md + +Models: + - Name: satrn_academic + In Collection: SATRN + Config: configs/textrecog/satrn/satrn_academic.py + Metadata: + Training Data: + - SynthText + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 96.1 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 93.5 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 95.7 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 84.1 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 88.5 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 90.3 + Weights: https://download.openmmlab.com/mmocr/textrecog/satrn/satrn_academic_20211009-cb8b1580.pth + + - Name: satrn_small + In Collection: SATRN + Config: configs/textrecog/satrn/satrn_small.py + Metadata: + Training Data: + - SynthText + - Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 94.7 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 91.3 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 95.4 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 81.9 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 85.9 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 86.5 + Weights: https://download.openmmlab.com/mmocr/textrecog/satrn/satrn_small_20211009-2cf13355.pth diff --git a/configs/textrecog/satrn/satrn_academic.py b/configs/textrecog/satrn/satrn_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..00a664e2093f4b4c5cbf77708813c66761428814 --- /dev/null +++ b/configs/textrecog/satrn/satrn_academic.py @@ -0,0 +1,68 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_pipelines/satrn_pipeline.py', + '../../_base_/recog_datasets/ST_MJ_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +model = dict( + type='SATRN', + backbone=dict(type='ShallowCNN', input_channels=3, hidden_dim=512), + encoder=dict( + type='SatrnEncoder', + n_layers=12, + n_head=8, + d_k=512 // 8, + d_v=512 // 8, + d_model=512, + n_position=100, + d_inner=512 * 4, + dropout=0.1), + decoder=dict( + type='NRTRDecoder', + n_layers=6, + d_embedding=512, + n_head=8, + d_model=512, + d_inner=512 * 4, + d_k=512 // 8, + d_v=512 // 8), + loss=dict(type='TFLoss'), + label_convertor=label_convertor, + max_seq_len=25) + +# optimizer +optimizer = dict(type='Adam', lr=3e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[3, 4]) +total_epochs = 6 + +data = dict( + samples_per_gpu=64, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/satrn/satrn_small.py b/configs/textrecog/satrn/satrn_small.py new file mode 100644 index 0000000000000000000000000000000000000000..96f86797f4700fd6ab9590fa983323f3e22d15c2 --- /dev/null +++ b/configs/textrecog/satrn/satrn_small.py @@ -0,0 +1,68 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_pipelines/satrn_pipeline.py', + '../../_base_/recog_datasets/ST_MJ_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +label_convertor = dict( + type='AttnConvertor', dict_type='DICT90', with_unknown=True) + +model = dict( + type='SATRN', + backbone=dict(type='ShallowCNN', input_channels=3, hidden_dim=256), + encoder=dict( + type='SatrnEncoder', + n_layers=6, + n_head=8, + d_k=256 // 8, + d_v=256 // 8, + d_model=256, + n_position=100, + d_inner=256 * 4, + dropout=0.1), + decoder=dict( + type='NRTRDecoder', + n_layers=6, + d_embedding=256, + n_head=8, + d_model=256, + d_inner=256 * 4, + d_k=256 // 8, + d_v=256 // 8), + loss=dict(type='TFLoss'), + label_convertor=label_convertor, + max_seq_len=25) + +# optimizer +optimizer = dict(type='Adam', lr=3e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[3, 4]) +total_epochs = 6 + +data = dict( + samples_per_gpu=64, + workers_per_gpu=4, + val_dataloader=dict(samples_per_gpu=1), + test_dataloader=dict(samples_per_gpu=1), + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/seg/README.md b/configs/textrecog/seg/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f8ab29e61727e3fa648c2aa090fcae8076bbf5e2 --- /dev/null +++ b/configs/textrecog/seg/README.md @@ -0,0 +1,48 @@ +# SegOCR + + + +## Abstract + +Just a simple Seg-based baseline for text recognition tasks. + +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | source | +| :-------: | :----------: | :--------: | :----: | +| SynthText | 7266686 | 1 | synth | + +### Test Dataset + +| testset | instance_num | type | +| :-----: | :----------: | :-------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| CT80 | 288 | irregular | + +## Results and Models + +| Backbone | Neck | Head | | | Regular Text | | | Irregular Text | download | +| :------: | :----: | :--: | :-: | :----: | :----------: | :--: | :-: | :------------: | :------------------------------------------------------------------------------------------------------------------------------------------: | +| | | | | IIIT5K | SVT | IC13 | | CT80 | | +| R31-1/16 | FPNOCR | 1x | | 90.9 | 81.8 | 90.7 | | 80.9 | [model](https://download.openmmlab.com/mmocr/textrecog/seg/seg_r31_1by16_fpnocr_academic-72235b11.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/seg/20210325_112835.log.json) | + +```{note} + +- `R31-1/16` means the size (both height and width ) of feature from backbone is 1/16 of input image. +- `1x` means the size (both height and width) of feature from head is the same with input image. +``` + +## Citation + +```bibtex +@unpublished{key, + title={SegOCR Simple Baseline.}, + author={}, + note={Unpublished Manuscript}, + year={2021} +} +``` diff --git a/configs/textrecog/seg/metafile.yml b/configs/textrecog/seg/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..937747f41dcdce01e297ab44d9a9ee9189073fd9 --- /dev/null +++ b/configs/textrecog/seg/metafile.yml @@ -0,0 +1,39 @@ +Collections: +- Name: SegOCR + Metadata: + Training Data: mixture + Training Techniques: + - Adam + Epochs: 5 + Batch Size: 64 + Training Resources: 4x GeForce GTX 1080 Ti + Architecture: + - ResNet31OCR + - FPNOCR + Paper: + README: configs/textrecog/seg/README.md + +Models: + - Name: seg_r31_1by16_fpnocr_academic + In Collection: SegOCR + Config: configs/textrecog/seg/seg_r31_1by16_fpnocr_academic.py + Metadata: + Training Data: SynthText + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 90.9 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 81.8 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 90.7 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 80.9 + Weights: https://download.openmmlab.com/mmocr/textrecog/seg/seg_r31_1by16_fpnocr_academic-72235b11.pth diff --git a/configs/textrecog/seg/seg_r31_1by16_fpnocr_academic.py b/configs/textrecog/seg/seg_r31_1by16_fpnocr_academic.py new file mode 100644 index 0000000000000000000000000000000000000000..4e37856c06fb43cb0b67a6a1760bd7ef9eeddb66 --- /dev/null +++ b/configs/textrecog/seg/seg_r31_1by16_fpnocr_academic.py @@ -0,0 +1,40 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_pipelines/seg_pipeline.py', + '../../_base_/recog_models/seg.py', + '../../_base_/recog_datasets/ST_charbox_train.py', + '../../_base_/recog_datasets/academic_test.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +# optimizer +optimizer = dict(type='Adam', lr=1e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[3, 4]) +total_epochs = 5 + +find_unused_parameters = True + +data = dict( + samples_per_gpu=16, + workers_per_gpu=2, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') diff --git a/configs/textrecog/seg/seg_r31_1by16_fpnocr_toy_dataset.py b/configs/textrecog/seg/seg_r31_1by16_fpnocr_toy_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..893bebba496c04e9364bdcea3caef651e3d426d0 --- /dev/null +++ b/configs/textrecog/seg/seg_r31_1by16_fpnocr_toy_dataset.py @@ -0,0 +1,39 @@ +_base_ = [ + '../../_base_/default_runtime.py', + '../../_base_/recog_datasets/seg_toy_data.py', + '../../_base_/recog_models/seg.py', + '../../_base_/recog_pipelines/seg_pipeline.py', +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +# optimizer +optimizer = dict(type='Adam', lr=1e-4) +optimizer_config = dict(grad_clip=None) +# learning policy +lr_config = dict(policy='step', step=[3, 4]) +total_epochs = 5 + +data = dict( + samples_per_gpu=8, + workers_per_gpu=1, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') + +find_unused_parameters = True diff --git a/configs/textrecog/tps/README.md b/configs/textrecog/tps/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0066fb154bf7f2fa26a3ac00acaddb2ed4d30f03 --- /dev/null +++ b/configs/textrecog/tps/README.md @@ -0,0 +1,52 @@ +# CRNN-STN + + + +## Abstract + +Image-based sequence recognition has been a long-standing research topic in computer vision. In this paper, we investigate the problem of scene text recognition, which is among the most important and challenging tasks in image-based sequence recognition. A novel neural network architecture, which integrates feature extraction, sequence modeling and transcription into a unified framework, is proposed. Compared with previous systems for scene text recognition, the proposed architecture possesses four distinctive properties: (1) It is end-to-end trainable, in contrast to most of the existing algorithms whose components are separately trained and tuned. (2) It naturally handles sequences in arbitrary lengths, involving no character segmentation or horizontal scale normalization. (3) It is not confined to any predefined lexicon and achieves remarkable performances in both lexicon-free and lexicon-based scene text recognition tasks. (4) It generates an effective yet much smaller model, which is more practical for real-world application scenarios. The experiments on standard benchmarks, including the IIIT-5K, Street View Text and ICDAR datasets, demonstrate the superiority of the proposed algorithm over the prior arts. Moreover, the proposed algorithm performs well in the task of image-based music score recognition, which evidently verifies the generality of it. + +
+ +
+ +```{note} +We use STN from this paper as the preprocessor and CRNN as the recognition network. +``` + +## Dataset + +### Train Dataset + +| trainset | instance_num | repeat_num | note | +| :------: | :----------: | :--------: | :---: | +| Syn90k | 8919273 | 1 | synth | + +### Test Dataset + +| testset | instance_num | note | +| :-----: | :----------: | :-------: | +| IIIT5K | 3000 | regular | +| SVT | 647 | regular | +| IC13 | 1015 | regular | +| IC15 | 2077 | irregular | +| SVTP | 645 | irregular | +| CT80 | 288 | irregular | + +## Results and models + +| methods | | Regular Text | | | | Irregular Text | | download | +| :-------------------------------------------------------------: | :----: | :----------: | :--: | :-: | :--: | :------------: | :--: | :----------------------------------------------------------------------------------------: | +| | IIIT5K | SVT | IC13 | | IC15 | SVTP | CT80 | | +| [CRNN-STN](/configs/textrecog/tps/crnn_tps_academic_dataset.py) | 80.8 | 81.3 | 85.0 | | 59.6 | 68.1 | 53.8 | [model](https://download.openmmlab.com/mmocr/textrecog/tps/crnn_tps_academic_dataset_20210510-d221a905.pth) \| [log](https://download.openmmlab.com/mmocr/textrecog/tps/20210510_204353.log.json) | + +## Citation + +```bibtex +@article{shi2016robust, + title={Robust Scene Text Recognition with Automatic Rectification}, + author={Shi, Baoguang and Wang, Xinggang and Lyu, Pengyuan and Yao, + Cong and Bai, Xiang}, + year={2016} +} +``` diff --git a/configs/textrecog/tps/crnn_tps_academic_dataset.py b/configs/textrecog/tps/crnn_tps_academic_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..15607538d0c31de2e4baadf0b30d781f534b99bb --- /dev/null +++ b/configs/textrecog/tps/crnn_tps_academic_dataset.py @@ -0,0 +1,33 @@ +_base_ = [ + '../../_base_/default_runtime.py', '../../_base_/recog_models/crnn_tps.py', + '../../_base_/recog_pipelines/crnn_tps_pipeline.py', + '../../_base_/recog_datasets/MJ_train.py', + '../../_base_/recog_datasets/academic_test.py', + '../../_base_/schedules/schedule_adadelta_5e.py' +] + +train_list = {{_base_.train_list}} +test_list = {{_base_.test_list}} + +train_pipeline = {{_base_.train_pipeline}} +test_pipeline = {{_base_.test_pipeline}} + +data = dict( + samples_per_gpu=64, + workers_per_gpu=4, + train=dict( + type='UniformConcatDataset', + datasets=train_list, + pipeline=train_pipeline), + val=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline), + test=dict( + type='UniformConcatDataset', + datasets=test_list, + pipeline=test_pipeline)) + +evaluation = dict(interval=1, metric='acc') + +cudnn_benchmark = True diff --git a/configs/textrecog/tps/metafile.yml b/configs/textrecog/tps/metafile.yml new file mode 100644 index 0000000000000000000000000000000000000000..afd9be9c2789f05547ba31dae165ccedb709e43f --- /dev/null +++ b/configs/textrecog/tps/metafile.yml @@ -0,0 +1,51 @@ +Collections: +- Name: TPS-CRNN + Metadata: + Training Data: OCRDataset + Training Techniques: + - Adadelta + Epochs: 5 + Batch Size: 256 + Training Resources: 4x GeForce GTX 1080 Ti + Architecture: + - TPSPreprocessor + - VeryDeepVgg + - CRNNDecoder + - CTCLoss + Paper: + URL: https://arxiv.org/pdf/1603.03915.pdf + Title: 'Robust Scene Text Recognition with Automatic Rectification' + README: configs/textrecog/tps/README.md + +Models: + - Name: crnn_tps_academic_dataset + In Collection: TPS-CRNN + Config: configs/textrecog/tps/crnn_tps_academic_dataset.py + Metadata: + Training Data: Syn90k + Results: + - Task: Text Recognition + Dataset: IIIT5K + Metrics: + word_acc: 80.8 + - Task: Text Recognition + Dataset: SVT + Metrics: + word_acc: 81.3 + - Task: Text Recognition + Dataset: ICDAR2013 + Metrics: + word_acc: 85.0 + - Task: Text Recognition + Dataset: ICDAR2015 + Metrics: + word_acc: 59.6 + - Task: Text Recognition + Dataset: SVTP + Metrics: + word_acc: 68.1 + - Task: Text Recognition + Dataset: CT80 + Metrics: + word_acc: 53.8 + Weights: https://download.openmmlab.com/mmocr/textrecog/tps/crnn_tps_academic_dataset_20210510-d221a905.pth diff --git a/packages.txt b/packages.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/requirements.txt b/requirements.txt index 684dd6426214ef1f6f3e8cfc90328a061bfffe74..671e6971df1cbc1621b6315d52097e420ffe2cf8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,2 @@ -mmcv-full -mmdet -mmocr gradio git+https://github.com/xianbaoqian/mmocr.git \ No newline at end of file