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

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

Open
robtow opened this issue Feb 4, 2024 · 1 comment

Comments

@robtow
Copy link

robtow commented Feb 4, 2024

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
Copy link

ukaprch commented May 26, 2024

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

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
@robtow @ukaprch and others