utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:pix2pix-human 作者: Engineering-Course 项目源码 文件源码
def load_lip_data_t2(image_id, flip=False, is_test=False):
    fine_size=64
    image_id = image_id[:-1] 
    image_path = './datasets/human/masks/{}.png'.format(image_id)
    img_A = scipy.misc.imread(image_path).astype(np.float)
    rows = img_A.shape[0]
    cols = img_A.shape[1]
    img_A = scipy.misc.imresize(img_A, [fine_size, fine_size])
    img_B = np.zeros((fine_size, fine_size), dtype=np.float64)
    with open('./datasets/human/pose/{}.txt'.format(image_id), 'r') as f:
        lines = f.readlines()
    points = lines[0].split(',')
    for idx, point in enumerate(points):
        if idx % 2 == 0:
            c_ = int(point)
            c_ = min(c_, cols-1)
            c_ = max(c_, 0)
            c_ = int(fine_size * 1.0 * c_ / cols)
        else:
            r_ = int(point)
            r_ = min(r_, rows-1)
            r_ = max(r_, 0)
            r_ = int(fine_size * 1.0 * r_ / rows)
            if c_ + r_ == 0:
                continue
            var = multivariate_normal(mean=[r_, c_], cov=2)
            for i in xrange(fine_size):
                for j in xrange(fine_size):
                    img_B[i, j] += var.pdf([i, j]) * 1.0
    img_A = img_A/127.5 - 1.
    img_BA = np.concatenate((img_B[:,:,np.newaxis], img_A), axis=2)
    # print img_BA.shape
    # img_AB shape: (fine_size, fine_size, input_c_dim + output_c_dim)
    return img_BA

#------------------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号