Skip to content

Instantly share code, notes, and snippets.

@neelriyer
Created July 19, 2020 08:30
Show Gist options
  • Save neelriyer/fe661783ff3c8c222bd085ef03a2bb5e to your computer and use it in GitHub Desktop.
Save neelriyer/fe661783ff3c8c222bd085ef03a2bb5e to your computer and use it in GitHub Desktop.
detectron2 web app low memory image transforms
import PIL
from PIL import Image
# adapted from: https://github.com/jantic/DeOldify/blob/master/deoldify/filters.py
def _scale_to_square(orig, targ):
targ_sz = (targ, targ)
return orig.resize(targ_sz, resample=PIL.Image.BILINEAR)
def _unsquare(image, orig):
targ_sz = orig.size
image = image.resize(targ_sz, resample=PIL.Image.BILINEAR)
return images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment