From c19b4e92e23ec948865b91868f8210da9ba9d851 Mon Sep 17 00:00:00 2001 From: kabachuha Date: Wed, 10 May 2023 13:10:02 +0300 Subject: [PATCH] use bicubic interpolation for masks instead of nearest by default to reduce pixelation --- scripts/deforum_helpers/word_masking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deforum_helpers/word_masking.py b/scripts/deforum_helpers/word_masking.py index 50752d19..342a7c76 100644 --- a/scripts/deforum_helpers/word_masking.py +++ b/scripts/deforum_helpers/word_masking.py @@ -41,6 +41,6 @@ def get_word_mask(root, frame, word_mask): preds = root.clipseg_model(img.repeat(len(word_masks),1,1,1), word_masks)[0] mask = torch.sigmoid(preds[0][0]).unsqueeze(0).unsqueeze(0) # add batch, channels dims - resized_mask = interpolate(mask, size=(frame.size[1], frame.size[0])).squeeze() # rescale mask back to the target resolution + resized_mask = interpolate(mask, size=(frame.size[1], frame.size[0]), mode='bicubic').squeeze() # rescale mask back to the target resolution numpy_array = resized_mask.multiply(255).to(dtype=torch.uint8,device='cpu').numpy() return Image.fromarray(cv2.threshold(numpy_array, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1])