コード例 #1
0
    def __init__(self, do_cuda=True): 
        self.lock = RLock()
        self.opts = rfnetOptions(do_cuda)
        print(self.opts)        

        print('rfnet init')

        #print(f"{gct()} model init")
        print("model init")
        det = RFDetSO(
            cfg.TRAIN.score_com_strength,
            cfg.TRAIN.scale_com_strength,
            cfg.TRAIN.NMS_THRESH,
            cfg.TRAIN.NMS_KSIZE,
            cfg.TRAIN.TOPK,
            cfg.MODEL.GAUSSIAN_KSIZE,
            cfg.MODEL.GAUSSIAN_SIGMA,
            cfg.MODEL.KSIZE,
            cfg.MODEL.padding,
            cfg.MODEL.dilation,
            cfg.MODEL.scale_list,
        )
        des = HardNetNeiMask(cfg.HARDNET.MARGIN, cfg.MODEL.COO_THRSH)
        model = RFNetSO(
            det, des, cfg.LOSS.SCORE, cfg.LOSS.PAIR, cfg.PATCH.SIZE, cfg.TRAIN.TOPK
        )

        device = torch.device("cuda")
        model = model.to(device)
        #resume = args.resume
        #resume = "/home/cviss3/PycharmProjects/gensynth_dev_env/pyslam/thirdparty/rfnet/runs/10_24_09_25/model/e121_NN_0.480_NNT_0.655_NNDR_0.813_MeanMS_0.649.pth.tar"
        resume = "/content/RFnetpyslam/thirdparty/rfnet/runs/10_24_09_25/model/e121_NN_0.480_NNT_0.655_NNDR_0.813_MeanMS_0.649.pth.tar"

        print('==> Loading pre-trained network.')
        checkpoint = torch.load(resume)
        model.load_state_dict(checkpoint["state_dict"])
        self.fe = model
        print('==> Successfully loaded pre-trained network.')

        self.device = device
        self.pts = []
        self.kps = []        
        self.des = []
        self.img = []
        self.heatmap = [] 
        self.frame = None 
        self.frameFloat = None 
        self.keypoint_size = 20  # just a representative size for visualization and in order to convert extracted points to cv2.KeyPoint 
コード例 #2
0
ファイル: train.py プロジェクト: iamwangyabin/FDLNet
        det_lr=cfg.TRAIN.DET_LR,
        des_lr=cfg.TRAIN.DES_LR,
        det_wd=cfg.TRAIN.DET_WD,
        des_wd=cfg.TRAIN.DES_WD,
        mgpu=mgpu,
    )

    ###############################################################################
    # resume model if exists
    ###############################################################################
    if args.resume:
        if os.path.isfile(args.resume):
            print(f"{gct()} : Loading checkpoint {args.resume}")
            checkpoint = torch.load(args.resume)
            args.start_epoch = checkpoint["epoch"]
            model.load_state_dict(checkpoint["state_dict"])
            det_optim.load_state_dict(checkpoint["det_optim"])
            des_optim.load_state_dict(checkpoint["des_optim"])
        else:
            print(f"{gct()} : Cannot found checkpoint {args.resume}")
    else:
        args.start_epoch = 0

    ###############################################################################
    # Visualization
    ###############################################################################
    train_writer = SummaryWriter(f"{args.save}/log/train")
    test_writer = SummaryWriter(f"{args.save}/log/test")

    ###############################################################################
    # Training function
コード例 #3
0
    cfg.TRAIN.NMS_THRESH,
    cfg.TRAIN.NMS_KSIZE,
    cfg.TRAIN.TOPK,
    cfg.MODEL.GAUSSIAN_KSIZE,
    cfg.MODEL.GAUSSIAN_SIGMA,
    cfg.MODEL.KSIZE,
    cfg.MODEL.padding,
    cfg.MODEL.dilation,
    cfg.MODEL.scale_list,
)
des = HardNetNeiMask(cfg.HARDNET.MARGIN, cfg.MODEL.COO_THRSH)
model = RFNetSO(det, des, cfg.LOSS.SCORE, cfg.LOSS.PAIR, cfg.PATCH.SIZE,
                cfg.TRAIN.TOPK)
model = model.to(device)
checkpoint = torch.load(model_file)
model.load_state_dict(checkpoint["state_dict"])
model.eval()


def distance_matrix_vector(anchor, positive):
    eps = 1e-8
    FeatSimi_Mat = 2 - 2 * torch.mm(anchor, positive.t())  # [0, 4]
    FeatSimi_Mat = FeatSimi_Mat.clamp(min=eps, max=4.0)
    FeatSimi_Mat = torch.sqrt(FeatSimi_Mat)  # euc [0, 2]

    return FeatSimi_Mat


def pairwise_distances(x, y=None):
    x_norm = (x**2).sum(1).view(-1, 1)
    if y is not None: