choose aspect ration dependent on landscape or portrait (#48)

This commit is contained in:
Anders Aaen Springborg 2020-11-03 03:10:22 +01:00 committed by GitHub
parent d24363f421
commit 2808411421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -127,7 +127,9 @@ if __name__ == "__main__":
else:
url = "https://raw.githubusercontent.com/karpathy/micrograd/master/puppy.jpg"
img = Image.open(io.BytesIO(fetch(url)))
aspect_ratio = img.size[0] / img.size[1]
aspect_ratio_landscape = img.size[0] / img.size[1]
aspect_ratio_portrait = img.size[1] / img.size[0]
aspect_ratio = max (aspect_ratio_landscape, aspect_ratio_portrait)
img = img.resize((int(224*max(aspect_ratio,1.0)), int(224*max(1.0/aspect_ratio,1.0))))
img = np.array(img)