1. 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)
完整错误
Traceback (most recent call last):
File "/home/featurize/work/1超分辨率/Real-ESRGAN-master/inference_realesrgan.py", line 167, in <module>
main()
File "/home/featurize/work/1超分辨率/Real-ESRGAN-master/inference_realesrgan.py", line 146, in main
_, _, output = face_enhancer.enhance(img, has_aligned=False, only_center_face=False, paste_back=True)
File "/environment/miniconda3/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/environment/miniconda3/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 "/environment/miniconda3/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)
这是因为处理的图片是png格式的,只需要将png格式的图片转化为jpg格式,以上问题即可解决,例如我的图片一开始是00017_gray.png
2. 转换代码
from PIL import Image
img = Image.open('path/xx.png')#你自己的png图片路径
img = img.convert('RGB')
img.save('path/xx.jpg')#你自己保存的jpg图片路径
3. 报错消失出现以下输出代表成功解决问题
Testing 0 00003
(256, 512, 3) =====================
Testing 1 00017_gray
(351, 500, 3) =====================