Skip to content

Commit

Permalink
add ctw1500
Browse files Browse the repository at this point in the history
  • Loading branch information
whai362 committed Mar 29, 2019
1 parent a096b65 commit 084a9ff
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 17 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* Polygon2
* OpenCV 3+ (for c++ version pse)

# Todo
* CTW1500 train and test

## Introduction
Progressive Scale Expansion Network (PSENet) is a text detector which is able to well detect the arbitrary-shape text in natural scene.

Expand All @@ -32,6 +29,13 @@ CUDA_VISIBLE_DEVICES=0 python test_ic15.py --scale 1 --resume [path of model]
| PSENet-1s (ResNet50) | pretrain on IC17 MLT | 86.92 | 84.5 | 85.69 | 3.8 | [baiduyun](https://pan.baidu.com/s/1oKVxHKuT3hdzDUmksbcgAQ)(extract code: aieo) |
| PSENet-4s (ResNet50) | pretrain on IC17 MLT | 86.1 | 83.77 | 84.92 | 3.8 | [baiduyun](https://pan.baidu.com/s/1oKVxHKuT3hdzDUmksbcgAQ)(extract code: aieo) |

### [SCUT-CTW1500](https://github.com/Yuliang-Liu/Curve-Text-Detector)
| Method | Extra Data | Precision (%) | Recall (%) | F-measure (%) | FPS | Model |
| - | - | - | - | - | - | - |
| PSENet-1s (ResNet50) | - | 80.57 | 75.55 | 78.0 | 3.9 | [baiduyun](https://pan.baidu.com/s/1BqJspFwBmHjoqlE0jOrJQg)(extract code: ksv7) |
| PSENet-1s (ResNet50) | pretrain on IC17 MLT | 84.84| 79.73 | 82.2 | 3.9 | todo |
| PSENet-4s (ResNet50) | pretrain on IC17 MLT | 82.09 | 77.84 | 79.9 | 8.4 | todo |

## Performance (old version paper on arxiv)
### [ICDAR 2015](http://rrc.cvc.uab.es/?ch=4&com=evaluation&task=1) (training with ICDAR 2017 MLT)
| Method | Precision (%) | Recall (%) | F-measure (%) |
Expand Down
5 changes: 4 additions & 1 deletion dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from dataset.icdar2015_loader import IC15Loader
from dataset.icdar2015_test_loader import IC15TestLoader
from dataset.icdar2015_test_loader import IC15TestLoader

from dataset.ctw1500_loader import CTW1500Loader
from dataset.ctw1500_test_loader import CTW1500TestLoader
1 change: 0 additions & 1 deletion dataset/ctw1500_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def shrink(bboxes, rate, max_shr=20):

class CTW1500Loader(data.Dataset):
def __init__(self, is_transform=False, img_size=None, kernel_num=7, min_scale=0.4):
self.split = split
self.is_transform = is_transform

self.img_size = img_size if (img_size is None or isinstance(img_size, tuple)) else (img_size, img_size)
Expand Down
20 changes: 10 additions & 10 deletions dataset/ctw1500_test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import pyclipper
import Polygon as plg

ctw_root_dir = '/home/shared/ctw1500/'
ctw_test_data_dir = ctw_root_dir + 'tmp/'
ctw_root_dir = './data/CTW1500/'
ctw_test_data_dir = ctw_root_dir + 'test/text_image/'

random.seed(123456)

Expand All @@ -25,7 +25,7 @@ def get_img(img_path):
raise
return img

def scale(img, long_size=2240):
def scale(img, long_size=1280):
h, w = img.shape[0:2]
scale = long_size * 1.0 / max(h, w)
img = cv2.resize(img, dsize=None, fx=scale, fy=scale)
Expand Down Expand Up @@ -63,10 +63,10 @@ def __getitem__(self, index):

img = get_img(img_path)

scaled_img = scale(img, self.long_size)
scaled_img = Image.fromarray(img)
scaled_img = img.convert('RGB')
scaled_img = transforms.ToTensor()(img)
scaled_img = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])(img)

return img[:, :, [2, 1, 0]]
scaled_img = scale(img, self.long_size)
scaled_img = Image.fromarray(scaled_img)
scaled_img = scaled_img.convert('RGB')
scaled_img = transforms.ToTensor()(scaled_img)
scaled_img = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])(scaled_img)
return img[:, :, [2, 1, 0]], scaled_img
94 changes: 94 additions & 0 deletions eval/ctw1500/eval_ctw1500.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import file_util
import Polygon as plg
import numpy as np

