(feat1, feat2, feat1_, feat2_, img_shape, psize=2, iteration=5, alpha=0.5)
return f
A deep patch match method based on two pairs data. Formulated in Deep Image Analogy
    Original version only use img1 and img2
    Params: img1(torch.Tensor):  shape C*H*W
A deep patch match method based on two pairs data. Formulated in Deep Image Analogy
    Original version only use img1 and img2
    Params: img1(torch.Tensor):  shape C*H*W
A deep patch match method based on two pairs data . Formulated in Deep Image Analogy Original version only use img1 and img2 Params : img1 ( torch . Tensor ) : shape C * H * W
def deep_patch_match(feat1, feat2, feat1_, feat2_, img_shape, psize=2, iteration=5, alpha=0.5):
    """
    A deep patch match method based on two pairs data. Formulated in Deep Image Analogy
    Original version only use img1 and img2
    Params: img1(torch.Tensor):  shape C*H*W
    """
    assert feat1.size() == feat2.size() == feat1_.size() == feat2_.size()
    eff_shape = get_effective_shape(img_shape, psize)
    #eff_shape = get_effective_shape(img_shape, psize)
    feat1, feat2, feat1_, feat2_ = feat1.to(device), feat2.to(device), feat1_.to(device), feat2_.to(device)
    # initialization
    f = torch.zeros(*((img_shape)+(2,)), device=device, dtype=torch.int32)
    dist_f = torch.zeros(*img_shape, device=device)
    for y in range(eff_shape[0]):
        for x in range(eff_shape[1]):
            pos = (y,x)
            pos_f = (np.random.randint(0,eff_shape[0]),np.random.randint(0,eff_shape[1]))
            f[y, x] = torch.tensor(pos_f, device=device).type(torch.LongTensor)
            dist_f[y, x] = feat_patch_distance(feat1, feat2, feat1_, feat2_, pos, pos_f, psize)

    for i in range(iteration):
        print("Iteration {}: Running".format(i+1))
        change, start, end = initialize_direction(i, eff_shape)
        print('start:{}, end:{}, change:{}'.format(start, end, change))
        ori_time = end_time = time.time()
        for y in range(int(start[0]), int(end[0]), int(change[0])):
            for x in range(int(start[1]), int(end[1]), int(change[1])):
                pos = (y,x)
                best_pos_f, best_dist = propagation(pos, change, f, dist_f, feat1, feat2, feat1_, feat2_, eff_shape, psize)
                best_pos_f, best_dist = random_search(pos, f, dist_f, best_pos_f, best_dist, feat1, feat2, feat1_, feat2_, eff_shape, psize=psize)
                f[y,x] = torch.tensor(best_pos_f, device=device, dtype=torch.int32)
                dist_f[y,x] = best_dist

        re_img1 = reconstruct_avg(feat2, f, psize=PSIZE)
        save_img(re_img1, "epoch_{}_re_test.png".format(i))
        print("Iteration {}: Finishing Time : {}".format(i+1, time.time()-ori_time))
    return f
def deep_patch_match ( feat1 , feat2 , feat1_ , feat2_ , img_shape , psize = 2 , iteration = 5 , alpha = 0.5 ) : assert feat1 . size ( ) == feat2 . size ( ) == feat1_ . size ( ) == feat2_ . size ( ) eff_shape = get_effective_shape ( img_shape , psize ) #eff_shape = get_effective_shape(img_shape, psize) feat1 , feat2 , feat1_ , feat2_ = feat1 . to ( device ) , feat2 . to ( device ) , feat1_ . to ( device ) , feat2_ . to ( device ) # initialization f = torch . zeros ( * ( ( img_shape ) + ( 2 , ) ) , device = device , dtype = torch . int32 ) dist_f = torch . zeros ( * img_shape , device = device ) for y in range ( eff_shape [ 0 ] ) : for x in range ( eff_shape [ 1 ] ) : pos = ( y , x ) pos_f = ( np . random . randint ( 0 , eff_shape [ 0 ] ) , np . random . randint ( 0 , eff_shape [ 1 ] ) ) f [ y , x ] = torch . tensor ( pos_f , device = device ) . type ( torch . LongTensor ) dist_f [ y , x ] = feat_patch_distance ( feat1 , feat2 , feat1_ , feat2_ , pos , pos_f , psize ) for i in range ( iteration ) : print ( "Iteration {}: Running" . format ( i + 1 ) ) change , start , end = initialize_direction ( i , eff_shape ) print ( 'start:{}, end:{}, change:{}' . format ( start , end , change ) ) ori_time = end_time = time . time ( ) for y in range ( int ( start [ 0 ] ) , int ( end [ 0 ] ) , int ( change [ 0 ] ) ) : for x in range ( int ( start [ 1 ] ) , int ( end [ 1 ] ) , int ( change [ 1 ] ) ) : pos = ( y , x ) best_pos_f , best_dist = propagation ( pos , change , f , dist_f , feat1 , feat2 , feat1_ , feat2_ , eff_shape , psize ) best_pos_f , best_dist = random_search ( pos , f , dist_f , best_pos_f , best_dist , feat1 , feat2 , feat1_ , feat2_ , eff_shape , psize = psize ) f [ y , x ] = torch . tensor ( best_pos_f , device = device , dtype = torch . int32 ) dist_f [ y , x ] = best_dist re_img1 = reconstruct_avg ( feat2 , f , psize = PSIZE ) save_img ( re_img1 , "epoch_{}_re_test.png" . format ( i ) ) print ( "Iteration {}: Finishing Time : {}" . format ( i + 1 , time . time ( ) - ori_time ) ) return f