zyddnys / manga-image-translator

Translate manga/image 一键翻译各类图片内文字 https://cotrans.touhou.ai/
https://cotrans.touhou.ai/
GNU General Public License v3.0
4.93k stars 512 forks source link

[Question] - How to improve performance #325

Open alb-ctrl opened 1 year ago

alb-ctrl commented 1 year ago

Hello, I first found this repo on 05/2022 and I just found some time again to use it today 04/2023 im running Python 3.9.9 on a MacBook Pro 2020 M1 Memory 8 GB when I first used this I was using this commit commit 2aa41c164ad43bdbf3f0a6066d5cdcffcb6a3542 it ran relatively fast (I tried it again today) although the translation wasn't as good as with the new code python3 translate_demo.py --target-lang=ENG --image <path> --mode batch --manga2eng

after getting the latest commit 83c3799a87c5dfd6969fe56c503b57989a11e96e I used google translate and It was taking too long and the translation wasn't as good (almost the same as the old code comparing the translations)

the one I liked the most is using sugoi in the new code but it is still taking too long. for 20 images is took 54 minutes with the following command python3 -m manga_translator -v --mode batch --translator=sugoi -l ENG --manga2eng --revert-upscaling -I<path>

For anyone who uses a Mac is there any way to improve performance ?

or any configuration to improve performance ?

this are some screenshots

Screen Shot 2023-04-30 at 4 44 37 PM
JustFrederik commented 1 year ago

The gpu usage doesn’t matter and python is only using a single core so the problem is most likely the memory, but could you upload the usage of memory and cpu for both commits?

you could host a gpu server and run it not on your Mac. Since sugoi is an offline translator the performance is depending on ctranslate2. There is nothing that can be done about that.

have you tried Google colab? I think it’s free and you can use cuda with it

cloud gpu free

alb-ctrl commented 1 year ago

im guessing this question is not smart but is there a way to use more cores, and would that help ?

this is in the old commit (05/2022) - the 20 pages were translated in ~5 min

Screen Shot 2023-04-30 at 8 18 54 PM

this is the new code (04/2023)

Screen Shot 2023-04-30 at 8 28 09 PM

the first spike is the first page, which is just the covert art and title

I'll try the gpu server and/or Google colab in a near future. but if anyone has any suggestions on how to improve performance it would be greatly appreciated

JustFrederik commented 1 year ago

I’m confused why the usage is evenly distributed. Usually python only uses one core and it’s a pain to implement multiprocessing. It could be because of a different cpu architecture.

the problem is that you are using to much memory. You have 12gb swap. I don’t know how much of it is due to the this repo. Are you using the offline translator with the newer version. Python is using 32gb of memory.

alb-ctrl commented 1 year ago

im using the latest commit with offline translation using sugoi (which is pretty good, I only used google translate and sugoi in the new code but sugoi was the best translation ) maybe if someone can recommend other translators that have better performance.

just for comparison this is the memory and cpu usage only using Safari (I dont use chrome but safari uses chromium I believe so pretty much the same)

Screen Shot 2023-05-01 at 6 21 10 AM

Perhaps im over complaining trying to save 5 min in translation. Does anyone know how long it takes to translate ~20 pages in their Mac m1. ? if the normal is ~50 min then there's nothing I can do other than use a better computer.

JustFrederik commented 1 year ago

i just ran it on my mac, but with google transate: Before:

Screenshot 2023-05-01 at 1 04 20 PM

After:

Screenshot 2023-05-01 at 1 09 09 PM

I translated the 4 example images and it took that long: 214.56s user 148.36s system 77% cpu 7:49.55 total. Without the inpainter it runs way faster: 98.68s user 25.17s system 272% cpu 45.429 total.

So dont use an inpainter and use an online translator.

JustFrederik commented 1 year ago

@alb-ctrl why are you using --revert-upscaling

alb-ctrl commented 1 year ago

I just tried it without in painter it worked way better 20 images in ~5 min python3 -m manga_translator -v --mode batch --translator=sugoi -l ENG --manga2eng --inpainter none thanks a lot

Screen Shot 2023-05-01 at 7 58 57 AM

I was trying to see if using --rever-upscaling makes the images smaller currently it goes from 286157 Apr 30 15:04 1.jpg to 1757664 May 1 07:55 1.png

BigEmperor26 commented 8 months ago

So, if you have a M1 or other apple silicon Mac you can use their GPUs by using mps instead of cuda. There is already some work doing it, apple silicon but there is a roadblock because the inpainting phase, which is the slowest part, seemengly cannot run on Apple GPUs.

BigEmperor26 commented 8 months ago

As I am working on it, with a M1 Pro, moving everything to the apple gpu using the mps I see a large improvement. I was able to test and successfully move to mps:

unfortunately the translation library:

for the inpainting I am working on it. I tested AotInpainter and it is able to more than double the performance of a test sample image, going from 13-14s to 4s. If I am able to complete the inpainter for llama_mpe and lama_large I'll open a PR

PR opened here https://github.com/zyddnys/manga-image-translator/pull/533