Training set
aiden013 opened this issue · comments
aiden commented
Your article is very enlightening to me. Can you tell me how you can crop the un-aligned face image. By choosing the center of the key or what?
aiden commented
And please tell me what kind of method do you use to implement bicubic sampling.
Zhenyu Jiang commented
Hi, we crop the face with keypoints. The code is like this:
def bbox_generator(anno, img_root, expand_scale=0.3):
split = anno.split()
img_name = split[0]
full_w, full_h = Image.open(os.path.join(img_root, img_name)).size
# here split[1:] should be
x_min, y_min, w, h = [int(x) for x in split[1:]]
# center_crop
if w > h:
dx = (w - h) / 2
x_min += dx
w = h
else:
dy = (h - w) / 2
y_min += dy
h = w
expand_x = int(w * expand_scale / 2)
expand_y = int(h * expand_scale / 2)
new_x_min = max(0, x_min - expand_x)
new_y_min = max(0, y_min - expand_y)
x_max = min(new_x_min + w + 2 * expand_x, full_w)
y_max = min(new_y_min + h + 2 * expand_y, full_h)
return img_name, (new_x_min, new_y_min, x_max, y_max)
For bicubic sampling, we use img.resize
, where img
is a PIL.Image
.
aiden commented
Hi, we crop the face with keypoints. The code is like this:
def bbox_generator(anno, img_root, expand_scale=0.3): split = anno.split() img_name = split[0] full_w, full_h = Image.open(os.path.join(img_root, img_name)).size # here split[1:] should be x_min, y_min, w, h = [int(x) for x in split[1:]] # center_crop if w > h: dx = (w - h) / 2 x_min += dx w = h else: dy = (h - w) / 2 y_min += dy h = w expand_x = int(w * expand_scale / 2) expand_y = int(h * expand_scale / 2) new_x_min = max(0, x_min - expand_x) new_y_min = max(0, y_min - expand_y) x_max = min(new_x_min + w + 2 * expand_x, full_w) y_max = min(new_y_min + h + 2 * expand_y, full_h) return img_name, (new_x_min, new_y_min, x_max, y_max)For bicubic sampling, we use
img.resize
, whereimg
is aPIL.Image
.
Thank you very much. I wish you all the best.