Skip to content
Snippets Groups Projects

WIP: [Transform class] add ResizeCrop for drhagis

Closed Driss KHALIL requested to merge DrhagisUpdates into master
7 unresolved threads
@@ -301,3 +301,18 @@ class SSLDataset(torch.utils.data.Dataset):
unlab = self._unlabelled[torch.randint(len(self._unlabelled), ())]
# only interested in key and data
return retval + unlab[:2]
def expand2square(pil_img, background_color):
width, height = pil_img.size
if width == height:
return pil_img
elif width > height:
result = PIL.Image.new(pil_img.mode, (width, width), background_color)
result.paste(pil_img, (0, (width - height) // 2))
return result
else:
result = PIL.Image.new(pil_img.mode, (height, height), background_color)
result.paste(pil_img, ((height - width) // 2, 0))
return result
Loading