Maclory / Deep-Iterative-Collaboration

Pytorch implementation of Deep Face Super-Resolution with Iterative Collaboration between Attentive Recovery and Landmark Estimation (CVPR 2020)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Training set

aiden013 opened this issue · comments

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?

commented

And please tell me what kind of method do you use to implement bicubic sampling.

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.

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.

Thank you very much. I wish you all the best.