well it got fixed, I had to pass mask_image=mask_pil but I was passing mask=mask_pil
mask_image=mask_pil
mask=mask_pil