Skip to content

Commit

Permalink
rename 'ICDAR2017MLT' config & add 'ICDAR2015' config and Model
Browse files Browse the repository at this point in the history
(cherry picked from commit 4f59eb9)
  • Loading branch information
JingChaoLiu committed Aug 1, 2019
1 parent c347ebb commit 131f3ba
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 14 deletions.
53 changes: 53 additions & 0 deletions configs/e2e_PMTD_R_50_FPN_1x_ICDAR2015_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
INPUT:
TO_BGR255: False
PIXEL_MEAN: [0.485, 0.456, 0.406]
PIXEL_STD: [0.229, 0.224, 0.225]
MIN_SIZE_TEST: -1
MAX_SIZE_TEST: 1920
TEST:
IMS_PER_BATCH: 2
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
WEIGHT: 'models/PMTD_ICDAR2015.pth'
BACKBONE:
CONV_BODY: "R-50-FPN"
RESNETS:
STEM_FUNC: "StemWithBatchNorm"
TRANS_FUNC: "BottleneckWithBatchNorm"
BACKBONE_OUT_CHANNELS: 256
STRIDE_IN_1X1: False
RPN:
RPN_HEAD: "SingleConvRPNHead_Softmax"
USE_FPN: True
ANCHOR_STRIDE: (4, 8, 16, 32, 64)
ANCHOR_SIZES: (16, 32, 64, 128, 256)
ASPECT_RATIOS: (0.17, 0.44, 1.13, 2.90, 7.46)
STRADDLE_THRESH: 10
PRE_NMS_TOP_N_TRAIN: 2000
PRE_NMS_TOP_N_TEST: 1000
POST_NMS_TOP_N_TEST: 1000
FPN_POST_NMS_TOP_N_TEST: 1000
FPN_POST_NMS_PER_BATCH: False
ROI_HEADS:
USE_FPN: True
ROI_BOX_HEAD:
NUM_CLASSES: 2
POOLER_RESOLUTION: 7
POOLER_SCALES: (0.25, 0.125, 0.0625, 0.03125)
POOLER_SAMPLING_RATIO: 2
FEATURE_EXTRACTOR: "FPN2MLPFeatureExtractor"
PREDICTOR: "FPNPredictor"
ROI_MASK_HEAD:
POOLER_SCALES: (0.25, 0.125, 0.0625, 0.03125)
FEATURE_EXTRACTOR: "MaskRCNNFPNFeatureExtractor"
PREDICTOR: "MaskRCNNC4Predictor_Upsample"
DILATION: 2
POOLER_RESOLUTION: 14
POOLER_SAMPLING_RATIO: 2
RESOLUTION: 28
SHARE_BOX_FEATURE_EXTRACTOR: False
MASK_ON: True
DATASETS:
TEST: ("icdar_2015_test",)
DATALOADER:
SIZE_DIVISIBILITY: 32
File renamed without changes.
2 changes: 1 addition & 1 deletion demo/PMTD_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_parser():


def create_pmtd_demo(args):
cfg.merge_from_file("configs/e2e_PMTD_R_50_FPN_1x_test.yaml")
cfg.merge_from_file("configs/e2e_PMTD_R_50_FPN_1x_ICDAR2017MLT_test.yaml")
cfg.merge_from_list([
'MODEL.DEVICE', args.device,
'MODEL.WEIGHT', args.model_path,
Expand Down
52 changes: 39 additions & 13 deletions demo/utils/convert_results_to_icdar.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import collections
import os
import pyclipper
import zipfile
from typing import List, Dict, DefaultDict
from zipfile import ZipFile

import cv2
import numpy as np
import pyclipper
import torch


Expand Down Expand Up @@ -60,17 +60,11 @@ def inter_of_union(item_a: Dict, item_b: Dict):
return np.asarray(items)[keep]


if __name__ == '__main__':
os.chdir('inference/icdar_2017_mlt_test')

tags = ['1600']
def output_results(output_dir, scales, image_num, cls_threshold_list, nms_threshold, line_format, pred_file_template):
os.chdir(output_dir)
result_merge_path = 'results_multi_scale.pth'
result_path_list = [f'results_{tag}.pth' for tag in tags]
results: dict = get_results(result_path_list, result_merge_path, 9000, regenerate=True)

cls_threshold_list = [0.5]
nms_threshold = 0.1
items: List[Dict]
result_path_list = [f'results_{tag}.pth' for tag in scales]
results: dict = get_results(result_path_list, result_merge_path, image_num, regenerate=True)
with ZipFile('icdar.zip', 'w', compression=zipfile.ZIP_DEFLATED) as result_zip:
for image_id, item_lists in results.items():
items = []
Expand All @@ -82,6 +76,38 @@ def inter_of_union(item_a: Dict, item_b: Dict):
lines = []
for item in items:
bbox = item['points'].ravel().astype(np.str).tolist()
line = f"{','.join(bbox)}, {item['cls_score']}\n"
score = item['cls_score']
line = line_format(bbox, score)
lines.append(line)
result_zip.writestr('res_img_%05d.txt' % image_id, str.join('', lines))
result_zip.writestr(pred_file_template % image_id, str.join('', lines))


if __name__ == '__main__':
# postprocess_config = {
# 'output_dir': None,
# 'scales': [],
# 'image_num': 0,
# 'cls_threshold_list': [],
# 'nms_threshold': 0,
# 'line_format': lambda bbox, cls_score: None,
# 'pred_file_template': None
# }
postprocess_config_17 = {
'output_dir': 'inference/icdar_2017_mlt_test',
'scales': [1600],
'image_num': 9000,
'cls_threshold_list': [0.5],
'nms_threshold': 0.1,
'line_format': lambda bbox, cls_score: f"{','.join(bbox)}, {cls_score}\n",
'pred_file_template': 'res_img_%05d.txt'
}
postprocess_config_15 = {
'output_dir': 'inference/icdar_2015_test',
'scales': [1920],
'image_num': 500,
'cls_threshold_list': [0.4],
'nms_threshold': 0.3,
'line_format': lambda bbox, cls_score: f"{','.join(bbox)}\n",
'pred_file_template': 'res_img_%d.txt'
}
output_results(**postprocess_config_17)
4 changes: 4 additions & 0 deletions maskrcnn_benchmark/config/paths_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class DatasetCatalog(object):
"img_dir": "cityscapes/images",
"ann_file": "cityscapes/annotations/instancesonly_filtered_gtFine_test.json"
},
"icdar_2015_test": {
"img_dir": "icdar2015/ch4_test_images",
"ann_file": "icdar2015/annotations/test_coco.json"
},
"icdar_2017_mlt_val": {
"img_dir": "icdar2017mlt/ch8_validation_images",
"ann_file": "icdar2017mlt/annotations/validate_coco_with_ignore.json"
Expand Down

0 comments on commit 131f3ba

Please sign in to comment.