microsoft / Bringing-Old-Photos-Back-to-Life

Bringing Old Photo Back to Life (CVPR 2020 oral)
https://arxiv.org/abs/2004.09484
MIT License
14.97k stars 1.97k forks source link

cast error - line 219 in align_warp_back_multiple_dlib.py, using Python 3.10.12 #291

Open robtow opened 7 months ago

robtow commented 7 months ago

Fresh install of the repo, and using a venv with Python 3.10.12:

Running Stage 4: Blending
Traceback (most recent call last):
  File "/home/rob/Bringing-Old-Photos-Back-to-Life/Bringing-Old-Photos-Back-to-Life/Face_Detection/align_warp_back_multiple_dlib.py", line 428, in <module>
    blended = blur_blending_cv2(warped_back, blended, backward_mask)
  File "/home/rob/Bringing-Old-Photos-Back-to-Life/Bringing-Old-Photos-Back-to-Life/Face_Detection/align_warp_back_multiple_dlib.py", line 219, in blur_blending_cv2
    mask *= 255.0
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'multiply' output from dtype('float64') to dtype('uint8') with casting rule 'same_kind'

Fix at line 219 in align_warp_back_multiple_dlib.py

    #mask *= 255.0
    mask = mask * 255.0
ukaprch commented 3 months ago

I have Windows 10 and I was receiving problems as well with this module. I had to make more changes to make it work. This function is mixing datatypes so I had to make all arrays of type numpy float64 to make it consistent.

Starting with the function at line 217: def blur_blending_cv2(im1, im2, mask):

mask = mask.astype(np.float64)         <===include this line
mask /= 255.                                       <===include this line
#mask *= 255.                                     <===comment out

kernel = np.ones((9, 9), np.float64)  #np.uint8)        <===modify this line
mask = cv2.erode(mask, kernel, iterations=3)

mask_blur = cv2.GaussianBlur(mask, (25, 25), 0)
mask_blur /= 255.

im2 = im2.astype(np.float64)               <===include this line
im = im1 * mask_blur + (1. - mask_blur) * im2

im /= 255.0
im = np.clip(im, 0.0, 1.0)

return im

Starting with line 433 I had to modify to: blended = blur_blending_cv2(warped_back, blended, backward_mask)

blended *= 255.0 <===comment out

    io.imsave(os.path.join(save_url, x), img_as_ubyte(blended)) # (blended / 255.0))     <=== modify