-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise
OcrEngine::prepare_input
API to reduce copies when loading i…
…mage The steps to load an image were: 1. Load the image into an RGB `ImageBuffer`, which holds bytes in channels-last (HWC) layout. 2. Copy image bytes from source into an RGB float tensor in channels-first (CHW) layout with values in [0, 1]. 3. Copy values into greyscale CHW float tensor with values in [-0.5, 0.5] Step (2) is wasteful, especially for large images, and the implementation also unnecessarily allocated zeroed output buffers for steps 2 and 3. This commit revises the `OcrEngine::prepare_input` API so that it can accept inputs as either floats or bytes, and in either CHW or HWC order. This enables fusing steps 2 and 3 together, avoiding a copy. For the convenience of the common use case of passing an image loaded using the `image` crate, there is also an `ImageSource::from_bytes(buffer, dimensions)` API. This will also help many consumers avoid the `rten-imageio` dependency. Tested on a large JPEG image (2028 x 3306) this reduced image loading time from ~200ms to ~150ms.
- Loading branch information
1 parent
971d9e9
commit fa4e7b4
Showing
8 changed files
with
233 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.