use bicubic interpolation for masks

instead of nearest by default to reduce pixelation
pull/696/head
kabachuha 2023-05-10 13:10:02 +03:00
parent 17df392c25
commit c19b4e92e2
1 changed files with 1 additions and 1 deletions

View File

@ -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])