xinntao / Real-ESRGAN

Real-ESRGAN aims at developing Practical Algorithms for General Image/Video Restoration.
BSD 3-Clause "New" or "Revised" License
27.11k stars 3.41k forks source link

ValueError: operands could not be broadcast together with shapes (1404,2000,1) (1404,2000) #555

Open Nolasaurus opened 1 year ago

Nolasaurus commented 1 year ago

I'm trying to run Real-ESRGAN with Python 3.10.8 on Ubuntu 22.04.1 through WSL2.

I followed the instructions found here:

When I run the code snippets wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights

python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance

I get the following error:

(test_esrgan) nolan@NolanDesktop:~/Python/Real-ESRGAN$ python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
/home/nolan/miniconda3/envs/test_esrgan/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
  warnings.warn(
/home/nolan/miniconda3/envs/test_esrgan/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=None`.
  warnings.warn(msg)
Testing 0 00003
Testing 1 00017_gray
Traceback (most recent call last):
  File "/home/nolan/Python/Real-ESRGAN/inference_realesrgan.py", line 166, in <module>
    main()
  File "/home/nolan/Python/Real-ESRGAN/inference_realesrgan.py", line 145, in main
    _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
  File "/home/nolan/miniconda3/envs/test_esrgan/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/home/nolan/miniconda3/envs/test_esrgan/lib/python3.10/site-packages/gfpgan/utils.py", line 145, in enhance
    restored_img = self.face_helper.paste_faces_to_input_image(upsample_img=bg_img)
  File "/home/nolan/miniconda3/envs/test_esrgan/lib/python3.10/site-packages/facexlib/utils/face_restoration_helper.py", line 355, in paste_faces_to_input_image
    upsample_img = inv_soft_mask * pasted_face + (1 - inv_soft_mask) * upsample_img
ValueError: operands could not be broadcast together with shapes (1404,2000,1) (1404,2000)

error message.txt

Nolasaurus commented 1 year ago

When I follow the code a little further down the page ...

wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights

python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs

I get this error instead:

python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
Testing 0 00003
Testing 1 00017_gray
Testing 2 0014
Testing 3 0030
Testing 4 ADE_val_00000114
Testing 5 OST_009
Testing 6 children-alpha
Testing 7 tree_alpha_16bit
        Input is a 16-bit image
Testing 8 video
Traceback (most recent call last):
  File "/home/nolan/Python/Real-ESRGAN/inference_realesrgan.py", line 166, in <module>
    main()
  File "/home/nolan/Python/Real-ESRGAN/inference_realesrgan.py", line 138, in main
    if len(img.shape) == 3 and img.shape[2] == 4:
AttributeError: 'NoneType' object has no attribute 'shape'
Nolasaurus commented 1 year ago

I don't know what the original issue was, but I reinstalled from scratch and it is now working.

Nolasaurus commented 1 year ago

Never mind, ran into the same error

Nolasaurus commented 1 year ago

I did not have the .pth files in the \Real-ESRGAN directory and now I no longer get the first error, only the one ending in AttributeError: 'NoneType' object has no attribute 'shape'

abhijiticelero commented 1 year ago

I got this error with 00017_gray.png (https://github.com/xinntao/Real-ESRGAN/blob/master/inputs/00017_gray.png)

$ python3 inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance

Traceback (most recent call last): File "/home/ubuntu/Real-ESRGAN/inference_realesrgan.py", line 166, in main() File "/home/ubuntu/Real-ESRGAN/inferencerealesrgan.py", line 145, in main , _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True) File "/home/ubuntu/.local/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) File "/home/ubuntu/.local/lib/python3.10/site-packages/gfpgan/utils.py", line 145, in enhance restored_img = self.face_helper.paste_faces_to_input_image(upsample_img=bg_img) File "/home/ubuntu/.local/lib/python3.10/site-packages/facexlib/utils/face_restoration_helper.py", line 355, in paste_faces_to_input_image upsample_img = inv_soft_mask pasted_face + (1 - inv_soft_mask) * upsample_img ValueError: operands could not be broadcast together with shapes (351,500,1) (351,500)

Eliya-Shalom commented 11 months ago

I'm getting the same error with the example input file 00017_gray.png. It only occurs with png file extension, and face_enhance arg.

Python 3.11 Windows OS I've tried with other models, but failed with the same error RealESRGAN_x4plus | RealESRNet_x4plus | RealESRGAN_x2plus | realesr-general-x4v3

Working well with jpg file extension.

`Testing 0 00017_gray Traceback (most recent call last): File "C:\AI\Real-ESRGAN\inference_realesrgan.py", line 167, in main() File "C:\AI\Real-ESRGAN\inferencerealesrgan.py", line 146, in main , _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\The Beast\anaconda3\Lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\gfpgan\utils.py", line 145, in enhance restored_img = self.face_helper.paste_faces_to_input_image(upsample_img=bg_img) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\facexlib\utils\face_restoration_helper.py", line 355, in paste_faces_to_input_image upsample_img = inv_soft_mask pasted_face + (1 - inv_soft_mask) * upsample_img


ValueError: operands could not be broadcast together with shapes (1404,2000,1) (1404,2000)`
AlionSSS commented 10 months ago

Here is a solution

Analyze

AlionSSS commented 10 months ago

I'm getting the same error with the example input file 00017_gray.png. It only occurs with png file extension, and face_enhance arg.

Python 3.11 Windows OS I've tried with other models, but failed with the same error RealESRGAN_x4plus | RealESRNet_x4plus | RealESRGAN_x2plus | realesr-general-x4v3

Working well with jpg file extension.

Testing 0 00017_gray Traceback (most recent call last): File "C:\AI\Real-ESRGAN\inference_realesrgan.py", line 167, in <module> main() File "C:\AI\Real-ESRGAN\inference_realesrgan.py", line 146, in main _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\The Beast\anaconda3\Lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\gfpgan\utils.py", line 145, in enhance restored_img = self.face_helper.paste_faces_to_input_image(upsample_img=bg_img) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\facexlib\utils\face_restoration_helper.py", line 355, in paste_faces_to_input_image upsample_img = inv_soft_mask * pasted_face + (1 - inv_soft_mask) * upsample_img ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ ValueError: operands could not be broadcast together with shapes (1404,2000,1) (1404,2000)

I'm getting the same error with the example input file 00017_gray.png. It only occurs with png file extension, and face_enhance arg.

Python 3.11 Windows OS I've tried with other models, but failed with the same error RealESRGAN_x4plus | RealESRNet_x4plus | RealESRGAN_x2plus | realesr-general-x4v3

Working well with jpg file extension.

Testing 0 00017_gray Traceback (most recent call last): File "C:\AI\Real-ESRGAN\inference_realesrgan.py", line 167, in <module> main() File "C:\AI\Real-ESRGAN\inference_realesrgan.py", line 146, in main _, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\The Beast\anaconda3\Lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\gfpgan\utils.py", line 145, in enhance restored_img = self.face_helper.paste_faces_to_input_image(upsample_img=bg_img) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\xxx\anaconda3\Lib\site-packages\facexlib\utils\face_restoration_helper.py", line 355, in paste_faces_to_input_image upsample_img = inv_soft_mask * pasted_face + (1 - inv_soft_mask) * upsample_img ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ ValueError: operands could not be broadcast together with shapes (1404,2000,1) (1404,2000)

See here https://github.com/xinntao/Real-ESRGAN/issues/555#issuecomment-1705470424

richardbransonzp commented 4 months ago

I did not have the .pth files in the \Real-ESRGAN directory and now I no longer get the first error, only the one ending in AttributeError: 'NoneType' object has no attribute 'shape'

Hi,do you find the solution about this issue?

WangJunjie97 commented 3 months ago

When I follow the code a little further down the page ...

wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights

python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs

I get this error instead:

python inference_realesrgan.py -n RealESRGAN_x4plus_anime_6B -i inputs
Testing 0 00003
Testing 1 00017_gray
Testing 2 0014
Testing 3 0030
Testing 4 ADE_val_00000114
Testing 5 OST_009
Testing 6 children-alpha
Testing 7 tree_alpha_16bit
        Input is a 16-bit image
Testing 8 video
Traceback (most recent call last):
  File "/home/nolan/Python/Real-ESRGAN/inference_realesrgan.py", line 166, in <module>
    main()
  File "/home/nolan/Python/Real-ESRGAN/inference_realesrgan.py", line 138, in main
    if len(img.shape) == 3 and img.shape[2] == 4:
AttributeError: 'NoneType' object has no attribute 'shape'

Testing 8 video video is a folder name, not an image file