INNER CODE UNIT · Python
start_x
Shilin-LU/TF-ICON · scripts/app.py:65
start_x = (target_size[0] - image_resize.width) // 2
start_y = (target_size[1] - image_resize.height) // 2
padded_image.paste(image_resize, (start_x, start_y))
# Update the variable "image" to contain the final padded image
image = padded_image
else:
# image = Image.open(path).convert("RGB")
w, h = image.size
# print(f"loaded input image of size ({w}, {h}) from {path}")
w, h = map(lambda x: x - x % 64, (w, h)) # resize to integer multiple of 64
w = h = 512
image = image.resize((w, h), resample=PIL.Image.LANCZOS)
image = np.array(image).astype(np.float32) / 255.0
image = image[None].transpose(0, 3, 1, 2)
image = torch.from_numpy(image)