Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support and CMake for lanms #370

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,16 @@ ENV/

# result files for demo
static/results

# model files
models/

# binary images
*.jpg
*.png

# output directory
outputs/

# training dataset directory
data/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lanms/pybind11"]
path = lanms/pybind11
url = https://github.com/pybind/pybind11/
5,386 changes: 5,386 additions & 0 deletions EAST_colab.ipynb

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
import locality_aware_nms as nms_locality
import lanms

tf.app.flags.DEFINE_string('test_data_path', '/tmp/ch4_test_images/images/', '')
tf.app.flags.DEFINE_string('gpu_list', '0', '')
tf.app.flags.DEFINE_string('checkpoint_path', '/tmp/east_icdar2015_resnet_v1_50_rbox/', '')
tf.app.flags.DEFINE_string('output_dir', '/tmp/ch4_test_images/images/', '')
tf.app.flags.DEFINE_bool('no_write_images', False, 'do not write images')

import model
from icdar import restore_rectangle

import flags
FLAGS = tf.app.flags.FLAGS

def get_images():
Expand Down Expand Up @@ -68,15 +63,15 @@ def resize_image(im, max_side_len=2400):
return im, (ratio_h, ratio_w)


def detect(score_map, geo_map, timer, score_map_thresh=0.8, box_thresh=0.1, nms_thres=0.2):
def detect(score_map, geo_map, timer, score_map_thresh=0.8, box_thresh=0.1, nms_thresh=0.2):
'''
restore text boxes from score map and geo map
:param score_map:
:param geo_map:
:param timer:
:param score_map_thresh: threshhold for score map
:param box_thresh: threshhold for boxes
:param nms_thres: threshold for nms
:param score_map_thresh: threshold for score map
:param box_thresh: threshold for boxes
:param nms_thresh: threshold for nms
:return:
'''
if len(score_map.shape) == 4:
Expand All @@ -96,8 +91,8 @@ def detect(score_map, geo_map, timer, score_map_thresh=0.8, box_thresh=0.1, nms_
timer['restore'] = time.time() - start
# nms part
start = time.time()
# boxes = nms_locality.nms_locality(boxes.astype(np.float64), nms_thres)
boxes = lanms.merge_quadrangle_n9(boxes.astype('float32'), nms_thres)
# boxes = nms_locality.nms_locality(boxes.astype(np.float64), nms_thresh)
boxes = lanms.merge_quadrangle_n9(boxes.astype('float32'), nms_thresh)
timer['nms'] = time.time() - start

if boxes.shape[0] == 0:
Expand Down
41 changes: 41 additions & 0 deletions flags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import tensorflow as tf

# required for both training and testing
tf.app.flags.DEFINE_string('checkpoint_path', './models/east_icdar2015_resnet_v1_50_rbox',
'model folder that contains checkpoint, index and meta')
tf.app.flags.DEFINE_integer('text_scale', 512, '')

# testing parameters
tf.app.flags.DEFINE_string('test_data_path', './training_samples',
'folder that contains images to test')
tf.app.flags.DEFINE_string('output_dir', './outputs',
'result will be written to this folder')
tf.app.flags.DEFINE_bool('no_write_images', False,
'do not write images')

# training parameters
tf.app.flags.DEFINE_boolean('restore', False,
'whether to restore from checkpoint')
tf.app.flags.DEFINE_integer('max_steps', 100000, '')
tf.app.flags.DEFINE_integer('save_checkpoint_steps', 1000, '')
tf.app.flags.DEFINE_integer('save_summary_steps', 100, '')
tf.app.flags.DEFINE_integer('batch_size_per_gpu', 14, '')
tf.app.flags.DEFINE_integer('num_readers', 16, '')
tf.app.flags.DEFINE_string('training_data_path', './training_samples/',
'training dataset to use')
tf.app.flags.DEFINE_string('pretrained_model_path', './models/resnet_v1_50.ckpt', '')
tf.app.flags.DEFINE_string('gpu_list', '0', '')
tf.app.flags.DEFINE_integer('input_size', 512, '')
tf.app.flags.DEFINE_float('learning_rate', 0.0001, '')
tf.app.flags.DEFINE_float('moving_average_decay', 0.997, '')
tf.app.flags.DEFINE_integer('max_image_large_side', 1280, 'max image size of training')
tf.app.flags.DEFINE_integer('max_text_size', 800,
'if the text in the input image is bigger than this, '
'then we resize the image according to this')
tf.app.flags.DEFINE_integer('min_text_size', 10,
'if the text size is smaller than this, we ignore it during training')
tf.app.flags.DEFINE_float('min_crop_side_ratio', 0.1,
'when doing random crop from input image, '
'the min length of min(H, W)')
tf.app.flags.DEFINE_string('geometry', 'RBOX',
'which geometry to generate, RBOX or QUAD')
20 changes: 2 additions & 18 deletions icdar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,10 @@
import matplotlib.patches as Patches
from shapely.geometry import Polygon

import tensorflow as tf

from data_util import GeneratorEnqueuer

tf.app.flags.DEFINE_string('training_data_path', '/data/ocr/icdar2015/',
'training dataset to use')
tf.app.flags.DEFINE_integer('max_image_large_side', 1280,
'max image size of training')
tf.app.flags.DEFINE_integer('max_text_size', 800,
'if the text in the input image is bigger than this, then we resize'
'the image according to this')
tf.app.flags.DEFINE_integer('min_text_size', 10,
'if the text size is smaller than this, we ignore it during training')
tf.app.flags.DEFINE_float('min_crop_side_ratio', 0.1,
'when doing random crop from input image, the'
'min length of min(H, W')
tf.app.flags.DEFINE_string('geometry', 'RBOX',
'which geometry to generate, RBOX or QUAD')


import flags
import tensorflow as tf
FLAGS = tf.app.flags.FLAGS


Expand Down
1 change: 1 addition & 0 deletions lanms/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
adaptor.so
build
26 changes: 26 additions & 0 deletions lanms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.4)
project(lanms)

set(CMAKE_CXX_STANDARD 11)
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
else(WIN32)
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-pthread)
endif(WIN32)

set(SOURCES "lanms.cpp" "include/clipper/clipper.cpp")

add_library(lanms_library SHARED ${SOURCES})
target_link_libraries(lanms_library)
target_include_directories(lanms_library PUBLIC ${CMAKE_CURRENT_LIST_DIR})

include_directories("include")

add_executable(main main.cpp ${SOURCES})
target_link_libraries(main)

add_subdirectory("pybind11")
pybind11_add_module(adaptor "adaptor.cpp" ${SOURCES})
target_link_libraries(adaptor PRIVATE lanms_library)
target_compile_definitions(adaptor PRIVATE)
9 changes: 0 additions & 9 deletions lanms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import subprocess
import os
import numpy as np

BASE_DIR = os.path.dirname(os.path.realpath(__file__))

if subprocess.call(['make', '-C', BASE_DIR]) != 0: # return value
raise RuntimeError('Cannot compile lanms: {}'.format(BASE_DIR))


def merge_quadrangle_n9(polys, thres=0.3, precision=10000):
from .adaptor import merge_quadrangle_n9 as nms_impl
if len(polys) == 0:
Expand All @@ -17,4 +9,3 @@ def merge_quadrangle_n9(polys, thres=0.3, precision=10000):
ret = np.array(nms_impl(p, thres), dtype='float32')
ret[:,:8] /= precision
return ret

Loading