Code Monkey home page Code Monkey logo

crafter's Introduction

Crafter

CRAFT text detection with ONNX Runtime

Based on the craft-text-detector. See also the source of the fork here.

Installation

$ pip install crafter

Usage

from crafter import Crafter

crafter = Crafter()

prediction = crafter('crafter/test/resources/idcard2.jpg')
for p1, p2, p3, p4 in prediction['boxes']:
    print(p1, p2, p3, p4)

Developing

$ pip install .
$ pip install onnx [email protected]:innodatalabs/craft-text-detector.git pytest

To download Pytorch weights and convert to ONNX, run this (once):

$ python convert/craftnet.py
$ python convert/refinenet.py

This will (re-)create the ONNX files in crafter/resources.

Testing

$ PYTHONPATH+. pytest

Building

$ make

crafter's People

Contributors

mkroutikov avatar

Watchers

David Nadeau avatar  avatar

crafter's Issues

too much infer time

hi
i tested on raspberry pi 4b aarch64 on my own image:

from crafter import Crafter
crafter = Crafter()
prediction = crafter('test.png')
#for p1, p2, p3, p4 in prediction['boxes']:
#    print(p1, p2, p3, p4)
print(prediction['times'])

{'resize_time': 0.1297764778137207, 'preprocessing_time': 0.07541060447692871, 'craftnet_time': 26.2554190158844, 'refinenet_time': 9.416042804718018, 'postprocess_time': 0.18222427368164062}
total time (h:min:sec): 0:00:36.063

and classic craft_text_detector:

from craft_text_detector import (
    read_image,
    load_craftnet_model,
    load_refinenet_model,
    get_prediction,
    export_detected_regions,
    export_extra_results,
    empty_cuda_cache
)

# set image path and export folder directory
image = 'test.png'
output_dir = 'outputs/'

# read image
image = read_image(image)

# load models
refine_net = load_refinenet_model(cuda=False)
craft_net = load_craftnet_model(cuda=False)

# perform prediction
prediction_result = get_prediction(
    image=image,
    craft_net=craft_net,
    refine_net=refine_net,
    text_threshold=0.7,
    link_threshold=0.4,
    low_text=0.4,
    cuda=False,
    long_size=700 #1280
)

# export detected text regions
exported_file_paths = export_detected_regions(
    image=image,
    regions=prediction_result["boxes"],
    output_dir=output_dir,
    rectify=True
)

{'resize_time': 0.005295991897583008, 'preprocessing_time': 0.01616811752319336, 'craftnet_time': 11.39028000831604, 'refinenet_time': 4.963781833648682, 'postprocess_time': 0.2027297019958496}
total time (h:min:sec): 0:00:31.478

dont know why crafter time exceeded classic craft_text_detector ? may be i missed something ? how to check i use .onnx model ?

i also try to make conversion:
python convert/craftnet.py
but got error:

Traceback (most recent call last):
  File "/home/pi/crafter/convert/craftnet.py", line 52, in <module>
    craftnet_to_onnx(craftnet, "crafter/resources/craftnet.onnx")
  File "/home/pi/crafter/convert/craftnet.py", line 47, in craftnet_to_onnx
    np.testing.assert_allclose(feature.numpy(), ort_outs[1], rtol=1e-03, atol=1e-05)
  File "/home/pi/.local/lib/python3.9/site-packages/numpy/testing/_private/utils.py", line 1527, in assert_allclose
    assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
  File "/home/pi/.local/lib/python3.9/site-packages/numpy/testing/_private/utils.py", line 844, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Not equal to tolerance rtol=0.001, atol=1e-05

Mismatched elements: 1 / 609280 (0.000164%)
Max absolute difference: 1.9073486e-05
Max relative difference: 0.05192127
 x: array([[[[0.000000e+00, 0.000000e+00, 0.000000e+00, ..., 0.000000e+00,
          0.000000e+00, 0.000000e+00],
         [0.000000e+00, 0.000000e+00, 0.000000e+00, ..., 0.000000e+00,...
 y: array([[[[0.000000e+00, 0.000000e+00, 0.000000e+00, ..., 0.000000e+00,
          0.000000e+00, 0.000000e+00],
         [0.000000e+00, 0.000000e+00, 0.000000e+00, ..., 0.000000e+00,...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.