Esempio n. 1
0
def visualize_hypothesis(image, seg_pred, vertex_pred, corner_target):
    from lib.ransac_voting_gpu_layer.ransac_voting_gpu import generate_hypothesis

    vertex_pred = vertex_pred.permute(0, 2, 3, 1)
    b, h, w, vn_2 = vertex_pred.shape
    vertex_pred = vertex_pred.view(b, h, w, vn_2 // 2, 2)
    mask = torch.argmax(seg_pred, 1)
    hyp, hyp_counts = generate_hypothesis(mask, vertex_pred, 1024, inlier_thresh=0.99)

    image = imagenet_to_uint8(image.detach().cpu().numpy())
    hyp = hyp.detach().cpu().numpy()
    hyp_counts = hyp_counts.detach().cpu().numpy()

    from lib.utils.draw_utils import visualize_hypothesis
    visualize_hypothesis(image, hyp, hyp_counts, corner_target)
Esempio n. 2
0
visualize_overlap_mask(img, np.squeeze(segPred.cpu().detach().numpy()), None)

# Vertex field
verWeight = segPred.float().cpu().detach()
verWeight = np.argmax(verWeight, axis=1)
verWeight = verWeight[None, :, :, :]
visualize_vertex_field(verPred, verWeight, keypointIdx=0)

# Ransac Hypotheses
_, nKeypoints_x2, h, w = verPred.shape
nKeypoints = nKeypoints_x2 // 2
verPredAlt = verPred.reshape([1, nKeypoints, 2, h, w]).permute([0, 3, 4, 1, 2])
hypothesisPoints, inlierCounts = ransac_voting_hypothesis(
    verWeight.squeeze(0).cuda(), verPredAlt, 1024, inlier_thresh=0.999)
visualize_hypothesis(img[None, :, :, :],
                     hypothesisPoints.cpu().detach().numpy(),
                     inlierCounts.cpu().detach().numpy(), None)

# Save hypothesis points and scores
hypPath = os.path.join('.', 'hypothesisPoints.npy')
scorePath = os.path.join('.', 'inlierCounts.npy')
np.save(hypPath, hypothesisPoints.cpu().detach().numpy())
np.save(scorePath, inlierCounts.cpu().detach().numpy())

non_maximum_supression_np(detections,
                          scores,
                          similarityThreshold,
                          similarityFun,
                          scoreThreshold=None,
                          neighborThreshold=None)