Add batch img inference support for ocr det with readtext_batched #458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Batched image inference for text detection
Caveats:
n_width
andn_height
parameters can be used inreadtext_batched
.readtext_batched
can also take a single image as input but returns a result list with one element, i.e. a further result[0] access will be required.cudnn.benchmark
mode set to True is better for batched inference hence I passcudnn_benchmark=True
ineasyocr.Reader
dummy = np.zeros([batch_size, 600, 800, 3], dtype=np.uint8); reader.readtext_batched(dummy)
before timing the inferences.Edited files
These changes although major should have no backward compatibility issues, but I would greatly appreciate extensive testing @rkcosmos . I am open to any suggestions or changes
utils.py
reformat_input_batched
to take a list of file paths, numpy ndarrays, or byte stream objectsdetection.py
get_textbox
function to process a list of lists of bboxes and polystest_net
functions to accumulate the input image and send all the inputs in a single tensor to the CRAFT torch modeleasyocr.py
readtext_batched
to take a list of file paths, numpy ndarrays, or byte stream objects now to process them in batch.detect
function to process a list of imagesI have a test script here to verify the functions are working as intended and added results for both CPU and GPU
As expected GPU batched inference is almost twice as fast as sequential GPU inference.
GPU results
CPU results
test_batch_easyocr.py
program to generate the outputs above