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

Add PaddleOCR-Standalone and Batch mode support #9283

Merged
merged 2 commits into from
Feb 2, 2025

Conversation

timminator
Copy link
Contributor

@timminator timminator commented Jan 28, 2025

This PR adds support for the PaddleOCR-Standalone version I have also made.

This enables the usage of PaddleOCR without requiring the user to install python, paddlepaddle and paddleocr. Instead it prompts the user to download the standalone version, similar to when using tesseract 5.5.0 for the first time.
The PR still detects if the user installed PaddleOCR beforehand and does not prompt the user in this case to download PaddleOCR again.
Furthermore it checks if the system supports the GPU version or not. If not, the CPU version is used instead.

This PR also adds one of two desired features mentioned in #9250.

Edit: The second commit also adds Batch mode support when using PaddleOCR.

Fixes: #9250

@timminator
Copy link
Contributor Author

Hi! @niksedk:
I think you pushed this commit in the wrong repo...
I am actually kinda puzzled that you could push a commit into my fork, but thats no problem.
I want to update my commit/add a commit and I am not sure if your added commit is now also in the Subtitle Edit repo. I saw that one change was also done in another commit there, but this change:

var result = list?.Where(c => c.Value.Character == letter).Cast<KeyValuePair<int, SpecialCharacter>?>().FirstOrDefault();
return result;

is not in the main repo. Are you aware of that?
Before I update/add another commit to my branch I wanted to ask you this...

@niksedk
Copy link
Member

niksedk commented Feb 1, 2025

Yes, I did commit to the wrong repro... I did not know I could do that, LOL
The commit is also in the main SE branch.

I will try to look at your PR tomorrow.

Also, do you know what this is; https://github.com/PaddlePaddle/PaddleOCR/blob/main/deploy/cpp_infer/readme.md ?

@timminator timminator changed the title Add PaddleOCR-Standalone support Add PaddleOCR-Standalone and Batch mode support Feb 1, 2025
@timminator
Copy link
Contributor Author

timminator commented Feb 1, 2025

I will try to look at your PR tomorrow.

That would be really cool. :-)

I've also added now batch mode support for PaddleOCR.
It is backwards compatible, so with the current version of paddleocr via pip (2.9.1) it is not active, but with the next version it will automatically activate it. With my standalone version it is used already.
I've also added a check that the paddleocr version has to be version 2.7 or greater due to us using the model PP-OCRv4 which is not supported on older versions. It prompts the user to upgrade paddleocr in this case.

I've had to change quite a few thing for this, but I tried to test everything to make sure that it works correctly.
I was not sure how to test the function DoBatch() - I think it is used when using SubtitleEdit from the command line? I've updated it to the best of my knowledge - but maybe you could test this one?

I'm quite happy how this turned out - I hope you like it aswell! :-)

Regarding your link: I've not seen this before and have not tried this out. Also the instructions for Windows are only in chinese...
But it seems interesting...

Edit:
I've done some speed benchmarks on 250 subtitles using the original implementation and the new batch mode. I've done them using Python and the Standalone version:

Mode GPU (Batch) GPU (Original) CPU (Batch) CPU (Original)
Python 34s 35m 1m 54s 30m
Standalone 22s - 1m 40s -

The Batch mode is soo much better.
Interestingly using just the CPU on the Original mode is faster than using the GPU.
The compiled Standalone version is once again a little bit faster.

@niksedk niksedk merged commit 68bb60d into SubtitleEdit:main Feb 2, 2025
1 check passed
@timminator
Copy link
Contributor Author

Thank you for your quick merge! I really appreciate it! :-)

@niksedk
Copy link
Member

niksedk commented Feb 2, 2025

Thank you for making PaddleOCR a lot better in SE :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Add PaddleOCR standalone executable for simpler usage
2 participants