def extract_local_features(gray_list, model_path): cv_kpts_list = [] loc_info_list = [] loc_feat_list = [] sift_feat_list = [] #model = get_model('loc_model')(model_path, **{'sift_desc': True, model = LocModel( model_path, **{ 'sift_desc': True, 'n_feature': 2000, 'n_sample': FLAGS.n_sample, 'peak_thld': 0.04, 'dense_desc': FLAGS.dense_desc, 'upright': False }) for _, val in enumerate(gray_list): loc_feat, kpt_mb, normalized_xy, cv_kpts, sift_desc = model.run_test_data( val) raw_kpts = [ np.array((i.pt[0], i.pt[1], i.size, i.angle, i.response)) for i in cv_kpts ] raw_kpts = np.stack(raw_kpts, axis=0) loc_info = np.concatenate((raw_kpts, normalized_xy, loc_feat, kpt_mb), axis=-1) cv_kpts_list.append(cv_kpts) loc_info_list.append(loc_info) sift_feat_list.append(sift_desc) loc_feat_list.append(loc_feat / np.linalg.norm(loc_feat, axis=-1, keepdims=True)) model.close() return cv_kpts_list, loc_info_list, loc_feat_list, sift_feat_list
def __init__(self, num_features=2000, n_sample=2048, # Maximum number of sampled keypoints per octave dense_desc=False, # Whether to use dense descriptor model model_type='pb', do_tf_logging=False): print('Using ContextDescFeature2D') self.lock = RLock() self.model_base_path= config.cfg.root_folder + '/thirdparty/contextdesc/' set_tf_logging(do_tf_logging) self.num_features = num_features self.n_sample = n_sample self.model_type = model_type self.dense_desc = dense_desc self.quantize = ContextDescFeature2D.quantize self.loc_model_path = self.model_base_path + 'pretrained/contextdesc++' self.reg_model_path = self.model_base_path + 'pretrained/retrieval_model' if self.model_type == 'pb': reg_model_path = os.path.join(self.reg_model_path, 'reg.pb') loc_model_path = os.path.join(self.loc_model_path, 'loc.pb') aug_model_path = os.path.join(self.loc_model_path, 'aug.pb') elif self.model_type == 'ckpt': reg_model_path = os.path.join(self.reg_model_path, 'model.ckpt-550000') loc_model_path = os.path.join(self.loc_model_path, 'model.ckpt-400000') aug_model_path = os.path.join(self.loc_model_path, 'model.ckpt-400000') else: raise NotImplementedError self.keypoint_size = 10 # just a representative size for visualization and in order to convert extracted points to cv2.KeyPoint self.pts = [] self.kps = [] self.des = [] self.scales = [] self.scores = [] self.frame = None print('==> Loading pre-trained network.') self.ref_model = RegModel(reg_model_path) #get_model('reg_model')(reg_model_path) #RegModel(reg_model_path) self.loc_model = LocModel(loc_model_path, **{'sift_desc': False, # compute or not SIFT descriptor (we do not need them here!) 'n_feature': self.num_features, 'n_sample': self.n_sample, 'peak_thld': 0.04, 'dense_desc': self.dense_desc, 'upright': False}) self.aug_model = AugModel(aug_model_path, **{'quantz': self.quantize}) print('==> Successfully loaded pre-trained network.')