(pos, f, dist_f, best_pos_f, best_dist, feat1, feat2, feat1_, feat2_,\
                    eff_shape, alpha=0.5, psize=2)
return best_pos_f, best_dist
Batch Random Search For patch Match
Batch Random Search For patch Match
Batch Random Search For patch Match
def random_search(pos, f, dist_f, best_pos_f, best_dist, feat1, feat2, feat1_, feat2_,\
                    eff_shape, alpha=0.5, psize=2):
    """
    Batch Random Search For patch Match
    """
    r = [eff_shape[0], eff_shape[1]]
    eh, ew = eff_shape
    while r[0] >= 1 and r[1] >= 1:
        best_y, best_x = best_pos_f
        #end_time = time.time()
        xmin, xmax = max(best_x-r[1], 0), min(best_x+r[1]+1, ew)
        ymin, ymax = max(best_y-r[0], 0), min(best_y+r[0]+1, eh)
        pos_random_f = (ymin+np.random.randint(0, ymax-ymin), xmin+np.random.randint(0, xmax-xmin))#(torch.tensor([ymin, xmin]) + torch.rand(2)*torch.tensor([ymax-ymin, xmax-xmin])).type(torch.LongTensor)
        #print("Random Search: Random Pos Time:{}".format(time.time() - end_time))
        #end_time = time.time()
        best_pos_f, best_dist = improve_guess(pos, pos_random_f, best_pos_f, best_dist, feat1, feat2, feat1_, feat2_)
        #print("Random Search: Improve Time:{}".format(time.time() - end_time))

        r = [int(alpha*r[0]), int(alpha*r[1])]

    return best_pos_f, best_dist
def random_search ( pos , f , dist_f , best_pos_f , best_dist , feat1 , feat2 , feat1_ , feat2_ , eff_shape , alpha = 0.5 , psize = 2 ) : r = [ eff_shape [ 0 ] , eff_shape [ 1 ] ] eh , ew = eff_shape while r [ 0 ] >= 1 and r [ 1 ] >= 1 : best_y , best_x = best_pos_f #end_time = time.time() xmin , xmax = max ( best_x - r [ 1 ] , 0 ) , min ( best_x + r [ 1 ] + 1 , ew ) ymin , ymax = max ( best_y - r [ 0 ] , 0 ) , min ( best_y + r [ 0 ] + 1 , eh ) pos_random_f = ( ymin + np . random . randint ( 0 , ymax - ymin ) , xmin + np . random . randint ( 0 , xmax - xmin ) ) #(torch.tensor([ymin, xmin]) + torch.rand(2)*torch.tensor([ymax-ymin, xmax-xmin])).type(torch.LongTensor) #print("Random Search: Random Pos Time:{}".format(time.time() - end_time)) #end_time = time.time() best_pos_f , best_dist = improve_guess ( pos , pos_random_f , best_pos_f , best_dist , feat1 , feat2 , feat1_ , feat2_ ) #print("Random Search: Improve Time:{}".format(time.time() - end_time)) r = [ int ( alpha * r [ 0 ] ) , int ( alpha * r [ 1 ] ) ] return best_pos_f , best_dist