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

ufunc 'right_shift' not supported for the input types #67

Closed
MaksymSofer opened this issue Jul 10, 2022 · 11 comments
Closed

ufunc 'right_shift' not supported for the input types #67

MaksymSofer opened this issue Jul 10, 2022 · 11 comments

Comments

@MaksymSofer
Copy link

Trying this tool on ubuntu 20.04.
got the latest version from git
I`m translating from Japanese to English

Error:


switch to google translator
 -- Rendering translated text
すごいな…
It's amazing ...
137 609 37 180
Traceback (most recent call last):
  File "translate_demo.py", line 354, in <module>
    loop.run_until_complete(main(args.mode))
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "translate_demo.py", line 270, in main
    await infer(img, mode, '', alpha_ch = alpha_ch)
  File "translate_demo.py", line 204, in infer
    output = await dispatch_rendering(np.copy(img_inpainted), args.text_mag_ratio, translated_sentences, textlines, text_regions, render_text_direction_overwrite)
  File "/home/maks/manga-image-translator/text_rendering/__init__.py", line 53, in dispatch
    img_canvas = render(img_canvas, font_size, text_mag_ratio, trans_text, region, majority_dir, fg, bg, False)
  File "/home/maks/manga-image-translator/text_rendering/__init__.py", line 83, in render
    font_size_enlarged = findNextPowerOf2(font_size) * text_mag_ratio
  File "/home/maks/manga-image-translator/utils.py", line 454, in findNextPowerOf2
    n = n >> 1
TypeError: ufunc 'right_shift' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
@zyddnys
Copy link
Owner

zyddnys commented Jul 11, 2022

Can you share the image you are translating so I can reproduce this error?

@MaksymSofer
Copy link
Author

1CanvasAsImage

@zyddnys
Copy link
Owner

zyddnys commented Jul 11, 2022

Can you also share the arguments you used

@MaksymSofer
Copy link
Author

python3 translate_demo.py --verbose --use-inpainting --translator=google --target-lang=ENG --image Downloads/26CanvasAsImage.png

@zyddnys
Copy link
Owner

zyddnys commented Jul 12, 2022

I was unable to reproduce this error, but I pushed a commit anyway. Let me know if the latest version still has the same issue.

@MaksymSofer
Copy link
Author

nohup.log
Here full nohup of run with your last commit

@MaksymSofer
Copy link
Author

pip_pkg_list.log
these are my pip packages

@zyddnys
Copy link
Owner

zyddnys commented Jul 16, 2022

I still wasn't able to reproduce this error, can you try changing n = n >> 1 to n = int(n) >> 1 and see if that helps

@MaksymSofer
Copy link
Author

MaksymSofer commented Jul 17, 2022

You talking about utils.py:
method:
def findNextPowerOf2(n): i = 0 while n != 0 : i += 1 n = n >> 1 return 1 << i

??

there 'n' is coming as float

changed and now got different issue:

Traceback (most recent call last): File "translate_demo.py", line 354, in <module> loop.run_until_complete(main(args.mode)) File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "translate_demo.py", line 270, in main await infer(img, mode, '', alpha_ch = alpha_ch) File "translate_demo.py", line 204, in infer output = await dispatch_rendering(np.copy(img_inpainted), args.text_mag_ratio, translated_sentences, textlines, text_regions, render_text_direction_overwrite) File "/home/maks/manga-image-translator/text_rendering/__init__.py", line 53, in dispatch img_canvas = render(img_canvas, font_size, text_mag_ratio, trans_text, region, majority_dir, fg, bg, False) File "/home/maks/manga-image-translator/text_rendering/__init__.py", line 111, in render temp_box = text_render.put_text_vertical( File "/home/maks/manga-image-translator/text_rendering/text_render.py", line 347, in put_text_vertical canvas_text = np.zeros((canvas_y, canvas_x), dtype=np.uint8) TypeError: 'numpy.float64' object cannot be interpreted as an integer

@MaksymSofer
Copy link
Author

issue seems resolved with --force-horizontal

@dennis-thevara
Copy link

I still wasn't able to reproduce this error, can you try changing n = n >> 1 to n = int(n) >> 1 and see if that helps

I had this same issue and you had the right idea, but using a straight int(n) will fail on numpy floats. n = n >> 1 to n = n.astype(int) >> 1 solved this issue.

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

No branches or pull requests

3 participants