Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.5 #8

Merged
merged 3 commits into from
Feb 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: unified resize without crop image.
  • Loading branch information
gesanqiu committed Feb 24, 2023
commit d43850639d1b9360727354ea7ee63bcec50c2170
30 changes: 17 additions & 13 deletions benckmark/yolov5s/create_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import numpy as np
import os

from PIL import Image
from PIL import Image, ImageOps


RESIZE_METHOD_ANTIALIAS = "antialias"
RESIZE_METHOD_BILINEAR = "bilinear"
Expand Down Expand Up @@ -75,22 +76,25 @@ def __resize_square_to_jpg(src, dst, width, height, resize_type):
src_img = Image.open(src)
# If black and white image, convert to rgb (all 3 channels the same)
if len(np.shape(src_img)) == 2: src_img = src_img.convert(mode = 'RGB')
# center crop to square

w, h = src_img.size
short_dim = min(h, w)
crop_coord = (
(w - short_dim) / 2,
(h - short_dim) / 2,
(w + short_dim) / 2,
(h + short_dim) / 2
)
img = src_img.crop(crop_coord)
# resize to inceptionv3 size
rho = min(width / w, height / h)
w, h = int(w * rho), int(h * rho)
if resize_type == RESIZE_METHOD_BILINEAR :
dst_img = img.resize((width, height), Image.BILINEAR)
dst_img = src_img.resize((w, h), Image.BILINEAR)
else :
dst_img = img.resize((width, height), Image.ANTIALIAS)
dst_img = src_img.resize((w, h), Image.ANTIALIAS)

# save output - save determined from file extension
left_pad, top_pad, right_pad, bottom_pad = 0, 0, 0, 0

if w == width:
top_pad = (height - h)
else:
left_pad = (width - w)

padding = (left_pad, top_pad, right_pad, bottom_pad)
dst_img = ImageOps.expand(dst_img, padding)
dst_img.save(dst)
return 0

Expand Down