Closed ELToulemonde closed 1 year ago
It seems like you are mixing something up here: The above construct will only call the branch actually needed, while Tesseract will use multiple threads by default when actually running (this is what you observed).
You can verify this with the following basic example as well:
choice = {
'key1': lambda: print('1'),
'key2': lambda: print('2'),
'key3': lambda: print('3'),
}['key2']
choice()
This will only print 2
as expected.
Indeed I miss-interpreted what I saw.
Thanks, I learn something and I close the issue.
Context
Exploring the code base to develop the functionality proposed in #159 I discovered that the call to tesseract is often performed multiple times on exact same data with same arguments for formatting purposes.
Example :
For function
image_to_string
it is called 3 times. I checked in terms of process, 3 process are indeed launched.Consequences
Computation seems to occur in parallel so it doesn't have an immediate impact on computation time. But it is sub-optimal :
Proposition
A small refacto could allow us to reduce by 2 to 3 the number of calls.
Refactoring would look like this.
Remove
return_bytes=False
option inrun_and_get_output
always return bytes Complete implementation would beNB: If we want to avoid changing the signature of this function, we could keep it as it is and always call it with
return_bytes=True
Implement a decode function
In interfaces functions make on call to
run_and_get_output
and manipulate output to have expected resultsFinally we would need to modify function
get_pandas_output
NB: If we want to avoid changing the signature of this function we could create another one named
get_pandas_from_tesseract_output
.Nice side effects from this refactoring
run_and_get_output
would be simpler :def run_and_get_output(image, extension='', lang=None, config='', nice=0, timeout=0) -> bytes
Conclusion
What do you think ? Did I miss something ?