pred_root = '../../outputs/submit_ctw1500/'
gt_root = '../../data/CTW1500/test/text_label_curve/'

def get_pred(path):
lines = file_util.read_file(path).split('\n')
bboxes = []
for line in lines:
if line == '':
continue
bbox = line.split(',')
if len(bbox) % 2 == 1:
print path
bbox = [(int)(x) for x in bbox]
bboxes.append(bbox)
return bboxes

def get_gt(path):
lines = file_util.read_file(path).split('\n')
bboxes = []
for line in lines:
if line == '':
continue
# line = util.str.remove_all(line, '\xef\xbb\xbf')
# gt = util.str.split(line, ',')
gt = line.split(',')

x1 = np.int(gt[0])
y1 = np.int(gt[1])

bbox = [np.int(gt[i]) for i in range(4, 32)]
bbox = np.asarray(bbox) + ([x1, y1] * 14)

bboxes.append(bbox)
return bboxes

def get_union(pD,pG):
areaA = pD.area();
areaB = pG.area();
return areaA + areaB - get_intersection(pD, pG);

def get_intersection(pD,pG):
pInt = pD & pG
if len(pInt) == 0:
return 0
return pInt.area()

if __name__ == '__main__':
th = 0.5
pred_list = file_util.read_dir(pred_root)

tp, fp, npos = 0, 0, 0

for pred_path in pred_list:
preds = get_pred(pred_path)
gt_path = gt_root + pred_path.split('/')[-1]
gts = get_gt(gt_path)
npos += len(gts)

cover = set()
for pred_id, pred in enumerate(preds):
pred = np.array(pred)
pred = pred.reshape(pred.shape[0] / 2, 2)
# if pred.shape[0] <= 2:
# continue
pred_p = plg.Polygon(pred)

flag = False
for gt_id, gt in enumerate(gts):
gt = np.array(gt)
gt = gt.reshape(gt.shape[0] / 2, 2)
gt_p = plg.Polygon(gt)

union = get_union(pred_p, gt_p)
inter = get_intersection(pred_p, gt_p)

if inter * 1.0 / union >= th:
if gt_id not in cover:
flag = True
cover.add(gt_id)
if flag:
tp += 1.0
else:
fp += 1.0

print tp, fp, npos
precision = tp / (tp + fp)
recall = tp / npos
hmean = 0 if (precision + recall) == 0 else 2.0 * precision * recall / (precision + recall)

print 'p: %.4f, r: %.4f, f: %.4f'%(precision, recall, hmean)
33 changes: 33 additions & 0 deletions eval/ctw1500/file_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os

def read_dir(root):
file_path_list = []
for file_path, dirs, files in os.walk(root):
for file in files:
file_path_list.append(os.path.join(file_path, file).replace('\\', '/'))
file_path_list.sort()
return file_path_list

def read_file(file_path):
file_object = open(file_path, 'r')
file_content = file_object.read()
file_object.close()
return file_content

def write_file(file_path, file_content):
if file_path.find('/') != -1:
father_dir = '/'.join(file_path.split('/')[0:-1])
if not os.path.exists(father_dir):
os.makedirs(father_dir)
file_object = open(file_path, 'w')
file_object.write(file_content)
file_object.close()


def write_file_not_cover(file_path, file_content):
father_dir = '/'.join(file_path.split('/')[0:-1])
if not os.path.exists(father_dir):
os.makedirs(father_dir)
file_object = open(file_path, 'a')
file_object.write(file_content)
file_object.close()
3 changes: 3 additions & 0 deletions eval/eval_ctw1500.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd ctw1500
python eval_ctw1500.py
cd ..
Loading

0 comments on commit 084a9ff

Please sign in to comment.